Beispiel #1
0
 private void HandleIpcDispatch_EventMessage(object sender, VfxIpcEventArgs args)
 {
     if (_mapIpcToFix.ContainsKey(args.Token))
     {
         _mapFixSessions[_mapIpcToFix[args.Token]].HandleRxMessage(args.EventData);
     }
 }
 /// <summary>
 /// The HandleIpc_EventMessage event handler is invoked in
 /// response to the service being notified that the IPC session
 /// has received some data 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_EventMessage(object sender, VfxIpcEventArgs args)
 {
     lock (_synch)
     {
         _fixSession.HandleRxMessage(args.EventData);
     }
 }
        /// <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 HandleDispatch event handler is invoked in response to
        /// one of the IPC sessions dispatching an event to the endpoint.
        /// </summary>
        /// <param name="sender">
        /// The IPC session that is dispatching the event.
        /// </param>
        /// <param name="args">
        /// The details of the event being dispatched. The Token property
        /// of the event args instance will be set to the session id of the
        /// session that generated the event so that subscribers know which
        /// of the endpoint's sessions the event originated from.
        /// </param>
        private void HandleDispatch(object sender, VfxIpcEventArgs args)
        {
            EventHandler <VfxIpcEventArgs> tmp = EventDispatch;

            if (tmp != null)
            {
                tmp(this, args);
            }
        }
Beispiel #5
0
        /// <summary>
        /// The HandleDispatch event handler is invoked in response
        /// to an IPC event being dispatched to the session by the
        /// session's associated IPC module. The session assigns its
        /// unique identifier to the event and then forwards the event
        /// up to the server endpoint that owns the session.
        /// </summary>
        /// <param name="sender">
        /// The IPC module that is dispatching the event.
        /// </param>
        /// <param name="args">
        /// The details of the event being dispatched.
        /// </param>
        private void HandleDispatch(object sender, VfxIpcEventArgs args)
        {
            args.Token = _instanceGuid.ToString();
            EventHandler <VfxIpcEventArgs> tmp = EventDispatch;

            if (tmp != null)
            {
                tmp(this, args);
            }
        }
        /// <summary>
        /// The HandleIpc_EventOpened method is invoked in response
        /// to the IPC endpoint establishing a connection to the peer
        /// system that the service is interacting with.
        /// </summary>
        /// <param name="sender">
        /// The VfxIpcEndpoint that dispatched the event.
        /// </param>
        /// <param name="args">
        /// The details associated with the event.
        /// </param>
        private void HandleIpc_EventOpened(object sender, VfxIpcEventArgs args)
        {
            lock (_synch)
            {
                // REC: The IPC session is now established.
                _ipcEstablished = true;

                // REC: Adjust the service's current status:
                _serviceStatus = VfxFixServiceStatus.Service_Status_Opened;
                // REC: Dispatch the 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: Retrieve the version definition from the version
                // definition registry and determine what kind of session
                // needs to be created in order to handle the connection:
                IVfxFixVxRegistry vxRegistry = this._localServices.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;


                // REC: Create a new instance of a FIX session to handle
                // the communication between the server and the peer:
                IVfxFixSession fixSession = null;

                // REC: Check the version definition in order to tell if
                // this is a FIX 4.x or FIX 5.x service:
                VfxFixVxRecord vxRecord = vxRegistry.Get(this._sxVersion);
                if (vxRecord.Layer.ToLower().CompareTo("combined") == 0)
                {
                    fixSession = new VfxFix4xClientSession();
                }
                else
                {
                    fixSession = new VfxFix5xClientSession();
                }


                _fixSession = fixSession;

                // REC: Initialize the session:
                _fixSession.Init(this._localServices, this);

                // REC: Construct an instance of the session wrapper
                // for the FIX application and bind it to the session
                // implementation that has been created:
                _appSession = new VfxFixClientSession(_fixSession);

                // REC: Notify the FIX session implementation that it
                // has been connected to a peer system:
                _fixSession.HandleConnect();
            }
        }
Beispiel #7
0
        /// <summary>
        /// The HandleIpc_Dispatch method is invoked in response
        /// to the IPC session handler dispatching an IPC event to
        /// the endpoint. The event is simply forwarded to the owner
        /// of the endpoint instance for processing.
        /// </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_Dispatch(object sender, VfxIpcEventArgs args)
        {
            // REC: The incoming event from the underlying IPC session
            // is simply forwarded to the endpoint's owner:
            EventHandler <VfxIpcEventArgs> tmp = EventDispatch;

            if (tmp != null)
            {
                tmp(this, args);
            }
        }
Beispiel #8
0
        /// <summary>
        /// The HandleTcpConnector_Failure event handler is invoked
        /// in response to the connector not being able to establish
        /// a connection to the peer system.
        /// </summary>
        /// <param name="sender">
        /// The connector that is dispatching the event.
        /// </param>
        /// <param name="args">
        /// The event details that are associated with the event.
        /// </param>
        private void HandleTcpConnector_Failure(object sender, VfxTcpConnectorEventArgs args)
        {
            // REC: Translate the connector's failure notification
            // into the corresponding IPC event and dispatch it:
            EventHandler <VfxIpcEventArgs> tmpDispatch = EventDispatch;

            if (tmpDispatch != null)
            {
                VfxIpcEventArgs tmpArgs = new VfxIpcEventArgs(VfxIpcEventTypes.Event_Connect_Failure);
                tmpDispatch(this, tmpArgs);
            }
        }
Beispiel #9
0
        /// <summary>
        /// The HandleIpcDispatch_EventOpened event handler is invoked in
        /// response to a new session being established between a peer
        /// system and the endpoint associated with the service.
        /// </summary>
        /// <param name="sender">
        /// The IPC endpoint that dispatched the event.
        /// </param>
        /// <param name="args">
        /// The details of the event being dispatched.
        /// </param>
        private void HandleIpcDispatch_EventOpened(object sender, VfxIpcEventArgs args)
        {
            // REC: Create a new instance of a FIX session to handle
            // the communication between the server and the peer:
            IVfxFixSession fixSession = null;

            // REC: Retrieve the version definition from the version
            // definition registry and determine what kind of session
            // needs to be created in order to handle the connection:
            IVfxFixVxRegistry vxRegistry = this._localServices.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            // REC: Check the version definition in order to tell if
            // this is a FIX 4.x or FIX 5.x service:
            VfxFixVxRecord vxRecord = vxRegistry.Get(this._sxVersion);

            if (vxRecord.Layer.ToLower().CompareTo("combined") == 0)
            {
                fixSession = new VfxFix4xServerSession();
            }
            else
            {
                fixSession = new VfxFix5xServerSession();
            }


            // REC: Initialize the session:
            fixSession.Init(_localServices, this);

            // REC: Create an entry for the session in the
            // local session map:
            _mapFixSessions.Add(fixSession.InstanceId, fixSession);

            // REC: Bind the FIX session to the IPC session:
            _mapFixToIpc.Add(fixSession.InstanceId, args.Token);
            // REC: Bind the IPC session to the FIX session:
            _mapIpcToFix.Add(args.Token, fixSession.InstanceId);

            // REC: Create the application session container
            // that will be passed to the app implementation
            // when events are generated on the session:
            VfxFixServerSession appSession = new VfxFixServerSession(fixSession);

            // REC: Create a binding between the FIX session
            // and the application session so that events from
            // the FIX session can be correlated to the correct
            // application session when events are dispatched to
            // the user's FIX application instance:
            _mapAppSessions.Add(fixSession.InstanceId, appSession);

            // REC: Inform the session that a peer system
            // has been connected to it:
            fixSession.HandleConnect();
        }
Beispiel #10
0
        /// <summary>
        /// The HandleIpc_Dispatch event handler is invoked in
        /// response to the IPC endpoint dispatching an event to
        /// an instance of the service. The service demultiplexes
        /// the dispatched event to the appropriate handler.
        /// </summary>
        /// <param name="sender">
        /// The IPC endpoint that generated the event.
        /// </param>
        /// <param name="args">
        /// The IPC event details for the dispatched event.
        /// </param>
        private void HandleIpc_Dispatch(object sender, VfxIpcEventArgs args)
        {
            switch (args.EventType)
            {
            case VfxIpcEventTypes.Event_Session_Opened:
                HandleIpc_EventOpened(sender, args);
                break;

            case VfxIpcEventTypes.Event_Session_Message:
                HandleIpc_EventMessage(sender, args);
                break;

            case VfxIpcEventTypes.Event_Session_Closed:
                HandleIpc_EventClosed(sender, args);
                break;
            }
        }
Beispiel #11
0
        /// <summary>
        /// The HandleIpcDispatch_EventClosed event handler is invoked
        /// when an IPC session disconnects from a peer system.
        /// </summary>
        /// <param name="sender">
        /// The IPC session that dispatched the event.
        /// </param>
        /// <param name="args">
        /// The details of the event being dispatched.
        /// </param>
        private void HandleIpcDispatch_EventClosed(object sender, VfxIpcEventArgs args)
        {
            // REC: Determine if there is currently an instance of
            // a FIX session associated with the IPC session:
            if (_mapIpcToFix.ContainsKey(args.Token))
            {
                // REC: Remove the binding between the FIX session
                // and the IPC session, since the IPC session has been
                // disconnected and can not be used by the FIX session
                // for any other operations:
                if (_mapFixToIpc.ContainsKey(_mapIpcToFix[args.Token]))
                {
                    _mapFixToIpc.Remove(_mapIpcToFix[args.Token]);
                }

                // REC: Notify the associated FIX session that the
                // connection has been broken:
                _mapFixSessions[_mapIpcToFix[args.Token]].HandleDisconnect();
            }
        }