示例#1
0
        /// <summary>
        /// The Create method creates a new instance of an endpoint
        /// implementation, based on the settings that are found in
        /// a section of a configuration metabase.
        /// </summary>
        /// <param name="settings">
        /// The section of a configuration metabase that contains
        /// configuration details for a specific endpoint type.
        /// </param>
        /// <returns>
        /// The resulting IPC endpoint.
        /// </returns>
        public static IVfxEndpoint Create(XmlDocument settings)
        {
            IVfxEndpoint result = null;

            // REC: Retrieve the endpoint type from the provided
            // settings and determine whether or not an instance
            // of that type can be created:
            XPathNavigator    xpn = settings.CreateNavigator();
            XPathNodeIterator xpi = xpn.Select("/Endpoint");

            if ((xpi.Count == 1) && (xpi.MoveNext()))
            {
                string requestedType = xpi.Current.GetAttribute("type", "");
                if (!string.IsNullOrEmpty(requestedType))
                {
                    switch (requestedType)
                    {
                    case "Tcp.Acceptor":
                        result = new VfxTcpServerEndpoint();
                        break;

                    case "Tcp.Connector":
                        result = new VfxTcpClientEndpoint();
                        break;
                    }
                }
                else
                {
                    throw new ArgumentException("An endpoint type must be specified.");
                }
            }

            if (result == null)
            {
                throw new ArgumentException("The specified endpoint type is not supported.");
            }

            result.Initialize(settings);
            return(result);
        }
示例#2
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);
            }
        }
示例#3
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);
            }
        }