private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isInitialized) { _isInitialized = true; // subscribe on connection successfully event Trader.Connected += () => { Trader.RegisterNews(); // update gui labes this.GuiAsync(() => ChangeConnectStatus(true)); }; Trader.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on connection error event Trader.ConnectionError += error => this.GuiAsync(() => { // update gui labes this.GuiAsync(() => ChangeConnectStatus(false)); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); // subscribe on error event Trader.Error += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // subscribe on error of market data subscription event Trader.MarketDataSubscriptionFailed += (security, type, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security))); Trader.NewSecurities += securities => _securitiesWindow.SecurityPicker.Securities.AddRange(securities); Trader.NewNews += news => _newsWindow.NewsGrid.News.Add(news); // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; ShowNews.IsEnabled = ShowSecurities.IsEnabled = true; } if (Trader.ConnectionState == ConnectionStates.Disconnected || Trader.ConnectionState == ConnectionStates.Failed) { // set connection settings Trader.Level1Address = Level1AddressCtrl.Text.To <EndPoint>(); Trader.Level2Address = Level2AddressCtrl.Text.To <EndPoint>(); Trader.LookupAddress = LookupAddressCtrl.Text.To <EndPoint>(); Trader.AdminAddress = AdminAddressCtrl.Text.To <EndPoint>(); Trader.IsDownloadSecurityFromSite = DownloadSecurityFromSiteCtrl.IsChecked == true; Trader.Connect(); } else { Trader.Disconnect(); } }
private void ConnectClick(object sender, RoutedEventArgs e) { if (!_isInitialized) { _isInitialized = true; // подписываемся на событие успешного экспорта Trader.ExportStarted += () => { Trader.RegisterNews(); // меняем надпись на Отключиться this.GuiAsync(() => ChangeConnectStatus(true)); }; Trader.ExportStopped += () => this.GuiAsync(() => ChangeConnectStatus(false)); // подписываемся на событие разрыва соединения Trader.ExportError += error => this.GuiAsync(() => { // меняем надпись на Подключиться this.GuiAsync(() => ChangeConnectStatus(false)); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); // подписываемся на ошибку обработки данных (транзакций и маркет) Trader.ProcessDataError += error => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // подписываемся на ошибку подписки маркет-данных Trader.MarketDataSubscriptionFailed += (security, type, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(type, security))); Trader.NewSecurities += securities => _securitiesWindow.SecurityPicker.Securities.AddRange(securities); Trader.NewNews += news => _newsWindow.NewsGrid.News.Add(news); // устанавливаем поставщик маркет-данных _securitiesWindow.SecurityPicker.MarketDataProvider = Trader; ShowNews.IsEnabled = ShowSecurities.IsEnabled = true; } if (Trader.ExportState == ConnectionStates.Disconnected || Trader.ExportState == ConnectionStates.Failed) { //устанавливаем настройки для подключения Trader.Level1Address = Level1AddressCtrl.Text.To <EndPoint>(); Trader.Level2Address = Level2AddressCtrl.Text.To <EndPoint>(); Trader.LookupAddress = LookupAddressCtrl.Text.To <EndPoint>(); Trader.AdminAddress = AdminAddressCtrl.Text.To <EndPoint>(); Trader.IsDownloadSecurityFromSite = DownloadSecurityFromSiteCtrl.IsChecked == true; Trader.StartExport(); } else { Trader.StopExport(); } }