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); } }
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); } }