Exemple #1
0
        /// <summary>
        /// The Init method is called to initialize the class
        /// with a reference to the service container that it
        /// needs in order to retrieve and initialize its own
        /// service references.
        /// </summary>
        /// <param name="services">
        /// The service container that contains the services
        /// that the class needs to access.
        /// </param>
        public void Init(IVfxServices services)
        {
            _vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (_vxRegistry == null)
            {
                throw new ArgumentException("The service container doesn't include a reference to IVfxFixVxRegistry.");
            }

            _dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (_dxRegistry == null)
            {
                throw new ArgumentException("The service container doesn't include a reference to IVfxFixDxRegistry.");
            }
        }
Exemple #2
0
        /// <summary>
        /// The Init method intialized the message assembler
        /// with the services that are needed in order to create
        /// instances of FIX messages. The assembler requires that
        /// the IVfxFixVxRegistry and IVfxFixDxRegistry services be
        /// available from the provided service container.
        /// </summary>
        /// <param name="services">
        /// The service container that provides access to the services
        /// that the assembler needs in order to construct messages.
        /// </param>
        public void Init(IVfxServices services)
        {
            _vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (_vxRegistry == null)
            {
                throw new ArgumentException("VfxFixAssembler requires the IVfxFixVxRegistry service.");
            }

            _dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (_dxRegistry == null)
            {
                throw new ArgumentException("VfxFixAssembler requires the IVfxFixDxRegistry service.");
            }
        }
Exemple #3
0
        /// <summary>
        /// The Activate method starts all of the services that
        /// have been instantiated by the engine.
        /// </summary>
        public void Activate(IVfxServices services)
        {
            this._mapServices.Clear();

            // REC: Retrieve the engine configuration settings from
            // the service container, by retrieving the reference to
            // the IVfxSettings interface:
            IVfxSettings configuration = services.GetService(typeof(IVfxSettings)) as IVfxSettings;

            if (configuration != null)
            {
                // REC: Retrieve all of the session definitions from the
                // application configuration document:
                XPathNavigator    xpn = configuration.Document.CreateNavigator();
                XPathNodeIterator xpi = xpn.Select("/Engine/Sessions/Session");
                while (xpi.MoveNext())
                {
                    string sessionName = xpi.Current.GetAttribute("name", "");
                    if (!string.IsNullOrEmpty(sessionName))
                    {
                        string sessionType = xpi.Current.GetAttribute("type", "");
                        if (sessionType != null)
                        {
                            // REC: Create a new XML document that represents the
                            // service's specific configuration details:
                            XmlDocument svxConfiguration = new XmlDocument();
                            svxConfiguration.LoadXml(xpi.Current.OuterXml);

                            IVfxFixService service = null;
                            switch (sessionType)
                            {
                            case "FIX":
                                service = VfxFixServiceFactory.CreateService(services, svxConfiguration);
                                break;

                            case "FAST":
                                break;
                            }

                            this._mapServices.Add(sessionName, service);
                        }
                    }
                }
            }

            foreach (string key in _mapServices.Keys)
            {
                IVfxFixService service = _mapServices[key];
                service.Activate();
            }
        }
Exemple #4
0
        /// <summary>
        /// The Activate method starts all of the services that
        /// have been instantiated by the engine.
        /// </summary>
        public void Activate(IVfxServices services)
        {
            this._mapServices.Clear();

            // REC: Retrieve the engine configuration settings from
            // the service container, by retrieving the reference to
            // the IVfxSettings interface:
            IVfxSettings configuration = services.GetService(typeof(IVfxSettings)) as IVfxSettings;
            if (configuration != null)
            {
                // REC: Retrieve all of the session definitions from the
                // application configuration document:
                XPathNavigator xpn = configuration.Document.CreateNavigator();
                XPathNodeIterator xpi = xpn.Select("/Engine/Sessions/Session");
                while (xpi.MoveNext())
                {
                    string sessionName = xpi.Current.GetAttribute("name", "");
                    if (!string.IsNullOrEmpty(sessionName))
                    {
                        string sessionType = xpi.Current.GetAttribute("type", "");
                        if (sessionType != null)
                        {
                            // REC: Create a new XML document that represents the
                            // service's specific configuration details:
                            XmlDocument svxConfiguration = new XmlDocument();
                            svxConfiguration.LoadXml(xpi.Current.OuterXml);

                            IVfxFixService service = null;
                            switch (sessionType)
                            {
                                case "FIX":
                                    service = VfxFixServiceFactory.CreateService(services, svxConfiguration);
                                    break;
                                case "FAST":
                                    break;

                            }

                            this._mapServices.Add(sessionName, service);
                        }
                    }
                }
            }

            foreach (string key in _mapServices.Keys)
            {
                IVfxFixService service = _mapServices[key];
                service.Activate();
            }
        }
        /// <summary>
        /// The Init method is invoked to initialize an instance of
        /// the session class with the services, setttings, and handler
        /// that it requires in order to be activated. All instances of
        /// a session must be initialized before they can start managing
        /// a FIX session for their owner.
        /// </summary>
        /// <param name="services">
        /// The service container that contains the references to all of
        /// the system services that an instance of the session needs.
        /// </param>
        /// <param name="handler">
        /// The callback interface that the session directs all of its
        /// events to as they occur.
        /// </param>
        public void Init(IVfxServices services, IVfxFixSessionHandler handler)
        {
            // REC: Retrieve the version registry that the session
            // has been configured to use:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            // REC: Retrieve the dictionary registry that the session
            // has been configured to use:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;

            // REC: Retrieve the session database service from the
            // set of services provided by the session's owner:
            _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase;

            // REC: Retrieve the session configuration from the
            // service container for relevant settings:
            IVfxSettings settings = services.GetService(typeof(IVfxSettings)) as IVfxSettings;

            // REC: Temporary container to simplify accessing the
            // session settings from the XML configuration document:
            Dictionary <string, string> mapSettings = new Dictionary <string, string>();

            XPathNavigator    xpn = settings.Document.CreateNavigator();
            XPathNodeIterator xpi;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }


            // REC: Retrieve application layer details:
            VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion);

            // REC: Adjust the session layer, if one has not been
            // specified for the connection.
            if (string.IsNullOrEmpty(this._sxVersion))
            {
                if (axDetails.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
            }

            // REC: Retrieve the session layer details:
            VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion);

            // REC: Construct a local instance of a version definition
            // registry so that the session relies only on the specific
            // versions that have been specified for the service:
            VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry();

            // REC: Add the session layer to the local registry:
            localVxRegistry.Add(this._sxVersion, sxDetails);

            // REC: Add the application layer to the local registry:
            localVxRegistry.Add(this._axVersion, axDetails);

            // REC: Construct a new instance of the service container
            // and populate it with the services for the session:
            IVfxServices localServices = new VfxServices();

            // REC: The session can use the global dictionaries:
            localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);

            // REC: The session can use its own version registry:
            localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry);

            // REC: Initialize the parser with the local services:
            _fixParser.Init(localServices);

            // REC: Configure the FIX session timer to fire every
            // second for conducting timeout checks, etc.
            _fixTimer.Interval = 1000;

            // REC: Subscribe to the timer in order to determine if
            // the session has timed out:
            this._fixTimer.Elapsed += HandleElapsed_Timer;

            // REC: Initialize the FIX message assembler:
            _fixAssembler.Init(localServices);

            // REC: Register required fields for messages:
            this._fixBeginString = sxDetails.FixBs;
            _fixAssembler.SetField(new FixField(8, this._fixBeginString));
            _fixAssembler.SetField(new FixField(9, ""));
            _fixAssembler.SetField(new FixField(98, "0"));


            _fixAssembler.SetField(new FixField(108, "60"));

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Heartbeat']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                string fixTimeout = xpi.Current.GetAttribute("content", "").Trim();

                // REC: The client sessions need to maintain their own
                // reference to the heartbeat value:
                this._fixTimeout = int.Parse(fixTimeout);

                // REC: Assign the timeout value to the assembler so it
                // becomes the default for any message that needs it:
                _fixAssembler.SetField(new FixField(108, fixTimeout));
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the SenderCompID for identification:
                this._fixSenderCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(49, this._fixSenderCompID));
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.TargetCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the TargetCompID for identification:
                this._fixTargetCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(56, this._fixTargetCompID));
            }

            _fixAssembler.SetField(new FixField(10, ""));

            // REC: The client session knows the FIX TargetCompID of the
            // peer system in advance, unlike the server sessions, so we
            // can construct the session id in the initialization code:
            _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID);

            // REC: Maintain a reference to the supplied callback
            // handler for issuing event notifications:
            _handler = handler;
        }
Exemple #6
0
        /// <summary>
        /// The Init method intializes the parser and provides
        /// it with a reference to a service container that has
        /// references to the services that the parser requires
        /// in order to parse messages. The parser requires that
        /// the IVfxFixVxRegistry and IVfxFixDxRegistry services
        /// be available from the service container, or it won't
        /// be able to parse messages properly.
        /// </summary>
        /// <param name="context">
        /// The service container that contains the services that
        /// are needed by an instance of the parser.
        /// </param>
        public void Init(IVfxServices context)
        {
            // REC: Attempt to retrieve the reference to the
            // version registry from the container:
            _vxRegistry = context.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (_vxRegistry == null)
            {
                throw new ArgumentException("VfxFixParser: service IVfxFixVxRegistry must be provided.");
            }

            // REC: Create a local instance of the version matcher
            // and initialize it with the provided registry:
            _vxMatcher = new VfxFixVxMatcher();
            _vxMatcher.Init(_vxRegistry);

            // REC: Attempt to retrieve the reference to the
            // dictionary registry from the container:
            _dxRegistry = context.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (_dxRegistry == null)
            {
                throw new ArgumentException("VfxFixParser: service IVfxFixDxRegistry must be provided.");
            }
        }
        void IVfxFixSession.Init(IVfxServices services, IVfxFixSessionHandler handler)
        {
            // REC: Maintain a reference to the set of configuration settings
            // that are supplied to the session instance:
            _localServices = services;

            // REC: Retrieve the version registry that the session
            // has been configured to use:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            // REC: Retrieve the dictionary registry that the session
            // has been configured to use:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;

            // REC: Retrieve the session database service from the
            // set of services provided by the session's owner:
            _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase;

            // REC: Retrieve the configuration settings and extract
            // the FIX session and application layer versions:
            IVfxSettings settings = this._localServices.GetService(typeof(IVfxSettings)) as IVfxSettings;

            XPathNavigator    xpn = settings.Document.CreateNavigator();
            XPathNodeIterator xpi;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            // REC: Retrieve application layer details:
            VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion);

            // REC: Adjust the session layer, if it was not specified
            // and the application layer is FIX 4.0-4.4:
            if (string.IsNullOrEmpty(this._sxVersion))
            {
                if (axDetails.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
            }

            // REC: Retrieve the session layer details:
            VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion);

            // REC: Construct a local instance of a version definition
            // registry so that the session relies only on the specific
            // versions that have been specified for the service:
            VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry();

            // REC: Add the session layer to the local registry:
            localVxRegistry.Add(this._sxVersion, sxDetails);

            // REC: Add the application layer to the local registry:
            localVxRegistry.Add(this._axVersion, axDetails);

            // REC: Construct a new service container and initialize
            // it with the appropriate services:
            IVfxServices localServices = new VfxServices();

            localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);
            localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry);

            // REC: Initialize the parser with the local services:
            _fixParser.Init(localServices);

            // REC: Configure the FIX session timer to fire every
            // second for conducting timeout checks, etc.
            _fixTimer.Interval = 1000;
            // REC: Subscribe to the timer in order to determine if
            // the session has timed out:
            _fixTimer.Elapsed += HandleElapsed_Timer;

            // REC: Construct the FIX BeginString using the major
            // and minor version numbers from the primary dictionary
            // that is assigned to the version:
            FixDictionary dxPrimary = dxRegistry.GetEntry(sxDetails.Dictionaries[0].Name);

            // REC: Construct the appropriate begin string, based on the
            // major and minor version numbers of the dictionary:
            this._fixBeginString = sxDetails.FixBs;
            _fixAssembler.SetField(new FixField(8, this._fixBeginString));

            // REC: Initialize the FIX message assembler:
            _fixAssembler.Init(localServices);

            // REC: Register required fields for messages:
            _fixAssembler.SetField(new FixField(8, _fixBeginString));
            _fixAssembler.SetField(new FixField(9, ""));
            _fixAssembler.SetField(new FixField(98, "0"));
            _fixAssembler.SetField(new FixField(10, ""));

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the SenderCompID for identification:
                this._fixSenderCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(49, this._fixSenderCompID));
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Reset']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                string resetSequence = xpi.Current.GetAttribute("content", "");
                if (resetSequence.CompareTo("true") == 0)
                {
                    this._resetSequence = true;
                }
            }

            // REC: Maintain a reference to the supplied callback
            // handler for issuing event notifications:
            _handler = handler;
        }
        public void Init(IVfxServices services, XmlDocument settings)
        {
            // REC: The client service creates its own instance of a
            // service container and populates it with references to
            // both application and local service references:
            _localServices = new VfxServices();

            // REC: Maintain a reference to the configuration that is
            // provided by the caller - this will be used to configure
            // the sessions that are created when clients connect to an
            // instance of the service:
            _localServices.AddService(typeof(IVfxSettings), new VfxSettings(settings));

            // REC: Retrieve the IVfxFixApp service and maintain a
            // reference to it so that events from the FIX sessions
            // can be routed to the user's application:
            _application = services.GetService(typeof(IVfxFixApp)) as IVfxFixApp;
            if (_application == null)
            {
                throw new ArgumentException("The IVfxFixApp service must be provided.");
            }

            // REC: Ensure that the FIX version registry has been provided
            // in the service container that was supplied by the caller:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (vxRegistry == null)
            {
                throw new ArgumentException("The IVfxFixVxRegistry service is not available.");
            }

            // REC: Ensure that the FIX dictionary registry has been provided
            // in the service container that was supplied by the caller:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (dxRegistry == null)
            {
                throw new ArgumentException("The IVfxFixDxRegistry service is not available.");
            }

            // REC: An XPathNavigator is used to retrieve all of the
            // relevant settings from the corresponding configuration
            // document that is provided by the settings instance:
            XPathNavigator xpn = settings.CreateNavigator();

            // REC: An XPathNodeIterator is used to retrieve all of
            // the relevant settings from the document. The instance
            // is created by calling the 'Select' method of the path
            // navigator that is created from the settings:
            XPathNodeIterator xpi = null;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            // REC: Attempt to retrieve the version information that
            // corresponds to the configured application layer:
            VfxFixVxRecord vxRecord = vxRegistry.Get(this._axVersion);
            if(vxRecord == null)
            {
                throw new ArgumentException("The specified application layer could not be resolved.");
            }

            // REC: If the session layer version of the protocol
            // has not been specified, this may indicate that the
            // application version is FIX 4.0-4.4. If that is the
            // case, then we can default the session layer to the
            // same version as the application layer:
            if(string.IsNullOrEmpty(this._sxVersion))
            {
                // REC: The layer "combined" is set on version definitions
                // to indicate that both the session layer and application
                // layer are defined within the same dictionary:
                if(vxRecord.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
                else
                {
                    // REC: If the application layer does not resolve to
                    // an instance of a version definition that represents
                    // a version of FIX earlier than 5.0, then the service
                    // cannot be configured based on the app layer:
                    throw new ArgumentException("The session layer must be specified...");
                }
            }

            // REC: Retrieve the endpoint configuration from the session
            // configuration and use it to create a new instance of that
            // type of endpoint:
            xpi = xpn.Select("/Session/Endpoint");
            if ((xpi.Count == 1) && (xpi.MoveNext()))
            {
                XmlDocument epxConfiguration = new XmlDocument();
                epxConfiguration.LoadXml(xpi.Current.OuterXml);

                this._endpoint = VfxEndpointFactory.Create(epxConfiguration);
            }

            this._endpoint.EventDispatch += HandleIpcDispatch;

            this._localServices.AddService(typeof(IVfxFixVxRegistry), vxRegistry);
            this._localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);

            // REC: Retrieve the session database configuration from
            // the configuration settings:
            xpi = xpn.Select("/Session/Database");
            if ((xpi.Count == 1) && (xpi.MoveNext()))
            {
                XmlDocument dbxConfiguration = new XmlDocument();
                dbxConfiguration.LoadXml(xpi.Current.OuterXml);

                IVfxFixDatabase database = VfxFixDatabaseFactory.Create(services, dbxConfiguration);
                this._localServices.AddService(typeof(IVfxFixDatabase), database);
            }
        }
        void IVfxFixSession.Init(IVfxServices services, IVfxFixSessionHandler handler)
        {
            // REC: Maintain a reference to the set of configuration settings
            // that are supplied to the session instance:
            _localServices = services;

            // REC: Retrieve the version registry that the session
            // has been configured to use:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            // REC: Retrieve the dictionary registry that the session
            // has been configured to use:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;

            // REC: Retrieve the session database service from the
            // set of services provided by the session's owner:
            _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase;

            // REC: Retrieve the configuration settings and extract
            // the FIX session and application layer versions:
            IVfxSettings settings = this._localServices.GetService(typeof(IVfxSettings)) as IVfxSettings;

            XPathNavigator xpn = settings.Document.CreateNavigator();
            XPathNodeIterator xpi;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            // REC: Retrieve application layer details:
            VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion);

            // REC: Adjust the session layer, if it was not specified
            // and the application layer is FIX 4.0-4.4:
            if (string.IsNullOrEmpty(this._sxVersion))
            {
                if (axDetails.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
            }

            // REC: Retrieve the session layer details:
            VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion);

            // REC: Construct a local instance of a version definition
            // registry so that the session relies only on the specific
            // versions that have been specified for the service:
            VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry();

            // REC: Add the session layer to the local registry:
            localVxRegistry.Add(this._sxVersion, sxDetails);

            // REC: Add the application layer to the local registry:
            localVxRegistry.Add(this._axVersion, axDetails);

            // REC: Construct a new service container and initialize
            // it with the appropriate services:
            IVfxServices localServices = new VfxServices();
            localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);
            localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry);

            // REC: Initialize the parser with the local services:
            _fixParser.Init(localServices);

            // REC: Configure the FIX session timer to fire every
            // second for conducting timeout checks, etc.
            _fixTimer.Interval = 1000;
            // REC: Subscribe to the timer in order to determine if
            // the session has timed out:
            _fixTimer.Elapsed += HandleElapsed_Timer;

            // REC: Construct the FIX BeginString using the major
            // and minor version numbers from the primary dictionary
            // that is assigned to the version:
            FixDictionary dxPrimary = dxRegistry.GetEntry(sxDetails.Dictionaries[0].Name);

            // REC: Construct the appropriate begin string, based on the
            // major and minor version numbers of the dictionary:
            this._fixBeginString = sxDetails.FixBs;
            _fixAssembler.SetField(new FixField(8, this._fixBeginString));

            // REC: Initialize the FIX message assembler:
            _fixAssembler.Init(localServices);

            // REC: Register required fields for messages:
            _fixAssembler.SetField(new FixField(8, _fixBeginString));
            _fixAssembler.SetField(new FixField(9, ""));
            _fixAssembler.SetField(new FixField(98, "0"));
            _fixAssembler.SetField(new FixField(10, ""));

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the SenderCompID for identification:
                this._fixSenderCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(49, this._fixSenderCompID));
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Reset']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                string resetSequence = xpi.Current.GetAttribute("content", "");
                if (resetSequence.CompareTo("true") == 0)
                {
                    this._resetSequence = true;
                }
            }

            // REC: Maintain a reference to the supplied callback
            // handler for issuing event notifications:
            _handler = handler;
        }
Exemple #10
0
        /// <summary>
        /// The Init method intialized the message assembler
        /// with the services that are needed in order to create
        /// instances of FIX messages. The assembler requires that
        /// the IVfxFixVxRegistry and IVfxFixDxRegistry services be
        /// available from the provided service container.
        /// </summary>
        /// <param name="services">
        /// The service container that provides access to the services
        /// that the assembler needs in order to construct messages.
        /// </param>
        public void Init(IVfxServices services)
        {
            _vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (_vxRegistry == null)
            {
                throw new ArgumentException("VfxFixAssembler requires the IVfxFixVxRegistry service.");
            }

            _dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (_dxRegistry == null)
            {
                throw new ArgumentException("VfxFixAssembler requires the IVfxFixDxRegistry service.");
            }
        }
        /// <summary>
        /// The Init method is invoked to initialize an instance of
        /// the session class with the services, setttings, and handler
        /// that it requires in order to be activated. All instances of
        /// a session must be initialized before they can start managing
        /// a FIX session for their owner.
        /// </summary>
        /// <param name="services">
        /// The service container that contains the references to all of
        /// the system services that an instance of the session needs.
        /// </param>
        /// <param name="handler">
        /// The callback interface that the session directs all of its
        /// events to as they occur.
        /// </param>
        public void Init(IVfxServices services, IVfxFixSessionHandler handler)
        {
            // REC: Retrieve the version registry that the session
            // has been configured to use:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            // REC: Retrieve the dictionary registry that the session
            // has been configured to use:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;

            // REC: Retrieve the session database service from the
            // set of services provided by the session's owner:
            _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase;

            // REC: Retrieve the session configuration from the
            // service container for relevant settings:
            IVfxSettings settings = services.GetService(typeof(IVfxSettings)) as IVfxSettings;

            // REC: Temporary container to simplify accessing the
            // session settings from the XML configuration document:
            Dictionary<string, string> mapSettings = new Dictionary<string, string>();

            XPathNavigator xpn = settings.Document.CreateNavigator();
            XPathNodeIterator xpi = null;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Default']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axDefault = xpi.Current.GetAttribute("content", "").Trim();
            }

            // REC: Retrieve application layer details:
            VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion);

            // REC: Adjust the session layer, if one has not been
            // specified for the connection.
            if (string.IsNullOrEmpty(this._sxVersion))
            {
                if (axDetails.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
            }

            // REC: Retrieve the session layer details:
            VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion);

            // REC: Construct a local instance of a version definition
            // registry so that the session relies only on the specific
            // versions that have been specified for the service:
            VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry();

            // REC: Add the session layer to the local registry:
            localVxRegistry.Add(this._sxVersion, sxDetails);

            // REC: Add the application layer to the local registry:
            localVxRegistry.Add(this._axVersion, axDetails);

            // REC: Construct a new instance of the service container
            // and populate it with the services for the session:
            IVfxServices localServices = new VfxServices();

            // REC: The session can use the global dictionaries:
            localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);

            // REC: The session can use its own version registry:
            localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry);

            // REC: Initialize the parser with the local services:
            _fixParser.Init(localServices);

            // REC: Configure the FIX session timer to fire every
            // second for conducting timeout checks, etc.
            _fixTimer.Interval = 1000;

            // REC: Subscribe to the timer in order to determine if
            // the session has timed out:
            this._fixTimer.Elapsed += HandleElapsed_Timer;

            // REC: Initialize the FIX message assembler:
            _fixAssembler.Init(localServices);

            // REC: Register required fields for messages:
            this._fixBeginString = sxDetails.FixBs;
            _fixAssembler.SetField(new FixField(8, this._fixBeginString));
            _fixAssembler.SetField(new FixField(9, ""));
            _fixAssembler.SetField(new FixField(98, "0"));
            _fixAssembler.SetField(new FixField(108, "60"));

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Heartbeat']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                string fixTimeout = xpi.Current.GetAttribute("content", "").Trim();

                // REC: The client sessions need to maintain their own
                // reference to the heartbeat value:
                this._fixTimeout = int.Parse(fixTimeout);

                // REC: Assign the timeout value to the assembler so it
                // becomes the default for any message that needs it:
                _fixAssembler.SetField(new FixField(108, fixTimeout));

            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the SenderCompID for identification:
                this._fixSenderCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(49, this._fixSenderCompID));

            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.TargetCompID']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                // REC: The client sessions need to maintain an independent
                // reference to the TargetCompID for identification:
                this._fixTargetCompID = xpi.Current.GetAttribute("content", "");

                // REC: Add the field to the assembler so that it gets put
                // into each outgoing message:
                _fixAssembler.SetField(new FixField(56, this._fixTargetCompID));
            }

            _fixAssembler.SetField(new FixField(10, ""));

            // REC: The client session knows the FIX TargetCompID of the
            // peer system in advance, unlike the server sessions, so we
            // can construct the session id in the initialization code:
            _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID);

            // REC: Maintain a reference to the supplied callback
            // handler for issuing event notifications:
            _handler = handler;
        }
Exemple #12
0
        /// <summary>
        /// The Init method is called to initialize the class
        /// with a reference to the service container that it
        /// needs in order to retrieve and initialize its own
        /// service references.
        /// </summary>
        /// <param name="services">
        /// The service container that contains the services
        /// that the class needs to access.
        /// </param>
        public void Init(IVfxServices services)
        {
            _vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;
            if (_vxRegistry == null)
            {
                throw new ArgumentException("The service container doesn't include a reference to IVfxFixVxRegistry.");
            }

            _dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;
            if (_dxRegistry == null)
            {
                throw new ArgumentException("The service container doesn't include a reference to IVfxFixDxRegistry.");
            }
        }
Exemple #13
0
        public void Init(IVfxServices services, XmlDocument settings)
        {
            // REC: The client service creates its own instance of a
            // service container and populates it with references to
            // both application and local service references:
            _localServices = new VfxServices();

            // REC: Maintain a reference to the configuration that is
            // provided by the caller - this will be used to configure
            // the sessions that are created when clients connect to an
            // instance of the service:
            _localServices.AddService(typeof(IVfxSettings), new VfxSettings(settings));

            // REC: Retrieve the IVfxFixApp service and maintain a
            // reference to it so that events from the FIX sessions
            // can be routed to the user's application:
            _application = services.GetService(typeof(IVfxFixApp)) as IVfxFixApp;
            if (_application == null)
            {
                throw new ArgumentException("The IVfxFixApp service must be provided.");
            }

            // REC: Ensure that the FIX version registry has been provided
            // in the service container that was supplied by the caller:
            IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry;

            if (vxRegistry == null)
            {
                throw new ArgumentException("The IVfxFixVxRegistry service is not available.");
            }

            // REC: Ensure that the FIX dictionary registry has been provided
            // in the service container that was supplied by the caller:
            IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry;

            if (dxRegistry == null)
            {
                throw new ArgumentException("The IVfxFixDxRegistry service is not available.");
            }

            // REC: An XPathNavigator is used to retrieve all of the
            // relevant settings from the corresponding configuration
            // document that is provided by the settings instance:
            XPathNavigator xpn = settings.CreateNavigator();

            // REC: An XPathNodeIterator is used to retrieve all of
            // the relevant settings from the document. The instance
            // is created by calling the 'Select' method of the path
            // navigator that is created from the settings:
            XPathNodeIterator xpi = null;

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._sxVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']");
            if ((xpi.Count > 0) && (xpi.MoveNext()))
            {
                this._axVersion = xpi.Current.GetAttribute("content", "").Trim();
            }

            // REC: Attempt to retrieve the version information that
            // corresponds to the configured application layer:
            VfxFixVxRecord vxRecord = vxRegistry.Get(this._axVersion);

            if (vxRecord == null)
            {
                throw new ArgumentException("The specified application layer could not be resolved.");
            }

            // REC: If the session layer version of the protocol
            // has not been specified, this may indicate that the
            // application version is FIX 4.0-4.4. If that is the
            // case, then we can default the session layer to the
            // same version as the application layer:
            if (string.IsNullOrEmpty(this._sxVersion))
            {
                // REC: The layer "combined" is set on version definitions
                // to indicate that both the session layer and application
                // layer are defined within the same dictionary:
                if (vxRecord.Layer.ToLower().CompareTo("combined") == 0)
                {
                    this._sxVersion = this._axVersion;
                }
                else
                {
                    // REC: If the application layer does not resolve to
                    // an instance of a version definition that represents
                    // a version of FIX earlier than 5.0, then the service
                    // cannot be configured based on the app layer:
                    throw new ArgumentException("The session layer must be specified...");
                }
            }

            // REC: Retrieve the endpoint configuration from the session
            // configuration and use it to create a new instance of that
            // type of endpoint:
            xpi = xpn.Select("/Session/Endpoint");
            if ((xpi.Count == 1) && (xpi.MoveNext()))
            {
                XmlDocument epxConfiguration = new XmlDocument();
                epxConfiguration.LoadXml(xpi.Current.OuterXml);

                this._endpoint = VfxEndpointFactory.Create(epxConfiguration);
            }

            this._endpoint.EventDispatch += HandleIpcDispatch;

            this._localServices.AddService(typeof(IVfxFixVxRegistry), vxRegistry);
            this._localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry);

            // REC: Retrieve the session database configuration from
            // the configuration settings:
            xpi = xpn.Select("/Session/Database");
            if ((xpi.Count == 1) && (xpi.MoveNext()))
            {
                XmlDocument dbxConfiguration = new XmlDocument();
                dbxConfiguration.LoadXml(xpi.Current.OuterXml);

                IVfxFixDatabase database = VfxFixDatabaseFactory.Create(services, dbxConfiguration);
                this._localServices.AddService(typeof(IVfxFixDatabase), database);
            }
        }