private void Activate_Entrypoint(object state) { // REC: The service can only be activated if it is // currently in the closed state. if (_serviceState == VfxFixServiceStates.Service_State_Closed) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Opened; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Opened; // REC: Dispatch the service started event: EventHandler <VfxFixServiceEventArgs> tmpDispatch_Started = EventDispatch; if (tmpDispatch_Started != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Started(this, tmpArgs); } // REC: The service doesn't support a timed wait right now, so the // connection attempts start immediately: _serviceStatus = VfxFixServiceStatus.Service_Status_Connecting; EventHandler <VfxFixServiceEventArgs> tmpDispatch_Connecting = EventDispatch; if (tmpDispatch_Connecting != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Connecting(this, tmpArgs); } // REC: Activate the IPC endpoint so that the // connection can be established to the peer: _ipcEndpoint.Activate(); } }
/// <summary> /// The HandleIpc_EventClosed event handler is invoked in /// response to the service being notified that the session /// has been disconnected from the peer system. /// </summary> /// <param name="sender"> /// The IPC session that is dispatching the event. /// </param> /// <param name="args"> /// The details of the IPC event being dispatched. /// </param> private void HandleIpc_EventClosed(object sender, VfxIpcEventArgs args) { lock (_synch) { // REC: The IPC session is no longer established: _ipcEstablished = false; // REC: Notify the FIX session that the peer system // is no longer connected: _fixSession.HandleDisconnect(); // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Disconnected; EventHandler <VfxFixServiceEventArgs> tmpDispatch_Update = EventDispatch; if (tmpDispatch_Update != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Updated, _serviceStatus); tmpDispatch_Update(this, tmpArgs); } // REC: If the service is closing, then the disconnection // of the IPC endpoint is the last thing that needs to be // completed before dispatching the stopped event back up // to the service's owner/subscribers: if (_serviceState == VfxFixServiceStates.Service_State_Closing) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler <VfxFixServiceEventArgs> tmpDispatch_Stopped = EventDispatch; if (tmpDispatch_Stopped != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch_Stopped(this, tmpArgs); } } else { // REC: If the service is not configured to reconnect // to the peer system, then it is now stopped: // NOTE: Add reconnect logic here! // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler <VfxFixServiceEventArgs> tmpDispatch_Stopped = EventDispatch; if (tmpDispatch_Stopped != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch_Stopped(this, tmpArgs); } } } }
/// <summary> /// The Shutdown_Entrypoint method is the asynchronous entrypoint /// for the shutdown operation. It is invoked by the thread pool. /// </summary> /// <param name="state"></param> private void Shutdown_Entrypoint(object state) { lock (_synch) { // REC: The service can only be shutdown if it // is currently in the opened state: if (_serviceState == VfxFixServiceStates.Service_State_Opened) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closing; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closing; // REC: Dispatch an update to the service's subscribers: EventHandler <VfxFixServiceEventArgs> tmpDispatch_Update = EventDispatch; if (tmpDispatch_Update != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Updated, _serviceStatus); tmpDispatch_Update(this, tmpArgs); } // REC: If the FIX session is established, it needs // to be shutdown before the service can stop: if (_fixEstablished == true) { _fixSession.HandleShutdown(); } else if (_ipcEstablished == true) { _ipcEndpoint.Shutdown(); } else { // REC: Neither the IPC session nor the FIX session // are currently established, so the service should // just dispatch the shutdown event to its owner: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's status to reflect the new state: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler <VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, tmpArgs); } } } } }
/// <summary> /// The OnSessionStopped callback method is invoked in response /// to an instance of a session being shutdown. /// </summary> /// <param name="session"> /// The FIX session that the event relates to. /// </param> public void OnSessionClosed(IVfxFixSession session) { // REC: Determine which application session corresponds to // the FIX session that the event is coming from and route // the appropriate notification to it. if (_mapAppSessions.ContainsKey(session.InstanceId)) { IVfxFixAppSession appSession = _mapAppSessions[session.InstanceId]; _application.OnSessionClosed(appSession); } // REC: If there is currently an IPC session in place // that corresponds to the FIX session, it needs to be // disconnected at this point: if (_mapFixToIpc.ContainsKey(session.InstanceId)) { _endpoint.Shutdown(_mapFixToIpc[session.InstanceId]); } else { // REC: Since the FIX session has been closed, it can // be removed from the active sessions map: if (_mapFixSessions.ContainsKey(session.InstanceId)) { _mapFixSessions.Remove(session.InstanceId); } } if (_serviceState == VfxFixServiceStates.Service_State_Closing) { if (_mapFixSessions.Count == 0) { // REC: Adjust the service's state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; // REC: Dispatch the closed event: EventHandler <VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs args = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, args); } } } }
private void Activate_Entrypoint(object state) { if (_serviceState == VfxFixServiceStates.Service_State_Closed) { _serviceState = VfxFixServiceStates.Service_State_Opened; _serviceStatus = VfxFixServiceStatus.Service_Status_Opened; // REC: Dispatch the service started event: EventHandler <VfxFixServiceEventArgs> tmpDispatch_Started = EventDispatch; if (tmpDispatch_Started != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Started(this, tmpArgs); } _endpoint.Activate(); } }
private void Shutdown_Entrypoint(object state) { if (_serviceState == VfxFixServiceStates.Service_State_Opened) { // REC: Adjust the service's state: _serviceState = VfxFixServiceStates.Service_State_Closing; // REC: Adjust the service's status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closing; // REC: Shutdown the IPC endpoint first: _endpoint.Shutdown(); // REC: If there are any active FIX sessions, then they // need to be shutdown before the service can be shutdown. if (_mapFixSessions.Count > 0) { // REC: Iterate over all of the sessions and instruct // each one to shut itself down: foreach (Guid key in _mapFixSessions.Keys) { _mapFixSessions[key].HandleShutdown(); } } else { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; // REC: Dispatch the service stopped notification: EventHandler <VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, tmpArgs); } } } }
private void Shutdown_Entrypoint(object state) { if (_serviceState == VfxFixServiceStates.Service_State_Opened) { // REC: Adjust the service's state: _serviceState = VfxFixServiceStates.Service_State_Closing; // REC: Adjust the service's status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closing; // REC: Shutdown the IPC endpoint first: _endpoint.Shutdown(); // REC: If there are any active FIX sessions, then they // need to be shutdown before the service can be shutdown. if (_mapFixSessions.Count > 0) { // REC: Iterate over all of the sessions and instruct // each one to shut itself down: foreach (Guid key in _mapFixSessions.Keys) { _mapFixSessions[key].HandleShutdown(); } } else { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; // REC: Dispatch the service stopped notification: EventHandler<VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, tmpArgs); } } } }
private void Activate_Entrypoint(object state) { if (_serviceState == VfxFixServiceStates.Service_State_Closed) { _serviceState = VfxFixServiceStates.Service_State_Opened; _serviceStatus = VfxFixServiceStatus.Service_Status_Opened; // REC: Dispatch the service started event: EventHandler<VfxFixServiceEventArgs> tmpDispatch_Started = EventDispatch; if (tmpDispatch_Started != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Started(this, tmpArgs); } _endpoint.Activate(); } }
/// <summary> /// The OnSessionStopped callback method is invoked in response /// to an instance of a session being shutdown. /// </summary> /// <param name="session"> /// The FIX session that the event relates to. /// </param> public void OnSessionClosed(IVfxFixSession session) { // REC: Determine which application session corresponds to // the FIX session that the event is coming from and route // the appropriate notification to it. if (_mapAppSessions.ContainsKey(session.InstanceId)) { IVfxFixAppSession appSession = _mapAppSessions[session.InstanceId]; _application.OnSessionClosed(appSession); } // REC: If there is currently an IPC session in place // that corresponds to the FIX session, it needs to be // disconnected at this point: if (_mapFixToIpc.ContainsKey(session.InstanceId)) { _endpoint.Shutdown(_mapFixToIpc[session.InstanceId]); } else { // REC: Since the FIX session has been closed, it can // be removed from the active sessions map: if (_mapFixSessions.ContainsKey(session.InstanceId)) { _mapFixSessions.Remove(session.InstanceId); } } if (_serviceState == VfxFixServiceStates.Service_State_Closing) { if (_mapFixSessions.Count == 0) { // REC: Adjust the service's state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; // REC: Dispatch the closed event: EventHandler<VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs args = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, args); } } } }
/// <summary> /// The Shutdown_Entrypoint method is the asynchronous entrypoint /// for the shutdown operation. It is invoked by the thread pool. /// </summary> /// <param name="state"></param> private void Shutdown_Entrypoint(object state) { lock (_synch) { // REC: The service can only be shutdown if it // is currently in the opened state: if (_serviceState == VfxFixServiceStates.Service_State_Opened) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closing; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closing; // REC: Dispatch an update to the service's subscribers: EventHandler<VfxFixServiceEventArgs> tmpDispatch_Update = EventDispatch; if (tmpDispatch_Update != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Updated, _serviceStatus); tmpDispatch_Update(this, tmpArgs); } // REC: If the FIX session is established, it needs // to be shutdown before the service can stop: if(_fixEstablished == true) { _fixSession.HandleShutdown(); } else if(_ipcEstablished == true) { _ipcEndpoint.Shutdown(); } else { // REC: Neither the IPC session nor the FIX session // are currently established, so the service should // just dispatch the shutdown event to its owner: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's status to reflect the new state: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler<VfxFixServiceEventArgs> tmpDispatch = EventDispatch; if (tmpDispatch != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch(this, tmpArgs); } } } } }
/// <summary> /// The HandleIpc_EventClosed event handler is invoked in /// response to the service being notified that the session /// has been disconnected from the peer system. /// </summary> /// <param name="sender"> /// The IPC session that is dispatching the event. /// </param> /// <param name="args"> /// The details of the IPC event being dispatched. /// </param> private void HandleIpc_EventClosed(object sender, VfxIpcEventArgs args) { lock (_synch) { // REC: The IPC session is no longer established: _ipcEstablished = false; // REC: Notify the FIX session that the peer system // is no longer connected: _fixSession.HandleDisconnect(); // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Disconnected; EventHandler<VfxFixServiceEventArgs> tmpDispatch_Update = EventDispatch; if (tmpDispatch_Update != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Updated, _serviceStatus); tmpDispatch_Update(this, tmpArgs); } // REC: If the service is closing, then the disconnection // of the IPC endpoint is the last thing that needs to be // completed before dispatching the stopped event back up // to the service's owner/subscribers: if (_serviceState == VfxFixServiceStates.Service_State_Closing) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler<VfxFixServiceEventArgs> tmpDispatch_Stopped = EventDispatch; if (tmpDispatch_Stopped != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch_Stopped(this, tmpArgs); } } else { // REC: If the service is not configured to reconnect // to the peer system, then it is now stopped: // NOTE: Add reconnect logic here! // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Closed; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Closed; EventHandler<VfxFixServiceEventArgs> tmpDispatch_Stopped = EventDispatch; if (tmpDispatch_Stopped != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Stopped, _serviceStatus); tmpDispatch_Stopped(this, tmpArgs); } } } }
private void Activate_Entrypoint(object state) { // REC: The service can only be activated if it is // currently in the closed state. if (_serviceState == VfxFixServiceStates.Service_State_Closed) { // REC: Adjust the service's current state: _serviceState = VfxFixServiceStates.Service_State_Opened; // REC: Adjust the service's current status: _serviceStatus = VfxFixServiceStatus.Service_Status_Opened; // REC: Dispatch the service started event: EventHandler<VfxFixServiceEventArgs> tmpDispatch_Started = EventDispatch; if (tmpDispatch_Started != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Started(this, tmpArgs); } // REC: The service doesn't support a timed wait right now, so the // connection attempts start immediately: _serviceStatus = VfxFixServiceStatus.Service_Status_Connecting; EventHandler<VfxFixServiceEventArgs> tmpDispatch_Connecting = EventDispatch; if (tmpDispatch_Connecting != null) { VfxFixServiceEventArgs tmpArgs = new VfxFixServiceEventArgs(VfxFixServiceEventTypes.Event_Service_Started, _serviceStatus); tmpDispatch_Connecting(this, tmpArgs); } // REC: Activate the IPC endpoint so that the // connection can be established to the peer: _ipcEndpoint.Activate(); } }