mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
Compare commits
172 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e33ba5b51f | |||
| a0a4263e24 | |||
| 5d18dd4ad3 | |||
| 03ff1f9176 | |||
| f376b4e0e5 | |||
| fc54b5dd4a | |||
| dd05804082 | |||
| 4349eb3538 | |||
| e0daf9a82e | |||
| 3997b6df74 | |||
| abfe1a281a | |||
| 93bfe8e56f | |||
| bb27b4e50d | |||
| 0f809cd60a | |||
| f22a6c21f0 | |||
| 625753d83a | |||
| d621312a8b | |||
| a4df4bbf1e | |||
| 43ef628c69 | |||
| 688149bd67 | |||
| c33a5ed6f5 | |||
| 828c1185b3 | |||
| 4b384d9da2 | |||
| 26de553443 | |||
| ee81cfe012 | |||
| 5f4ae3cd9e | |||
| 13b8aa9644 | |||
| e364b313c3 | |||
| 68f2a7ae07 | |||
| 42a1da3356 | |||
| 44fab4dae1 | |||
| d1387148df | |||
| bb4ac426cd | |||
| 34b4e33cc9 | |||
| f01ec01a5f | |||
| 0c38d37559 | |||
| 897892dc89 | |||
| 1a5882b75a | |||
| 0f717f1cb7 | |||
| 5d78ad5067 | |||
| 6c45f28a05 | |||
| ca3c0e735f | |||
| f71151104b | |||
| 28816a75ac | |||
| 6023bffed6 | |||
| fd34f009cd | |||
| 1bb2b65cdf | |||
| 37e8275465 | |||
| 52ca4fae1e | |||
| 6b327e017a | |||
| 10a758bd93 | |||
| 4a9642b60c | |||
| 6ba6496e46 | |||
| 1ffbba5ee3 | |||
| 8cdfd6fb91 | |||
| 7c3ddbabac | |||
| 83e0145a3a | |||
| f17c7cd554 | |||
| 4aefdd554b | |||
| 820ed9a631 | |||
| 95c55e90be | |||
| 486a1979a6 | |||
| faef5f7d18 | |||
| bd45c45fa1 | |||
| 29be184136 | |||
| 9bfda95cf7 | |||
| 24b881d8a0 | |||
| 07dd83f890 | |||
| 9afd30e463 | |||
| 16f454ca61 | |||
| f3a3a582fd | |||
| 93aaae86ed | |||
| bce68fd168 | |||
| 0812229538 | |||
| d0fa4af1d0 | |||
| 8eb4bcfabe | |||
| 9ea58354be | |||
| 02774d7328 | |||
| cbff71f8d0 | |||
| 951a91976c | |||
| 6a37826486 | |||
| cab2de6d24 | |||
| ec6c71607b | |||
| 0a39b69b15 | |||
| fe94ec21de | |||
| 34c78c73c0 | |||
| d7b8ef894c | |||
| 7f33cebce1 | |||
| 84740787d5 | |||
| ad6bad5187 | |||
| 0086b02bc8 | |||
| f7e06c1570 | |||
| c86a3a3752 | |||
| be8a17c0fd | |||
| 5c6751de9b | |||
| 83776f8b7a | |||
| f1c1df1e00 | |||
| d6640300f5 | |||
| c9c188f697 | |||
| 3a4f561836 | |||
| bdb30edee3 | |||
| 29f501b055 | |||
| 521d7ea2c0 | |||
| 0e5bb40a6f | |||
| 14079dc3c1 | |||
| 3600a86971 | |||
| 83e62fbff7 | |||
| 5c96aeb2fd | |||
| a238e5eb36 | |||
| 11fd5b7527 | |||
| cbe75cfbf6 | |||
| 9581431a9f | |||
| acf0c12531 | |||
| 1eccda9b2c | |||
| fd4aac7c32 | |||
| 36c90c8481 | |||
| fefa451371 | |||
| 1c57f88cb1 | |||
| 08ba45c65f | |||
| b8314e9ed7 | |||
| 9587b10c8c | |||
| b838084ba2 | |||
| cd24891022 | |||
| add69a4c03 | |||
| 5a3407e47c | |||
| ce8cfbbb70 | |||
| 8470bbd5cc | |||
| 5c7ae748a5 | |||
| 7abb4d3b5e | |||
| 486c42685a | |||
| f41ab37b6f | |||
| 9e129fb6e2 | |||
| f7b00a8d88 | |||
| a7cb14de25 | |||
| f50925c8d3 | |||
| e29a11de68 | |||
| 12141775f3 | |||
| b6d24b8aa9 | |||
| 7175fae18c | |||
| 3c4d8d52ca | |||
| 6873363d41 | |||
| 947599327a | |||
| 5645902a48 | |||
| c82787473f | |||
| c213fb709a | |||
| 2ac29dc871 | |||
| 1f72b2b790 | |||
| 3a62ff56d7 | |||
| d25fe529b4 | |||
| 15538e81f4 | |||
| a33be3c764 | |||
| 023fe8c7c9 | |||
| b77516e324 | |||
| 4b48423c3f | |||
| 9800177b08 | |||
| a33d4a4594 | |||
| 29722f362d | |||
| e072343fe1 | |||
| acb0c20ca8 | |||
| 83543fee88 | |||
| 3ce6b042de | |||
| 9dd770e768 | |||
| abb8b8afaa | |||
| 1d6569caa8 | |||
| 441a3cb8de | |||
| 443f5c982c | |||
| 515a12ab15 | |||
| 84b00b605a | |||
| 10e267d031 | |||
| abcd489367 | |||
| d630e61e3c | |||
| 280bab7faf |
@@ -18,6 +18,9 @@ bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
|
||||
# Roslyn cache directories
|
||||
*.ide/
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<Window x:Class="ConnectionsManager.AboutWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="About" Height="130" Width="300"
|
||||
WindowStyle="ToolWindow"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Window.Resources>
|
||||
<BitmapImage x:Key="MtApiIcon" UriSource="pack://application:,,,/ConnectionsManager;component/favicon.ico"/>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Source="{StaticResource MtApiIcon}" Width="50" Height="50" HorizontalAlignment="Left" Margin="5"/>
|
||||
<TextBlock Grid.Column="1" Text="Connection manager for MtApi" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
|
||||
<Button Grid.Row="1" Content="OK" Margin="5"
|
||||
Width="70" IsDefault="True" IsCancel="True"
|
||||
DockPanel.Dock="Bottom"
|
||||
VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AboutWindow.xaml
|
||||
/// </summary>
|
||||
public partial class AboutWindow : Window
|
||||
{
|
||||
public AboutWindow(Window owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Owner = owner;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<Window x:Class="ConnectionsManager.AddProfileDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Add new connection profile" Height="180" Width="300"
|
||||
WindowStyle="ToolWindow"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid x:Name="_MainLayout">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Profile name" Margin="5"/>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Margin="5"
|
||||
Text="{Binding Path=ProfileName, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Host" Margin="5"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1" Margin="5"
|
||||
ItemsSource="{Binding HostList}"
|
||||
SelectedItem="{Binding Host}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="Port" Margin="5"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Margin="5"
|
||||
Text="{Binding Path=Port, UpdateSourceTrigger=PropertyChanged}"
|
||||
PreviewTextInput="TextBox_PreviewTextInput"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
|
||||
<StackPanel Grid.Row="3" Grid.ColumnSpan="2" Margin="0,10,0,0"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom">
|
||||
<Button Content="OK" Width="70" Margin="4" IsDefault="True" Command="{Binding OkCommand}"/>
|
||||
<Button Content="Cancel" Width="70" Margin="4" IsCancel="True"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,97 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AddProfileDialog.xaml
|
||||
/// </summary>
|
||||
public partial class AddProfileDialog : Window
|
||||
{
|
||||
// private const string PIPE_SERVER_NAME = "localhost(pipe)";
|
||||
private const string LOCALHOST_NAME = "localhost";
|
||||
|
||||
public string ProfileName { get; set; }
|
||||
|
||||
public static readonly DependencyProperty HostProperty = DependencyProperty.Register("Host", typeof(string), typeof(AddProfileDialog));
|
||||
public string Host
|
||||
{
|
||||
get { return (string)this.GetValue(HostProperty); }
|
||||
set { this.SetValue(HostProperty, value); }
|
||||
}
|
||||
|
||||
public string Port { get; set; }
|
||||
|
||||
public DelegateCommand OkCommand { get; set; }
|
||||
|
||||
public List<string> HostList { get; set; }
|
||||
|
||||
public AddProfileDialog(Window owner)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Owner = owner;
|
||||
|
||||
OkCommand = new DelegateCommand(ExecuteOk, CanExecuteOk);
|
||||
_MainLayout.DataContext = this;
|
||||
|
||||
Loaded += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
|
||||
|
||||
IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());
|
||||
|
||||
HostList = new List<string>();
|
||||
HostList.Add(string.Empty);
|
||||
HostList.Add(LOCALHOST_NAME);
|
||||
|
||||
if (ips != null)
|
||||
{
|
||||
foreach (IPAddress ipAddress in ips.AddressList)
|
||||
{
|
||||
HostList.Add(ipAddress.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
Host = HostList.First();
|
||||
}
|
||||
|
||||
private bool CanExecuteOk(object o)
|
||||
{
|
||||
return string.IsNullOrEmpty(ProfileName) == false
|
||||
&& string.IsNullOrEmpty(Port) == false;
|
||||
}
|
||||
|
||||
private void ExecuteOk(object o)
|
||||
{
|
||||
this.DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
private static bool IsTextAllowed(string text)
|
||||
{
|
||||
Regex regex = new Regex("[^0-9]+");
|
||||
return !regex.IsMatch(text);
|
||||
}
|
||||
|
||||
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !IsTextAllowed(e.Text);
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
OkCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<Application x:Class="ConnectionsManager.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C8751BA1-6A85-468C-87BD-758F37B8C0DD}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ConnectionsManager</RootNamespace>
|
||||
<AssemblyName>ConnectionsManager</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Debug\ConnectionsManager.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Release\ConnectionsManager.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>favicon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="AboutWindow.xaml.cs">
|
||||
<DependentUpon>AboutWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="AddProfileDialog.xaml.cs">
|
||||
<DependentUpon>AddProfileDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="DelegateCommand.cs" />
|
||||
<Compile Include="ViewModel.cs" />
|
||||
<Page Include="AboutWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="AddProfileDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
<Project>{DE76D5C7-B99C-4467-8408-78173BDD84E0}</Project>
|
||||
<Name>MTApiService</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="favicon.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy $(TargetPath) $(SolutionDir)Release\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
private readonly Predicate<object> _canExecute;
|
||||
private readonly Action<object> _execute;
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public DelegateCommand(Action<object> execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public DelegateCommand(Action<object> execute,
|
||||
Predicate<object> canExecute)
|
||||
{
|
||||
_execute = execute;
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
if (_canExecute == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _canExecute(parameter);
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute(parameter);
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
if (CanExecuteChanged != null)
|
||||
{
|
||||
CanExecuteChanged(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<Window x:Class="ConnectionsManager.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="MtApi Connections Manager" Height="300" Width="440"
|
||||
Loaded="Window_Loaded">
|
||||
<Grid x:Name="_MainLayout">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Menu>
|
||||
<MenuItem Header="Edit">
|
||||
<MenuItem Header="Add Profile..." Command="{Binding AddProfileCommand}"/>
|
||||
<MenuItem Header="Delete Profile" Command="{Binding DeleteProfileCommand}"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Help">
|
||||
<MenuItem Header="About" Command="{Binding ShowAboutCommand}"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
<ListView Grid.Row="1"
|
||||
ItemsSource="{Binding ConnectionProfiles}"
|
||||
SelectionMode="Single"
|
||||
SelectedItem="{Binding SelectedProfile}">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Width="140" Header="Profile" DisplayMemberBinding="{Binding Name}" />
|
||||
<GridViewColumn Width="180" Header="Host" DisplayMemberBinding="{Binding Host}" />
|
||||
<GridViewColumn Width="80" Header="Port" DisplayMemberBinding="{Binding Port}" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private ViewModel _vm;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_vm = new ViewModel();
|
||||
_MainLayout.DataContext = _vm;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_vm.Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ConnectionsManager")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ConnectionsManager")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.18034
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ConnectionsManager.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ConnectionsManager.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.18034
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ConnectionsManager.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -1,114 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.ObjectModel;
|
||||
using MTApiService;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
|
||||
namespace ConnectionsManager
|
||||
{
|
||||
class ViewModel : INotifyPropertyChanged
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private ObservableCollection<MtConnectionProfile> _ConnectionProfiles = new ObservableCollection<MtConnectionProfile>();
|
||||
public ObservableCollection<MtConnectionProfile> ConnectionProfiles
|
||||
{
|
||||
get { return _ConnectionProfiles; }
|
||||
}
|
||||
|
||||
public DelegateCommand AddProfileCommand { get; private set; }
|
||||
public DelegateCommand DeleteProfileCommand { get; private set; }
|
||||
public DelegateCommand ShowAboutCommand { get; private set; }
|
||||
|
||||
private MtConnectionProfile _SelectedProfile;
|
||||
public MtConnectionProfile SelectedProfile
|
||||
{
|
||||
get { return _SelectedProfile; }
|
||||
set
|
||||
{
|
||||
_SelectedProfile = value;
|
||||
OnPropertyChanged("SelectedProfile");
|
||||
DeleteProfileCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
public ViewModel()
|
||||
{
|
||||
AddProfileCommand = new DelegateCommand(ExecuteAddProfile);
|
||||
DeleteProfileCommand = new DelegateCommand(ExecuteDeleteProfile, CanExecuteDeleteProfile);
|
||||
ShowAboutCommand = new DelegateCommand(ExecuteShowAbout);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var profiles = MtRegistryManager.LoadConnectionProfiles();
|
||||
if (profiles != null)
|
||||
{
|
||||
foreach(var prof in profiles)
|
||||
{
|
||||
ConnectionProfiles.Add(prof);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void ExecuteAddProfile(object o)
|
||||
{
|
||||
var dlg = new AddProfileDialog(App.Current.MainWindow);
|
||||
var result = dlg.ShowDialog();
|
||||
|
||||
if (result == true)
|
||||
{
|
||||
var profile = new MtConnectionProfile(dlg.ProfileName);
|
||||
profile.Host = dlg.Host;
|
||||
profile.Port = int.Parse(dlg.Port);
|
||||
|
||||
MtRegistryManager.AddConnectionProfile(profile);
|
||||
ConnectionProfiles.Add(profile);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanExecuteDeleteProfile(object o)
|
||||
{
|
||||
return SelectedProfile != null;
|
||||
}
|
||||
|
||||
private void ExecuteDeleteProfile(object o)
|
||||
{
|
||||
var result = MessageBox.Show("Do you want to delete connection profile '" + SelectedProfile.Name + "' ?"
|
||||
, "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
MtRegistryManager.RemoveConnectionProfile(SelectedProfile.Name);
|
||||
ConnectionProfiles.Remove(SelectedProfile);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteShowAbout(object o)
|
||||
{
|
||||
var dlg = new AboutWindow(App.Current.MainWindow);
|
||||
dlg.ShowDialog();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region INotifyPropertyChanged
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 894 B |
@@ -1,61 +0,0 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Security;
|
||||
|
||||
namespace Licensing
|
||||
{
|
||||
public class DigitalSignatureHelper
|
||||
{
|
||||
public static String GeneratePrivateKey()
|
||||
{
|
||||
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
|
||||
return dsa.ToXmlString(true);
|
||||
}
|
||||
|
||||
public static String GetPublicKey(String privateKey)
|
||||
{
|
||||
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
|
||||
dsa.FromXmlString(privateKey);
|
||||
return dsa.ToXmlString(false);
|
||||
}
|
||||
|
||||
public static string CreateSignature(string inputData, String privateKey)
|
||||
{
|
||||
// create the crypto-service provider:
|
||||
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
|
||||
|
||||
// setup the dsa from the private key:
|
||||
dsa.FromXmlString(privateKey);
|
||||
|
||||
byte[] data = UTF8Encoding.ASCII.GetBytes(inputData);
|
||||
|
||||
// get the signature:
|
||||
byte[] signature = dsa.SignData(data);
|
||||
|
||||
return Convert.ToBase64String(signature);
|
||||
}
|
||||
|
||||
public static bool VerifySignature(string inputData, string signature, string publicKey)
|
||||
{
|
||||
// create the crypto-service provider:
|
||||
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
|
||||
|
||||
// setup the provider from the public key:
|
||||
dsa.FromXmlString(publicKey);
|
||||
|
||||
// get the license terms data:
|
||||
//byte[] data = Convert.FromBase64String(inputData);
|
||||
byte[] data = UTF8Encoding.ASCII.GetBytes(inputData);
|
||||
|
||||
// get the signature data:
|
||||
byte[] signatureData = Convert.FromBase64String(signature);
|
||||
|
||||
// verify that the license-terms match the signature data
|
||||
if (dsa.VerifyData(data, signatureData) == false)
|
||||
throw new SecurityException("Signature Not Verified!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{21FA6E21-EE5D-4A84-B0ED-E1D8876B41FB}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Licensing</RootNamespace>
|
||||
<AssemblyName>Licensing</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DigitalSignatureHelper.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainForm.Designer.cs">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
<Project>{DE76D5C7-B99C-4467-8408-78173BDD84E0}</Project>
|
||||
<Name>MTApiService</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Generated
-326
@@ -1,326 +0,0 @@
|
||||
namespace Licensing
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.textBoxPublicKey = new System.Windows.Forms.TextBox();
|
||||
this.buttonGenerateKey = new System.Windows.Forms.Button();
|
||||
this.buttonLoadKey = new System.Windows.Forms.Button();
|
||||
this.buttonSaveKey = new System.Windows.Forms.Button();
|
||||
this.textBoxPrivateKey = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.textBoxAccountName = new System.Windows.Forms.TextBox();
|
||||
this.textBoxAccountNumber = new System.Windows.Forms.TextBox();
|
||||
this.buttonSign = new System.Windows.Forms.Button();
|
||||
this.textBoxSignature = new System.Windows.Forms.TextBox();
|
||||
this.buttonGetPublicKey = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.clipboardCopyBtn = new System.Windows.Forms.Button();
|
||||
this.buttonExportPublicKey = new System.Windows.Forms.Button();
|
||||
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.groupBox4 = new System.Windows.Forms.GroupBox();
|
||||
this.saveToRegBtn = new System.Windows.Forms.Button();
|
||||
this.buttonVerify = new System.Windows.Forms.Button();
|
||||
this.buttonExportSignature = new System.Windows.Forms.Button();
|
||||
this.readRegBtn = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
this.groupBox4.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// textBoxPublicKey
|
||||
//
|
||||
this.textBoxPublicKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.textBoxPublicKey.Name = "textBoxPublicKey";
|
||||
this.textBoxPublicKey.ReadOnly = true;
|
||||
this.textBoxPublicKey.Size = new System.Drawing.Size(620, 20);
|
||||
this.textBoxPublicKey.TabIndex = 0;
|
||||
//
|
||||
// buttonGenerateKey
|
||||
//
|
||||
this.buttonGenerateKey.Location = new System.Drawing.Point(6, 45);
|
||||
this.buttonGenerateKey.Name = "buttonGenerateKey";
|
||||
this.buttonGenerateKey.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonGenerateKey.TabIndex = 2;
|
||||
this.buttonGenerateKey.Text = "Generate";
|
||||
this.buttonGenerateKey.UseVisualStyleBackColor = true;
|
||||
this.buttonGenerateKey.Click += new System.EventHandler(this.buttonGenerateKey_Click);
|
||||
//
|
||||
// buttonLoadKey
|
||||
//
|
||||
this.buttonLoadKey.Location = new System.Drawing.Point(168, 45);
|
||||
this.buttonLoadKey.Name = "buttonLoadKey";
|
||||
this.buttonLoadKey.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonLoadKey.TabIndex = 3;
|
||||
this.buttonLoadKey.Text = "Load";
|
||||
this.buttonLoadKey.UseVisualStyleBackColor = true;
|
||||
this.buttonLoadKey.Click += new System.EventHandler(this.buttonLoadKey_Click);
|
||||
//
|
||||
// buttonSaveKey
|
||||
//
|
||||
this.buttonSaveKey.Location = new System.Drawing.Point(87, 45);
|
||||
this.buttonSaveKey.Name = "buttonSaveKey";
|
||||
this.buttonSaveKey.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSaveKey.TabIndex = 4;
|
||||
this.buttonSaveKey.Text = "Save";
|
||||
this.buttonSaveKey.UseVisualStyleBackColor = true;
|
||||
this.buttonSaveKey.Click += new System.EventHandler(this.buttonSaveKey_Click);
|
||||
//
|
||||
// textBoxPrivateKey
|
||||
//
|
||||
this.textBoxPrivateKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.textBoxPrivateKey.Name = "textBoxPrivateKey";
|
||||
this.textBoxPrivateKey.ReadOnly = true;
|
||||
this.textBoxPrivateKey.Size = new System.Drawing.Size(620, 20);
|
||||
this.textBoxPrivateKey.TabIndex = 0;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(8, 48);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(47, 13);
|
||||
this.label4.TabIndex = 6;
|
||||
this.label4.Text = "Number:";
|
||||
//
|
||||
// textBoxAccountName
|
||||
//
|
||||
this.textBoxAccountName.Location = new System.Drawing.Point(67, 19);
|
||||
this.textBoxAccountName.Name = "textBoxAccountName";
|
||||
this.textBoxAccountName.Size = new System.Drawing.Size(559, 20);
|
||||
this.textBoxAccountName.TabIndex = 7;
|
||||
//
|
||||
// textBoxAccountNumber
|
||||
//
|
||||
this.textBoxAccountNumber.Location = new System.Drawing.Point(67, 45);
|
||||
this.textBoxAccountNumber.Name = "textBoxAccountNumber";
|
||||
this.textBoxAccountNumber.Size = new System.Drawing.Size(559, 20);
|
||||
this.textBoxAccountNumber.TabIndex = 7;
|
||||
//
|
||||
// buttonSign
|
||||
//
|
||||
this.buttonSign.Location = new System.Drawing.Point(10, 45);
|
||||
this.buttonSign.Name = "buttonSign";
|
||||
this.buttonSign.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSign.TabIndex = 8;
|
||||
this.buttonSign.Text = "Sign";
|
||||
this.buttonSign.UseVisualStyleBackColor = true;
|
||||
this.buttonSign.Click += new System.EventHandler(this.buttonSign_Click);
|
||||
//
|
||||
// textBoxSignature
|
||||
//
|
||||
this.textBoxSignature.Location = new System.Drawing.Point(10, 19);
|
||||
this.textBoxSignature.Name = "textBoxSignature";
|
||||
this.textBoxSignature.Size = new System.Drawing.Size(615, 20);
|
||||
this.textBoxSignature.TabIndex = 10;
|
||||
//
|
||||
// buttonGetPublicKey
|
||||
//
|
||||
this.buttonGetPublicKey.Location = new System.Drawing.Point(6, 45);
|
||||
this.buttonGetPublicKey.Name = "buttonGetPublicKey";
|
||||
this.buttonGetPublicKey.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonGetPublicKey.TabIndex = 11;
|
||||
this.buttonGetPublicKey.Text = "Get Key";
|
||||
this.buttonGetPublicKey.UseVisualStyleBackColor = true;
|
||||
this.buttonGetPublicKey.Click += new System.EventHandler(this.buttonGetPublicKey_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.textBoxPrivateKey);
|
||||
this.groupBox1.Controls.Add(this.buttonGenerateKey);
|
||||
this.groupBox1.Controls.Add(this.buttonLoadKey);
|
||||
this.groupBox1.Controls.Add(this.buttonSaveKey);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(632, 78);
|
||||
this.groupBox1.TabIndex = 12;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Private Key";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.clipboardCopyBtn);
|
||||
this.groupBox2.Controls.Add(this.buttonExportPublicKey);
|
||||
this.groupBox2.Controls.Add(this.textBoxPublicKey);
|
||||
this.groupBox2.Controls.Add(this.buttonGetPublicKey);
|
||||
this.groupBox2.Location = new System.Drawing.Point(12, 96);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(632, 77);
|
||||
this.groupBox2.TabIndex = 13;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Public Key";
|
||||
//
|
||||
// clipboardCopyBtn
|
||||
//
|
||||
this.clipboardCopyBtn.Location = new System.Drawing.Point(169, 46);
|
||||
this.clipboardCopyBtn.Name = "clipboardCopyBtn";
|
||||
this.clipboardCopyBtn.Size = new System.Drawing.Size(113, 23);
|
||||
this.clipboardCopyBtn.TabIndex = 13;
|
||||
this.clipboardCopyBtn.Text = "Copy to Clipboard";
|
||||
this.clipboardCopyBtn.UseVisualStyleBackColor = true;
|
||||
this.clipboardCopyBtn.Click += new System.EventHandler(this.clipboardCopyBtn_Click);
|
||||
//
|
||||
// buttonExportPublicKey
|
||||
//
|
||||
this.buttonExportPublicKey.Location = new System.Drawing.Point(88, 46);
|
||||
this.buttonExportPublicKey.Name = "buttonExportPublicKey";
|
||||
this.buttonExportPublicKey.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonExportPublicKey.TabIndex = 12;
|
||||
this.buttonExportPublicKey.Text = "Export";
|
||||
this.buttonExportPublicKey.UseVisualStyleBackColor = true;
|
||||
this.buttonExportPublicKey.Click += new System.EventHandler(this.buttonExportPublicKey_Click);
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
this.groupBox3.Controls.Add(this.textBoxAccountName);
|
||||
this.groupBox3.Controls.Add(this.label3);
|
||||
this.groupBox3.Controls.Add(this.textBoxAccountNumber);
|
||||
this.groupBox3.Controls.Add(this.label4);
|
||||
this.groupBox3.Location = new System.Drawing.Point(12, 180);
|
||||
this.groupBox3.Name = "groupBox3";
|
||||
this.groupBox3.Size = new System.Drawing.Size(635, 81);
|
||||
this.groupBox3.TabIndex = 14;
|
||||
this.groupBox3.TabStop = false;
|
||||
this.groupBox3.Text = "Account";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(8, 22);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(38, 13);
|
||||
this.label3.TabIndex = 5;
|
||||
this.label3.Text = "Name:";
|
||||
//
|
||||
// groupBox4
|
||||
//
|
||||
this.groupBox4.Controls.Add(this.readRegBtn);
|
||||
this.groupBox4.Controls.Add(this.saveToRegBtn);
|
||||
this.groupBox4.Controls.Add(this.buttonVerify);
|
||||
this.groupBox4.Controls.Add(this.buttonExportSignature);
|
||||
this.groupBox4.Controls.Add(this.textBoxSignature);
|
||||
this.groupBox4.Controls.Add(this.buttonSign);
|
||||
this.groupBox4.Location = new System.Drawing.Point(13, 268);
|
||||
this.groupBox4.Name = "groupBox4";
|
||||
this.groupBox4.Size = new System.Drawing.Size(631, 76);
|
||||
this.groupBox4.TabIndex = 15;
|
||||
this.groupBox4.TabStop = false;
|
||||
this.groupBox4.Text = "Signature";
|
||||
//
|
||||
// saveToRegBtn
|
||||
//
|
||||
this.saveToRegBtn.Location = new System.Drawing.Point(172, 45);
|
||||
this.saveToRegBtn.Name = "saveToRegBtn";
|
||||
this.saveToRegBtn.Size = new System.Drawing.Size(101, 23);
|
||||
this.saveToRegBtn.TabIndex = 13;
|
||||
this.saveToRegBtn.Text = "Save To Reg";
|
||||
this.saveToRegBtn.UseVisualStyleBackColor = true;
|
||||
this.saveToRegBtn.Click += new System.EventHandler(this.saveToRegBtn_Click);
|
||||
//
|
||||
// buttonVerify
|
||||
//
|
||||
this.buttonVerify.Location = new System.Drawing.Point(550, 45);
|
||||
this.buttonVerify.Name = "buttonVerify";
|
||||
this.buttonVerify.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonVerify.TabIndex = 12;
|
||||
this.buttonVerify.Text = "Verify";
|
||||
this.buttonVerify.UseVisualStyleBackColor = true;
|
||||
this.buttonVerify.Click += new System.EventHandler(this.buttonVerify_Click);
|
||||
//
|
||||
// buttonExportSignature
|
||||
//
|
||||
this.buttonExportSignature.Location = new System.Drawing.Point(91, 45);
|
||||
this.buttonExportSignature.Name = "buttonExportSignature";
|
||||
this.buttonExportSignature.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonExportSignature.TabIndex = 11;
|
||||
this.buttonExportSignature.Text = "Export";
|
||||
this.buttonExportSignature.UseVisualStyleBackColor = true;
|
||||
this.buttonExportSignature.Click += new System.EventHandler(this.buttonExportSignature_Click);
|
||||
//
|
||||
// readRegBtn
|
||||
//
|
||||
this.readRegBtn.Location = new System.Drawing.Point(279, 45);
|
||||
this.readRegBtn.Name = "readRegBtn";
|
||||
this.readRegBtn.Size = new System.Drawing.Size(132, 23);
|
||||
this.readRegBtn.TabIndex = 14;
|
||||
this.readRegBtn.Text = "Read from Registry";
|
||||
this.readRegBtn.UseVisualStyleBackColor = true;
|
||||
this.readRegBtn.Click += new System.EventHandler(this.readRegBtn_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(659, 351);
|
||||
this.Controls.Add(this.groupBox4);
|
||||
this.Controls.Add(this.groupBox3);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Name = "MainForm";
|
||||
this.Text = "Liccensing";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.groupBox3.ResumeLayout(false);
|
||||
this.groupBox3.PerformLayout();
|
||||
this.groupBox4.ResumeLayout(false);
|
||||
this.groupBox4.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox textBoxPublicKey;
|
||||
private System.Windows.Forms.Button buttonGenerateKey;
|
||||
private System.Windows.Forms.Button buttonLoadKey;
|
||||
private System.Windows.Forms.Button buttonSaveKey;
|
||||
private System.Windows.Forms.TextBox textBoxPrivateKey;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.TextBox textBoxAccountName;
|
||||
private System.Windows.Forms.TextBox textBoxAccountNumber;
|
||||
private System.Windows.Forms.Button buttonSign;
|
||||
private System.Windows.Forms.TextBox textBoxSignature;
|
||||
private System.Windows.Forms.Button buttonGetPublicKey;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.GroupBox groupBox3;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Button buttonExportPublicKey;
|
||||
private System.Windows.Forms.GroupBox groupBox4;
|
||||
private System.Windows.Forms.Button buttonExportSignature;
|
||||
private System.Windows.Forms.Button buttonVerify;
|
||||
private System.Windows.Forms.Button clipboardCopyBtn;
|
||||
private System.Windows.Forms.Button saveToRegBtn;
|
||||
private System.Windows.Forms.Button readRegBtn;
|
||||
}
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using MTApiService;
|
||||
|
||||
namespace Licensing
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private bool mIsSaved = true;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void buttonGenerateKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
textBoxPrivateKey.Text = DigitalSignatureHelper.GeneratePrivateKey();
|
||||
|
||||
mIsSaved = false;
|
||||
}
|
||||
|
||||
private void buttonGetPublicKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
string privateKey = textBoxPrivateKey.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(privateKey) == false)
|
||||
{
|
||||
textBoxPublicKey.Text = DigitalSignatureHelper.GetPublicKey(privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Private Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSaveKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
string privateKey = textBoxPrivateKey.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(privateKey) == false)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
|
||||
dlg.Filter = "MetaTraderApi Key Files (*.mtk)|*.mtk";
|
||||
dlg.Title = "Save MetaTraderApi Key File";
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (TextWriter file = new StreamWriter(dlg.FileName, true))
|
||||
{
|
||||
file.WriteLine(privateKey);
|
||||
}
|
||||
|
||||
mIsSaved = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMsg = string.Format("Saving failed!\n{0}", ex.Message);
|
||||
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Private Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonLoadKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (mIsSaved == false)
|
||||
{
|
||||
if (MessageBox.Show("Private Key is not saved. Continue?", "Private Key", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
|
||||
OpenFileDialog dlg = new OpenFileDialog();
|
||||
|
||||
dlg.Filter = "MetaTraderApi Key Files (*.mtk)|*.mtk";
|
||||
dlg.Title = "Load MetaTraderApi Key File";
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxPrivateKey.Text = string.Empty;
|
||||
textBoxPublicKey.Text = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
using (TextReader file = new StreamReader(dlg.FileName))
|
||||
{
|
||||
textBoxPrivateKey.Text = file.ReadLine();
|
||||
}
|
||||
|
||||
mIsSaved = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMsg = string.Format("Saving failed!\n{0}", ex.Message);
|
||||
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSign_Click(object sender, EventArgs e)
|
||||
{
|
||||
string privateKey = textBoxPrivateKey.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(privateKey) == false)
|
||||
{
|
||||
string accountName = textBoxAccountName.Text;
|
||||
string accountNumber = textBoxAccountNumber.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) == false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(accountNumber) == false)
|
||||
{
|
||||
string inputData = accountName + accountNumber;
|
||||
|
||||
textBoxSignature.Text = DigitalSignatureHelper.CreateSignature(inputData, privateKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Private Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonExportPublicKey_Click(object sender, EventArgs e)
|
||||
{
|
||||
string publicKey = textBoxPublicKey.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(publicKey) == false)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
|
||||
dlg.Filter = "MetaTraderApi Key Files (*.mtk)|*.mtk";
|
||||
dlg.Title = "Export MetaTraderApi Key File";
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (TextWriter file = new StreamWriter(dlg.FileName, true))
|
||||
{
|
||||
file.WriteLine(publicKey);
|
||||
}
|
||||
|
||||
mIsSaved = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMsg = string.Format("Export failed!\n{0}", ex.Message);
|
||||
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Public Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonExportSignature_Click(object sender, EventArgs e)
|
||||
{
|
||||
string signature = textBoxSignature.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(signature) == false)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
|
||||
dlg.Filter = "MetaTraderApi Key (*.mta)|*.mta";
|
||||
dlg.Title = "Export MetaTraderApi Key";
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (TextWriter file = new StreamWriter(dlg.FileName))
|
||||
{
|
||||
file.WriteLine(signature);
|
||||
}
|
||||
|
||||
mIsSaved = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorMsg = string.Format("Export failed!\n{0}", ex.Message);
|
||||
MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Signature is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonVerify_Click(object sender, EventArgs e)
|
||||
{
|
||||
string publicKey = textBoxPublicKey.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(publicKey) == false)
|
||||
{
|
||||
string signature = textBoxSignature.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(signature) == false)
|
||||
{
|
||||
string accountName = textBoxAccountName.Text;
|
||||
string accountNumber = textBoxAccountNumber.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(accountName) == false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(accountNumber) == false)
|
||||
{
|
||||
string inputData = accountName + accountNumber;
|
||||
var verifyResult = false;
|
||||
try
|
||||
{
|
||||
verifyResult = DigitalSignatureHelper.VerifySignature(inputData, signature, publicKey);
|
||||
}
|
||||
catch (SecurityException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Verify", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
verifyResult = false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string errorMsg = string.Format("Verify process failed!\n{0}", ex.Message);
|
||||
MessageBox.Show(errorMsg, "Verify", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
verifyResult = false;
|
||||
}
|
||||
|
||||
if (verifyResult == true)
|
||||
{
|
||||
MessageBox.Show("Signature good", "Verify", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Signature is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Public Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void clipboardCopyBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
Clipboard.SetText(textBoxPublicKey.Text);
|
||||
}
|
||||
|
||||
private void saveToRegBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
string signature = textBoxSignature.Text;
|
||||
string accountName = textBoxAccountName.Text;
|
||||
string accountNumber = textBoxAccountNumber.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(signature))
|
||||
{
|
||||
MessageBox.Show("Signature is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(accountName))
|
||||
{
|
||||
MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(accountNumber))
|
||||
{
|
||||
MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
|
||||
dlg.Filter = "Registry files (*.reg)|*.reg";
|
||||
dlg.Title = "Registry files";
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string key = MtRegistryManager.SaveSignatureKey(accountName, accountNumber, signature);
|
||||
|
||||
bool exported = MtRegistryManager.ExportKey(key, dlg.FileName);
|
||||
|
||||
if (exported)
|
||||
{
|
||||
MessageBox.Show("Export successed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Export failed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readRegBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
string accountName = textBoxAccountName.Text;
|
||||
string accountNumber = textBoxAccountNumber.Text;
|
||||
|
||||
if (string.IsNullOrEmpty(accountName))
|
||||
{
|
||||
MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(accountNumber))
|
||||
{
|
||||
MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string signature = MtRegistryManager.ReadSignatureKey(accountName, accountNumber);
|
||||
textBoxSignature.Text = signature;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Licensing
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Licensing")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("DW")]
|
||||
[assembly: AssemblyProduct("Licensing")]
|
||||
[assembly: AssemblyCopyright("Copyright © DW 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("2c3df81b-2285-44ff-a152-0111e25d9b1a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -35,6 +35,4 @@ using namespace System::Security::Permissions;
|
||||
|
||||
[assembly:ComVisible(false)];
|
||||
|
||||
[assembly:CLSCompliantAttribute(true)];
|
||||
|
||||
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
|
||||
[assembly:CLSCompliantAttribute(true)];
|
||||
+136
-360
@@ -6,14 +6,15 @@
|
||||
#include "MT5Handler.h"
|
||||
|
||||
#include "Windows.h"
|
||||
#include < vcclr.h >
|
||||
#include <vcclr.h>
|
||||
#include <functional>
|
||||
|
||||
using namespace System;
|
||||
using namespace MTApiService;
|
||||
using namespace System::Runtime::InteropServices;
|
||||
using namespace System::Reflection;
|
||||
using namespace System::Text;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace System::Collections::Generic;
|
||||
using namespace System::Diagnostics;
|
||||
using namespace System::Security::Cryptography;
|
||||
using namespace System::Security;
|
||||
@@ -30,297 +31,166 @@ public struct CMqlRates
|
||||
int spread; // Spread
|
||||
__int64 real_volume; // Trade volume
|
||||
};
|
||||
|
||||
public struct CMqlTick
|
||||
{
|
||||
__int64 time; // Time of the last prices update
|
||||
double bid; // Current Bid price
|
||||
double ask; // Current Ask price
|
||||
double last; // Price of the last deal (Last)
|
||||
unsigned __int64 volume; // Volume for the current Last price
|
||||
};
|
||||
|
||||
public struct CMqlBookInfo
|
||||
{
|
||||
int type; // Order type from ENUM_BOOK_TYPE enumeration
|
||||
double price; // Price
|
||||
__int64 volume; // Volume
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
void convertSystemString(wchar_t* dest, String^ src)
|
||||
{
|
||||
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
||||
memcpy(dest, wch, wcslen(wch) * sizeof(wchar_t));
|
||||
dest[wcslen(wch)] = '\0';
|
||||
if (src != nullptr) {
|
||||
pin_ptr<const wchar_t> wch = PtrToStringChars(src);
|
||||
memcpy(dest, wch, wcsnlen(wch, 1000) * sizeof(wchar_t));
|
||||
dest[wcsnlen(wch, 1000)] = L'\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
dest[0] = L'\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool VerifySignature(System::String^ inputData, System::String^ signature, System::String^ publicKey)
|
||||
{
|
||||
bool verifyResult = false;
|
||||
#define _DLLAPI extern "C" __declspec(dllexport)
|
||||
|
||||
template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default_value)
|
||||
{
|
||||
T result = default_value;
|
||||
try
|
||||
{
|
||||
DSACryptoServiceProvider^ dsa = gcnew DSACryptoServiceProvider();
|
||||
dsa->FromXmlString(publicKey);
|
||||
array<System::Byte>^ data = UTF8Encoding::ASCII->GetBytes(inputData);
|
||||
array<System::Byte>^ signatureData = Convert::FromBase64String(signature);
|
||||
verifyResult = dsa->VerifyData(data, signatureData);
|
||||
}
|
||||
catch(Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:VerifySignature(): failed. " + e->Message);
|
||||
verifyResult = false;
|
||||
}
|
||||
|
||||
return verifyResult;
|
||||
}
|
||||
|
||||
bool g_IsVerified = true;
|
||||
|
||||
void _stdcall verify(int isDemo, wchar_t* accountName, long accountNumber)
|
||||
{
|
||||
if (isDemo != 0)
|
||||
{
|
||||
g_IsVerified = true;
|
||||
return;
|
||||
}
|
||||
|
||||
System::String^ signature = MtRegistryManager::ReadSignatureKey(gcnew String(accountName), accountNumber.ToString());
|
||||
Resources::ResourceManager^ rm = gcnew Resources::ResourceManager(L"MT5Connector.cl", Assembly::GetExecutingAssembly());
|
||||
System::String^ inputData = gcnew System::String(accountName);
|
||||
inputData += accountNumber.ToString();
|
||||
System::String^ publicKey = rm->GetString(L"cl");
|
||||
g_IsVerified = VerifySignature(inputData, gcnew System::String(signature), publicKey);
|
||||
}
|
||||
|
||||
int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||
{
|
||||
if (g_IsVerified == false)
|
||||
{
|
||||
System::String^ errorVerified = "Verification is failed!\nPlease contact with support.";
|
||||
convertSystemString(err, errorVerified);
|
||||
Debug::WriteLine("[ERROR] MT5Connector:initExpert(): not verified");
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
MT5Handler^ mtHander = gcnew MT5Handler();
|
||||
MtAdapter::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHander);
|
||||
result = func();
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
convertSystemString(err, e->Message);
|
||||
Debug::WriteLine("[ERROR] MT5Connector:initExpert(): " + e->Message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
int _stdcall deinitExpert(int expertHandle, wchar_t* err)
|
||||
_DLLAPI int _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, int isTestMode, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
MtAdapter::GetInstance()->DeinitExpert(expertHandle);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
convertSystemString(err, e->Message);
|
||||
Debug::WriteLine("[ERROR] MT5Connector:deinitExpert(): " + e->Message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Execute<int>([&expertHandle, &port, symbol, &bid, &ask, &isTestMode]() {
|
||||
bool isTesting = (isTestMode != 0) ? true : false;
|
||||
auto expert = gcnew Mt5Expert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT5Handler(), isTesting);
|
||||
MtAdapter::GetInstance()->AddExpert(port, expert);
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||
_DLLAPI int _stdcall deinitExpert(int expertHandle, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle]() {
|
||||
MtAdapter::GetInstance()->RemoveExpert(expertHandle);
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
_DLLAPI int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle, symbol, &bid, &ask]() {
|
||||
MtAdapter::GetInstance()->SendQuote(expertHandle, gcnew String(symbol), bid, ask);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
convertSystemString(err, e->Message);
|
||||
Debug::WriteLine("[ERROR] MT5Connector:updateQuote(): " + e->Message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendIntResponse(int expertHandle, int response)
|
||||
_DLLAPI bool _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<bool>([&expertHandle, &eventType, payload]() {
|
||||
MtAdapter::GetInstance()->SendEvent(expertHandle, eventType, gcnew String(payload));
|
||||
return true;
|
||||
}, err, false);
|
||||
}
|
||||
|
||||
_DLLAPI int _stdcall sendIntResponse(int expertHandle, int response, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseInt(response));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendIntResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendLongResponse(int expertHandle, __int64 response)
|
||||
_DLLAPI int _stdcall sendLongResponse(int expertHandle, __int64 response, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLong(response));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response)
|
||||
_DLLAPI int _stdcall sendULongResponse(int expertHandle, unsigned __int64 response, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseULong(response));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendBooleanResponse(int expertHandle, int response)
|
||||
_DLLAPI int _stdcall sendBooleanResponse(int expertHandle, int response, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
bool value = (response != 0) ? true : false;
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseBool(value));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendBooleanResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendDoubleResponse(int expertHandle, double response)
|
||||
_DLLAPI int _stdcall sendDoubleResponse(int expertHandle, double response, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, &response]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDouble(response));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendStringResponse(int expertHandle, wchar_t* response)
|
||||
_DLLAPI int _stdcall sendStringResponse(int expertHandle, wchar_t* response, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, response]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseString(gcnew String(response)));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendStringResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendVoidResponse(int expertHandle)
|
||||
_DLLAPI int _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendVoidResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Execute<int>([&expertHandle]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseObject(nullptr));
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size)
|
||||
_DLLAPI int _stdcall sendDoubleArrayResponse(int expertHandle, double* values, int size, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, values, &size]() {
|
||||
array<double>^ list = gcnew array<double>(size);
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
list[i] = values[i];
|
||||
}
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseDoubleArray(list));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendDoubleArrayResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size)
|
||||
_DLLAPI int _stdcall sendIntArrayResponse(int expertHandle, int* values, int size, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, values, &size]() {
|
||||
array<int>^ list = gcnew array<int>(size);
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
list[i] = values[i];
|
||||
}
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseIntArray(list));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendIntArrayResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendLongArrayResponse(int expertHandle, __int64* values, int size)
|
||||
_DLLAPI int _stdcall sendLongArrayResponse(int expertHandle, __int64* values, int size, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, values, &size]() {
|
||||
array<System::Int64>^ list = gcnew array<System::Int64>(size);
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
list[i] = values[i];
|
||||
}
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseLongArray(list));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendLongArrayResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int size)
|
||||
_DLLAPI int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int size, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, values, &size]() {
|
||||
array<MtMqlRates^>^ list = gcnew array<MtMqlRates^>(size);
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
MtMqlRates^ rates = gcnew MtMqlRates();
|
||||
rates->time = values[i].time;
|
||||
@@ -331,180 +201,86 @@ int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates values[], int
|
||||
rates->tick_volume = values[i].tick_volume;
|
||||
rates->spread = values[i].spread;
|
||||
rates->real_volume = values[i].real_volume;
|
||||
|
||||
list[i] = rates;
|
||||
}
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlRatesArray(list));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, int size)
|
||||
_DLLAPI bool _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* message, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
MtMqlTick^ mtResponse = gcnew MtMqlTick();
|
||||
|
||||
mtResponse->time = response->time;
|
||||
mtResponse->bid = response->bid;
|
||||
mtResponse->ask = response->ask;
|
||||
mtResponse->last = response->last;
|
||||
mtResponse->volume = response->volume;
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlTick(mtResponse));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlTickResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[], int size)
|
||||
{
|
||||
try
|
||||
{
|
||||
array<MtMqlBookInfo^>^ list = gcnew array<MtMqlBookInfo^>(size);
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
MtMqlBookInfo^ info = gcnew MtMqlBookInfo();
|
||||
|
||||
info->type = values[i].type;
|
||||
info->price = values[i].price;
|
||||
info->volume = values[i].volume;
|
||||
|
||||
list[i] = info;
|
||||
}
|
||||
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseMqlBookInfoArray(list));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:sendMqlRatesArrayResponse(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Execute<bool>([&expertHandle, &code, message]() {
|
||||
MtResponseString^ res = gcnew MtResponseString(gcnew String(message));
|
||||
res->ErrorCode = code;
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, res);
|
||||
return true;
|
||||
}, err, false);
|
||||
}
|
||||
|
||||
//----------- get values -------------------------------
|
||||
|
||||
int _stdcall getCommandType(int expertHandle, int* res)
|
||||
_DLLAPI int _stdcall getCommandType(int expertHandle, int* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, res]() {
|
||||
*res = MtAdapter::GetInstance()->GetCommandType(expertHandle);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getCommandType(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getIntValue(int expertHandle, int paramIndex, int* res)
|
||||
_DLLAPI int _stdcall getIntValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
*res = (int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getIntValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res)
|
||||
_DLLAPI int _stdcall getDoubleValue(int expertHandle, int paramIndex, double* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
*res = (double)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getDoubleValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res)
|
||||
_DLLAPI int _stdcall getStringValue(int expertHandle, int paramIndex, wchar_t* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
convertSystemString(res, (String^)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex));
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getStringValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* res)
|
||||
_DLLAPI int _stdcall getULongValue(int expertHandle, int paramIndex, unsigned __int64* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
*res = (unsigned long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getULongValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
*res = (unsigned __int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res)
|
||||
_DLLAPI int _stdcall getLongValue(int expertHandle, int paramIndex, __int64* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
*res = (long)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getLongValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
*res = (__int64)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res)
|
||||
_DLLAPI int _stdcall getBooleanValue(int expertHandle, int paramIndex, int* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
bool val = (bool)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
*res = val == true ? 1 : 0;
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getBooleanValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res)
|
||||
_DLLAPI int _stdcall getUIntValue(int expertHandle, int paramIndex, unsigned int* res, wchar_t* err)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Execute<int>([&expertHandle, ¶mIndex, res]() {
|
||||
*res = (unsigned int)MtAdapter::GetInstance()->GetCommandParameter(expertHandle, paramIndex);
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
Debug::WriteLine("[ERROR] MT5Connector:getUIntValue(): " + e->Message);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
LIBRARY MT5Connector
|
||||
|
||||
EXPORTS initExpert
|
||||
deinitExpert
|
||||
updateQuote
|
||||
sendIntResponse
|
||||
sendBooleanResponse
|
||||
sendDoubleResponse
|
||||
sendStringResponse
|
||||
sendVoidResponse
|
||||
sendDoubleArrayResponse
|
||||
sendIntArrayResponse
|
||||
sendLongArrayResponse
|
||||
sendMqlRatesArrayResponse
|
||||
sendLongResponse
|
||||
sendULongResponse
|
||||
sendMqlTickResponse
|
||||
sendMqlBookInfoArrayResponse
|
||||
getCommandType
|
||||
getIntValue
|
||||
getUIntValue
|
||||
getDoubleValue
|
||||
getStringValue
|
||||
getLongValue
|
||||
getULongValue
|
||||
getBooleanValue
|
||||
verify
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -23,6 +23,7 @@
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>MT5Connector</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@@ -30,28 +31,28 @@
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
@@ -95,7 +96,6 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>user32.lib</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
@@ -108,7 +108,6 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -120,7 +119,6 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@@ -132,7 +130,6 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\MT5Connector.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
@@ -157,7 +154,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.ico" />
|
||||
<None Include="MT5Connector.def" />
|
||||
<None Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -44,9 +44,6 @@
|
||||
<None Include="app.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="MT5Connector.def">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="app.rc">
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MTApiService
|
||||
namespace MTApiService
|
||||
{
|
||||
public interface IMetaTraderHandler
|
||||
{
|
||||
|
||||
@@ -8,9 +8,53 @@ using log4net.Repository.Hierarchy;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
public class MtLog
|
||||
{
|
||||
#region ctor
|
||||
internal MtLog(Type type)
|
||||
{
|
||||
_log = LogManager.GetLogger(type);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
_log.Debug(message);
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
_log.Error(message);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
_log.Fatal(message);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
_log.Info(message);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
_log.Warn(message);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
|
||||
private readonly ILog _log;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class LogConfigurator
|
||||
{
|
||||
private const string LogFileNameExtension = "txt";
|
||||
private const string LogFileNameExtension = "log";
|
||||
|
||||
public static void Setup(string profileName)
|
||||
{
|
||||
@@ -48,5 +92,13 @@ namespace MTApiService
|
||||
#endif
|
||||
hierarchy.Configured = true;
|
||||
}
|
||||
|
||||
public static MtLog GetLogger(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
|
||||
return new MtLog(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
<Compile Include="IMetaTraderHandler.cs" />
|
||||
<Compile Include="ITaskExecutor.cs" />
|
||||
<Compile Include="LogConfigurator.cs" />
|
||||
<Compile Include="Mt5Expert.cs" />
|
||||
<Compile Include="MtCommandEventArgs.cs" />
|
||||
<Compile Include="IDisposableChannel.cs" />
|
||||
<Compile Include="IMtApiServer.cs" />
|
||||
@@ -71,9 +72,7 @@
|
||||
<Compile Include="MtClient.cs" />
|
||||
<Compile Include="MtCommandTask.cs" />
|
||||
<Compile Include="MtEvent.cs" />
|
||||
<Compile Include="MtMqlBookInfo.cs" />
|
||||
<Compile Include="MtMqlRates.cs" />
|
||||
<Compile Include="MtMqlTick.cs" />
|
||||
<Compile Include="MtMqlTradeRequest.cs" />
|
||||
<Compile Include="MtRegistryManager.cs" />
|
||||
<Compile Include="MtConnectionProfile.cs" />
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using log4net;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
public class Mt5Expert : MtExpert
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Mt5Expert));
|
||||
private const int StopExpertInterval = 2000; // 2 sec for testing mode
|
||||
private System.Timers.Timer _stopTimer;
|
||||
|
||||
|
||||
public Mt5Expert(int handle, string symbol, double bid, double ask, IMetaTraderHandler mtHandler, bool isTestMode) :
|
||||
base(handle, symbol, bid, ask, mtHandler)
|
||||
{
|
||||
IsTestMode = isTestMode;
|
||||
}
|
||||
|
||||
public bool IsTestMode { get; }
|
||||
|
||||
public override int GetCommandType()
|
||||
{
|
||||
Log.Debug("GetCommandType: called.");
|
||||
|
||||
if (IsTestMode)
|
||||
{
|
||||
ResetTestModeTimer();
|
||||
}
|
||||
|
||||
return base.GetCommandType();
|
||||
}
|
||||
|
||||
public override void SendEvent(MtEvent mtEvent)
|
||||
{
|
||||
Log.DebugFormat("SendEvent: begin. event = {0}", mtEvent);
|
||||
|
||||
if (IsTestMode)
|
||||
{
|
||||
if (_stopTimer == null)
|
||||
{
|
||||
_stopTimer = new System.Timers.Timer
|
||||
{
|
||||
Interval = StopExpertInterval,
|
||||
AutoReset = false
|
||||
};
|
||||
_stopTimer.Elapsed += _stopTimer_Elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
base.SendEvent(mtEvent);
|
||||
|
||||
Log.Debug("SendEvent: end.");
|
||||
}
|
||||
|
||||
private void _stopTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
Log.Debug("_stopTimer_Elapsed: begin.");
|
||||
|
||||
Log.Warn("Mt5Expert has received new tick during 2 sec in testing mode. The possible cause: user has stopped the tester manually in MetaTrader 5.");
|
||||
Deinit();
|
||||
|
||||
_stopTimer.Elapsed -= _stopTimer_Elapsed;
|
||||
_stopTimer = null;
|
||||
|
||||
Log.Debug("_stopTimer_Elapsed: end.");
|
||||
}
|
||||
|
||||
private void ResetTestModeTimer()
|
||||
{
|
||||
if (_stopTimer == null)
|
||||
return;
|
||||
|
||||
//reset timer
|
||||
_stopTimer.Stop();
|
||||
_stopTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
-16
@@ -36,12 +36,12 @@ namespace MTApiService
|
||||
|
||||
|
||||
#region Public Methods
|
||||
public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
|
||||
public void AddExpert(int port, MtExpert expert)
|
||||
{
|
||||
if (mtHandler == null)
|
||||
throw new ArgumentNullException(nameof(mtHandler));
|
||||
if (expert == null)
|
||||
throw new ArgumentNullException(nameof(expert));
|
||||
|
||||
Log.InfoFormat("InitExpert: begin. symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);
|
||||
Log.InfoFormat("AddExpert: begin. expert = {0}", expert);
|
||||
|
||||
MtServer server;
|
||||
lock (_servers)
|
||||
@@ -60,21 +60,20 @@ namespace MTApiService
|
||||
}
|
||||
}
|
||||
|
||||
var expert = new MtExpert(expertHandle, new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle }, mtHandler);
|
||||
|
||||
lock (_experts)
|
||||
{
|
||||
_experts[expert.Handle] = expert;
|
||||
}
|
||||
|
||||
server.AddExpert(expert);
|
||||
expert.Deinited += ExpertOnDeinited;
|
||||
|
||||
Log.Info("InitExpert: end");
|
||||
Log.Info("AddExpert: end");
|
||||
}
|
||||
|
||||
public void DeinitExpert(int expertHandle)
|
||||
public void RemoveExpert(int expertHandle)
|
||||
{
|
||||
Log.InfoFormat("DeinitExpert: begin. expertHandle = {0}", expertHandle);
|
||||
Log.InfoFormat("RemoveExpert: begin. expertHandle = {0}", expertHandle);
|
||||
|
||||
MtExpert expert = null;
|
||||
|
||||
@@ -83,7 +82,6 @@ namespace MTApiService
|
||||
if (_experts.ContainsKey(expertHandle))
|
||||
{
|
||||
expert = _experts[expertHandle];
|
||||
_experts.Remove(expertHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,15 +91,15 @@ namespace MTApiService
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WarnFormat("DeinitExpert: expert with id {0} has not been found.", expertHandle);
|
||||
Log.WarnFormat("RemoveExpert: expert with id {0} has not been found.", expertHandle);
|
||||
}
|
||||
|
||||
Log.Info("DeinitExpert: end");
|
||||
Log.Info("RemoveExpert: end");
|
||||
}
|
||||
|
||||
public void SendQuote(int expertHandle, string symbol, double bid, double ask)
|
||||
{
|
||||
Log.DebugFormat("SendQuote: begin. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
|
||||
Log.DebugFormat("UpdateQuote: begin. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);
|
||||
|
||||
MtExpert expert;
|
||||
lock (_experts)
|
||||
@@ -111,14 +109,14 @@ namespace MTApiService
|
||||
|
||||
if (expert != null)
|
||||
{
|
||||
expert.Quote = new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle };
|
||||
expert.UpdateQuote(new MtQuote { Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle });
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WarnFormat("SendQuote: expert with id {0} has not been found.", expertHandle);
|
||||
Log.WarnFormat("UpdateQuote: expert with id {0} has not been found.", expertHandle);
|
||||
}
|
||||
|
||||
Log.Debug("SendQuote: end");
|
||||
Log.Debug("UpdateQuote: end");
|
||||
}
|
||||
|
||||
public void SendEvent(int expertHandle, int eventType, string payload)
|
||||
@@ -272,6 +270,31 @@ namespace MTApiService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ExpertOnDeinited(object sender, EventArgs eventArgs)
|
||||
{
|
||||
Log.Debug("ExpertOnDeinited: begin.");
|
||||
|
||||
var expert = sender as MtExpert;
|
||||
if (expert == null)
|
||||
{
|
||||
Log.Warn("expert_Deinited: end. Expert is not defined.");
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_experts)
|
||||
{
|
||||
if (_experts.ContainsKey(expert.Handle))
|
||||
{
|
||||
_experts.Remove(expert.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
Log.DebugFormat("ExpertOnDeinited: removed expert {0}", expert.Handle);
|
||||
|
||||
Log.Debug("ExpertOnDeinited: end.");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace MTApiService
|
||||
Command = command;
|
||||
}
|
||||
|
||||
public MtCommand Command { get; private set; }
|
||||
public MtCommand Command { get; }
|
||||
|
||||
public MtResponse WaitResult(int time)
|
||||
{
|
||||
|
||||
+17
-29
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
internal class MtExpert: ITaskExecutor
|
||||
public class MtExpert: ITaskExecutor
|
||||
{
|
||||
public delegate void MtQuoteHandler(MtExpert expert, MtQuote quote);
|
||||
public delegate void MtEventHandler(MtExpert expert, MtEvent e);
|
||||
@@ -19,21 +19,20 @@ namespace MTApiService
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
public MtExpert(int handle, MtQuote quote, IMetaTraderHandler mtHandler)
|
||||
public MtExpert(int handle, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
|
||||
{
|
||||
if (mtHandler == null)
|
||||
throw new ArgumentNullException(nameof(mtHandler));
|
||||
|
||||
Quote = quote;
|
||||
_quote = new MtQuote { ExpertHandle = handle, Instrument = symbol, Bid = bid, Ask = ask};
|
||||
Handle = handle;
|
||||
_mtHadler = mtHandler;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
public virtual void Deinit()
|
||||
{
|
||||
Log.Debug("Deinit: begin.");
|
||||
|
||||
IsEnable = false;
|
||||
FireOnDeinited();
|
||||
|
||||
Log.Debug("Deinit: end.");
|
||||
@@ -49,7 +48,7 @@ namespace MTApiService
|
||||
Log.Debug("SendResponse: end.");
|
||||
}
|
||||
|
||||
public int GetCommandType()
|
||||
public virtual int GetCommandType()
|
||||
{
|
||||
Log.Debug("GetCommandType: called.");
|
||||
|
||||
@@ -111,7 +110,7 @@ namespace MTApiService
|
||||
return command.NamedParams.ContainsKey(name);
|
||||
}
|
||||
|
||||
public void SendEvent(MtEvent mtEvent)
|
||||
public virtual void SendEvent(MtEvent mtEvent)
|
||||
{
|
||||
Log.DebugFormat("SendEvent: begin. event = {0}", mtEvent);
|
||||
|
||||
@@ -120,9 +119,18 @@ namespace MTApiService
|
||||
Log.Debug("SendEvent: end.");
|
||||
}
|
||||
|
||||
public void UpdateQuote(MtQuote quote)
|
||||
{
|
||||
Log.DebugFormat("UpdateQuote: begin. quote = {0}", quote);
|
||||
|
||||
Quote = quote;
|
||||
|
||||
Log.Debug("UpdateQuote: end.");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"ExpertHandle = {Handle}";
|
||||
return $"ExpertHandle = {Handle}, Quote = {Quote}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -153,7 +161,7 @@ namespace MTApiService
|
||||
return _quote;
|
||||
}
|
||||
}
|
||||
set
|
||||
private set
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
@@ -165,26 +173,6 @@ namespace MTApiService
|
||||
}
|
||||
|
||||
public int Handle { get; }
|
||||
|
||||
private bool _isEnable = true;
|
||||
public bool IsEnable
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
return _isEnable;
|
||||
}
|
||||
}
|
||||
private set
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_isEnable = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
[DataContract]
|
||||
public class MtMqlBookInfo
|
||||
{
|
||||
[DataMember]
|
||||
public int type { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public double price { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public long volume { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MTApiService
|
||||
{
|
||||
[DataContract]
|
||||
public class MtMqlTick
|
||||
{
|
||||
[DataMember]
|
||||
public long time { get; set; } // Time of the last prices update
|
||||
|
||||
[DataMember]
|
||||
public double bid { get; set; } // Current Bid price
|
||||
|
||||
[DataMember]
|
||||
public double ask { get; set; } // Current Ask price
|
||||
|
||||
[DataMember]
|
||||
public double last { get; set; } // Price of the last deal (Last)
|
||||
|
||||
[DataMember]
|
||||
public ulong volume { get; set; } // Volume for the current Last price
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ namespace MTApiService
|
||||
[DataMember]
|
||||
public int Action { get; set; }
|
||||
[DataMember]
|
||||
public uint Magic { get; set; }
|
||||
public ulong Magic { get; set; }
|
||||
[DataMember]
|
||||
public uint Order { get; set; }
|
||||
public ulong Order { get; set; }
|
||||
[DataMember]
|
||||
public string Symbol { get; set; }
|
||||
[DataMember]
|
||||
@@ -25,7 +25,7 @@ namespace MTApiService
|
||||
[DataMember]
|
||||
public double Tp { get; set; }
|
||||
[DataMember]
|
||||
public uint Deviation { get; set; }
|
||||
public ulong Deviation { get; set; }
|
||||
[DataMember]
|
||||
public int Type { get; set; }
|
||||
[DataMember]
|
||||
@@ -36,5 +36,9 @@ namespace MTApiService
|
||||
public DateTime Expiration { get; set; }
|
||||
[DataMember]
|
||||
public string Comment { get; set; }
|
||||
[DataMember]
|
||||
public ulong Position { get; set; }
|
||||
[DataMember]
|
||||
public ulong PositionBy { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,8 @@ namespace MTApiService
|
||||
typeof(MtResponseString), typeof(MtResponseBool),
|
||||
typeof(MtResponseLong), typeof(MtResponseULong),
|
||||
typeof(MtResponseDoubleArray), typeof(MtResponseIntArray),
|
||||
typeof(MtResponseLongArray), typeof(MtResponseMqlTick),
|
||||
typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray),
|
||||
typeof(MtResponseMqlBookInfoArray)};
|
||||
typeof(MtResponseLongArray),
|
||||
typeof(MtResponseArrayList), typeof(MtResponseMqlRatesArray)};
|
||||
}
|
||||
|
||||
public abstract object GetValue();
|
||||
@@ -255,43 +254,4 @@ namespace MTApiService
|
||||
return Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MtResponseMqlTick : MtResponse
|
||||
{
|
||||
public MtResponseMqlTick(MtMqlTick value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public MtMqlTick Value { get; private set; }
|
||||
|
||||
public override object GetValue() { return Value; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MtResponseMqlBookInfoArray : MtResponse
|
||||
{
|
||||
public MtResponseMqlBookInfoArray(MtMqlBookInfo[] value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public MtMqlBookInfo[] Value { get; private set; }
|
||||
|
||||
public override object GetValue() { return Value; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,11 +80,6 @@ namespace MTApiService
|
||||
//init network hosts
|
||||
var dnsHostName = Dns.GetHostName();
|
||||
var ips = Dns.GetHostEntry(dnsHostName);
|
||||
if (ips == null)
|
||||
{
|
||||
Log.WarnFormat("InitHosts: end. Dns.GetHostEntry has returned null for DNS Host Name {0}", dnsHostName);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var ipAddress in ips.AddressList)
|
||||
{
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.27.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.27.0")]
|
||||
[assembly: AssemblyVersion("1.0.32.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.32.0")]
|
||||
@@ -44,17 +44,16 @@ template <typename T> T Execute(std::function<T()> func, wchar_t* err, T default
|
||||
_DLLAPI bool _stdcall initExpert(int expertHandle, int port, wchar_t* symbol, double bid, double ask, wchar_t* err)
|
||||
{
|
||||
return Execute<bool>([&expertHandle, &port, symbol, &bid, &ask]() {
|
||||
MT4Handler^ mtHandler = gcnew MT4Handler();
|
||||
MtAdapter::GetInstance()->InitExpert(expertHandle, port, gcnew String(symbol), bid, ask, mtHandler);
|
||||
auto expert = gcnew MtExpert(expertHandle, gcnew String(symbol), bid, ask, gcnew MT4Handler());
|
||||
MtAdapter::GetInstance()->AddExpert(port, expert);
|
||||
return true;
|
||||
}, err, false);
|
||||
|
||||
}
|
||||
|
||||
_DLLAPI bool _stdcall deinitExpert(int expertHandle, wchar_t* err)
|
||||
{
|
||||
return Execute<bool>([&expertHandle]() {
|
||||
MtAdapter::GetInstance()->DeinitExpert(expertHandle);
|
||||
MtAdapter::GetInstance()->RemoveExpert(expertHandle);
|
||||
return true;
|
||||
}, err, false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -24,6 +24,7 @@
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>MTConnector</RootNamespace>
|
||||
<ProjectName>MTConnector</ProjectName>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
@@ -31,28 +32,28 @@
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CLRSupport>true</CLRSupport>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
public class ChartEventArgs : EventArgs
|
||||
{
|
||||
internal ChartEventArgs(int expertHandle, MtChartEvent chartEvent)
|
||||
{
|
||||
ExpertHandle = expertHandle;
|
||||
ChartId = chartEvent.ChartId;
|
||||
EventId = chartEvent.EventId;
|
||||
Lparam = chartEvent.Lparam;
|
||||
Dparam = chartEvent.Dparam;
|
||||
Sparam = chartEvent.Sparam;
|
||||
}
|
||||
|
||||
public int ExpertHandle { get; }
|
||||
public long ChartId { get; }
|
||||
public int EventId { get; }
|
||||
public long Lparam { get; }
|
||||
public double Dparam { get; }
|
||||
public string Sparam { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi
|
||||
{
|
||||
public enum EnumAlignMode
|
||||
{
|
||||
ALIGN_LEFT = 1,
|
||||
ALIGN_CENTER = 2,
|
||||
ALIGN_RIGHT = 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace MtApi
|
||||
{
|
||||
public enum EnumChartEvent
|
||||
{
|
||||
CHARTEVENT_KEYDOWN = 0,
|
||||
CHARTEVENT_MOUSE_MOVE = 10,
|
||||
CHARTEVENT_OBJECT_CREATE = 7,
|
||||
CHARTEVENT_OBJECT_CHANGE = 8,
|
||||
CHARTEVENT_OBJECT_DELETE = 6,
|
||||
CHARTEVENT_CLICK = 4,
|
||||
CHARTEVENT_OBJECT_CLICK = 1,
|
||||
CHARTEVENT_OBJECT_DRAG = 2,
|
||||
CHARTEVENT_OBJECT_ENDEDIT = 3,
|
||||
CHARTEVENT_CHART_CHANGE = 9,
|
||||
CHARTEVENT_CUSTOM = 1000,
|
||||
CHARTEVENT_CUSTOM_LAST = 66534
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace MtApi
|
||||
{
|
||||
public enum EnumChartPropertyDouble
|
||||
{
|
||||
CHART_SHIFT_SIZE = 3,
|
||||
CHART_FIXED_POSITION = 41,
|
||||
CHART_FIXED_MAX = 8,
|
||||
CHART_FIXED_MIN = 9,
|
||||
CHART_POINTS_PER_BAR = 11,
|
||||
CHART_PRICE_MIN = 108,
|
||||
CHART_PRICE_MAX = 109
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace MtApi
|
||||
{
|
||||
public enum EnumChartPropertyInteger
|
||||
{
|
||||
CHART_BRING_TO_TOP = 35,
|
||||
CHART_MOUSE_SCROLL = 42,
|
||||
CHART_EVENT_MOUSE_MOVE = 40,
|
||||
CHART_EVENT_OBJECT_CREATE = 38,
|
||||
CHART_EVENT_OBJECT_DELETE = 39,
|
||||
CHART_MODE = 0,
|
||||
CHART_FOREGROUND = 1,
|
||||
CHART_SHIFT = 2,
|
||||
CHART_AUTOSCROLL = 4,
|
||||
CHART_QUICK_NAVIGATION = 45,
|
||||
CHART_SCALE = 5,
|
||||
CHART_SCALEFIX = 6,
|
||||
CHART_SCALEFIX_11 = 7,
|
||||
CHART_SCALE_PT_PER_BAR = 10,
|
||||
CHART_SHOW_OHLC = 12,
|
||||
CHART_SHOW_BID_LINE = 13,
|
||||
CHART_SHOW_ASK_LINE = 14,
|
||||
CHART_SHOW_LAST_LINE = 15,
|
||||
CHART_SHOW_PERIOD_SEP = 16,
|
||||
CHART_SHOW_GRID = 17,
|
||||
CHART_SHOW_VOLUMES = 18,
|
||||
CHART_SHOW_OBJECT_DESCR = 19,
|
||||
CHART_VISIBLE_BARS = 100,
|
||||
CHART_WINDOWS_TOTAL = 101,
|
||||
CHART_WINDOW_IS_VISIBLE = 102,
|
||||
CHART_WINDOW_HANDLE = 103,
|
||||
CHART_WINDOW_YDISTANCE = 110,
|
||||
CHART_FIRST_VISIBLE_BAR = 104,
|
||||
CHART_WIDTH_IN_BARS = 105,
|
||||
CHART_WIDTH_IN_PIXELS = 106,
|
||||
CHART_HEIGHT_IN_PIXELS = 107,
|
||||
CHART_COLOR_BACKGROUND = 21,
|
||||
CHART_COLOR_FOREGROUND = 22,
|
||||
CHART_COLOR_GRID = 23,
|
||||
CHART_COLOR_VOLUME = 24,
|
||||
CHART_COLOR_CHART_UP = 25,
|
||||
CHART_COLOR_CHART_DOWN = 26,
|
||||
CHART_COLOR_CHART_LINE = 27,
|
||||
CHART_COLOR_CANDLE_BULL = 28,
|
||||
CHART_COLOR_CANDLE_BEAR = 29,
|
||||
CHART_COLOR_BID = 30,
|
||||
CHART_COLOR_ASK = 31,
|
||||
CHART_COLOR_LAST = 32,
|
||||
CHART_COLOR_STOP_LEVEL = 33,
|
||||
CHART_SHOW_TRADE_LEVELS = 34,
|
||||
CHART_DRAG_TRADE_LEVELS = 43,
|
||||
CHART_SHOW_DATE_SCALE = 36,
|
||||
CHART_SHOW_PRICE_SCALE = 37,
|
||||
CHART_IS_OFFLINE = 112
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MtApi
|
||||
{
|
||||
public enum EnumChartPropertyString
|
||||
{
|
||||
CHART_COMMENT = 20
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,12 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChartEventArgs.cs" />
|
||||
<Compile Include="ChartPeriod.cs" />
|
||||
<Compile Include="EnumAlignMode.cs" />
|
||||
<Compile Include="EnumChartPropertyDouble.cs" />
|
||||
<Compile Include="EnumChartPropertyInteger.cs" />
|
||||
<Compile Include="EnumChartPropertyString.cs" />
|
||||
<Compile Include="EnumColorFormat.cs" />
|
||||
<Compile Include="EnumObject.cs" />
|
||||
<Compile Include="EnumObjectPropertyDouble.cs" />
|
||||
@@ -73,6 +78,7 @@
|
||||
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MqlTick.cs" />
|
||||
<Compile Include="MtChartEvent.cs" />
|
||||
<Compile Include="MtConnectionEventArgs.cs" />
|
||||
<Compile Include="MtConnectionException.cs" />
|
||||
<Compile Include="MtConnectionState.cs" />
|
||||
|
||||
+680
-15
@@ -271,31 +271,77 @@ namespace MtApi
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||
, string comment, int magic, DateTime expiration)
|
||||
{
|
||||
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, Color.Empty);
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Cmd = (int)cmd,
|
||||
Volume = volume,
|
||||
Price = price,
|
||||
Slippage = slippage,
|
||||
Stoploss = stoploss,
|
||||
Takeprofit = takeprofit,
|
||||
Comment = comment,
|
||||
Magic = magic,
|
||||
Expiration = MtApiTimeConverter.ConvertToMtTime(expiration)
|
||||
});
|
||||
return response?.Ticket ?? -1;
|
||||
}
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||
, string comment, int magic)
|
||||
{
|
||||
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, DateTime.MinValue, Color.Empty);
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Cmd = (int)cmd,
|
||||
Volume = volume,
|
||||
Price = price,
|
||||
Slippage = slippage,
|
||||
Stoploss = stoploss,
|
||||
Takeprofit = takeprofit,
|
||||
Comment = comment,
|
||||
Magic = magic
|
||||
});
|
||||
return response?.Ticket ?? -1;
|
||||
}
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||
, string comment)
|
||||
{
|
||||
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment, 0, DateTime.MinValue, Color.Empty);
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Cmd = (int)cmd,
|
||||
Volume = volume,
|
||||
Price = price,
|
||||
Slippage = slippage,
|
||||
Stoploss = stoploss,
|
||||
Takeprofit = takeprofit,
|
||||
Comment = comment
|
||||
});
|
||||
return response?.Ticket ?? -1;
|
||||
}
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit)
|
||||
{
|
||||
return OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty);
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
Cmd = (int)cmd,
|
||||
Volume = volume,
|
||||
Price = price,
|
||||
Slippage = slippage,
|
||||
Stoploss = stoploss,
|
||||
Takeprofit = takeprofit,
|
||||
});
|
||||
return response?.Ticket ?? -1;
|
||||
}
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit)
|
||||
{
|
||||
double dPrice;
|
||||
return double.TryParse(price, out dPrice) ?
|
||||
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit, null, 0, DateTime.MinValue, Color.Empty) : 0;
|
||||
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit) : 0;
|
||||
}
|
||||
|
||||
public int OrderSendBuy(string symbol, double volume, int slippage)
|
||||
@@ -740,7 +786,7 @@ namespace MtApi
|
||||
|
||||
#endregion
|
||||
|
||||
#region Account Information
|
||||
#region Account functions
|
||||
|
||||
public double AccountBalance()
|
||||
{
|
||||
@@ -823,6 +869,12 @@ namespace MtApi
|
||||
return SendCommand<int>(MtCommandType.AccountStopoutMode, null);
|
||||
}
|
||||
|
||||
public bool ChangeAccount(string login, string password, string host)
|
||||
{
|
||||
var commandParameters = new ArrayList { login, password, host};
|
||||
return SendCommand<bool>(MtCommandType.ChangeAccount, commandParameters);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Common Function
|
||||
@@ -942,6 +994,12 @@ namespace MtApi
|
||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||
}
|
||||
|
||||
public DateTime TimeGMT()
|
||||
{
|
||||
var commandResponse = SendCommand<int>(MtCommandType.TimeGMT, null);
|
||||
return MtApiTimeConverter.ConvertFromMtTime(commandResponse);
|
||||
}
|
||||
|
||||
public int TimeDay(DateTime date)
|
||||
{
|
||||
var commandParameters = new ArrayList { MtApiTimeConverter.ConvertToMtTime(date) };
|
||||
@@ -1681,9 +1739,9 @@ namespace MtApi
|
||||
///</summary>
|
||||
///<param name="symbolName">Symbol name.</param>
|
||||
///<param name="propId">Identifier of a symbol property. The value can be one of the values of the ENUM_SYMBOL_INFO_DOUBLE enumeration.</param>
|
||||
/// <returns>
|
||||
///<returns>
|
||||
/// The value of double type.
|
||||
/// </returns>
|
||||
///</returns>
|
||||
public double SymbolInfoDouble(string symbolName, EnumSymbolInfoDouble propId)
|
||||
{
|
||||
var response = SendRequest<SymbolInfoDoubleResponse>(new SymbolInfoDoubleRequest
|
||||
@@ -1699,9 +1757,9 @@ namespace MtApi
|
||||
///Returns the corresponding property of a specified symbol.
|
||||
///</summary>
|
||||
///<param name="symbol">Symbol name.</param>
|
||||
/// <returns>
|
||||
///<returns>
|
||||
/// MqlTick object, to which the current prices and time of the last price update will be placed.
|
||||
/// </returns>
|
||||
///</returns>
|
||||
public MqlTick SymbolInfoTick(string symbol)
|
||||
{
|
||||
var response = SendRequest<SymbolInfoTickResponse>(new SymbolInfoTickRequest
|
||||
@@ -1734,6 +1792,606 @@ namespace MtApi
|
||||
var commandParameters = new ArrayList { chartId };
|
||||
SendCommand<object>(MtCommandType.ChartRedraw, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Applies a specific template from a specified file to the chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID.</param>
|
||||
///<param name="filename">The name of the file containing the template.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartApplyTemplate(long chartId, string filename)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, filename };
|
||||
return SendCommand<bool>(MtCommandType.ChartApplyTemplate, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Saves current chart settings in a template with a specified name.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID.</param>
|
||||
///<param name="filename">The filename to save the template. The ".tpl" extension will be added to the filename automatically; there is no need to specify it. The template is saved in data_folder\templates\ and can be used for manual application in the terminal. If a template with the same filename already exists, the contents of this file will be overwritten.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartSaveTemplate(long chartId, string filename)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, filename };
|
||||
return SendCommand<bool>(MtCommandType.ChartSaveTemplate, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the number of a subwindow where an indicator is drawn.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID.</param>
|
||||
///<param name="indicatorShortname">Short name of the indicator.</param>
|
||||
///<returns>
|
||||
///Subwindow number in case of success. In case of failure the function returns -1.
|
||||
///</returns>
|
||||
public int ChartWindowFind(long chartId, string indicatorShortname)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, indicatorShortname };
|
||||
return SendCommand<int>(MtCommandType.ChartWindowFind, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the number of a subwindow where an indicator is drawn.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID.</param>
|
||||
///<param name="subWindow">The number of the chart subwindow. 0 means the main chart window.</param>
|
||||
///<param name="time">The time value on the chart, for which the value in pixels along the X axis will be received.</param>
|
||||
///<param name="price">The price value on the chart, for which the value in pixels along the Y axis will be received.</param>
|
||||
///<param name="x">The variable, into which the conversion of time to X will be received. The origin is in the upper left corner of the main chart window.</param>
|
||||
///<param name="y">The variable, into which the conversion of price to Y will be received. The origin is in the upper left corner of the main chart window.</param>
|
||||
///<returns>
|
||||
///Subwindow number in case of success. In case of failure the function returns -1.
|
||||
///</returns>
|
||||
public bool ChartTimePriceToXY(long chartId, int subWindow, DateTime? time, double price, out int x, out int y)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, subWindow, MtApiTimeConverter.ConvertToMtTime(time), price };
|
||||
var str = SendCommand<string>(MtCommandType.ChartTimePriceToXY, commandParameters);
|
||||
var res = false;
|
||||
x = 0;
|
||||
y = 0;
|
||||
if (!string.IsNullOrEmpty(str) && str.Contains(";"))
|
||||
{
|
||||
var values = str.Split(';');
|
||||
if (values.Length > 1)
|
||||
{
|
||||
int.TryParse(values[0], out x);
|
||||
int.TryParse(values[1], out y);
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///The function returns the number of a subwindow where an indicator is drawn.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID.</param>
|
||||
///<param name="x">The variable, into which the conversion of time to X will be received. The origin is in the upper left corner of the main chart window.</param>
|
||||
///<param name="y">The variable, into which the conversion of price to Y will be received. The origin is in the upper left corner of the main chart window.</param>
|
||||
///<param name="subWindow">The number of the chart subwindow. 0 means the main chart window.</param>
|
||||
///<param name="time">The time value on the chart, for which the value in pixels along the X axis will be received.</param>
|
||||
///<param name="price">The price value on the chart, for which the value in pixels along the Y axis will be received.</param>
|
||||
///<returns>
|
||||
///Subwindow number in case of success. In case of failure the function returns -1.
|
||||
///</returns>
|
||||
public bool ChartXYToTimePrice(long chartId, int x, int y, out int subWindow, out DateTime? time, out double price)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, x, y };
|
||||
var str = SendCommand<string>(MtCommandType.ChartXYToTimePrice, commandParameters);
|
||||
var res = false;
|
||||
subWindow = 0;
|
||||
time = null;
|
||||
price = double.NaN;
|
||||
if (!string.IsNullOrEmpty(str) && str.Contains(";"))
|
||||
{
|
||||
var values = str.Split(';');
|
||||
if (values.Length > 2)
|
||||
{
|
||||
int.TryParse(values[0], out subWindow);
|
||||
int mt4Time;
|
||||
int.TryParse(values[1], out mt4Time);
|
||||
time = MtApiTimeConverter.ConvertFromMtTime(mt4Time);
|
||||
double.TryParse(values[2], out price);
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Opens a new chart with the specified symbol and period.
|
||||
///</summary>
|
||||
///<param name="symbol">Chart symbol. NULL means the symbol of the current chart (the Expert Advisor is attached to).</param>
|
||||
///<param name="period"> Chart period (timeframe). Can be one of the ENUM_TIMEFRAMES values. 0 means the current chart period.</param>
|
||||
///<returns>
|
||||
///If successful, it returns the opened chart ID. Otherwise returns 0.
|
||||
///</returns>
|
||||
public long ChartOpen(string symbol, ENUM_TIMEFRAMES period)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol, (int)period };
|
||||
return SendCommand<long>(MtCommandType.ChartOpen, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the ID of the first chart of the client terminal.
|
||||
///</summary>
|
||||
public long ChartFirst()
|
||||
{
|
||||
return SendCommand<long>(MtCommandType.ChartFirst, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the chart ID of the chart next to the specified one.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 does not mean the current chart. 0 means "return the first chart ID".</param>
|
||||
///<returns>
|
||||
///Chart ID. If this is the end of the chart list, it returns -1.
|
||||
///</returns>
|
||||
public long ChartNext(long chartId)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId };
|
||||
return SendCommand<long>(MtCommandType.ChartNext, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Closes the specified chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<returns>
|
||||
///If successful, returns true, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartClose(long chartId)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId };
|
||||
return SendCommand<bool>(MtCommandType.ChartClose, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the symbol name for the specified chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<returns>
|
||||
///If chart does not exist, the result will be an empty string.
|
||||
///</returns>
|
||||
public string ChartSymbol(long chartId)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId };
|
||||
return SendCommand<string>(MtCommandType.ChartSymbol, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the timeframe period of specified chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<returns>
|
||||
///The function returns one of the ENUM_TIMEFRAMES values. If chart does not exist, it returns 0.
|
||||
///</returns>
|
||||
public ENUM_TIMEFRAMES ChartPeriod(long chartId)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId };
|
||||
return (ENUM_TIMEFRAMES) SendCommand<int>(MtCommandType.ChartPeriod, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Sets a value for a corresponding property of the specified chart. Chart property should be of a double type.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. Can be one of the ENUM_CHART_PROPERTY_DOUBLE values (except the read-only properties).</param>
|
||||
///<param name="value">Property value.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartSetDouble(long chartId, EnumChartPropertyDouble propId, double value)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId, value };
|
||||
return SendCommand<bool>(MtCommandType.ChartSetDouble, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Sets a value for a corresponding property of the specified chart. Chart property must be datetime, int, color, bool or char.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. It can be one of the ENUM_CHART_PROPERTY_INTEGER value (except the read-only properties).</param>
|
||||
///<param name="value">Property value.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartSetInteger(long chartId, EnumChartPropertyInteger propId, long value)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId, value };
|
||||
return SendCommand<bool>(MtCommandType.ChartSetInteger, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Sets a value for a corresponding property of the specified chart. Chart property must be of the string type.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. Its value can be one of the ENUM_CHART_PROPERTY_STRING values (except the read-only properties).</param>
|
||||
///<param name="value">Property value string. String length cannot exceed 2045 characters (extra characters will be truncated).</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartSetString(long chartId, EnumChartPropertyString propId, string value)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId, value };
|
||||
return SendCommand<bool>(MtCommandType.ChartSetString, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Sets a value for a corresponding property of the specified chart. Chart property must be of the string type.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_DOUBLE values.</param>
|
||||
///<param name="subWindow">Number of the chart subwindow. For the first case, the default value is 0 (main chart window). The most of the properties do not require a subwindow number.</param>
|
||||
///<returns>
|
||||
///The value of double type.
|
||||
///</returns>
|
||||
public double ChartGetDouble(long chartId, EnumChartPropertyDouble propId, int subWindow = 0)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId, subWindow };
|
||||
return SendCommand<double>(MtCommandType.ChartGetDouble, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the value of a corresponding property of the specified chart. Chart property must be of datetime, int or bool type.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_INTEGER values.</param>
|
||||
///<param name="subWindow">Number of the chart subwindow. For the first case, the default value is 0 (main chart window). The most of the properties do not require a subwindow number.</param>
|
||||
///<returns>
|
||||
///The value of long type.
|
||||
///</returns>
|
||||
public long ChartGetInteger(long chartId, EnumChartPropertyInteger propId, int subWindow = 0)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId, subWindow };
|
||||
return SendCommand<long>(MtCommandType.ChartGetInteger, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the value of a corresponding property of the specified chart. Chart property must be of string type.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="propId">Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_STRING values.</param>
|
||||
///<returns>
|
||||
///The value of string type.
|
||||
///</returns>
|
||||
public string ChartGetString(long chartId, EnumChartPropertyString propId)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, (int)propId };
|
||||
return SendCommand<string>(MtCommandType.ChartGetString, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Performs shift of the specified chart by the specified number of bars relative to the specified position in the chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="position">Chart position to perform a shift. Can be one of the ENUM_CHART_POSITION values.</param>
|
||||
///<param name="shift">Number of bars to shift the chart. Positive value means the right shift (to the end of chart), negative value means the left shift (to the beginning of chart). The zero shift can be used to navigate to the beginning or end of chart.</param>
|
||||
///<returns>
|
||||
///Returns true if successful, otherwise returns false.
|
||||
///</returns>
|
||||
public bool ChartNavigate(long chartId, int position, int shift = 0)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, position, shift };
|
||||
return SendCommand<bool>(MtCommandType.ChartNavigate, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Performs shift of the specified chart by the specified number of bars relative to the specified position in the chart.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="subWindow">Number of the chart subwindow. 0 denotes the main chart subwindow.</param>
|
||||
///<param name="indicatorShortname">The short name of the indicator which is set in the INDICATOR_SHORTNAME property with the IndicatorSetString() function. To get the short name of an indicator use the ChartIndicatorName() function.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartIndicatorDelete(long chartId, int subWindow, string indicatorShortname)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, subWindow, indicatorShortname };
|
||||
return SendCommand<bool>(MtCommandType.ChartIndicatorDelete, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the short name of the indicator by the number in the indicators list on the specified chart window.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="subWindow">Number of the chart subwindow. 0 denotes the main chart subwindow.</param>
|
||||
///<param name="index">the index of the indicator in the list of indicators. The numeration of indicators start with zero, i.e. the first indicator in the list has the 0 index. To obtain the number of indicators in the list use the ChartIndicatorsTotal() function.</param>
|
||||
///<returns>
|
||||
///The short name of the indicator which is set in the INDICATOR_SHORTNAME property with the IndicatorSetString() function.
|
||||
///</returns>
|
||||
public string ChartIndicatorName(long chartId, int subWindow, int index)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, subWindow, index };
|
||||
return SendCommand<string>(MtCommandType.ChartIndicatorName, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the number of all indicators applied to the specified chart window.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="subWindow">Number of the chart subwindow. 0 denotes the main chart subwindow.</param>
|
||||
///<returns>
|
||||
///The number of indicators in the specified chart window.
|
||||
///</returns>
|
||||
public int ChartIndicatorsTotal(long chartId, int subWindow)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, subWindow };
|
||||
return SendCommand<int>(MtCommandType.ChartIndicatorsTotal, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the number (index) of the chart subwindow the Expert Advisor or script has been dropped to. 0 means the main chart window.
|
||||
///</summary>
|
||||
public int ChartWindowOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.ChartWindowOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the price coordinate corresponding to the chart point the Expert Advisor or script has been dropped to.
|
||||
///</summary>
|
||||
public double ChartPriceOnDropped()
|
||||
{
|
||||
return SendCommand<double>(MtCommandType.ChartPriceOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the time coordinate corresponding to the chart point the Expert Advisor or script has been dropped to.
|
||||
///</summary>
|
||||
public DateTime ChartTimeOnDropped()
|
||||
{
|
||||
var res = SendCommand<int>(MtCommandType.ChartTimeOnDropped, null);
|
||||
return MtApiTimeConverter.ConvertFromMtTime(res);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the X coordinate of the chart point the Expert Advisor or script has been dropped to.
|
||||
///</summary>
|
||||
public int ChartXOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.ChartXOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the Y coordinateof the chart point the Expert Advisor or script has been dropped to.
|
||||
///</summary>
|
||||
public int ChartYOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.ChartYOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="symbol">Chart symbol. NULL value means the current chart symbol (Expert Advisor is attached to)</param>
|
||||
///<param name="period">Chart period (timeframe). Can be one of the ENUM_TIMEFRAMES values. 0 means the current chart period.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartSetSymbolPeriod(long chartId, string symbol, ENUM_TIMEFRAMES period)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, symbol, (int)period };
|
||||
return SendCommand<bool>(MtCommandType.ChartSetSymbolPeriod, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Saves current chart screen shot as a GIF, PNG or BMP file depending on specified extension.
|
||||
///</summary>
|
||||
///<param name="chartId">Chart ID. 0 means the current chart.</param>
|
||||
///<param name="filename">Screenshot file name. Cannot exceed 63 characters. Screenshot files are placed in the \Files directory.</param>
|
||||
///<param name="width">Screenshot width in pixels.</param>
|
||||
///<param name="height">Screenshot height in pixels.</param>
|
||||
///<param name="alignMode">Output mode of a narrow screenshot.</param>
|
||||
///<returns>
|
||||
///Returns true if the command has been added to chart queue, otherwise false.
|
||||
///</returns>
|
||||
public bool ChartScreenShot(long chartId, string filename, int width, int height, EnumAlignMode alignMode = EnumAlignMode.ALIGN_RIGHT)
|
||||
{
|
||||
var commandParameters = new ArrayList { chartId, filename, width, height, (int)alignMode };
|
||||
return SendCommand<bool>(MtCommandType.ChartScreenShot, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the amount of bars visible on the chart.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The amount of bars visible on the chart.
|
||||
///</returns>
|
||||
public int WindowBarsPerChart()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowBarsPerChart, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the name of the executed Expert Advisor, script, custom indicator, or library.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The name of the executed Expert Advisor, script, custom indicator, or library, depending on the MQL4 program, from which this function has been called.
|
||||
///</returns>
|
||||
public string WindowExpertName()
|
||||
{
|
||||
return SendCommand<string>(MtCommandType.WindowExpertName, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the window index containing this specified indicator.
|
||||
///</summary>
|
||||
///<param name="name">Indicator short name.</param>
|
||||
///<returns>
|
||||
///If indicator with name was found, the function returns the window index containing this specified indicator, otherwise it returns -1.
|
||||
///</returns>
|
||||
public int WindowFind(string name)
|
||||
{
|
||||
var commandParameters = new ArrayList { name };
|
||||
return SendCommand<int>(MtCommandType.WindowFind, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns index of the first visible bar in the current chart window.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///Index of the first visible bar number in the current chart window.
|
||||
///</returns>
|
||||
public int WindowFirstVisibleBar()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowFirstVisibleBar, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the system handle of the chart window.
|
||||
///</summary>
|
||||
///<param name="symbol">Symbol.</param>
|
||||
///<param name="timeframe">Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.</param>
|
||||
///<returns>
|
||||
///Returns the system handle of the chart window. If the chart of symbol and timeframe has not been opened by the moment of function calling, 0 will be returned.
|
||||
///</returns>
|
||||
public int WindowHandle(string symbol, int timeframe)
|
||||
{
|
||||
var commandParameters = new ArrayList { symbol, timeframe };
|
||||
return SendCommand<int>(MtCommandType.WindowHandle, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the visibility flag of the chart subwindow.
|
||||
///</summary>
|
||||
///<param name="index">Subwindow index.</param>
|
||||
///<returns>
|
||||
///Returns true if the chart subwindow is visible, otherwise returns false. The chart subwindow can be hidden due to the visibility properties of the indicator placed in it.
|
||||
///</returns>
|
||||
public bool WindowIsVisible(int index)
|
||||
{
|
||||
var commandParameters = new ArrayList { index };
|
||||
return SendCommand<bool>(MtCommandType.WindowIsVisible, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the window index where Expert Advisor, custom indicator or script was dropped.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The window index where Expert Advisor, custom indicator or script was dropped. This value is valid if the Expert Advisor, custom indicator or script was dropped by mouse.
|
||||
///</returns>
|
||||
public int WindowOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the maximal value of the vertical scale of the specified subwindow of the current chart.
|
||||
///</summary>
|
||||
///<param name="index">Chart subwindow index (0 - main chart window).</param>
|
||||
///<returns>
|
||||
///The maximal value of the vertical scale of the specified subwindow of the current chart.
|
||||
///</returns>
|
||||
public int WindowPriceMax(int index = 0)
|
||||
{
|
||||
var commandParameters = new ArrayList { index };
|
||||
return SendCommand<int>(MtCommandType.WindowPriceMax, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the minimal value of the vertical scale of the specified subwindow of the current chart.
|
||||
///</summary>
|
||||
///<param name="index">Chart subwindow index (0 - main chart window).</param>
|
||||
///<returns>
|
||||
///The minimal value of the vertical scale of the specified subwindow of the current chart.
|
||||
///</returns>
|
||||
public int WindowPriceMin(int index = 0)
|
||||
{
|
||||
var commandParameters = new ArrayList { index };
|
||||
return SendCommand<int>(MtCommandType.WindowPriceMin, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the price of the chart point where Expert Advisor or script was dropped.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The price of the chart point where Expert Advisor or script was dropped. This value is only valid if the expert or script was dropped by mouse.
|
||||
///</returns>
|
||||
public double WindowPriceOnDropped()
|
||||
{
|
||||
return SendCommand<double>(MtCommandType.WindowPriceOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Redraws the current chart forcedly.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///Redraws the current chart forcedly. It is normally used after the objects properties have been changed.
|
||||
///</returns>
|
||||
public void WindowRedraw()
|
||||
{
|
||||
SendCommand<object>(MtCommandType.WindowRedraw, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Saves current chart screen shot as a GIF file.
|
||||
///</summary>
|
||||
///<param name="filename">Screen shot file name. Screenshot is saved to \Files folder.</param>
|
||||
///<param name="sizeX">Screen shot width in pixels.</param>
|
||||
///<param name="sizeY">Screen shot height in pixels.</param>
|
||||
///<param name="startBar">Index of the first visible bar in the screen shot. If 0 value is set, the current first visible bar will be shot. If no value or negative value has been set, the end-of-chart screen shot will be produced, indent being taken into consideration.</param>
|
||||
///<param name="chartScale">Horizontal chart scale for screen shot. Can be in the range from 0 to 5. If no value or negative value has been set, the current chart scale will be used.</param>
|
||||
///<param name="chartMode"> Chart displaying mode. It can take the following values: CHART_BAR (0 is a sequence of bars), CHART_CANDLE (1 is a sequence of candlesticks), CHART_LINE (2 is a close prices line). If no value or negative value has been set, the chart will be shown in its current mode.</param>
|
||||
///<returns>
|
||||
///Returns true if succeed, otherwise false.
|
||||
///</returns>
|
||||
public bool WindowScreenShot(string filename, int sizeX, int sizeY, int startBar = -1, int chartScale = -1, int chartMode = -1)
|
||||
{
|
||||
var commandParameters = new ArrayList { filename, sizeX, sizeY, startBar, chartScale, chartMode };
|
||||
return SendCommand<bool>(MtCommandType.WindowScreenShot, commandParameters);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the time of the chart point where Expert Advisor or script was dropped.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The time value of the chart point where expert or script was dropped. This value is only valid if the expert or script was dropped by mouse.
|
||||
///</returns>
|
||||
public DateTime WindowTimeOnDropped()
|
||||
{
|
||||
var res = SendCommand<int>(MtCommandType.WindowTimeOnDropped, null);
|
||||
return MtApiTimeConverter.ConvertFromMtTime(res);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns total number of indicator windows on the chart.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///Total number of indicator windows on the chart (including main chart).
|
||||
///</returns>
|
||||
public int WindowsTotal()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowsTotal, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the value at X axis in pixels for the chart window client area point at which the Expert Advisor or script was dropped.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///The value at X axis in pixels for the chart window client area point at which the expert or script was dropped. The value will be true only if the expert or script were moved with the mouse ("Drag'n'Drop") technique.
|
||||
///</returns>
|
||||
public int WindowXOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowXOnDropped, null);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
///Returns the value at Y axis in pixels for the chart window client area point at which the Expert Advisor or script was dropped.
|
||||
///</summary>
|
||||
///<returns>
|
||||
///Returns the value at Y axis in pixels for the chart window client area point at which the Expert Advisor or script was dropped. The value will be true only if the expert or script were moved with the mouse ("Drag'n'Drop") technique.
|
||||
///</returns>
|
||||
public int WindowYOnDropped()
|
||||
{
|
||||
return SendCommand<int>(MtCommandType.WindowYOnDropped, null);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Object Functions
|
||||
@@ -2416,18 +3074,24 @@ namespace MtApi
|
||||
switch(eventType)
|
||||
{
|
||||
case MtEventTypes.LastTimeBar:
|
||||
{
|
||||
FireOnLastTimeBar(JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
||||
}
|
||||
FireOnLastTimeBar(e.ExpertHandle, JsonConvert.DeserializeObject<MtTimeBar>(e.Payload));
|
||||
break;
|
||||
case MtEventTypes.ChartEvent:
|
||||
FireOnChartEvent(e.ExpertHandle, JsonConvert.DeserializeObject<MtChartEvent>(e.Payload));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void FireOnLastTimeBar(MtTimeBar timeBar)
|
||||
private void FireOnLastTimeBar(int expertHandler, MtTimeBar timeBar)
|
||||
{
|
||||
OnLastTimeBar?.Invoke(this, new TimeBarArgs(timeBar));
|
||||
OnLastTimeBar?.Invoke(this, new TimeBarArgs(expertHandler, timeBar));
|
||||
}
|
||||
|
||||
private void FireOnChartEvent(int expertHandler, MtChartEvent chartEvent)
|
||||
{
|
||||
OnChartEvent?.Invoke(this, new ChartEventArgs(expertHandler, chartEvent));
|
||||
}
|
||||
|
||||
private void BacktestingReady()
|
||||
@@ -2445,6 +3109,7 @@ namespace MtApi
|
||||
public event EventHandler<MtQuoteEventArgs> QuoteRemoved;
|
||||
public event EventHandler<MtConnectionEventArgs> ConnectionStateChanged;
|
||||
public event EventHandler<TimeBarArgs> OnLastTimeBar;
|
||||
public event EventHandler<ChartEventArgs> OnChartEvent;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace MtApi
|
||||
{
|
||||
internal class MtChartEvent
|
||||
{
|
||||
public long ChartId { get; set; }
|
||||
public int EventId { get; set; }
|
||||
public long Lparam { get; set; }
|
||||
public double Dparam { get; set; }
|
||||
public string Sparam { get; set; }
|
||||
}
|
||||
}
|
||||
Executable → Regular
+52
-3
@@ -111,6 +111,7 @@
|
||||
TimeSeconds = 86,
|
||||
TimeYear = 87,
|
||||
Year = 88,
|
||||
TimeGMT = 281,
|
||||
|
||||
//Global Variables
|
||||
GlobalVariableCheck = 89,
|
||||
@@ -197,8 +198,6 @@
|
||||
SymbolName = 201,
|
||||
SymbolSelect = 202,
|
||||
SymbolInfoInteger = 203,
|
||||
ChartId = 206,
|
||||
ChartRedraw = 207,
|
||||
|
||||
//Object Functions
|
||||
ObjectCreate = 208,
|
||||
@@ -229,6 +228,56 @@
|
||||
ObjectSetText = 233,
|
||||
ObjectType = 234,
|
||||
|
||||
UnlockTicks = 235
|
||||
UnlockTicks = 235,
|
||||
|
||||
//Chart Operations
|
||||
ChartId = 206,
|
||||
ChartRedraw = 207,
|
||||
ChartApplyTemplate = 236,
|
||||
ChartSaveTemplate = 237,
|
||||
ChartWindowFind = 238,
|
||||
ChartTimePriceToXY = 239,
|
||||
ChartXYToTimePrice = 240,
|
||||
ChartOpen = 241,
|
||||
ChartFirst = 242,
|
||||
ChartNext = 243,
|
||||
ChartClose = 244,
|
||||
ChartSymbol = 245,
|
||||
ChartPeriod = 246,
|
||||
ChartSetDouble = 247,
|
||||
ChartSetInteger = 248,
|
||||
ChartSetString = 249,
|
||||
ChartGetDouble = 250,
|
||||
ChartGetInteger = 251,
|
||||
ChartGetString = 252,
|
||||
ChartNavigate = 253,
|
||||
ChartIndicatorDelete = 254,
|
||||
ChartIndicatorName = 255,
|
||||
ChartIndicatorsTotal = 256,
|
||||
ChartWindowOnDropped = 257,
|
||||
ChartPriceOnDropped = 258,
|
||||
ChartTimeOnDropped = 259,
|
||||
ChartXOnDropped = 260,
|
||||
ChartYOnDropped = 261,
|
||||
ChartSetSymbolPeriod = 262,
|
||||
ChartScreenShot = 263,
|
||||
WindowBarsPerChart = 264,
|
||||
WindowExpertName = 265,
|
||||
WindowFind = 266,
|
||||
WindowFirstVisibleBar = 267,
|
||||
WindowHandle = 268,
|
||||
WindowIsVisible = 269,
|
||||
WindowOnDropped = 270,
|
||||
WindowPriceMax = 271,
|
||||
WindowPriceMin = 272,
|
||||
WindowPriceOnDropped = 273,
|
||||
WindowRedraw = 274,
|
||||
WindowScreenShot = 275,
|
||||
WindowTimeOnDropped = 276,
|
||||
WindowsTotal = 277,
|
||||
WindowXOnDropped = 278,
|
||||
WindowYOnDropped = 279,
|
||||
|
||||
ChangeAccount = 280
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
public enum MtEventTypes
|
||||
{
|
||||
LastTimeBar = 1
|
||||
LastTimeBar = 1,
|
||||
ChartEvent = 2
|
||||
}
|
||||
}
|
||||
|
||||
+2
-11
@@ -11,16 +11,7 @@ namespace MtApi
|
||||
public double Close { get; set; }
|
||||
public double High { get; set; }
|
||||
public double Low { get; set; }
|
||||
|
||||
public DateTime OpenTime
|
||||
{
|
||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtOpenTime); }
|
||||
}
|
||||
|
||||
public DateTime CloseTime
|
||||
{
|
||||
get { return MtApiTimeConverter.ConvertFromMtTime(MtCloseTime); }
|
||||
}
|
||||
|
||||
public DateTime OpenTime => MtApiTimeConverter.ConvertFromMtTime(MtOpenTime);
|
||||
public DateTime CloseTime => MtApiTimeConverter.ConvertFromMtTime(MtCloseTime);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace MtApi
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi
|
||||
{
|
||||
public enum ENUM_TERMINAL_INFO_STRING
|
||||
{
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.35.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.35.0")]
|
||||
[assembly: AssemblyVersion("1.0.41.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.41.0")]
|
||||
@@ -4,11 +4,18 @@ namespace MtApi
|
||||
{
|
||||
public class TimeBarArgs: EventArgs
|
||||
{
|
||||
internal TimeBarArgs(int expertHandle, MtTimeBar timeBar)
|
||||
: this(timeBar)
|
||||
{
|
||||
ExpertHandle = expertHandle;
|
||||
}
|
||||
|
||||
public TimeBarArgs(MtTimeBar timeBar)
|
||||
{
|
||||
TimeBar = timeBar;
|
||||
}
|
||||
|
||||
public MtTimeBar TimeBar { get; private set; }
|
||||
public int ExpertHandle { get; }
|
||||
public MtTimeBar TimeBar { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
OP_BUYLIMIT = 2,
|
||||
OP_SELLLIMIT = 3,
|
||||
OP_BUYSTOP = 4,
|
||||
OP_SELLSTOP = 5
|
||||
OP_SELLSTOP = 5,
|
||||
OP_BALANCE = 6,
|
||||
OP_CREDIT = 7,
|
||||
OP_REBATE = 8
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal enum Mt5EventTypes
|
||||
{
|
||||
OnTradeTransaction = 1,
|
||||
OnBookEvent = 2,
|
||||
OnTick = 3,
|
||||
OnLastTimeBar = 4,
|
||||
OnLockTicks = 5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnBookEvent
|
||||
{
|
||||
public string Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
public class OnLastTimeBarEvent
|
||||
{
|
||||
public MqlRates Rates { get; set; }
|
||||
public string Instrument { get; set; }
|
||||
public int ExpertHandle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnLockTicksEvent
|
||||
{
|
||||
public string Instrument { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnTickEvent
|
||||
{
|
||||
public MqlTick Tick { get; set; }
|
||||
public string Instrument { get; set; }
|
||||
public int ExpertHandle { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Events
|
||||
{
|
||||
internal class OnTradeTransactionEvent
|
||||
{
|
||||
public MqlTradeTransaction Trans { get; set; }
|
||||
public MqlTradeRequest Request { get; set; }
|
||||
public MqlTradeResult Result { get; set; }
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlBookInfo
|
||||
@@ -14,8 +10,17 @@ namespace MtApi5
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public ENUM_BOOK_TYPE type { get; private set; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; private set; } // Price
|
||||
public long volume { get; private set; } // Volume
|
||||
public MqlBookInfo()
|
||||
{ }
|
||||
|
||||
public ENUM_BOOK_TYPE type { get; set; } // Order type from ENUM_BOOK_TYPE enumeration
|
||||
public double price { get; set; } // Price
|
||||
public long volume { get; set; } // Volume
|
||||
public double volume_real { get; set; } // Volume for the current Last price with greater accuracy
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"type = {type}; price = {price}; volume = {volume}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlParam
|
||||
{
|
||||
public ENUM_DATATYPE DataType { get; set; }
|
||||
public long? IntegerValue { get; set; }
|
||||
public double? DoubleValue { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
}
|
||||
}
|
||||
+17
-3
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -6,7 +7,19 @@ namespace MtApi5
|
||||
{
|
||||
public MqlRates(DateTime time, double open, double high, double low, double close, long tick_volume, int spread, long real_volume)
|
||||
{
|
||||
this.time = time;
|
||||
mt_time = Mt5TimeConverter.ConvertToMtTime(time);
|
||||
this.open = open;
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
this.close = close;
|
||||
this.tick_volume = tick_volume;
|
||||
this.spread = spread;
|
||||
this.real_volume = real_volume;
|
||||
}
|
||||
|
||||
internal MqlRates(long time, double open, double high, double low, double close, long tick_volume, int spread, long real_volume)
|
||||
{
|
||||
mt_time = time;
|
||||
this.open = open;
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
@@ -20,7 +33,8 @@ namespace MtApi5
|
||||
{
|
||||
}
|
||||
|
||||
public DateTime time { get; set; } // Period start time
|
||||
public DateTime time => Mt5TimeConverter.ConvertFromMtTime(mt_time); // Period start time
|
||||
public long mt_time { get; set; } // Period start time (original MT time)
|
||||
public double open { get; set; } // Open price
|
||||
public double high { get; set; } // The highest price of the period
|
||||
public double low { get; set; } // The lowest price of the period
|
||||
|
||||
+4
-2
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -22,7 +23,8 @@ namespace MtApi5
|
||||
public double bid { get; set; } // Current Bid price
|
||||
public double ask { get; set; } // Current Ask price
|
||||
public double last { get; set; } // Price of the last deal (Last)
|
||||
public ulong volume { get; set; } // Volume for the current Last price
|
||||
public ulong volume { get; set; } // Volume for the current Last price
|
||||
public double volume_real { get; set; } // Volume for the current Last price with greater accuracy
|
||||
|
||||
public DateTime time => Mt5TimeConverter.ConvertFromMtTime(MtTime);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeCheckResult
|
||||
{
|
||||
public uint Retcode { get; private set; } // Reply code
|
||||
public double Balance { get; private set; } // Balance after the execution of the deal
|
||||
public double Equity { get; private set; } // Equity after the execution of the deal
|
||||
public double Profit { get; private set; } // Floating profit
|
||||
public double Margin { get; private set; } // Margin requirements
|
||||
public double Margin_free { get; private set; } // Free margin
|
||||
public double Margin_level { get; private set; } // Margin level
|
||||
public string Comment { get; private set; } // Comment to the reply code (description of the error)
|
||||
public uint Retcode { get; set; } // Reply code
|
||||
public double Balance { get; set; } // Balance after the execution of the deal
|
||||
public double Equity { get; set; } // Equity after the execution of the deal
|
||||
public double Profit { get; set; } // Floating profit
|
||||
public double Margin { get; set; } // Margin requirements
|
||||
public double Margin_free { get; set; } // Free margin
|
||||
public double Margin_level { get; set; } // Margin level
|
||||
public string Comment { get; set; } // Comment to the reply code (description of the error)
|
||||
|
||||
public MqlTradeCheckResult(uint retcode
|
||||
, double balance
|
||||
@@ -34,5 +31,13 @@ namespace MtApi5
|
||||
Margin_level = margin_level;
|
||||
Comment = comment;
|
||||
}
|
||||
|
||||
public MqlTradeCheckResult()
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Retcode={Retcode}; Comment={Comment}; Balance={Balance}; Equity={Equity}; Profit={Profit}; Margin={Margin}; Margin_free={Margin_free}; Margin_level={Margin_level}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeRequest
|
||||
{
|
||||
public ENUM_TRADE_REQUEST_ACTIONS Action { get; set; } // Trade operation type
|
||||
public uint Magic { get; set; } // Expert Advisor ID (magic number)
|
||||
public ulong Magic { get; set; } // Expert Advisor ID (magic number)
|
||||
public ulong Order { get; set; } // Order ticket
|
||||
public string Symbol { get; set; } // Trade symbol
|
||||
public double Volume { get; set; } // Requested volume for a deal in lots
|
||||
@@ -13,11 +15,27 @@ namespace MtApi5
|
||||
public double Stoplimit { get; set; } // StopLimit level of the order
|
||||
public double Sl { get; set; } // Stop Loss level of the order
|
||||
public double Tp { get; set; } // Take Profit level of the order
|
||||
public uint Deviation { get; set; } // Maximal possible deviation from the requested price
|
||||
public ulong Deviation { get; set; } // Maximal possible deviation from the requested price
|
||||
public ENUM_ORDER_TYPE Type { get; set; } // Order type
|
||||
public ENUM_ORDER_TYPE_FILLING Type_filling { get; set; } // Order execution type
|
||||
public ENUM_ORDER_TYPE_TIME Type_time { get; set; } // Order expiration type
|
||||
public DateTime Expiration { get; set; } // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime Expiration // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
|
||||
{
|
||||
get { return Mt5TimeConverter.ConvertFromMtTime(MtExpiration); }
|
||||
set { MtExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||
}
|
||||
|
||||
public string Comment { get; set; } // Order comment
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // The ticket of an opposite position
|
||||
|
||||
public int MtExpiration { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Action={Action}; Magic={Magic}; Order={Order}; Symbol={Symbol}; Volume={Volume}; Price={Price}; Stoplimit={Stoplimit}; Sl={Sl}; Tp={Tp}; Deviation={Deviation}; Type={Type}; Type_filling={Type_filling}; Type_time={Type_time}; Expiration={Expiration}; Comment={Comment}; Position={Position}; PositionBy={PositionBy}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
-12
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -19,14 +17,32 @@ namespace MtApi5
|
||||
Request_id = request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; private set; } // Operation return code
|
||||
public ulong Deal { get; private set; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; private set; } // Order ticket, if it is placed
|
||||
public double Volume { get; private set; } // Deal volume, confirmed by broker
|
||||
public double Price { get; private set; } // Deal price, confirmed by broker
|
||||
public double Bid { get; private set; } // Current Bid price
|
||||
public double Ask { get; private set; } // Current Ask price
|
||||
public string Comment { get; private set; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; private set; } // Request ID set by the terminal during the dispatch
|
||||
internal MqlTradeResult(MqlTradeResult o)
|
||||
{
|
||||
Retcode = o.Retcode;
|
||||
Deal = o.Deal;
|
||||
Order = o.Order;
|
||||
Volume = o.Volume;
|
||||
Price = o.Price;
|
||||
Bid = o.Bid;
|
||||
Ask = o.Ask;
|
||||
Comment = o.Comment;
|
||||
Request_id = o.Request_id;
|
||||
}
|
||||
|
||||
public uint Retcode { get; } // Operation return code
|
||||
public ulong Deal { get; } // Deal ticket, if it is performed
|
||||
public ulong Order { get; } // Order ticket, if it is placed
|
||||
public double Volume { get; } // Deal volume, confirmed by broker
|
||||
public double Price { get; } // Deal price, confirmed by broker
|
||||
public double Bid { get; } // Current Bid price
|
||||
public double Ask { get; } // Current Ask price
|
||||
public string Comment { get; } // Broker comment to operation (by default it is filled by the operation description)
|
||||
public uint Request_id { get; } // Request ID set by the terminal during the dispatch
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Retcode={Retcode}; Comment={Comment}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Request_id={Request_id}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeTransaction
|
||||
{
|
||||
public ulong Deal { get; set; } // Deal ticket
|
||||
public ulong Order { get; set; } // Order ticket
|
||||
public string Symbol { get; set; } // Trade symbol name
|
||||
public ENUM_TRADE_TRANSACTION_TYPE Type { get; set; } // Trade transaction type
|
||||
public ENUM_ORDER_TYPE OrderType { get; set; } // Order type
|
||||
public ENUM_ORDER_STATE OrderState { get; set; } // Order state
|
||||
public ENUM_DEAL_TYPE DealType { get; set; } // Deal type
|
||||
public ENUM_ORDER_TYPE_TIME TimeType { get; set; } // Order type by action period
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime TimeExpiration // Order expiration time
|
||||
{
|
||||
get { return Mt5TimeConverter.ConvertFromMtTime(MtTimeExpiration); }
|
||||
set { MtTimeExpiration = Mt5TimeConverter.ConvertToMtTime(value); }
|
||||
}
|
||||
|
||||
public double Price { get; set; } // Price
|
||||
public double PriceTrigger { get; set; } // Stop limit order activation price
|
||||
public double PriceSl { get; set; } // Stop Loss level
|
||||
public double PriceTp { get; set; } // Take Profit level
|
||||
public double Volume { get; set; } // Volume in lots
|
||||
public ulong Position { get; set; } // Position ticket
|
||||
public ulong PositionBy { get; set; } // Ticket of an opposite position
|
||||
|
||||
public int MtTimeExpiration { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Deal={Deal}; Order={Order}; Symbol={Symbol}; Type={Type}; OrderType={OrderType}; OrderState={OrderState}; DealType={DealType}; TimeType={TimeType}; TimeExpiration={TimeExpiration}; Price={Price}; PriceTrigger{PriceTrigger}; PriceSl={PriceSl}; PriceTp={PriceTp}; Volume={Volume}; Position={Position}; PositionBy={PositionBy}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5BookEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public string Symbol { get; set; } //Symbol of OnBookEvent event.
|
||||
}
|
||||
}
|
||||
+152
-10
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5
|
||||
{
|
||||
internal enum Mt5CommandType
|
||||
@@ -10,10 +6,9 @@ namespace MtApi5
|
||||
//NoCommand = 0
|
||||
|
||||
//trade operations
|
||||
OrderSend = 1,
|
||||
//OrderSend = 1,
|
||||
OrderCalcMargin = 2,
|
||||
OrderCalcProfit = 3,
|
||||
OrderCheck = 4,
|
||||
//OrderSendAsync = 5,
|
||||
PositionsTotal = 6,
|
||||
PositionGetSymbol = 7,
|
||||
@@ -21,6 +16,7 @@ namespace MtApi5
|
||||
PositionGetDouble = 9,
|
||||
PositionGetInteger = 10,
|
||||
PositionGetString = 11,
|
||||
PositionGetTicket = 4,
|
||||
OrdersTotal = 12,
|
||||
OrderGetTicket = 13,
|
||||
OrderSelect = 14,
|
||||
@@ -99,20 +95,166 @@ namespace MtApi5
|
||||
SymbolInfoSessionTrade = 59,
|
||||
MarketBookAdd = 60,
|
||||
MarketBookRelease = 61,
|
||||
MarketBookGet = 62,
|
||||
//MarketBookGet = 62,
|
||||
OrderCloseAll = 63,
|
||||
|
||||
//CTrade
|
||||
PositionClose = 64,
|
||||
PositionOpen = 65,
|
||||
PositionModify = 6066,
|
||||
PositionClosePartial_bySymbol = 6067,
|
||||
PositionClosePartial_byTicket = 6068,
|
||||
//PositionOpenWithResult = 1065,
|
||||
|
||||
//Backtesting
|
||||
BacktestingReady = 66,
|
||||
IsTesting = 67,
|
||||
|
||||
Print = 68,
|
||||
|
||||
//Requests
|
||||
MtRequest = 155,
|
||||
|
||||
PositionSelectByTicket = 69,
|
||||
|
||||
ObjectCreate = 70,
|
||||
ObjectName = 71,
|
||||
ObjectDelete = 72,
|
||||
ObjectsDeleteAll = 73,
|
||||
ObjectFind = 74,
|
||||
ObjectGetTimeByValue = 75,
|
||||
ObjectGetValueByTime = 76,
|
||||
ObjectMove = 77,
|
||||
ObjectsTotal = 78,
|
||||
ObjectGetDouble = 79,
|
||||
ObjectGetInteger = 80,
|
||||
ObjectGetString = 81,
|
||||
ObjectSetDouble = 82,
|
||||
ObjectSetInteger = 83,
|
||||
ObjectSetString = 84,
|
||||
//TextSetFont = 85,
|
||||
//TextOut = 86,
|
||||
//TextGetSize = 87,
|
||||
|
||||
iAC = 88,
|
||||
iAD = 89,
|
||||
iADX = 90,
|
||||
iADXWilder = 91,
|
||||
iAlligator = 92,
|
||||
iAMA = 93,
|
||||
iAO = 94,
|
||||
iATR = 95,
|
||||
iBearsPower = 96,
|
||||
iBands = 97,
|
||||
iBullsPower = 98,
|
||||
iCCI = 99,
|
||||
iChaikin = 100,
|
||||
//iCustom = 101,
|
||||
iDEMA = 102,
|
||||
iDeMarker = 103,
|
||||
iEnvelopes = 104,
|
||||
iForce = 105,
|
||||
iFractals = 106,
|
||||
iFrAMA = 107,
|
||||
iGator = 108,
|
||||
iIchimoku = 109,
|
||||
iBWMFI = 110,
|
||||
iMomentum = 111,
|
||||
iMFI = 112,
|
||||
iMA = 113,
|
||||
iOsMA = 114,
|
||||
iMACD = 115,
|
||||
iOBV = 116,
|
||||
iSAR = 117,
|
||||
iRSI = 118,
|
||||
iRVI = 119,
|
||||
iStdDev = 120,
|
||||
iStochastic = 121,
|
||||
iTEMA = 122,
|
||||
iTriX = 123,
|
||||
iWPR = 124,
|
||||
iVIDyA = 125,
|
||||
iVolumes = 126,
|
||||
|
||||
//Date and Time
|
||||
TimeCurrent = 127,
|
||||
TimeTradeServer = 128,
|
||||
TimeLocal = 129,
|
||||
TimeGMT = 130,
|
||||
|
||||
IndicatorRelease = 131,
|
||||
|
||||
//Chart Operations
|
||||
ChartId = 206,
|
||||
ChartRedraw = 207,
|
||||
ChartApplyTemplate = 236,
|
||||
ChartSaveTemplate = 237,
|
||||
ChartWindowFind = 238,
|
||||
//ChartTimePriceToXY = 239,
|
||||
//ChartXYToTimePrice = 240,
|
||||
ChartOpen = 241,
|
||||
ChartFirst = 242,
|
||||
ChartNext = 243,
|
||||
ChartClose = 244,
|
||||
ChartSymbol = 245,
|
||||
ChartPeriod = 246,
|
||||
ChartSetDouble = 247,
|
||||
ChartSetInteger = 248,
|
||||
ChartSetString = 249,
|
||||
ChartGetDouble = 250,
|
||||
ChartGetInteger = 251,
|
||||
ChartGetString = 252,
|
||||
ChartNavigate = 253,
|
||||
ChartIndicatorDelete = 254,
|
||||
ChartIndicatorName = 255,
|
||||
ChartIndicatorsTotal = 256,
|
||||
ChartWindowOnDropped = 257,
|
||||
ChartPriceOnDropped = 258,
|
||||
ChartTimeOnDropped = 259,
|
||||
ChartXOnDropped = 260,
|
||||
ChartYOnDropped = 261,
|
||||
ChartSetSymbolPeriod = 262,
|
||||
ChartScreenShot = 263,
|
||||
ChartIndicatorAdd = 280,
|
||||
ChartIndicatorGet = 281,
|
||||
|
||||
// Terminal Operations
|
||||
TerminalCompany = 68,
|
||||
TerminalName = 69,
|
||||
TerminalPath = 70,
|
||||
|
||||
//Checkup
|
||||
GetLastError = 132,
|
||||
TerminalInfoString = 153,
|
||||
TerminalInfoInteger = 204,
|
||||
TerminalInfoDouble = 205,
|
||||
|
||||
//Common Functions
|
||||
Alert = 136,
|
||||
Comment = 137, //TODO
|
||||
GetTickCount = 138, //TODO
|
||||
GetMicrosecondCount = 139, //TODO
|
||||
MessageBox = 140, //TODO
|
||||
PeriodSeconds = 141, //TODO
|
||||
PlaySound = 142, //TODO
|
||||
Print = 68,
|
||||
ResetLastError = 143,
|
||||
SendNotification = 144, //TODO
|
||||
SendMail = 145, //TODO
|
||||
|
||||
//Global Variables
|
||||
GlobalVariableCheck = 146,
|
||||
GlobalVariableTime = 147,
|
||||
GlobalVariableDel = 148,
|
||||
GlobalVariableGet = 149,
|
||||
GlobalVariableName = 150,
|
||||
GlobalVariableSet = 151,
|
||||
GlobalVariablesFlush = 152,
|
||||
GlobalVariableTemp = 154,
|
||||
GlobalVariableSetOnCondition = 156,
|
||||
GlobalVariablesDeleteAll = 157,
|
||||
GlobalVariablesTotal = 158,
|
||||
|
||||
UnlockTicks = 159,
|
||||
PositionCloseAll = 160,
|
||||
TesterStop = 161
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace MtApi5
|
||||
{
|
||||
public class Mt5ConnectionEventArgs: EventArgs
|
||||
{
|
||||
public Mt5ConnectionState Status { get; private set; }
|
||||
public string ConnectionMessage { get; private set; }
|
||||
public Mt5ConnectionState Status { get; }
|
||||
public string ConnectionMessage { get; }
|
||||
|
||||
public Mt5ConnectionEventArgs(Mt5ConnectionState status, string message)
|
||||
{
|
||||
|
||||
+821
-212
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5LockTicksEventArgs : EventArgs
|
||||
{
|
||||
internal Mt5LockTicksEventArgs(string symbol)
|
||||
{
|
||||
Symbol = symbol;
|
||||
}
|
||||
|
||||
public string Symbol { get; }
|
||||
}
|
||||
}
|
||||
+17
-7
@@ -1,21 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MTApiService;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5Quote
|
||||
{
|
||||
public string Instrument { get; private set; }
|
||||
public double Bid { get; private set; }
|
||||
public double Ask { get; private set; }
|
||||
public string Instrument { get; }
|
||||
public double Bid { get; }
|
||||
public double Ask { get; }
|
||||
public int ExpertHandle { get; set; }
|
||||
public DateTime Time { get; set; }
|
||||
public double Last { get; set; }
|
||||
public ulong Volume { get; set; }
|
||||
// public long TimeMsc { get; set; }
|
||||
// public uint Flags { get; set; }
|
||||
|
||||
public Mt5Quote(string instrument, double bid, double ask)
|
||||
internal Mt5Quote(string instrument, double bid, double ask)
|
||||
{
|
||||
Instrument = instrument;
|
||||
Bid = bid;
|
||||
Ask = ask;
|
||||
}
|
||||
|
||||
internal Mt5Quote(MtQuote quote)
|
||||
:this(quote.Instrument, quote.Bid, quote.Ask)
|
||||
{
|
||||
ExpertHandle = quote.ExpertHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5QuoteEventArgs: EventArgs
|
||||
{
|
||||
public Mt5Quote Quote { get; private set; }
|
||||
public Mt5Quote Quote { get; }
|
||||
|
||||
public Mt5QuoteEventArgs(Mt5Quote quote)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5TimeBarArgs: EventArgs
|
||||
{
|
||||
internal Mt5TimeBarArgs(int expertHandle, string symbol, MqlRates rates)
|
||||
{
|
||||
ExpertHandle = expertHandle;
|
||||
Rates = rates;
|
||||
Symbol = symbol;
|
||||
}
|
||||
|
||||
public int ExpertHandle { get; }
|
||||
public string Symbol { get; }
|
||||
public MqlRates Rates { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
class Mt5TimeConverter
|
||||
internal class Mt5TimeConverter
|
||||
{
|
||||
public static DateTime ConvertFromMtTime(int time)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||
}
|
||||
|
||||
public static DateTime ConvertFromMtTime(long time)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
return new DateTime(tmpTime.Ticks + (time * 0x989680L));
|
||||
}
|
||||
|
||||
public static int ConvertToMtTime(DateTime time)
|
||||
public static int ConvertToMtTime(DateTime? time)
|
||||
{
|
||||
int result = 0;
|
||||
if (time != DateTime.MinValue)
|
||||
{
|
||||
DateTime tmpTime = new DateTime(1970, 1, 1);
|
||||
result = (int)((time.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||
}
|
||||
var result = 0;
|
||||
if (time == null || time == DateTime.MinValue)
|
||||
return result;
|
||||
var tmpTime = new DateTime(1970, 1, 1);
|
||||
result = (int)((time.Value.Ticks - tmpTime.Ticks) / 0x989680L);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class Mt5TradeTransactionEventArgs : EventArgs
|
||||
{
|
||||
public int ExpertHandle { get; set; }
|
||||
public MqlTradeTransaction Trans { get; set; } // trade transaction structure
|
||||
public MqlTradeRequest Request { get; set; } // request structure
|
||||
public MqlTradeResult Result { get; set; } // result structure
|
||||
}
|
||||
}
|
||||
+32
-4
@@ -32,8 +32,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
@@ -48,10 +48,20 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CopyTicksFlag.cs" />
|
||||
<Compile Include="Events\OnBookEvent.cs" />
|
||||
<Compile Include="Events\OnLastTimeBarEvent.cs" />
|
||||
<Compile Include="Events\OnLockTicksEvent.cs" />
|
||||
<Compile Include="Events\OnTickEvent.cs" />
|
||||
<Compile Include="Events\OnTradeTransactionEvent.cs" />
|
||||
<Compile Include="Mt5LockTicksEventArgs.cs" />
|
||||
<Compile Include="Mt5TimeBarArgs.cs" />
|
||||
<Compile Include="MqlBookInfo.cs" />
|
||||
<Compile Include="MqlParam.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MqlTick.cs" />
|
||||
<Compile Include="MqlTradeCheckResult.cs" />
|
||||
<Compile Include="MqlTradeTransaction.cs" />
|
||||
<Compile Include="Mt5BookEventArgs.cs" />
|
||||
<Compile Include="Mt5TimeConverter.cs" />
|
||||
<Compile Include="Mt5Enums.cs" />
|
||||
<Compile Include="Mt5ConnectionEventArgs.cs" />
|
||||
@@ -59,18 +69,36 @@
|
||||
<Compile Include="MqlTradeRequest.cs" />
|
||||
<Compile Include="MqlTradeResult.cs" />
|
||||
<Compile Include="Mt5QuoteEventArgs.cs" />
|
||||
<Compile Include="Mt5TradeTransactionEventArgs.cs" />
|
||||
<Compile Include="MtApi5Client.cs" />
|
||||
<Compile Include="Mt5CommandType.cs" />
|
||||
<Compile Include="MtConverters.cs" />
|
||||
<Compile Include="ErrorCode.cs" />
|
||||
<Compile Include="ExecutionException.cs" />
|
||||
<Compile Include="Events\Mt5EventTypes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Mt5Quote.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyRequest.cs" />
|
||||
<Compile Include="Requests\ChartTimePriceToXyResult.cs" />
|
||||
<Compile Include="Requests\ChartXyToTimePriceRequest.cs" />
|
||||
<Compile Include="Requests\ChartXyToTimePriceResult.cs" />
|
||||
<Compile Include="Requests\CopyTicksRequest.cs" />
|
||||
<Compile Include="Requests\ICustomRequest.cs" />
|
||||
<Compile Include="Requests\IndicatorCreateRequest.cs" />
|
||||
<Compile Include="Requests\MarketBookGetRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckRequest.cs" />
|
||||
<Compile Include="Requests\OrderCheckResult.cs" />
|
||||
<Compile Include="Requests\OrderSendRequest.cs" />
|
||||
<Compile Include="Requests\PositionCloseRequest.cs" />
|
||||
<Compile Include="Requests\PositionCloseResult.cs" />
|
||||
<Compile Include="Requests\PositionOpenRequest.cs" />
|
||||
<Compile Include="Requests\RequestBase.cs" />
|
||||
<Compile Include="Requests\RequestType.cs" />
|
||||
<Compile Include="Responses\CopyTicksResponse.cs" />
|
||||
<Compile Include="Responses\ResponseBase.cs" />
|
||||
<Compile Include="Requests\OrderSendResult.cs" />
|
||||
<Compile Include="Requests\Response.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
||||
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
|
||||
+1878
-63
File diff suppressed because it is too large
Load Diff
+19
-77
@@ -6,84 +6,14 @@ namespace MtApi5
|
||||
{
|
||||
internal static class MtConverters
|
||||
{
|
||||
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtConverters));
|
||||
|
||||
#region Values Converters
|
||||
public static Mt5Quote Parse(this MtQuote quote)
|
||||
{
|
||||
return (quote != null) ? new Mt5Quote(quote.Instrument, quote.Bid, quote.Ask) : null;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeResult result)
|
||||
{
|
||||
var retVal = false;
|
||||
result = null;
|
||||
|
||||
if (string.IsNullOrEmpty(inputString) == false)
|
||||
{
|
||||
var values = inputString.Split(separator);
|
||||
if (values.Length == 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
retVal = int.Parse(values[0]) != 0;
|
||||
|
||||
var retcode = uint.Parse(values[1]);
|
||||
var deal = ulong.Parse(values[2]);
|
||||
var order = ulong.Parse(values[3]);
|
||||
var volume = double.Parse(values[4]);
|
||||
var price = double.Parse(values[5]);
|
||||
var bid = double.Parse(values[6]);
|
||||
var ask = double.Parse(values[7]);
|
||||
var comment = values[8];
|
||||
var requestId = uint.Parse(values[9]);
|
||||
|
||||
result = new MqlTradeResult(retcode, deal, order, volume, price, bid, ask, comment, requestId);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out MqlTradeCheckResult result)
|
||||
{
|
||||
var retVal = false;
|
||||
result = null;
|
||||
|
||||
if (string.IsNullOrEmpty(inputString) == false)
|
||||
{
|
||||
var values = inputString.Split(separator);
|
||||
if (values.Length == 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
retVal = int.Parse(values[0]) != 0;
|
||||
|
||||
var retcode = uint.Parse(values[1]);
|
||||
var balance = double.Parse(values[2]);
|
||||
var equity = double.Parse(values[3]);
|
||||
var profit = double.Parse(values[4]);
|
||||
var margin = double.Parse(values[5]);
|
||||
var marginFree = double.Parse(values[6]);
|
||||
var marginLevel = double.Parse(values[7]);
|
||||
var comment = values[8];
|
||||
|
||||
result = new MqlTradeCheckResult(retcode, balance, equity, profit, margin, marginFree, marginLevel, comment);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
retVal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out double result)
|
||||
{
|
||||
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||
|
||||
var retVal = false;
|
||||
result = 0;
|
||||
|
||||
@@ -98,18 +28,25 @@ namespace MtApi5
|
||||
|
||||
result = double.Parse(values[1]);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal = false;
|
||||
Log.Error($"ParseResult: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("ParseResult: input srting is null or empty!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool ParseResult(this string inputString, char separator, out DateTime from, out DateTime to)
|
||||
{
|
||||
Log.Debug($"ParseResult: inputString = {inputString}, separator = {separator}");
|
||||
|
||||
var retVal = false;
|
||||
|
||||
from = new DateTime();
|
||||
@@ -130,12 +67,17 @@ namespace MtApi5
|
||||
var iTo= int.Parse(values[2]);
|
||||
to = Mt5TimeConverter.ConvertFromMtTime(iTo);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal = false;
|
||||
Log.Error($"ParseResult: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn("ParseResult: input srting is null or empty!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
@@ -149,7 +91,7 @@ namespace MtApi5
|
||||
|
||||
return new ArrayList { (int)request.Action, request.Magic, request.Order, request.Symbol, request.Volume
|
||||
, request.Price, request.Stoplimit, request.Sl, request.Tp, request.Deviation, (int)request.Type
|
||||
, (int)request.Type_filling, (int)request.Type_time, exp, request.Comment };
|
||||
, (int)request.Type_filling, (int)request.Type_time, exp, request.Comment, request.Position, request.PositionBy };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.12")]
|
||||
[assembly: AssemblyFileVersion("1.0.12")]
|
||||
[assembly: AssemblyVersion("1.0.22")]
|
||||
[assembly: AssemblyFileVersion("1.0.22")]
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ChartTimePriceToXyRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.ChartTimePriceToXY;
|
||||
|
||||
public long ChartId { get; set; }
|
||||
public int SubWindow { get; set; }
|
||||
public DateTime? Time { get; set; }
|
||||
public double Price { get; set; }
|
||||
|
||||
public int MtTime => Mt5TimeConverter.ConvertToMtTime(Time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ChartTimePriceToXyResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ChartXyToTimePriceRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.ChartXYToTimePrice;
|
||||
|
||||
public long ChartId { get; set; }
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ChartXyToTimePriceResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public int SubWindow { get; set; }
|
||||
public DateTime? Time => Mt5TimeConverter.ConvertFromMtTime(MtTime);
|
||||
public double Price { get; set; }
|
||||
|
||||
public int MtTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class ICustomRequest : RequestBase
|
||||
{
|
||||
public enum ParametersType
|
||||
{
|
||||
Int = 0,
|
||||
Double = 1,
|
||||
String = 2,
|
||||
Boolean = 3
|
||||
}
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public int Timeframe { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ArrayList Params { get; set; }
|
||||
public ParametersType ParamsType { get; set; }
|
||||
|
||||
public override RequestType RequestType => RequestType.iCustom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class IndicatorCreateRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.IndicatorCreate;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
public ENUM_TIMEFRAMES Period { get; set; }
|
||||
public ENUM_INDICATOR IndicatorType { get; set; }
|
||||
public List<MqlParam> Parameters { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class MarketBookGetRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.MarketBookGet;
|
||||
|
||||
public string Symbol { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderCheckRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderCheck;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
public class OrderCheckResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeCheckResult TradeCheckResult { get; set; }
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user