// // #endregion//Event Handlers #region Public Methods // ************************************************************************* // **** Public Methods **** // ************************************************************************* public EngineEventArgs Copy() { EngineEventArgs newEventArg = new EngineEventArgs(); this.CopyTo(newEventArg); return(newEventArg); }
// // // ***************************************** // **** Controls **** // ***************************************** public static EngineEventArgs RequestAllControls(string engineHubName) { EngineEventArgs req = new EngineEventArgs(); req.MsgType = EventType.GetControls; req.Status = EventStatus.Request; req.EngineHubName = engineHubName; return(req); }//end Request AllControls
}//end Request AllControls public static EngineEventArgs ConfirmNewControls(string engineHubName, int engineContainerId = -1) { EngineEventArgs req = new EngineEventArgs(); req.MsgType = EventType.GetControls; req.Status = EventStatus.Request; req.EngineHubName = engineHubName; req.EngineContainerID = engineContainerId; // request controls for single engine container. return(req); }
}// GetParameterValue() // // // // // // **** Get Event For Parameter Values **** // /// <summary> /// This method allows an outsider to ask the Engine to automatically create /// the appropriate EngineEventArg that can be used to have it broadcast its /// current parameter values. /// This is useful when the Engine's parameters have been changed internally /// by some method, orther than the usual EngineEventArg parameter Change request, /// which will usually produce a response event automatically anyway. /// For example, use this when an engine parameter spontaneously changes (from /// a market event, or fill, or by the action of a model) to send the new parameter /// values to all GUIs, even though no one requested one. /// </summary> public virtual EngineEventArgs GetEventForParameterValues(IEngineContainer parent) { EngineEventArgs newEvent = new EngineEventArgs(); newEvent.MsgType = EngineEventArgs.EventType.ParameterValue; newEvent.Status = EngineEventArgs.EventStatus.Request; newEvent.EngineContainerID = parent.EngineContainerID; newEvent.EngineID = this.EngineID; return(newEvent); }// GetEventForParameterValues();
// ***************************************** // **** Parameter Values **** // ***************************************** /// <summary> /// Requests all parameter values from one engine. /// </summary> public static EngineEventArgs RequestAllParameters(string engineHubName, int containerId, int engineId) { EngineEventArgs req = new EngineEventArgs(); req.MsgType = EventType.ParameterValue; req.Status = EventStatus.Request; req.EngineHubName = engineHubName; req.EngineContainerID = containerId; req.EngineID = engineId; return(req); }
}//end Request AllControls // // // ***************************************** // **** RequestSaveEngines **** // ***************************************** public static EngineEventArgs RequestSaveEngines(string engineHubName, int engineContainerId = -1) { EngineEventArgs req = new EngineEventArgs(); req.MsgType = EventType.SaveEngines; req.Status = EventStatus.Request; req.EngineHubName = engineHubName; req.EngineContainerID = engineContainerId; // request controls for single engine container. // TODO: In future, allow data with file path to be addded. return(req); }//end Request AllControls
}//RequestParameterChange() // // // ***************************************** // **** NewEngine **** // ***************************************** public static EngineEventArgs ConfirmNewEngine(string engineHubName, int containerId, Engine newEngine) { EngineEventArgs e = new EngineEventArgs(); e.EngineHubName = engineHubName; e.EngineContainerID = containerId; e.EngineID = newEngine.EngineID; e.MsgType = EngineEventArgs.EventType.NewEngine; e.Status = EngineEventArgs.EventStatus.Confirm; // Load necessary information for RemoteEngine back at the StrategyHub e.DataObjectList = new List <object>(); e.DataObjectList.AddRange(newEngine.GetGuiTemplates()); return(e); }//end Request AllControls
// // // // ***************************************** // **** Parameter Change **** // ***************************************** public static EngineEventArgs RequestParameterChange(ParameterInfo pInfo, object newValue)//, int RequestingHubID) { EngineEventArgs req = new EngineEventArgs(); req.EngineHubName = pInfo.EngineHubName; req.EngineContainerID = pInfo.EngineContainerID; req.EngineID = pInfo.EngineID; req.MsgType = EngineEventArgs.EventType.ParameterChange; req.Status = EngineEventArgs.EventStatus.Request; req.DataIntA = new int[] { pInfo.ParameterID }; req.DataObjectList = new List <object>(); req.DataObjectList.Add(newValue); return(req); }//RequestParameterChange()
} // GetEventForParameterValues(); // // /// <summary> /// This method allows an engine to broadcast all of his own parameters even if not /// requested by the user. This is useful when the engine changed its parameters automatically, /// and now wants to ensure the user knows about it. /// </summary> /// <param name="hub"></param> /// <param name="parent"></param> public void BroadcastAllParameters(IEngineHub hub, IEngineContainer parent) { EngineEventArgs eArgs = new EngineEventArgs(); eArgs.MsgType = EngineEventArgs.EventType.ParameterValue; eArgs.Status = EngineEventArgs.EventStatus.Confirm; eArgs.EngineHubName = hub.ServiceName; eArgs.EngineContainerID = parent.EngineContainerID; eArgs.EngineID = this.EngineID; if (GetParameterValue(ref eArgs.DataIntA, ref eArgs.DataObjectList)) { m_EventQueue.Add(eArgs); } } // BroadcastParameters()
} // BroadcastParameters() // // /// <summary> /// This methods allows an engine to broadcast a single parameter that has not been requested by the user /// If a parameter is changed internally (programatically) this can be used to transmit to the gui. /// </summary> /// <param name="hub"></param> /// <param name="parent"></param> /// <param name="propertyId"></param> public void BroadcastParameter(IEngineHub hub, IEngineContainer parent, int propertyId) { EngineEventArgs eArgs = new EngineEventArgs(); eArgs.MsgType = EngineEventArgs.EventType.ParameterValue; eArgs.Status = EngineEventArgs.EventStatus.Confirm; eArgs.EngineHubName = hub.ServiceName; eArgs.EngineContainerID = parent.EngineContainerID; eArgs.EngineID = this.EngineID; eArgs.DataIntA = new int[] { propertyId }; eArgs.DataObjectList = new List <object>(); if (GetParameterValue(ref eArgs.DataIntA, ref eArgs.DataObjectList)) { m_EventQueue.Add(eArgs); } }
// protected void CopyTo(EngineEventArgs newArg) { newArg.MsgType = this.MsgType; newArg.Status = this.Status; newArg.EngineHubName = this.EngineHubName; newArg.EngineContainerID = this.EngineContainerID; newArg.EngineID = this.EngineID; // Object data if (this.DataObjectList != null) { object[] oArray = new object[DataObjectList.Count]; this.DataObjectList.CopyTo(oArray); newArg.DataObjectList = new List <object>(oArray); } // Integer data. if (this.DataIntA != null) { newArg.DataIntA = new int[this.DataIntA.Length]; this.DataIntA.CopyTo(newArg.DataIntA, 0); } if (this.DataIntB != null) { newArg.DataIntB = new int[this.DataIntB.Length]; this.DataIntB.CopyTo(newArg.DataIntB, 0); } if (this.DataIntC != null) { newArg.DataIntC = new int[this.DataIntC.Length]; this.DataIntC.CopyTo(newArg.DataIntC, 0); } // double data. if (this.DataA != null) { newArg.DataA = new double[this.DataA.Length]; this.DataA.CopyTo(newArg.DataA, 0); } if (this.DataB != null) { newArg.DataB = new double[this.DataB.Length]; this.DataB.CopyTo(newArg.DataB, 0); } if (this.DataC != null) { newArg.DataC = new double[this.DataC.Length]; this.DataC.CopyTo(newArg.DataC, 0); } } // CopyTo()
// ***************************************************************** // **** Control Management **** // ***************************************************************** //public HudPanel GetHudPanel() //{ // return null; //} //public IEngineControl GetControl() //{ // return null; //} // // **** GetControl() **** // // <summary> // This implements part of IEngine. It automatically creates a copy of the // generic Pop Up control panel for displaying parameters of this engine. // </summary> // <returns></returns> /* * public IEngineControl GetControl() * { * if (m_EnginePopUpControl != null) * { * Type t = m_EnginePopUpControl.GetType(); * object p = null; * p = t.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, m_EnginePopUpControl, new object[] { this.EngineID, m_PInfo }); * return (IEngineControl)p; * } * else * return null; * }// GetControl(). * // * // * // **** GetHudPanel() **** * // * /// <summary> * /// This implements part of IEngine. Automatically creates a copy of the heads up panel * /// to display critical parameters. * /// </summary> * /// <returns></returns> * public HudPanel GetHudPanel() * { * if (m_HudPanel != null) * { * Type t = m_HudPanel.GetType(); * object p = null; * p = t.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, m_HudPanel, new object[] { this.EngineID, m_PInfo }); * return (HudPanel)p; * } * else * return null; * }// GetControl(). * // * // This overload allows outsiders to reset and change EnginePanels. * public HudPanel GetHudPanel(HudPanel newPanel) * { * m_HudPanel = newPanel; * return newPanel; * } */ // // // // #endregion//Control Management #region Engine Event Processing // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // **** ProcessEvent() **** // /// <summary> /// This method is the way that EngineEventArgs are passed to an engine to process. /// The action taken depends on the type of engine. /// The implementation is required by IEngine; engines can override this implementation. /// Current implementation: /// 1. This implementation is most common, for a Strategy engine that receives from outsiders /// (normally user requests for parameter changes) to change its internal parameters. /// A. It tries to make the requested changes and respond to the caller the results. /// 2. If an engine overrides this with additional functionality, this method can still be /// called to process all EngineEventArgs events, it does nothing and returns when passed /// any other type of event. /// </summary> /// <param name="e">Request passed in via an EngineEventArg.</param> public virtual void ProcessEvent(EventArgs e) { if (e.GetType() != typeof(EngineEventArgs)) { return; // here is processing of EngineEventArgs only! } EngineEventArgs eArgs = (EngineEventArgs)e; EngineEventArgs.EventType requestType = eArgs.MsgType; EngineEventArgs.EventStatus requestStatus = eArgs.Status; // Validate this message if (requestStatus != EngineEventArgs.EventStatus.Request) { return; // I ignore all but requests. } // // Process the request. // switch (requestType) { // // **** Parameter Value Request **** // case EngineEventArgs.EventType.ParameterValue: // This is a request to broadcast the values of a single, multiple or all parameters. // eArgs.DataIntA contains parameter IDs for each parameter requested, or // eArgs.DataIntA = null, if all are requested. eArgs.DataObjectList = new List <object>(); if (GetParameterValue(ref eArgs.DataIntA, ref eArgs.DataObjectList)) { eArgs.Status = EngineEventArgs.EventStatus.Confirm; // found parameters } else { eArgs.Status = EngineEventArgs.EventStatus.Failed; // did not find parameters } break; // // **** Parameter Change Request **** // case EngineEventArgs.EventType.ParameterChange: // This is a request to change the value of one or more parameters. if (eArgs.DataIntA == null) { // Here, cannot blindly change all parameter values, this should NOT be null. eArgs.Status = EngineEventArgs.EventStatus.Failed; } else { // eArgs.DataIntA contains list of parameter IDs that user wants changed. // eArgs.DataObjectList contains new values desired. bool logEnabled = false; if (m_Log != null) { logEnabled = m_Log.BeginEntry(Hubs.LogLevel.Major, "ProcessEvent: {2} {0} #{1} parameter change request: ", m_EngineName, m_EngineID, (m_Parent != null ? string.Format("{0} #{1}", m_Parent.EngineContainerName, m_Parent.EngineContainerID) : string.Empty)); } for (int i = 0; i < eArgs.DataIntA.Length; ++i) //ith parameter in the list inside the event. { int pID = eArgs.DataIntA[i]; // propertyID of parameter ParameterInfo pInfo = m_PInfo[pID]; PropertyInfo property = this.GetType().GetProperty(pInfo.Name); if (logEnabled) { m_Log.AppendEntry("[{0}, requested value={1},", pInfo.Name, eArgs.DataObjectList[i]); } if (property.CanWrite) { // If writable, try to set value of this parameter in *this* object. try { property.SetValue(this, eArgs.DataObjectList[i], null); } catch (Exception) { } } // Regardless of result, get the current value object o = property.GetValue(this, null); eArgs.DataObjectList[i] = o; if (logEnabled) { m_Log.AppendEntry(" final value={0}] ", eArgs.DataObjectList[i]); } } if (logEnabled) { m_Log.EndEntry(); } // Set status to confirm signifying that the values in the message // are the correct, confirmed values from the engine. eArgs.Status = EngineEventArgs.EventStatus.Confirm; this.IsUpdateRequired = true; // signal that we need updating! } break; default: eArgs.Status = EngineEventArgs.EventStatus.Failed; break; } }//end ProcessEngineEvent()