mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9eedf15e9e | |||
| 373bfe4997 | |||
| 0cd8edb933 | |||
| a66f18c2b3 | |||
| 71964c3303 | |||
| 4e7f8b93f4 | |||
| 5715e7e2b8 | |||
| 833ce1f192 | |||
| 724162f29d | |||
| 739567d871 | |||
| a12ddba765 | |||
| 9a5acac2db | |||
| 7a776de8d3 | |||
| ce7953eee0 | |||
| 93aed4e44c | |||
| 4c8c3b8766 | |||
| 73ebde8b6b | |||
| 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 |
@@ -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")]
|
||||
@@ -31,22 +31,6 @@ 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)
|
||||
@@ -104,6 +88,14 @@ _DLLAPI int _stdcall updateQuote(int expertHandle, wchar_t* symbol, double bid,
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
_DLLAPI bool _stdcall sendEvent(int expertHandle, int eventType, wchar_t* payload, wchar_t* err)
|
||||
{
|
||||
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]() {
|
||||
@@ -156,7 +148,7 @@ _DLLAPI int _stdcall sendStringResponse(int expertHandle, wchar_t* response, wch
|
||||
_DLLAPI int _stdcall sendVoidResponse(int expertHandle, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle]() {
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, nullptr);
|
||||
MtAdapter::GetInstance()->SendResponse(expertHandle, gcnew MtResponseObject(nullptr));
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
@@ -216,35 +208,14 @@ _DLLAPI int _stdcall sendMqlRatesArrayResponse(int expertHandle, CMqlRates value
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
_DLLAPI int _stdcall sendMqlTickResponse(int expertHandle, CMqlTick* response, wchar_t* err)
|
||||
_DLLAPI bool _stdcall sendErrorResponse(int expertHandle, int code, wchar_t* message, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle, response]() {
|
||||
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));
|
||||
return 1;
|
||||
}, err, 0);
|
||||
}
|
||||
|
||||
_DLLAPI int _stdcall sendMqlBookInfoArrayResponse(int expertHandle, CMqlBookInfo values[], int size, wchar_t* err)
|
||||
{
|
||||
return Execute<int>([&expertHandle, values, &size]() {
|
||||
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));
|
||||
return 1;
|
||||
}, err, 0);
|
||||
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 -------------------------------
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -8,24 +8,89 @@ 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 enum LogLevel
|
||||
{
|
||||
Off,
|
||||
Debug,
|
||||
Info
|
||||
}
|
||||
|
||||
public class LogConfigurator
|
||||
{
|
||||
private const string LogFileNameExtension = "txt";
|
||||
private const string LogFileNameExtension = "log";
|
||||
|
||||
public static void Setup(string profileName)
|
||||
{
|
||||
#if (DEBUG)
|
||||
const LogLevel logLevel = LogLevel.Debug;
|
||||
#else
|
||||
const LogLevel logLevel = LogLevel.Info;
|
||||
#endif
|
||||
Setup(profileName, logLevel);
|
||||
}
|
||||
|
||||
public static void Setup(string profileName, LogLevel logLevel)
|
||||
{
|
||||
if (string.IsNullOrEmpty(profileName))
|
||||
throw new ArgumentNullException();
|
||||
|
||||
var hierarchy = (Hierarchy) LogManager.GetRepository();
|
||||
|
||||
//check if logger is already configurated to avoid creation many empty logs files
|
||||
if (hierarchy.Configured)
|
||||
return;
|
||||
|
||||
var patternLayout = new PatternLayout
|
||||
{
|
||||
ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
|
||||
};
|
||||
patternLayout.ActivateOptions();
|
||||
|
||||
string filename = $"{DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}-{Process.GetCurrentProcess().Id}.{LogFileNameExtension}";
|
||||
var filename = $"{DateTime.Now:yyyy-dd-M--HH-mm-ss}-{Process.GetCurrentProcess().Id}.{LogFileNameExtension}";
|
||||
|
||||
var roller = new RollingFileAppender
|
||||
{
|
||||
@@ -40,13 +105,28 @@ namespace MTApiService
|
||||
};
|
||||
roller.ActivateOptions();
|
||||
hierarchy.Root.AddAppender(roller);
|
||||
|
||||
#if (DEBUG)
|
||||
hierarchy.Root.Level = Level.Debug;
|
||||
#else
|
||||
hierarchy.Root.Level = Level.Info;
|
||||
#endif
|
||||
hierarchy.Root.Level = ConvertLogLevel(logLevel);
|
||||
hierarchy.Configured = true;
|
||||
}
|
||||
|
||||
public static MtLog GetLogger(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
|
||||
return new MtLog(type);
|
||||
}
|
||||
|
||||
private static Level ConvertLogLevel(LogLevel logLevel)
|
||||
{
|
||||
switch (logLevel)
|
||||
{
|
||||
case LogLevel.Debug: return Level.Debug;
|
||||
case LogLevel.Info: return Level.Info;
|
||||
case LogLevel.Off: return Level.Off;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,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" />
|
||||
|
||||
+41
-12
@@ -4,35 +4,51 @@ namespace MTApiService
|
||||
{
|
||||
public class Mt5Expert : MtExpert
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(MtExpert));
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Mt5Expert));
|
||||
private const int StopExpertInterval = 2000; // 2 sec for testing mode
|
||||
private readonly System.Timers.Timer _stopTimer = new System.Timers.Timer();
|
||||
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;
|
||||
_stopTimer.Interval = StopExpertInterval;
|
||||
_stopTimer.Elapsed += _stopTimer_Elapsed;
|
||||
}
|
||||
|
||||
public bool IsTestMode { get; }
|
||||
|
||||
public override void UpdateQuote(MtQuote quote)
|
||||
public override int GetCommandType()
|
||||
{
|
||||
Log.Debug("UpdateQuote: begin.");
|
||||
|
||||
base.UpdateQuote(quote);
|
||||
Log.Debug("GetCommandType: called.");
|
||||
|
||||
if (IsTestMode)
|
||||
{
|
||||
//reset timer
|
||||
_stopTimer.Stop();
|
||||
_stopTimer.Start();
|
||||
ResetTestModeTimer();
|
||||
}
|
||||
|
||||
Log.Debug("UpdateQuote: end.");
|
||||
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)
|
||||
@@ -42,7 +58,20 @@ namespace MTApiService
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@ namespace MTApiService
|
||||
}
|
||||
|
||||
server.AddExpert(expert);
|
||||
expert.Deinited += ExpertOnDeinited;
|
||||
|
||||
Log.Info("AddExpert: end");
|
||||
}
|
||||
@@ -81,7 +82,6 @@ namespace MTApiService
|
||||
if (_experts.ContainsKey(expertHandle))
|
||||
{
|
||||
expert = _experts[expertHandle];
|
||||
_experts.Remove(expertHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace MTApiService
|
||||
Log.Debug("SendResponse: end.");
|
||||
}
|
||||
|
||||
public int GetCommandType()
|
||||
public virtual int GetCommandType()
|
||||
{
|
||||
Log.Debug("GetCommandType: called.");
|
||||
|
||||
@@ -110,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);
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace MTApiService
|
||||
Log.Debug("SendEvent: end.");
|
||||
}
|
||||
|
||||
public virtual void UpdateQuote(MtQuote quote)
|
||||
public void UpdateQuote(MtQuote quote)
|
||||
{
|
||||
Log.DebugFormat("UpdateQuote: begin. quote = {0}", quote);
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.28.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.28.0")]
|
||||
[assembly: AssemblyVersion("1.0.33.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.33.0")]
|
||||
@@ -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">
|
||||
|
||||
@@ -10,8 +10,13 @@ namespace MtApi.Monitors
|
||||
Opened = opened;
|
||||
Closed = closed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains all newly opened orders since the last time the monitor checked the open orders.
|
||||
/// </summary>
|
||||
public List<MtOrder> Opened { get; private set; }
|
||||
/// <summary>
|
||||
/// Contains all newly closed orders since the last time the monitor checked the open orders.
|
||||
/// </summary>
|
||||
public List<MtOrder> Closed { get; private set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using MtApi.Monitors.Triggers;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public abstract class MtMonitorBase
|
||||
{
|
||||
#region Fields
|
||||
private volatile bool _isStarted = false;
|
||||
private bool _syncTrigger;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// ApiClient
|
||||
/// </summary>
|
||||
protected MtApiClient ApiClient { get; }
|
||||
/// <summary>
|
||||
/// Returns true if the <see cref="ApiClient"/> is connected.
|
||||
/// </summary>
|
||||
public bool IsMtConnected => ApiClient.ConnectionState == MtConnectionState.Connected;
|
||||
/// <summary>
|
||||
/// Returns the trigger which will be used to raise the monitoring call.
|
||||
/// </summary>
|
||||
public IMonitorTrigger MonitorTrigger { get; }
|
||||
/// <summary>
|
||||
/// Returns true if the Monitor is started.
|
||||
/// </summary>
|
||||
public bool IsStarted { get => _isStarted; }
|
||||
/// <summary>
|
||||
/// If true, the <see cref="MonitorTrigger"/> will be stopped or started automatically when <see cref="Start"/> or <see cref="Stop"/> will be called.
|
||||
/// <para>CAUTION: If you use the MonitorTrigger for different Monitors, this will stop all monitors if you call stop and <see cref="SyncTrigger"/> is <c>true</c>.</para>
|
||||
/// </summary>
|
||||
public bool SyncTrigger { get => _syncTrigger; set => _syncTrigger = value; }
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
/// <summary>
|
||||
/// Default constructor for Monitors
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The apiClient which will be used to work with.</param>
|
||||
/// <param name="monitorTrigger">The trigger which lead this Monitor to do his work.</param>
|
||||
/// <param name="syncTrigger">See property <see cref="SyncTrigger"/>.</param>
|
||||
public MtMonitorBase(MtApiClient apiClient, IMonitorTrigger monitorTrigger, bool syncTrigger = false)
|
||||
{
|
||||
ApiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
|
||||
MonitorTrigger = monitorTrigger ?? throw new ArgumentNullException(nameof(monitorTrigger));
|
||||
SyncTrigger = syncTrigger;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
/// <summary>
|
||||
/// Let the monitor listen to the <see cref="MonitorTrigger"/>.
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
if (!_isStarted)
|
||||
{
|
||||
ApiClient.ConnectionStateChanged += ApiClientConnectionStateChanged;
|
||||
MonitorTrigger.Raised += MonitorTriggerRaised;
|
||||
_isStarted = true;
|
||||
OnStart();
|
||||
if (SyncTrigger)
|
||||
MonitorTrigger.Start();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Let the monitor stop listening to the <see cref="MonitorTrigger"/>.
|
||||
/// </summary>
|
||||
public virtual void Stop()
|
||||
{
|
||||
if (_isStarted)
|
||||
{
|
||||
MonitorTrigger.Raised -= MonitorTriggerRaised;
|
||||
ApiClient.ConnectionStateChanged -= ApiClientConnectionStateChanged;
|
||||
_isStarted = false;
|
||||
OnStop();
|
||||
if (SyncTrigger)
|
||||
MonitorTrigger.Stop();
|
||||
}
|
||||
}
|
||||
private void MonitorTriggerRaised(object sender, EventArgs e) => OnTriggerRaised();
|
||||
private void ApiClientConnectionStateChanged(object sender, MtConnectionEventArgs e)
|
||||
{
|
||||
if (e.Status == MtConnectionState.Connected)
|
||||
OnMtConnected();
|
||||
else if (e.Status == MtConnectionState.Failed || e.Status == MtConnectionState.Disconnected)
|
||||
OnMtDisconnected();
|
||||
}
|
||||
/// <summary>
|
||||
/// Will be called when <see cref="Start"/> will be called.
|
||||
/// </summary>
|
||||
protected virtual void OnStart() { }
|
||||
/// <summary>
|
||||
/// Will be called when <see cref="Stop"/> will be called.
|
||||
/// </summary>
|
||||
protected virtual void OnStop() { }
|
||||
/// <summary>
|
||||
/// Will be called when the <see cref="ApiClient"/> is successfully connected.
|
||||
/// </summary>
|
||||
protected virtual void OnMtConnected() { }
|
||||
/// <summary>
|
||||
/// Will be called when <see cref="ApiClient"/> is disconnected.
|
||||
/// </summary>
|
||||
protected virtual void OnMtDisconnected() { }
|
||||
/// <summary>
|
||||
/// Will be called when the <see cref="MonitorTrigger"/> raised.
|
||||
/// </summary>
|
||||
protected abstract void OnTriggerRaised();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public class ModifiedOrdersEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a list of all modified orders
|
||||
/// </summary>
|
||||
public List<MtModifiedOrder> ModifiedOrders { get; }
|
||||
public ModifiedOrdersEventArgs(List<MtModifiedOrder> modifiedOrders)
|
||||
{
|
||||
ModifiedOrders = modifiedOrders;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using MtApi.Monitors.Triggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public class ModifiedOrdersMonitor : MtMonitorBase
|
||||
{
|
||||
#region Fields
|
||||
private List<MtOrder> _lastOrders = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Define on which types of modification this monitor should raise <see cref="OrdersModified"/>
|
||||
/// </summary>
|
||||
public OrderModifiedTypes OrderModifiedTypes { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Will be raised when this monitor detects changes on open orders
|
||||
/// </summary>
|
||||
public event EventHandler<ModifiedOrdersEventArgs> OrdersModified;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
public ModifiedOrdersMonitor(MtApiClient apiClient, IMonitorTrigger monitorTrigger, OrderModifiedTypes orderModifiedTypes = OrderModifiedTypes.All, bool syncTrigger = false)
|
||||
: base(apiClient, monitorTrigger, syncTrigger)
|
||||
{
|
||||
_lastOrders = GetOrders();
|
||||
OrderModifiedTypes = orderModifiedTypes;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Requests all current open orders
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private List<MtOrder> GetOrders() => IsMtConnected ? ApiClient.GetOrders(OrderSelectSource.MODE_TRADES) : null;
|
||||
protected override void OnTriggerRaised()
|
||||
{
|
||||
if(_lastOrders == null)
|
||||
{
|
||||
_lastOrders = GetOrders();
|
||||
return;
|
||||
}
|
||||
List<MtOrder> currentOrders = GetOrders();
|
||||
OrderModifiedTypes omt = OrderModifiedTypes;
|
||||
var mtModifiedOrders = currentOrders
|
||||
.Select(co => new MtModifiedOrder(_lastOrders.FirstOrDefault(x => x.Ticket == co.Ticket), co))
|
||||
.ToList();
|
||||
List<MtModifiedOrder> modifiedOrders = new List<MtModifiedOrder>();
|
||||
modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.TakeProfit)); //If the takeprofit were changed between both calls
|
||||
modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.StopLoss)); //If the stoploss were changed between both calls
|
||||
modifiedOrders.AddRange(GetMtModifiedOrdersWithModType(mtModifiedOrders, omt, OrderModifiedTypes.Operation)); //If an order changed from limit / stop order to an open order
|
||||
if (modifiedOrders.Count > 0)
|
||||
OrdersModified?.Invoke(this, new ModifiedOrdersEventArgs(modifiedOrders));
|
||||
_lastOrders = currentOrders;
|
||||
}
|
||||
private static IEnumerable<MtModifiedOrder> GetMtModifiedOrdersWithModType(IEnumerable<MtModifiedOrder> orders, OrderModifiedTypes globalSearchFlag, OrderModifiedTypes modifiedType)
|
||||
=> globalSearchFlag.HasFlag(modifiedType) ? orders.Where(o => o.ModifyType.HasFlag(modifiedType)) : new List<MtModifiedOrder>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public class MtModifiedOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// The order in its old state (before the changes)
|
||||
/// </summary>
|
||||
public MtOrder OldOrder { get; }
|
||||
/// <summary>
|
||||
/// The order in its new state (after the changes)
|
||||
/// </summary>
|
||||
public MtOrder NewOrder { get; }
|
||||
/// <summary>
|
||||
/// The changes found by this instance
|
||||
/// </summary>
|
||||
public OrderModifiedTypes ModifyType { get; private set; }
|
||||
/// <summary>
|
||||
/// Initializes an instance and compare the order in its old and new state
|
||||
/// </summary>
|
||||
/// <param name="oldOrder">The order in its old state (before the changes)</param>
|
||||
/// <param name="newOrder">The order in its new state (after the changes)</param>
|
||||
public MtModifiedOrder(MtOrder oldOrder, MtOrder newOrder)
|
||||
{
|
||||
if (oldOrder != null && newOrder != null && oldOrder.Ticket != newOrder.Ticket)
|
||||
throw new ArgumentException(nameof(oldOrder) + " and " + nameof(newOrder) + " need to have the same ticket id");
|
||||
OldOrder = oldOrder;
|
||||
NewOrder = newOrder;
|
||||
ModifyType = OrderModifiedTypes.None;
|
||||
Compare();
|
||||
}
|
||||
private void Compare()
|
||||
{
|
||||
if(NewOrder != null && OldOrder != null)
|
||||
{
|
||||
if (OldOrder.StopLoss != NewOrder.StopLoss)
|
||||
ModifyType |= OrderModifiedTypes.StopLoss;
|
||||
if (OldOrder.TakeProfit != NewOrder.TakeProfit)
|
||||
ModifyType |= OrderModifiedTypes.TakeProfit;
|
||||
if (OldOrder.Operation != NewOrder.Operation)
|
||||
ModifyType |= OrderModifiedTypes.Operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
[Flags]
|
||||
public enum OrderModifiedTypes
|
||||
{
|
||||
None = 0x0,
|
||||
TakeProfit = 1 << 0,
|
||||
StopLoss = 1 << 1,
|
||||
Operation = 1 << 2,
|
||||
All = 7
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,18 @@
|
||||
|
||||
using MtApi.Monitors.Triggers;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public class TimeframeTradeMonitor : TradeMonitor
|
||||
{
|
||||
#region Fields
|
||||
private volatile bool _isStarted;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
public TimeframeTradeMonitor(MtApiClient apiClient)
|
||||
: base(apiClient)
|
||||
/// <summary>
|
||||
/// Constructor for initializing a new instance with a trigger instance of <see cref="NewBarTrigger"/>.
|
||||
/// <para>SyncTrigger is set to true by default</para>
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||
public TimeframeTradeMonitor(MtApiClient apiClient)
|
||||
: base(apiClient, new NewBarTrigger(apiClient))
|
||||
{
|
||||
apiClient.OnLastTimeBar += ApiClient_OnLastTimeBar;
|
||||
SyncTrigger = true; //Sync-Trigger set to true, to have the same behavior as before
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
//
|
||||
// Summary:
|
||||
// Gets a value indicating whether the TimeframeTradeMonitor should raise checking orders
|
||||
//
|
||||
// Returns:
|
||||
// true if PositionMonitor should check orders
|
||||
// otherwise, false.
|
||||
public override bool IsStarted => _isStarted;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
protected override void OnMtConnected() {}
|
||||
|
||||
protected override void OnMtDisconnected() {}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
_isStarted = true;
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
_isStarted = false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void ApiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||
{
|
||||
if (_isStarted)
|
||||
{
|
||||
Check();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +1,47 @@
|
||||
using System.Timers;
|
||||
using System;
|
||||
using MtApi.Monitors.Triggers;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public class TimerTradeMonitor : TradeMonitor
|
||||
{
|
||||
#region Fields
|
||||
private readonly Timer _timer = new Timer();
|
||||
private readonly TimeElapsedTrigger _timeElapsedTrigger;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
public TimerTradeMonitor(MtApiClient apiClient)
|
||||
: base(apiClient)
|
||||
{
|
||||
_timer.Interval = 10000; //default interval 10 sec
|
||||
_timer.Elapsed += _timer_Elapsed;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
//
|
||||
// Summary:
|
||||
// Gets or sets the interval, expressed in milliseconds, at which to check orders
|
||||
//
|
||||
// Returns:
|
||||
// The time, in milliseconds, between checking events. The value
|
||||
// must be greater than zero, and less than or equal to System.Int32.MaxValue.
|
||||
// The default is 10000 milliseconds.
|
||||
//
|
||||
// Exceptions:
|
||||
// T:System.ArgumentException:
|
||||
// The interval is less than or equal to zero.-or-The interval is greater than System.Int32.MaxValue,
|
||||
// and the PositionMonitor is currently started.
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Interval for raising the trigger
|
||||
/// </summary>
|
||||
public double Interval
|
||||
{
|
||||
get { return _timer.Interval; }
|
||||
set { _timer.Interval = value; }
|
||||
}
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Gets a value indicating whether the PositionMonitor should raise checking orders
|
||||
//
|
||||
// Returns:
|
||||
// true if TimerTradeMonitor should check orders
|
||||
// otherwise, false.
|
||||
public override bool IsStarted
|
||||
{
|
||||
get { return _timer.Enabled; }
|
||||
get => _timeElapsedTrigger.Interval.TotalMilliseconds;
|
||||
set => _timeElapsedTrigger.Interval = TimeSpan.FromMilliseconds(value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
protected override void OnStart()
|
||||
#region ctors
|
||||
/// <summary>
|
||||
/// Constructor for initializing a new instance with a default <see cref="Interval"/> of 10 seconds.
|
||||
/// <para>SyncTrigger is set to true by default</para>
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||
public TimerTradeMonitor(MtApiClient apiClient)
|
||||
: this(apiClient, new TimeElapsedTrigger(TimeSpan.FromSeconds(10)))
|
||||
{
|
||||
if (IsMtConnected)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
SyncTrigger = true; //Sync-Trigger set to true, to have the same behavior as before
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
/// <summary>
|
||||
/// Constructor for initializing a new instance with a custom instance of <see cref="TimeElapsedTrigger"/>.
|
||||
/// <para>SyncTrigger is set to false by default</para>
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||
/// <param name="timeElapsedTrigger">The custom instance of <see cref="TimeElapsedTrigger"/> which will be used to trigger this instance of <see cref="TradeMonitor"/>.</param>
|
||||
public TimerTradeMonitor(MtApiClient apiClient, TimeElapsedTrigger timeElapsedTrigger)
|
||||
: base(apiClient, timeElapsedTrigger)
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
|
||||
protected override void OnMtConnected()
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
protected override void OnMtDisconnected()
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
_timer.Elapsed -= _timer_Elapsed; //unregister from events to prevent rise condition during work with orders
|
||||
|
||||
Check();
|
||||
|
||||
_timer.Elapsed += _timer_Elapsed; //register again
|
||||
_timeElapsedTrigger = timeElapsedTrigger;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
-116
@@ -1,63 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MtApi.Monitors.Triggers;
|
||||
|
||||
namespace MtApi.Monitors
|
||||
{
|
||||
public abstract class TradeMonitor
|
||||
public class TradeMonitor : MtMonitorBase
|
||||
{
|
||||
#region Fields
|
||||
private readonly MtApiClient _apiClient;
|
||||
private List<MtOrder> _prevOrders;
|
||||
private readonly object _locker = new object();
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
protected TradeMonitor(MtApiClient apiClient)
|
||||
{
|
||||
if (apiClient == null)
|
||||
throw new ArgumentNullException(nameof(apiClient));
|
||||
|
||||
_apiClient = apiClient;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
//
|
||||
// Summary:
|
||||
// Gets a value indicating whether the TradeMonitor should raise checking orders
|
||||
//
|
||||
// Returns:
|
||||
// true if TradeMonitor should check orders
|
||||
// otherwise, false.
|
||||
public abstract bool IsStarted { get; }
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Start checking orders.
|
||||
//
|
||||
public void Start()
|
||||
{
|
||||
_apiClient.ConnectionStateChanged += _apiClient_ConnectionStateChanged;
|
||||
if (IsMtConnected)
|
||||
{
|
||||
InitialCheck();
|
||||
}
|
||||
|
||||
OnStart();
|
||||
}
|
||||
|
||||
//
|
||||
// Summary:
|
||||
// Stop checking orders.
|
||||
//
|
||||
public void Stop()
|
||||
{
|
||||
_apiClient.ConnectionStateChanged -= _apiClient_ConnectionStateChanged;
|
||||
OnStop();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
//
|
||||
// Summary:
|
||||
@@ -65,17 +20,34 @@ namespace MtApi.Monitors
|
||||
public event EventHandler<AvailabilityOrdersEventArgs> AvailabilityOrdersChanged;
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
#region ctor
|
||||
/// <summary>
|
||||
/// Constructor for initializing an instance of <see cref="TradeMonitor"/>.
|
||||
/// </summary>
|
||||
/// <param name="apiClient">The <see cref="MtApiClient"/> which will be used to communicate with MetaTrader.</param>
|
||||
/// <param name="monitorTrigger">The custom instance of <see cref="IMonitorTrigger"/> which will be used to trigger this instance of <see cref="TradeMonitor"/>.</param>
|
||||
public TradeMonitor(MtApiClient apiClient, IMonitorTrigger monitorTrigger) : base(apiClient, monitorTrigger) { }
|
||||
#endregion
|
||||
|
||||
protected abstract void OnStart();
|
||||
protected abstract void OnStop();
|
||||
protected override void OnMtConnected()
|
||||
{
|
||||
InitialCheck();
|
||||
base.OnMtConnected();
|
||||
}
|
||||
protected override void OnStart()
|
||||
{
|
||||
if (IsMtConnected)
|
||||
InitialCheck();
|
||||
base.OnStart();
|
||||
}
|
||||
|
||||
protected abstract void OnMtConnected();
|
||||
protected abstract void OnMtDisconnected();
|
||||
|
||||
public bool IsMtConnected => _apiClient.ConnectionState == MtConnectionState.Connected;
|
||||
|
||||
protected void Check()
|
||||
protected override void OnTriggerRaised()
|
||||
{
|
||||
if (IsMtConnected)
|
||||
Check();
|
||||
}
|
||||
|
||||
private void Check()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -90,92 +62,48 @@ namespace MtApi.Monitors
|
||||
//TODO: write error to log
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
private void InitialCheck()
|
||||
{
|
||||
lock (_locker)
|
||||
_prevOrders = null;
|
||||
|
||||
#region Private Methods
|
||||
Task.Factory.StartNew(Check);
|
||||
}
|
||||
private void CheckOrders()
|
||||
{
|
||||
var openedOrders = new List<MtOrder>();
|
||||
var closedOrders = new List<MtOrder>();
|
||||
List<MtOrder> prevOrders;
|
||||
|
||||
// get current orders from MetaTrader
|
||||
var tradesOrders = _apiClient.GetOrders(OrderSelectSource.MODE_TRADES);
|
||||
var tradesOrders = ApiClient.GetOrders(OrderSelectSource.MODE_TRADES);
|
||||
|
||||
List<MtOrder> prevOrders;
|
||||
lock(_locker)
|
||||
{
|
||||
lock (_locker)
|
||||
prevOrders = _prevOrders;
|
||||
}
|
||||
|
||||
if (prevOrders != null) //skip checking on first load orders
|
||||
{
|
||||
//check open orders
|
||||
foreach (var order in tradesOrders)
|
||||
{
|
||||
if (prevOrders.Find(a => a.Ticket == order.Ticket) == null)
|
||||
{
|
||||
openedOrders.Add(order);
|
||||
}
|
||||
}
|
||||
openedOrders = tradesOrders.Where(to => prevOrders.Find(a => a.Ticket == to.Ticket) == null).ToList();
|
||||
|
||||
//check closed orders
|
||||
var closeOrdersTemp = new List<MtOrder>();
|
||||
foreach (var order in prevOrders)
|
||||
{
|
||||
if (tradesOrders.Find(a => a.Ticket == order.Ticket) == null)
|
||||
{
|
||||
closeOrdersTemp.Add(order);
|
||||
}
|
||||
}
|
||||
var closeOrdersTemp = prevOrders.Where(po => tradesOrders.Find(a => a.Ticket == po.Ticket) == null).ToList();
|
||||
|
||||
if (closeOrdersTemp.Count > 0)
|
||||
{
|
||||
//get closed orders from history with actual values
|
||||
var historyOrders = _apiClient.GetOrders(OrderSelectSource.MODE_HISTORY);
|
||||
foreach (var order in closeOrdersTemp)
|
||||
{
|
||||
var closedOrder = historyOrders.Find(a => a.Ticket == order.Ticket);
|
||||
if (closedOrder != null)
|
||||
{
|
||||
closedOrders.Add(closedOrder);
|
||||
}
|
||||
}
|
||||
var historyOrders = ApiClient.GetOrders(OrderSelectSource.MODE_HISTORY);
|
||||
closedOrders = closeOrdersTemp.Where(cot => historyOrders.Find(a => a.Ticket == cot.Ticket) != null).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
lock(_locker)
|
||||
{
|
||||
lock (_locker)
|
||||
_prevOrders = tradesOrders;
|
||||
}
|
||||
|
||||
if (openedOrders.Count > 0 || closedOrders.Count > 0)
|
||||
{
|
||||
AvailabilityOrdersChanged?.Invoke(this, new AvailabilityOrdersEventArgs(openedOrders, closedOrders));
|
||||
}
|
||||
}
|
||||
|
||||
private void _apiClient_ConnectionStateChanged(object sender, MtConnectionEventArgs e)
|
||||
{
|
||||
if (e.Status == MtConnectionState.Connected)
|
||||
{
|
||||
InitialCheck();
|
||||
OnMtConnected();
|
||||
}
|
||||
else if (e.Status == MtConnectionState.Failed || e.Status == MtConnectionState.Disconnected)
|
||||
{
|
||||
OnMtDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitialCheck()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_prevOrders = null;
|
||||
}
|
||||
|
||||
Task.Factory.StartNew(Check);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi.Monitors.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for triggers which can be used to trigger a <see cref="MtMonitorBase"/>.
|
||||
/// </summary>
|
||||
public interface IMonitorTrigger
|
||||
{
|
||||
/// <summary>
|
||||
/// Event will be called if the trigger raised.
|
||||
/// </summary>
|
||||
event EventHandler Raised;
|
||||
/// <summary>
|
||||
/// Returns whether the trigger is started
|
||||
/// </summary>
|
||||
bool IsStarted { get; }
|
||||
/// <summary>
|
||||
/// Stops the trigger and prevents further calls of the <see cref="Raised"/> event.
|
||||
/// </summary>
|
||||
void Stop();
|
||||
/// <summary>
|
||||
/// Starts the trigger.
|
||||
/// </summary>
|
||||
void Start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
|
||||
namespace MtApi.Monitors.Triggers
|
||||
{
|
||||
/// <summary>
|
||||
/// Raises the <see cref="Raised"/> event if a bar is closed and a new one started.
|
||||
/// </summary>
|
||||
public class NewBarTrigger : IMonitorTrigger
|
||||
{
|
||||
#region Fields
|
||||
private volatile bool _isStarted;
|
||||
private readonly MtApiClient _apiClient;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Returns true if the trigger is started, otherwise false
|
||||
/// </summary>
|
||||
public bool IsStarted => _isStarted;
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Event will be called if the trigger raised.
|
||||
/// </summary>
|
||||
public event EventHandler Raised;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
public NewBarTrigger(MtApiClient apiClient)
|
||||
{
|
||||
_apiClient = apiClient;
|
||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
/// <summary>
|
||||
/// Starts the trigger
|
||||
/// </summary>
|
||||
public void Start() => SetIsStarted(true);
|
||||
/// <summary>
|
||||
/// Stops the trigger
|
||||
/// </summary>
|
||||
public void Stop() => SetIsStarted(false);
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
private void _apiClient_OnLastTimeBar(object sender, TimeBarArgs e)
|
||||
{
|
||||
if (_isStarted)
|
||||
Raised?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void SetIsStarted(bool value)
|
||||
{
|
||||
if (value != _isStarted)
|
||||
{
|
||||
_isStarted = value;
|
||||
if (value)
|
||||
_apiClient.OnLastTimeBar += _apiClient_OnLastTimeBar;
|
||||
else
|
||||
_apiClient.OnLastTimeBar -= _apiClient_OnLastTimeBar;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
|
||||
namespace MtApi.Monitors.Triggers
|
||||
{
|
||||
public class TimeElapsedTrigger : IMonitorTrigger
|
||||
{
|
||||
#region Fields
|
||||
readonly Timer _timer;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Interval for raising the trigger
|
||||
/// </summary>
|
||||
public TimeSpan Interval
|
||||
{
|
||||
get => TimeSpan.FromMilliseconds(_timer.Interval);
|
||||
set => _timer.Interval = value.TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the trigger is started, otherwise false
|
||||
/// </summary>
|
||||
public bool IsStarted => _timer.Enabled;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the trigger will raise continuosly after elapsed <see cref="Interval"/>, otherwise the trigger will raise only once after elapsed <see cref="Interval"/>.
|
||||
/// </summary>
|
||||
public bool AutoReset { get => _timer.AutoReset; set => _timer.AutoReset = value; }
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
/// <summary>
|
||||
/// Returns true if the trigger is started, otherwise false
|
||||
/// </summary>
|
||||
public event EventHandler Raised;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
/// <summary>
|
||||
/// Constructor for initializing TimeElapsedTrigger
|
||||
/// </summary>
|
||||
/// <param name="time">Defines the interval for raising the event.</param>
|
||||
/// <param name="autoReset">If true, the trigger will raise continuosly after elapsed <see cref="Interval"/>, otherwise the trigger will raise only once after elapsed <see cref="Interval"/>.</param>
|
||||
public TimeElapsedTrigger(TimeSpan time, bool autoReset = true)
|
||||
{
|
||||
_timer = new Timer(time.TotalMilliseconds);
|
||||
_timer.Elapsed += _timer_Elapsed;
|
||||
AutoReset = autoReset;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
/// <summary>
|
||||
/// Starts the trigger
|
||||
/// </summary>
|
||||
public void Start() => _timer.Start();
|
||||
/// <summary>
|
||||
/// Stops the trigger
|
||||
/// </summary>
|
||||
public void Stop() => _timer.Stop();
|
||||
#endregion
|
||||
|
||||
#region private methods
|
||||
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
_timer.Elapsed -= _timer_Elapsed;
|
||||
Raised?.Invoke(this, EventArgs.Empty);
|
||||
_timer.Elapsed += _timer_Elapsed;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
## Monitors
|
||||
|
||||
Monitors can be used to monitor different changes on Mt4 structs.
|
||||
|
||||
## MtMonitorBase
|
||||
This is the base class for monitoring extensions. If inherited `MtMonitorBase` needs an instance of `MtApiClient` and `IMonitorTrigger`.
|
||||
|
||||
`SyncTrigger` (which can be set in the constructor or as Property) can be used to define whether the trigger should be started and stopped as well if `Start()` or `Stop()` will be called on an instance of a child class of `MtMonitorBase`.
|
||||
Keep in mind: If an `IMonitorTrigger` will be used for several monitors, `SyncTrigger` set to `true` would cause that all monitors related to this trigger would stop:
|
||||
|
||||
```
|
||||
var fooTrigger = new FooTrigger();
|
||||
var fooMonitor = new FooMonitor(apiClient, fooTrigger, true);
|
||||
var barMonitor = new FooMonitor(apiClient, fooTrigger, false);
|
||||
|
||||
fooTrigger.Start();
|
||||
barMonitor.Start();
|
||||
fooMonitor.Start();
|
||||
|
||||
fooMonitor.Stop(); //Because of SyncTrigger = true in the constructor of FooMonitor, fooTrigger.Stop() were triggered as well. Therefore barMonitor will not get any further triggers.
|
||||
```
|
||||
|
||||
## IMonitorTrigger
|
||||
An `IMonitorTrigger` is for defining when the monitor should check whether his conditions are met for invoking his event.
|
||||
|
||||
There are already two `IMonitorTrigger`s which can be used:
|
||||
### NewBarTrigger
|
||||
Triggers when a new bar starts
|
||||
### TimeElapsedTrigger
|
||||
Triggers when a defined time elapsed
|
||||
|
||||
## Default monitors:
|
||||
There are already two different monitors defined. You can extend them or define new ones by inheriting from `MtMonitorBase`.
|
||||
|
||||
### TradeMonitor
|
||||
Can be used to get updates on new opened trades or closed trades.
|
||||
|
||||
## ModifiedOrdersMonitor
|
||||
Can be used to get updates on modified trades (takeprofit, stoploss, operation).
|
||||
|
||||
`OrderModifiedTypes` defines which modifications should be monitored:
|
||||
|
||||
1. `None` would cause no monitoring. But please use `Start()` and `Stop()` instead.
|
||||
2. `TakeProfit` would cause observing whether the TakeProfit were changed.
|
||||
3. `StopLoss` would cause observing whether the StopLoss were changed.
|
||||
4. `Operation` would cause observing trades which changed from a stop / limit order to an open order.
|
||||
5. `All` would cause observing all above defined.
|
||||
|
||||
Because `OrderModifiedTypes` is defined with the Flag-Attribute, you can combine the above monitoring types with a pipe: `OrderModifiedTypes.TakeProfit | OrderModifiedTypes.StopLoss`.
|
||||
|
||||
### Example
|
||||
```
|
||||
var orderModifyMonitor = new ModifiedOrdersMonitor(
|
||||
_apiClient,
|
||||
new MtApi.Monitors.Triggers.TimeElapsedTrigger(TimeSpan.FromSeconds(1)),
|
||||
OrderModifiedTypes.All,
|
||||
true
|
||||
);
|
||||
orderModifyMonitor.OrdersModified += OrderModifyMonitor_OrdersModified;
|
||||
orderModifyMonitor.Start();
|
||||
|
||||
private void OrderModifyMonitor_OrdersModified(object sender, ModifiedOrdersEventArgs e)
|
||||
{
|
||||
//Receives the event
|
||||
}
|
||||
```
|
||||
@@ -76,6 +76,14 @@
|
||||
<Compile Include="EnumTerminalInfoInteger.cs" />
|
||||
<Compile Include="FlagFontStyle.cs" />
|
||||
<Compile Include="Monitors\AvailabilityOrdersEventArgs.cs" />
|
||||
<Compile Include="Monitors\OrderModification\ModifiedOrdersEventArgs.cs" />
|
||||
<Compile Include="Monitors\OrderModification\ModifiedOrdersMonitor.cs" />
|
||||
<Compile Include="Monitors\OrderModification\MtModifiedOrder.cs" />
|
||||
<Compile Include="Monitors\MtMonitorBase.cs" />
|
||||
<Compile Include="Monitors\OrderModification\OrderModifiedTypes.cs" />
|
||||
<Compile Include="Monitors\Triggers\IMonitorTrigger.cs" />
|
||||
<Compile Include="Monitors\Triggers\NewBarTrigger.cs" />
|
||||
<Compile Include="Monitors\Triggers\TimeElapsedTrigger.cs" />
|
||||
<Compile Include="MqlRates.cs" />
|
||||
<Compile Include="MqlTick.cs" />
|
||||
<Compile Include="MtChartEvent.cs" />
|
||||
|
||||
+68
-1
@@ -26,6 +26,8 @@ namespace MtApi
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApiClient));
|
||||
|
||||
private MtClient _client;
|
||||
private readonly object _locker = new object();
|
||||
private MtConnectionState _connectionState = MtConnectionState.Disconnected;
|
||||
@@ -37,7 +39,12 @@ namespace MtApi
|
||||
|
||||
public MtApiClient()
|
||||
{
|
||||
LogConfigurator.Setup(LogProfileName);
|
||||
#if (DEBUG)
|
||||
const LogLevel logLevel = LogLevel.Debug;
|
||||
#else
|
||||
const LogLevel logLevel = LogLevel.Info;
|
||||
#endif
|
||||
LogConfigurator.Setup(LogProfileName, logLevel);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -49,6 +56,7 @@ namespace MtApi
|
||||
///<param name="port">Port of host connection (default 8222) </param>
|
||||
public void BeginConnect(string host, int port)
|
||||
{
|
||||
Log.Info($"BeginConnect: host = {host}, port = {port}");
|
||||
Task.Factory.StartNew(() => Connect(host, port));
|
||||
}
|
||||
|
||||
@@ -58,6 +66,7 @@ namespace MtApi
|
||||
///<param name="port">Port of host connection (default 8222) </param>
|
||||
public void BeginConnect(int port)
|
||||
{
|
||||
Log.Info($"BeginConnect: port = {port}");
|
||||
Task.Factory.StartNew(() => Connect(port));
|
||||
}
|
||||
|
||||
@@ -66,6 +75,7 @@ namespace MtApi
|
||||
///</summary>
|
||||
public void BeginDisconnect()
|
||||
{
|
||||
Log.Info("BeginDisconnect called.");
|
||||
Task.Factory.StartNew(() => Disconnect(false));
|
||||
}
|
||||
|
||||
@@ -251,6 +261,8 @@ 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, Color arrowColor)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}, expiration = {expiration}, arrowColor = {arrowColor}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -271,6 +283,8 @@ 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)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}, expiration = {expiration}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -290,6 +304,8 @@ namespace MtApi
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||
, string comment, int magic)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -308,6 +324,8 @@ namespace MtApi
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit
|
||||
, string comment)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -324,6 +342,8 @@ namespace MtApi
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, double price, int slippage, double stoploss, double takeprofit)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -339,6 +359,8 @@ namespace MtApi
|
||||
|
||||
public int OrderSend(string symbol, TradeOperation cmd, double volume, string price, int slippage, double stoploss, double takeprofit)
|
||||
{
|
||||
Log.Debug($"OrderSend: symbol = {symbol}, cmd = {cmd}, volume = {volume}, price = {price}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}");
|
||||
|
||||
double dPrice;
|
||||
return double.TryParse(price, out dPrice) ?
|
||||
OrderSend(symbol, cmd, volume, dPrice, slippage, stoploss, takeprofit) : 0;
|
||||
@@ -346,6 +368,8 @@ namespace MtApi
|
||||
|
||||
public int OrderSendBuy(string symbol, double volume, int slippage)
|
||||
{
|
||||
Log.Debug($"OrderSendBuy: symbol = {symbol}, volume = {volume}, slippage = {slippage}");
|
||||
|
||||
return OrderSendBuy(symbol, volume, slippage, 0, 0, null, 0);
|
||||
}
|
||||
|
||||
@@ -366,6 +390,8 @@ namespace MtApi
|
||||
|
||||
public int OrderSendBuy(string symbol, double volume, int slippage, double stoploss, double takeprofit, string comment, int magic)
|
||||
{
|
||||
Log.Debug($"OrderSendBuy: symbol = {symbol}, volume = {volume}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -382,6 +408,8 @@ namespace MtApi
|
||||
|
||||
public int OrderSendSell(string symbol, double volume, int slippage, double stoploss, double takeprofit, string comment, int magic)
|
||||
{
|
||||
Log.Debug($"OrderSendSell: symbol = {symbol}, volume = {volume}, slippage = {slippage}, stoploss = {stoploss}, takeprofit = {takeprofit}, comment = {comment}, magic = {magic}");
|
||||
|
||||
var response = SendRequest<OrderSendResponse>(new OrderSendRequest
|
||||
{
|
||||
Symbol = symbol,
|
||||
@@ -398,6 +426,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderClose(int ticket, double lots, double price, int slippage, Color color)
|
||||
{
|
||||
Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, price = {price}, slippage = {slippage}, color = {color}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -411,6 +441,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderClose(int ticket, double lots, double price, int slippage)
|
||||
{
|
||||
Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, price = {price}, slippage = {slippage}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -423,6 +455,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderClose(int ticket, double lots, int slippage)
|
||||
{
|
||||
Log.Debug($"OrderClose: ticket = {ticket}, lots = {lots}, slippage = {slippage}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -434,6 +468,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderClose(int ticket, int slippage)
|
||||
{
|
||||
Log.Debug($"OrderClose: ticket = {ticket}, slippage = {slippage}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -444,6 +480,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderCloseBy(int ticket, int opposite, Color color)
|
||||
{
|
||||
Log.Debug($"OrderCloseBy: ticket = {ticket}, opposite = {opposite}, color = {color}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseByRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -455,6 +493,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderCloseBy(int ticket, int opposite)
|
||||
{
|
||||
Log.Debug($"OrderCloseBy: ticket = {ticket}, opposite = {opposite}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderCloseByRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -465,6 +505,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderDelete(int ticket, Color color)
|
||||
{
|
||||
Log.Debug($"OrderDelete: ticket = {ticket}, color = {color}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderDeleteRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -475,6 +517,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderDelete(int ticket)
|
||||
{
|
||||
Log.Debug($"OrderDelete: ticket = {ticket}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderDeleteRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -484,6 +528,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration, Color arrowColor)
|
||||
{
|
||||
Log.Debug($"OrderModify: ticket = {ticket}, price = {price}, stoploss = {stoploss}, takeprofit = {takeprofit}, expiration = {expiration}, arrowColor = {arrowColor}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -498,6 +544,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderModify(int ticket, double price, double stoploss, double takeprofit, DateTime expiration)
|
||||
{
|
||||
Log.Debug($"OrderModify: ticket = {ticket}, price = {price}, stoploss = {stoploss}, takeprofit = {takeprofit}, expiration = {expiration}");
|
||||
|
||||
var response = SendRequest<ResponseBase>(new OrderModifyRequest
|
||||
{
|
||||
Ticket = ticket,
|
||||
@@ -516,6 +564,8 @@ namespace MtApi
|
||||
|
||||
public bool OrderSelect(int index, OrderSelectMode select, OrderSelectSource pool)
|
||||
{
|
||||
Log.Debug($"OrderSelect: index = {index}, select = {select}, pool = {pool}");
|
||||
|
||||
var commandParameters = new ArrayList { index, (int)select, (int)pool };
|
||||
return SendCommand<bool>(MtCommandType.OrderSelect, commandParameters);
|
||||
}
|
||||
@@ -994,6 +1044,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) };
|
||||
@@ -2888,6 +2944,8 @@ namespace MtApi
|
||||
{
|
||||
client.Dispose();
|
||||
message = string.IsNullOrEmpty(client.Host) ? $"Failed connection to localhost:{client.Port}. {e.Message}" : $"Failed connection to {client.Host}:{client.Port}. {e.Message}";
|
||||
|
||||
Log.Warn(message);
|
||||
}
|
||||
|
||||
if (state == MtConnectionState.Connected)
|
||||
@@ -2900,6 +2958,8 @@ namespace MtApi
|
||||
_client.ServerFailed += _client_ServerFailed;
|
||||
_client.MtEventReceived += _client_MtEventReceived;
|
||||
message = string.IsNullOrEmpty(client.Host) ? $"Connected to localhost:{client.Port}" : $"Connected to { client.Host}:{client.Port}";
|
||||
|
||||
Log.Info(message);
|
||||
}
|
||||
|
||||
_connectionState = state;
|
||||
@@ -2967,6 +3027,7 @@ namespace MtApi
|
||||
_connectionState = state;
|
||||
}
|
||||
|
||||
Log.Info(message);
|
||||
|
||||
ConnectionStateChanged?.Invoke(this, new MtConnectionEventArgs(state, message));
|
||||
}
|
||||
@@ -2978,6 +3039,7 @@ namespace MtApi
|
||||
var client = Client;
|
||||
if (client == null)
|
||||
{
|
||||
Log.Warn("SendCommand: No connection");
|
||||
throw new MtConnectionException("No connection");
|
||||
}
|
||||
|
||||
@@ -2987,16 +3049,19 @@ namespace MtApi
|
||||
}
|
||||
catch (CommunicationException ex)
|
||||
{
|
||||
Log.Warn($"SendCommand: {ex.Message}");
|
||||
throw new MtConnectionException(ex.Message, ex);
|
||||
}
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
Log.Warn("SendCommand: Response from MetaTrader is null");
|
||||
throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null");
|
||||
}
|
||||
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Warn($"SendCommand: ErrorCode = {response.ErrorCode}. {response}");
|
||||
throw new MtExecutionException((MtErrorCode)response.ErrorCode, response.ToString());
|
||||
}
|
||||
|
||||
@@ -3020,12 +3085,14 @@ namespace MtApi
|
||||
|
||||
if (res == null)
|
||||
{
|
||||
Log.Warn("SendRequest: Response from MetaTrader is null");
|
||||
throw new MtExecutionException(MtErrorCode.MtApiCustomError, "Response from MetaTrader is null");
|
||||
}
|
||||
|
||||
var response = JsonConvert.DeserializeObject<T>(res);
|
||||
if (response.ErrorCode != 0)
|
||||
{
|
||||
Log.Warn($"SendRequest: ErrorCode = {response.ErrorCode}. {response}");
|
||||
throw new MtExecutionException((MtErrorCode)response.ErrorCode, response.ErrorMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@
|
||||
TimeSeconds = 86,
|
||||
TimeYear = 87,
|
||||
Year = 88,
|
||||
TimeGMT = 281,
|
||||
|
||||
//Global Variables
|
||||
GlobalVariableCheck = 89,
|
||||
|
||||
+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.38.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.38.0")]
|
||||
[assembly: AssemblyVersion("1.0.42.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.42.0")]
|
||||
@@ -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,15 +1,17 @@
|
||||
namespace MtApi5
|
||||
// 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
|
||||
@@ -29,5 +31,13 @@
|
||||
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,4 +1,6 @@
|
||||
using System;
|
||||
// ReSharper disable InconsistentNaming
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
@@ -17,9 +19,23 @@ namespace MtApi5
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-11
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
public class MqlTradeResult
|
||||
{
|
||||
@@ -15,19 +17,32 @@
|
||||
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}; Deal={Deal}; Order={Order}; Volume={Volume}; Price={Price}; Bid={Bid}; Ask={Ask}; Comment={Comment}; Request_id={Request_id}";
|
||||
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.
|
||||
}
|
||||
}
|
||||
+133
-8
@@ -1,14 +1,14 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace MtApi5
|
||||
{
|
||||
internal enum Mt5CommandType
|
||||
{
|
||||
//NoCommand = 0
|
||||
|
||||
//trade operations
|
||||
OrderSend = 1,
|
||||
//OrderSend = 1,
|
||||
OrderCalcMargin = 2,
|
||||
OrderCalcProfit = 3,
|
||||
OrderCheck = 4,
|
||||
//OrderSendAsync = 5,
|
||||
PositionsTotal = 6,
|
||||
PositionGetSymbol = 7,
|
||||
@@ -16,6 +16,7 @@
|
||||
PositionGetDouble = 9,
|
||||
PositionGetInteger = 10,
|
||||
PositionGetString = 11,
|
||||
PositionGetTicket = 4,
|
||||
OrdersTotal = 12,
|
||||
OrderGetTicket = 13,
|
||||
OrderSelect = 14,
|
||||
@@ -94,20 +95,21 @@
|
||||
SymbolInfoSessionTrade = 59,
|
||||
MarketBookAdd = 60,
|
||||
MarketBookRelease = 61,
|
||||
MarketBookGet = 62,
|
||||
//MarketBookGet = 62,
|
||||
OrderCloseAll = 63,
|
||||
|
||||
//CTrade
|
||||
PositionClose = 64,
|
||||
PositionOpen = 65,
|
||||
PositionOpenWithResult = 1065,
|
||||
PositionModify = 6066,
|
||||
PositionClosePartial_bySymbol = 6067,
|
||||
PositionClosePartial_byTicket = 6068,
|
||||
//PositionOpenWithResult = 1065,
|
||||
|
||||
//Backtesting
|
||||
BacktestingReady = 66,
|
||||
IsTesting = 67,
|
||||
|
||||
Print = 68,
|
||||
|
||||
//Requests
|
||||
MtRequest = 155,
|
||||
|
||||
@@ -130,6 +132,129 @@
|
||||
ObjectSetString = 84,
|
||||
//TextSetFont = 85,
|
||||
//TextOut = 86,
|
||||
//TextGetSize = 87
|
||||
//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)
|
||||
{
|
||||
|
||||
+210
-14
@@ -1,4 +1,6 @@
|
||||
namespace MtApi5
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace MtApi5
|
||||
{
|
||||
|
||||
// Chart Constants:
|
||||
@@ -34,6 +36,96 @@
|
||||
#endregion //Chart Timeframes
|
||||
|
||||
|
||||
#region Charts Properties
|
||||
|
||||
public enum ENUM_CHART_PROPERTY_DOUBLE
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
public enum ENUM_CHART_PROPERTY_INTEGER
|
||||
{
|
||||
CHART_SHOW = 46,
|
||||
CHART_IS_OBJECT = 111,
|
||||
CHART_BRING_TO_TOP = 35,
|
||||
CHART_CONTEXT_MENU = 50,
|
||||
CHART_CROSSHAIR_TOOL = 49,
|
||||
CHART_MOUSE_SCROLL = 42,
|
||||
CHART_EVENT_MOUSE_WHEEL = 48,
|
||||
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_KEYBOARD_CONTROL = 47,
|
||||
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_SHOW_ONE_CLICK = 44,
|
||||
CHART_IS_MAXIMIZED = 115,
|
||||
CHART_IS_MINIMIZED = 116
|
||||
}
|
||||
|
||||
public enum ENUM_CHART_PROPERTY_STRING
|
||||
{
|
||||
CHART_COMMENT = 20,
|
||||
CHART_EXPERT_NAME = 113,
|
||||
CHART_SCRIPT_NAME = 114
|
||||
}
|
||||
|
||||
public enum ENUM_CHART_POSITION
|
||||
{
|
||||
CHART_BEGIN = 0, // Chart beginning (the oldest prices)
|
||||
CHART_CURRENT_POS = 1, // Current position
|
||||
CHART_END = 2 // Chart end (the latest prices)
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// Environment State:
|
||||
|
||||
#region Client Terminal Properties
|
||||
@@ -89,8 +181,7 @@
|
||||
SYMBOL_BACKGROUND_COLOR = 79,
|
||||
SYMBOL_CHART_MODE = 80,
|
||||
SYMBOL_SELECT = 0,
|
||||
//FIXME: SYMBOL_VISIBLE not found in MQL5 environment!
|
||||
//SYMBOL_VISIBLE = ?
|
||||
SYMBOL_VISIBLE = 76,
|
||||
SYMBOL_SESSION_DEALS = 56,
|
||||
SYMBOL_SESSION_BUY_ORDERS = 60,
|
||||
SYMBOL_SESSION_SELL_ORDERS = 62,
|
||||
@@ -132,6 +223,9 @@
|
||||
SYMBOL_LAST = 7,
|
||||
SYMBOL_LASTHIGH = 8,
|
||||
SYMBOL_LASTLOW = 9,
|
||||
SYMBOL_VOLUME_REAL = 10,
|
||||
SYMBOL_VOLUMEHIGH_REAL = 11,
|
||||
SYMBOL_VOLUMELOW_REAL = 12,
|
||||
SYMBOL_OPTION_STRIKE = 72,
|
||||
SYMBOL_POINT = 16,
|
||||
SYMBOL_TRADE_TICK_VALUE = 26,
|
||||
@@ -457,7 +551,6 @@
|
||||
POSITION_SL = 6, //Stop Loss level of opened position
|
||||
POSITION_TP = 7, //Take Profit level of opened position
|
||||
POSITION_PRICE_CURRENT = 5, //Current price of the position symbol
|
||||
POSITION_COMMISSION = 8, //FIXME: Undocumented!
|
||||
POSITION_SWAP = 9, //Cumulative swap
|
||||
POSITION_PROFIT = 10 //Current profit
|
||||
}
|
||||
@@ -580,16 +673,16 @@
|
||||
public enum ENUM_TRADE_TRANSACTION_TYPE
|
||||
{
|
||||
TRADE_TRANSACTION_ORDER_ADD = 0, //Adding a new open order
|
||||
TRADE_TRANSACTION_ORDER_UPDATE = 1, //Updating an open order
|
||||
TRADE_TRANSACTION_ORDER_DELETE = 2, //Removing an order from the list of the open ones
|
||||
TRADE_TRANSACTION_DEAL_ADD = 6, //Adding a deal to the history
|
||||
TRADE_TRANSACTION_DEAL_UPDATE = 7, //Updating a deal in the history
|
||||
TRADE_TRANSACTION_DEAL_DELETE = 8, //Deleting a deal from the history
|
||||
TRADE_TRANSACTION_HISTORY_ADD = 3, //Adding an order to the history as a result of execution or cancellation
|
||||
TRADE_TRANSACTION_HISTORY_UPDATE = 4, //Changing an order located in the orders history
|
||||
TRADE_TRANSACTION_HISTORY_DELETE = 5, //Deleting an order from the orders history
|
||||
TRADE_TRANSACTION_POSITION = 9, //Changing a position not related to a deal execution
|
||||
TRADE_TRANSACTION_REQUEST = 10 //Notification of the fact that a trade request has been processed by a server and processing result has been received
|
||||
TRADE_TRANSACTION_ORDER_UPDATE = 1, //Updating an open order. The updates include not only evident changes from the client terminal or a trade server sides but also changes of an order state when setting it (for example, transition from ORDER_STATE_STARTED to ORDER_STATE_PLACED or from ORDER_STATE_PLACED to ORDER_STATE_PARTIAL, etc.).
|
||||
TRADE_TRANSACTION_ORDER_DELETE = 2, //Removing an order from the list of the open ones. An order can be deleted from the open ones as a result of setting an appropriate request or execution (filling) and moving to the history.
|
||||
TRADE_TRANSACTION_DEAL_ADD = 6, //Adding a deal to the history. The action is performed as a result of an order execution or performing operations with an account balance.
|
||||
TRADE_TRANSACTION_DEAL_UPDATE = 7, //Updating a deal in the history. There may be cases when a previously executed deal is changed on a server. For example, a deal has been changed in an external trading system (exchange) where it was previously transferred by a broker.
|
||||
TRADE_TRANSACTION_DEAL_DELETE = 8, //Deleting a deal from the history. There may be cases when a previously executed deal is deleted from a server. For example, a deal has been deleted in an external trading system (exchange) where it was previously transferred by a broker.
|
||||
TRADE_TRANSACTION_HISTORY_ADD = 3, //Adding an order to the history as a result of execution or cancellation.
|
||||
TRADE_TRANSACTION_HISTORY_UPDATE = 4, //Changing an order located in the orders history. This type is provided for enhancing functionality on a trade server side.
|
||||
TRADE_TRANSACTION_HISTORY_DELETE = 5, //Deleting an order from the orders history. This type is provided for enhancing functionality on a trade server side.
|
||||
TRADE_TRANSACTION_POSITION = 9, //Changing a position not related to a deal execution. This type of transaction shows that a position has been changed on a trade server side. Position volume, open price, Stop Loss and Take Profit levels can be changed. Data on changes are submitted in MqlTradeTransaction structure via OnTradeTransaction handler. Position change (adding, changing or closing), as a result of a deal execution, does not lead to the occurrence of TRADE_TRANSACTION_POSITION transaction.
|
||||
TRADE_TRANSACTION_REQUEST = 10 //Notification of the fact that a trade request has been processed by a server and processing result has been received. Only type field (trade transaction type) must be analyzed for such transactions in MqlTradeTransaction structure. The second and third parameters of OnTradeTransaction (request and result) must be analyzed for additional data.
|
||||
}
|
||||
|
||||
#endregion //Trade Transaction Types
|
||||
@@ -742,5 +835,108 @@
|
||||
ALIGN_CENTER = 2, // Centered (only for the Edit object)
|
||||
ALIGN_RIGHT = 0, // Right alignment
|
||||
}
|
||||
#endregion //Object Properties
|
||||
|
||||
#region Price Constants
|
||||
|
||||
public enum ENUM_APPLIED_PRICE
|
||||
{
|
||||
PRICE_CLOSE = 1, //Close price
|
||||
PRICE_OPEN = 2, //Open price
|
||||
PRICE_HIGH = 3, //The maximum price for the period
|
||||
PRICE_LOW = 4, //The minimum price for the period
|
||||
PRICE_MEDIAN = 5, //Median price, (high + low)/2
|
||||
PRICE_TYPICAL = 6, //Typical price, (high + low + close)/3
|
||||
PRICE_WEIGHTED = 7 //Average price, (high + low + close + close)/4
|
||||
}
|
||||
|
||||
public enum ENUM_APPLIED_VOLUME
|
||||
{
|
||||
VOLUME_TICK = 0, //Tick volume
|
||||
VOLUME_REAL = 1 //Trade volume
|
||||
}
|
||||
|
||||
public enum ENUM_STO_PRICE
|
||||
{
|
||||
STO_LOWHIGH = 0, //Calculation is based on Low/High prices
|
||||
STO_CLOSECLOSE = 1 //Calculation is based on Close/Close prices
|
||||
}
|
||||
|
||||
#endregion //Price Constants
|
||||
|
||||
#region Smoothing Methods
|
||||
|
||||
public enum ENUM_MA_METHOD
|
||||
{
|
||||
MODE_SMA = 0, //Simple averaging
|
||||
MODE_EMA = 1, //Exponential averaging
|
||||
MODE_SMMA = 2, //Smoothed averaging
|
||||
MODE_LWMA = 3 //Linear-weighted averaging
|
||||
}
|
||||
|
||||
#endregion //Smoothing Methods
|
||||
|
||||
#region Indicator constants
|
||||
|
||||
public enum ENUM_INDICATOR
|
||||
{
|
||||
IND_AC = 5, // Accelerator Oscillator
|
||||
IND_AD = 6, // Accumulation/Distribution
|
||||
IND_ADX = 8, // Average Directional Index
|
||||
IND_ADXW = 9, // ADX by Welles Wilder
|
||||
IND_ALLIGATOR = 7, // Alligator
|
||||
IND_AMA = 40, // Adaptive Moving Average
|
||||
IND_AO = 11, // Awesome Oscillator
|
||||
IND_ATR = 10, // Average True Range
|
||||
IND_BANDS = 13, // Bollinger Bands®
|
||||
IND_BEARS = 12, // Bears Power
|
||||
IND_BULLS = 14, // Bulls Power
|
||||
IND_BWMFI = 22, // Market Facilitation Index
|
||||
IND_CCI = 15, // Commodity Channel Index
|
||||
IND_CHAIKIN = 41, // Chaikin Oscillator
|
||||
IND_CUSTOM = 43, // Custom indicator
|
||||
IND_DEMA = 36, // Double Exponential Moving Average
|
||||
IND_DEMARKER = 16, // DeMarker
|
||||
IND_ENVELOPES = 17, // Envelopes
|
||||
IND_FORCE = 18, // Force Index
|
||||
IND_FRACTALS = 19, // Fractals
|
||||
IND_FRAMA = 39, // Fractal Adaptive Moving Average
|
||||
IND_GATOR = 20, // Gator Oscillator
|
||||
IND_ICHIMOKU = 21, // Ichimoku Kinko Hyo
|
||||
IND_MA = 26, // Moving Average
|
||||
IND_MACD = 23, // MACD
|
||||
IND_MFI = 25, // Money Flow Index
|
||||
IND_MOMENTUM = 24, // Momentum
|
||||
IND_OBV = 28, // On Balance Volume
|
||||
IND_OSMA = 27, // OsMA
|
||||
IND_RSI = 30, // Relative Strength Index
|
||||
IND_RVI = 31, // Relative Vigor Index
|
||||
IND_SAR = 29, // Parabolic SAR
|
||||
IND_STDDEV = 32, // Standard Deviation
|
||||
IND_STOCHASTIC = 33, // Stochastic Oscillator
|
||||
IND_TEMA = 37, // Triple Exponential Moving Average
|
||||
IND_TRIX = 38, // Triple Exponential Moving Averages Oscillator
|
||||
IND_VIDYA = 42, // Variable Index Dynamic Average
|
||||
IND_VOLUMES = 34, // Volumes
|
||||
IND_WPR = 35 // Williams' Percent Ranges
|
||||
}
|
||||
|
||||
public enum ENUM_DATATYPE
|
||||
{
|
||||
TYPE_BOOL = 1,
|
||||
TYPE_CHAR = 2,
|
||||
TYPE_UCHAR = 3,
|
||||
TYPE_SHORT = 4,
|
||||
TYPE_USHORT = 5,
|
||||
TYPE_COLOR = 6,
|
||||
TYPE_INT = 7,
|
||||
TYPE_UINT = 8,
|
||||
TYPE_DATETIME = 9,
|
||||
TYPE_LONG = 10,
|
||||
TYPE_ULONG = 11,
|
||||
TYPE_FLOAT = 12,
|
||||
TYPE_DOUBLE = 13,
|
||||
TYPE_STRING = 14
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
+35
-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,39 @@
|
||||
<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\BuyRequest.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\OrderSendAsyncRequest.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\SellRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringRequest.cs" />
|
||||
<Compile Include="Requests\SymbolInfoStringResult.cs" />
|
||||
<Compile Include="Requests\SymbolInfoTickRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MTApiService\MTApiService.csproj">
|
||||
|
||||
+1742
-66
File diff suppressed because it is too large
Load Diff
+18
-76
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.13")]
|
||||
[assembly: AssemblyFileVersion("1.0.13")]
|
||||
[assembly: AssemblyVersion("1.0.23")]
|
||||
[assembly: AssemblyFileVersion("1.0.23")]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class BuyRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.Buy;
|
||||
|
||||
public double Volume { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public double Sl { get; set; }
|
||||
public double Tp { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderSendAsyncRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderSendAsync;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderSendRequest: RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.OrderSend;
|
||||
|
||||
public MqlTradeRequest TradeRequest { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class OrderSendResult
|
||||
{
|
||||
public bool RetVal { get; set; }
|
||||
public MqlTradeResult TradeResult { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace MtApi5.Requests
|
||||
{
|
||||
internal class PositionCloseRequest : RequestBase
|
||||
{
|
||||
public override RequestType RequestType => RequestType.PositionClose;
|
||||
|
||||
public ulong Ticket { get; set; }
|
||||
public ulong Deviation { 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