private void InitConnector(IEntityRegistry entityRegistry, SnapshotRegistry snapshotRegistry, INativeIdStorage nativeIdStorage) { // subscribe on connection successfully event Connector.Connected += () => { this.GuiAsync(() => ChangeConnectStatus(true)); if (Connector.Adapter.IsMarketDataTypeSupported(DataType.News) && !Connector.Adapter.IsSecurityNewsOnly) { Connector.SubscribeNews(); } }; // subscribe on connection error event Connector.ConnectionError += error => this.GuiAsync(() => { ChangeConnectStatus(false); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); Connector.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on error event //Connector.Error += error => // this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); // subscribe on error of market data subscription event Connector.MarketDataSubscriptionFailed += (security, msg, error) => this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security))); Connector.NewSecurity += _securitiesWindow.SecurityPicker.Securities.Add; Connector.NewTrade += _tradesWindow.TradeGrid.Trades.Add; Connector.NewOrderLogItem += _orderLogWindow.OrderLogGrid.LogItems.Add; Connector.NewOrder += _ordersWindow.OrderGrid.Orders.Add; Connector.NewMyTrade += _myTradesWindow.TradeGrid.Trades.Add; Connector.NewPortfolio += _portfoliosWindow.PortfolioGrid.Positions.Add; Connector.NewPosition += _portfoliosWindow.PortfolioGrid.Positions.Add; // subscribe on error of order registration event Connector.OrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail; // subscribe on error of order cancelling event Connector.OrderCancelFailed += OrderFailed; // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Connector; // set news provider _newsWindow.NewsPanel.NewsProvider = Connector; Connector.LookupTimeFramesResult += (message, timeFrames, error) => { if (error == null) { this.GuiAsync(() => _securitiesWindow.UpdateTimeFrames(timeFrames)); } }; Connector.Adapter.NativeIdStorage = nativeIdStorage; try { nativeIdStorage.Init(); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } if (Connector.StorageAdapter == null) { return; } try { entityRegistry.Init(); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } Connector.Adapter.StorageProcessor.DaysLoad = TimeSpan.FromDays(3); Connector.Adapter.StorageProcessor.Mode = StorageModes.Snapshot; Connector.LookupAll(); snapshotRegistry.Init(); ConfigManager.RegisterService <IExchangeInfoProvider>(new StorageExchangeInfoProvider(entityRegistry)); ConfigManager.RegisterService <IMessageAdapterProvider>(new FullInMemoryMessageAdapterProvider(Connector.Adapter.InnerAdapters)); try { if (File.Exists(_settingsFile)) { var ctx = new ContinueOnExceptionContext(); ctx.Error += ex => ex.LogError(); using (ctx.ToScope()) Connector.Load(new XmlSerializer <SettingsStorage>().Deserialize(_settingsFile)); } } catch { } }
private void InitConnector(IEntityRegistry entityRegistry, SnapshotRegistry snapshotRegistry) { // subscribe on connection successfully event Connector.Connected += () => { this.GuiAsync(() => ChangeConnectStatus(true)); }; // subscribe on connection error event Connector.ConnectionError += error => this.GuiAsync(() => { ChangeConnectStatus(false); MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959); }); Connector.Disconnected += () => this.GuiAsync(() => ChangeConnectStatus(false)); // subscribe on error event Connector.Error += error => { this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2955)); }; // subscribe on error of market data subscription event Connector.MarketDataSubscriptionFailed += (security, msg, error) => { this.GuiAsync(() => MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2956Params.Put(msg.DataType, security))); }; Connector.SecurityReceived += (sub, s) => _securitiesWindow.SecurityPicker.Securities.Add(s); Connector.NewOrder += order => { _ordersWindow.OrderGrid.Orders.Add(order); _securitiesWindow.ProcessOrder(order); }; // display order as own volume in quotes window Connector.OrderChanged += _securitiesWindow.ProcessOrder; // put the registration error into order's table Connector.OrderRegisterFailed += _ordersWindow.OrderGrid.AddRegistrationFail; Connector.NewMyTrade += _myTradesWindow.TradeGrid.Trades.Add; Connector.PositionReceived += (sub, p) => _portfoliosWindow.PortfolioGrid.Positions.TryAdd(p); // set market data provider _securitiesWindow.SecurityPicker.MarketDataProvider = Connector; if (Connector.StorageAdapter == null) { return; } entityRegistry.Init(); snapshotRegistry.Init(); Connector.LookupAll(); ConfigManager.RegisterService <IMessageAdapterProvider>(new FullInMemoryMessageAdapterProvider(Connector.Adapter.InnerAdapters)); try { if (File.Exists(_settingsFile) || File.Exists(_settingsFile.MakeLegacy())) { var ctx = new ContinueOnExceptionContext(); ctx.Error += ex => ex.LogError(); using (ctx.ToScope()) Connector.LoadIfNotNull(_settingsFile.DeserializeWithMigration <SettingsStorage>()); } } catch { } }