/// <summary> /// Deserialization constructor. /// </summary> public ExpertHost(SerializationInfo info, StreamingContext context) : base(info, context) { _expertType = (Type)info.GetValue("expertType", typeof(Type)); _expert = (Expert)info.GetValue("expert", typeof(Expert)); _sessions = (List<PlatformExpertSession>)info.GetValue("existingSessions", _sessions.GetType()); }
void SetExpert(Expert expert) { SystemMonitor.CheckError(expert == null || _expert == null || expert == _expert, "Change expert mode not supported yet. Use one control per expert."); _expert = expert; if (_expert == null) { expertSessionControl.Session = null; accountControl1.Account = null; expertSessionControl.CorrespondingOrdersControl = null; return; } toolStripButtonInitialize.Enabled = _expert.Manager != null && _expert.Manager.SessionCount == 0; expertSessionControl.CorrespondingOrdersControl = ordersControlExpertSession; if (_expert.Manager != null) { int height = 0; if (((ExpertHost)_expert.Manager).UISerializationInfo.TryGetValue<int>("tabControl1.Height", ref height)) { tabControl1.Height = height; } } if (_expert.Manager != null && _expert.Manager.SessionCount > 0) { expertSessionControl.Session = (PlatformExpertSession)_expert.Manager.SessionsArray[0]; //toolStripButtonOrders.Checked = expertSessionControl.Session.OrderExecutionProvider != null; positionsControl1.Initialize(_expert.Manager, _expert.Manager.GetDataDelivery(_expert.Manager.SessionsArray[0].DataProvider.SourceId), _expert.Manager.SessionsArray[0].OrderExecutionProvider); if (_expert.Manager.SessionsArray[0].OrderExecutionProvider != null) { _expert.Manager.SessionsArray[0].OrderExecutionProvider.AccountInfoUpdateEvent += new AccountInfoUpdateDelegate(OrderExecutionProvider_AccountInfoUpdateEvent); if (_expert.Manager.SessionsArray[0].OrderExecutionProvider.DefaultAccount != null) { accountControl1.Account = _expert.Manager.SessionsArray[0].OrderExecutionProvider.DefaultAccount; } } tabControl1.Visible = _expert.Manager.SessionsArray[0].OrderExecutionProvider != null; accountControl1.Visible = tabControl1.Visible; if (tabControl1.Visible == false) { tabControl1.SelectedTab = tabControl1.TabPages[2]; } } else { //toolStripButtonOrders.Checked = false; expertSessionControl.Session = null; } }
protected override bool OnInitialize(Platform platform) { TracerHelper.TraceEntry(); if (base.OnInitialize(platform) == false) { return false; } string expertName = this.Name + ".expert"; // Clean expertname since we might be sending it trough command line. expertName = expertName.Replace(" ", "_"); expertName = expertName.Replace("\"", ""); lock (this) { if (_expert == null) {// Create the expert. SystemMonitor.CheckThrow(_expertType.IsSubclassOf(typeof(Expert)), "Invalid expert type passed in."); ConstructorInfo constructor = _expertType.GetConstructor(new Type[] { typeof(ISourceAndExpertSessionManager), typeof(string) }); if (constructor == null) {// Try the second option for construction. constructor = _expertType.GetConstructor(new Type[] { typeof(ISourceAndExpertSessionManager) }); } if (constructor == null) { SystemMonitor.Error("Failed to find corresponding constructor for expert type [" + _expertType.ToString() + "]."); return false; } if (constructor.GetParameters().Length == 2) { _expert = (Expert)constructor.Invoke(new object[] { this, expertName }); } else { _expert = (Expert)constructor.Invoke(new object[] { this }); } } if (_expert.Initialize() == false) { SystemMonitor.Error("Expert host failed to connect to platform."); return false; } if (_expert != null) { _expert.PersistenceDataUpdateEvent += new Expert.ExpertUpdateDelegate(_expert_PersistenceDataUpdateEvent); } } foreach (PlatformExpertSession session in SessionsArray) { if (session.Initialize(null) == false) { SystemMonitor.OperationWarning("Failed to initialize session."); } } ChangeOperationalState(OperationalStateEnum.Operational); TracerHelper.TraceExit(); return true; }
void _expert_PersistenceDataUpdateEvent(Expert expert) { RaisePersistenceDataUpdatedEvent(); }
protected override void OnDispose() { base.OnDispose(); // Destroy all sessions. while (_sessions.Count > 0) { UnRegisterExpertSession(_sessions[0]); } _expert.Dispose(); _expert = null; }