/// <summary> /// The Shutdown method is invoked to shutdown all of /// the services that the engine is currently managing. /// </summary> public void Shutdown() { foreach (string key in _mapServices.Keys) { IVfxFixService service = _mapServices[key]; service.Shutdown(); } }
/// <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 CreateService method is invoked to create a new instance /// of a service, based on the configuration information that is /// provided in the specified XML document. /// </summary> /// <param name="services"></param> /// <param name="settings"></param> /// <returns></returns> public static IVfxFixService CreateService(IVfxServices services, XmlDocument settings) { IVfxFixService result = null; XPathNavigator xpn = settings.CreateNavigator(); XPathNodeIterator xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Role']"); if ((xpi.Count == 1) && (xpi.MoveNext())) { string role = xpi.Current.GetAttribute("content", ""); if (!string.IsNullOrEmpty(role)) { switch (role) { case "Client": result = new VfxFixClientService(); break; case "Server": result = new VfxFixServerService(); break; } if (result != null) { result.Init(services, settings); } } } else { throw new ArgumentException("The setting 'Fix.Session.Role' was not found in the specified configuration."); } return(result); }