/// <summary> /// Override to perform custom population/registration of modules /// </summary> protected virtual void DoConfigureChildModules(IConfigSectionNode node) { cleanupChildren(false); if (node == null || !node.Exists) { return; } var allModules = DoGetAllChildModuleConfigNodes(node); foreach (var mnode in allModules) { var module = FactoryUtils.MakeAndConfigure <ModuleBase>(mnode, null, new [] { this }); if (!m_Children.Register(module)) { throw new NFXException(StringConsts.APP_MODULE_DUPLICATE_CHILD_ERROR.Args(this, module)); } } }
protected MdbArea(MdbDataStore store, IConfigSectionNode node) : base(store) { if (store == null || node == null || !node.Exists) { throw new MdbException(StringConsts.ARGUMENT_ERROR + "MdbArea.ctor(store==null|node==null|!Exists)"); } ConfigAttribute.Apply(this, node); var dsnode = node[CommonApplicationLogic.CONFIG_DATA_STORE_SECTION]; if (!dsnode.Exists) { throw new MdbException(StringConsts.MDB_AREA_CONFIG_NO_DATASTORE_ERROR.Args(node.RootPath)); } m_PhysicalDataStore = FactoryUtils.MakeAndConfigure <ICRUDDataStoreImplementation>(dsnode, args: new [] { this }); }
protected override void DoConfigure(IConfigSectionNode node) { base.DoConfigure(node); deleteChannels(); if (node == null || !node.Exists) { return; } m_Gateway.Configure(node[CONFIG_GATEWAY_SECTION]);//Configure gateway foreach (var cnode in node.Children.Where(cn => cn.IsSameName(CONFIG_CHANNEL_SECTION))) { var channel = FactoryUtils.MakeAndConfigure <Channel>(cnode, args: new object[] { this }); if (!m_Channels.Register(channel)) { throw new WebMessagingException(StringConsts.WM_SERVICE_NO_CHANNELS_ERROR.Args(GetType().Name)); } } }
protected override void DoConfigure(NFX.Environment.IConfigSectionNode node) { try { base.DoConfigure(node); m_Provider = FactoryUtils.MakeAndConfigure(node[CONFIG_PROVIDER_SECTION]) as InstrumentationProvider; if (m_Provider == null) { throw new NFXException("Provider is null"); } m_Provider.__setComponentDirector(this); } catch (Exception error) { throw new NFXException(StringConsts.INSTRUMENTATIONSVC_PROVIDER_CONFIG_ERROR + error.Message, error); } }
/// <summary> /// Automatically starts systems designated in config with auto-start attribute /// </summary> public static void AutoStartSystems() { foreach (var fsNode in App.ConfigRoot[CONFIG_FILESYSTEMS_SECTION].Children.Where(cn => cn.IsSameName(CONFIG_FILESYSTEM_SECTION))) { var name = fsNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value; if (!fsNode.AttrByName(CONFIG_AUTO_START_ATTR).ValueAsBool()) { continue; } var system = FactoryUtils.MakeAndConfigure <FileSystem>(fsNode, typeof(FileSystem), new object[] { name, fsNode }); if (s_Instances[system.Name] != null) // already started { throw new FileSystemException("AutoStart: " + StringConsts.FS_DUPLICATE_NAME_ERROR.Args(system.GetType().FullName, system.Name)); } s_Instances.Register(system); } }
private static void run(ServiceBaseApplication app) { //The command-line arguments are already parsed into configuration object accessible via `CommandArgs` //property of the application context if (app.CommandArgs["?", "h", "help"].Exists) { //`GetText(path)` is an extension method that reads an embedded resource //relative to the specfied type location ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt")); return; } var silent = app.CommandArgs["s", "silent"].Exists; if (!silent) { ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt")); } if (!silent) { Console.WriteLine(); } //Get logic switch ' -logic' from command args line as config section //notice no `if` statements, if addressed nodes do not exist, sentinels are returned instead //we could use `if (cfgLogic.Exists)....` var cfgLogic = app.CommandArgs["logic"]; //Inject the logic from config (BY CONFIGURATION), use DefaultLogic if type is not specified (BY CONVENTION). //This will call Configure(cfgLogic) on the Logic instance after its creation var logic = FactoryUtils.MakeAndConfigure <Logic>(cfgLogic, typeof(DefaultLogic)); //execute injected logic module logic.Execute(); if (!silent) { ConsoleUtils.Info("The End"); } }
void IApplicationStarter.ApplicationStartAfterInit(IApplication application) { application.RegisterAppFinishNotifiable(this); var nDataSore = m_Config[SocialConsts.CONFIG_DATA_STORE_SECTION]; if (!nDataSore.Exists) { throw new SocialException(StringConsts.GS_INIT_NOT_CONF_ERRROR.Args(this.GetType().Name, SocialConsts.CONFIG_DATA_STORE_SECTION)); } m_DataStore = FactoryUtils.MakeAndConfigure <MDBDataStore>(nDataSore, args: new object[] { "GraphSystem", this }); m_DataStore.Start(); var nHost = m_Config[SocialConsts.CONFIG_GRAPH_HOST_SECTION]; if (!nHost.Exists) { throw new SocialException(StringConsts.GS_INIT_NOT_CONF_ERRROR.Args(this.GetType().Name, SocialConsts.CONFIG_GRAPH_HOST_SECTION)); } m_GraphHost = FactoryUtils.MakeAndConfigure <GraphHost>(nHost, args: new object[] { this, nHost }); }
protected override void DoConfigure(IConfigSectionNode node) { if (node == null) { node = App.ConfigRoot[CONFIG_SHIPPING_PROCESSING_SECTION]; if (!node.Exists) { return; } //1 try to find the server with the same name as this instance var snode = node.Children.FirstOrDefault(cn => cn.IsSameName(CONFIG_SHIPPING_SYSTEM_SECTION) && cn.IsSameNameAttr(Name)); //2 try to find a server without a name if (snode == null) { snode = node.Children.FirstOrDefault(cn => cn.IsSameNameAttr(CONFIG_SHIPPING_SYSTEM_SECTION) && cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value.IsNullOrWhiteSpace()); } if (snode == null) { return; } node = snode; } ConfigAttribute.Apply(this, node); var carriers = new Registry <ShippingCarrier>(); var snodes = node[CONFIG_CARRIERS_SECTION].Children.Where(n => n.IsSameName(CONFIG_CARRIER_SECTION)); foreach (var snode in snodes) { var carrier = FactoryUtils.MakeAndConfigure <ShippingCarrier>(snode, typeof(ShippingCarrier), new object[] { this }); carriers.Register(carrier); } m_PreconfiguredShippingCarriers = carriers; }
public static void Run() { var tplSource = typeof(NHTTemplate).GetText("Template.htm"); var config = CONFIG.AsLaconicConfig(); var type = typeof(NHTCompiler); var args = new object[] { new TemplateStringContentSource(tplSource) }; var cmp = FactoryUtils.MakeAndConfigure <NHTCompiler>(config, type, args); cmp.Compile(); var unit = cmp.First(); if (unit.CompilationException != null) { Console.WriteLine(unit.CompilationException.ToMessageWithType()); } else { Console.Write(unit.CompiledSource); } }
private static void run(ServiceBaseApplication app) { if (app.CommandArgs["?", "h", "help"].Exists) { //GetText is an extension method that reads an embedded resource //relative to the specfied type location ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Help.txt")); return; } var silent = app.CommandArgs["s", "silent"].Exists; if (!silent) { ConsoleUtils.WriteMarkupContent(typeof(Program).GetText("Welcome.txt")); } if (!silent) { Console.WriteLine(); } //Get logic switch ' -logic' from command args line as config section //notice no if statements, if nodes does not exist, sentinels are returned //we could use if (cfgLogic.Exists).... var cfgLogic = app.CommandArgs["logic"]; //Inject the logic from config, use DefaultLogic if type is not specified //this will call Configure(cfgLogic) on the Logic instance var logic = FactoryUtils.MakeAndConfigure <Logic>(cfgLogic, typeof(DefaultLogic)); //execute injected logic module logic.Execute(); if (!silent) { ConsoleUtils.Info("The End"); } }
protected override void DoConfigure(IConfigSectionNode node) { base.DoConfigure(node); deleteVolumes(); if (node == null || !node.Exists) { return; } var nHost = node[CONFIG_TRENDING_HOST_SECTION]; m_TrendingHost = FactoryUtils.Make <TrendingSystemHost>(nHost, args: new object[] { this, nHost }); foreach (var cnode in node.Children.Where(cn => cn.IsSameName(CONFIG_VOLUME_SECTION))) { var volume = FactoryUtils.MakeAndConfigure <Volume>(cnode, args: new object[] { this }); if (!m_Volumes.Register(volume)) { throw new WebMessagingException(StringConsts.TS_SERVICE_DUPLICATE_VOLUMES_ERROR.Args(GetType().Name, volume.Name)); } } }
public virtual void Configure(IConfigSectionNode config) { if (config == null) { return; } ConfigAttribute.Apply(this, config); var loc = config[TimeLocation.CONFIG_TIMELOCATION_SECTION]; if (loc.Exists) { m_TimeLocation = FactoryUtils.MakeAndConfigure <TimeLocation>(loc, typeof(TimeLocation)); } var ehnode = config[CONFIG_HANDLER_SECTION]; if (ehnode.Exists) { EventHandler = FactoryUtils.MakeUsingCtor <IEventHandler>(ehnode); } }
public void ThrottleConfigTest() { var xml = @" <my-config ns='NFX.Throttling' type='$(/$ns).ThrottlingService' name='MyTestService'> <throttle type='$(/$ns).TimeSpacingThrottle' name='t1' limit='10' interval='1'/> <throttle type='$(/$ns).TimeSpacingThrottle' name='t2' limit='5' interval='2'/> <throttle type='$(/$ns).SlidingWindowThrottle' name='t3' limit='10' interval='1' buckets-per-sec='4'/> </my-config>"; var conf = NFX.Environment.XMLConfiguration.CreateFromXML(xml); var svc = FactoryUtils.MakeAndConfigure(conf.Root) as ThrottlingService; svc.Start(); var t1 = svc.Get <TimeSpacingThrottle>("t1"); Assert.AreEqual(10, t1.Limit); Assert.AreEqual(1, t1.Interval); var t2 = svc.Get <TimeSpacingThrottle>("t2"); Assert.AreEqual(5, t2.Limit); Assert.AreEqual(2, t2.Interval); var t3 = svc.Get <SlidingWindowThrottle>("t3"); Assert.AreEqual(10, t3.Limit); Assert.AreEqual(1, t3.Interval); Assert.AreEqual(4, t3.BucketsPerSec); new TimeSpacingThrottle("t4", 100, unit: "kaka").Register(svc); var t4 = svc.Get <TimeSpacingThrottle>("t4"); Assert.AreEqual("kaka", t4.Unit); svc.WaitForCompleteStop(); }
void IConfigurable.Configure(IConfigSectionNode node) { if (node == null || !node.Exists) { throw new WaveException(StringConsts.CONFIG_PORTAL_HUB_NODE_ERROR); } foreach (var cn in node.Children.Where(cn => cn.IsSameName(CONFIG_PORTAL_SECTION))) { m_Portals.Register(FactoryUtils.Make <Portal>(cn, typeof(Portal), args: new object[] { cn })); } //Make File System var fsNode = node[CONFIG_CONTENT_FS_SECTION]; m_ContentFS = FactoryUtils.MakeAndConfigure <FileSystem>(fsNode, typeof(NFX.IO.FileSystem.Local.LocalFileSystem), args: new object[] { GetType().Name, fsNode }); var fsPNode = fsNode[CONFIG_FS_CONNECT_PARAMS_SECTION]; if (fsPNode.Exists) { m_ContentFSConnect = FileSystemSessionConnectParams.Make <FileSystemSessionConnectParams>(fsPNode); } else { m_ContentFSConnect = new FileSystemSessionConnectParams() { User = NFX.Security.User.Fake }; } m_ContentFSRootPath = fsNode.AttrByName(CONFIG_FS_ROOT_PATH_ATTR).Value; if (m_ContentFSRootPath.IsNullOrWhiteSpace()) { throw new WaveException(StringConsts.CONFIG_PORTAL_HUB_FS_ROOT_PATH_ERROR.Args(CONFIG_CONTENT_FS_SECTION, CONFIG_FS_ROOT_PATH_ATTR)); } }
public void Configure(IConfigSectionNode node) { ConfigAttribute.Apply(this, node); var mnodes = node[CONFIG_METHODS_SECTION].Children.Where(n => n.IsSameName(CONFIG_METHOD_SECTION)); foreach (var mnode in mnodes) { var method = FactoryUtils.MakeAndConfigure <Method>(mnode, typeof(Method), new object[] { this }); m_Methods.Register(method); } var templates = new List <Package>(); var tnodes = node[CONFIG_PACKAGES_SECTION].Children.Where(n => n.IsSameName(CONFIG_PACKAGE_SECTION)); foreach (var tnode in tnodes) { var template = FactoryUtils.MakeAndConfigure <Package>(tnode, typeof(Package), new object[] { this }); m_Packages.Register(template); } NLSName = new NLSMap(node[CONFIG_NLS_SECTION]); }
/// <summary> /// Automatically starts systems designated in config with auto-start attribute /// </summary> public static void AutoStartSystems() { App.Instance.RegisterAppFinishNotifiable(PayProcessingFinisher.Instance); WebSettings.RequireInitializedSettings(); var pHost = App.ConfigRoot[WebSettings.CONFIG_WEBSETTINGS_SECTION][CONFIG_PAYMENT_PROCESSING_SECTION][CONFIG_PAY_SYSTEM_HOST_SECTION]; if (pHost.Exists) { var host = FactoryUtils.MakeAndConfigure <PaySystemHost>(pHost, typeof(PaySystemHost), new object[] { null, pHost }); host.Start(); ___SetPaySystemHost(host); } foreach (var psNode in App.ConfigRoot[WebSettings.CONFIG_WEBSETTINGS_SECTION][CONFIG_PAYMENT_PROCESSING_SECTION] .Children .Where(cn => cn.IsSameName(CONFIG_PAY_SYSTEM_SECTION))) { var name = psNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value; if (!psNode.AttrByName(CONFIG_AUTO_START_ATTR).ValueAsBool()) { continue; } var system = FactoryUtils.MakeAndConfigure <PaySystem>(psNode, typeof(PaySystem), new object[] { null, psNode }); if (s_Instances[system.Name] != null) // already started { throw new PaymentException("AutoStart: " + StringConsts.PAYMENT_SYSTEM_DUPLICATE_NAME_ERROR.Args(system.GetType().FullName, system.Name)); } system.Start(); } }
public void FromConf(IConfigSectionNode def, bool expect) { // def.See(); var filter = FactoryUtils.MakeAndConfigure <LogMessageFilter>(def, typeof(LogMessageFilter)); var msg = new Message { Topic = "apple", From = "Hydra.Records", Text = "Lenin loved mushrooms", Host = "cleveland.com", Channel = Atom.Encode("meduza"), App = Atom.Encode("dud") }; //var cnt = 500_000; //var time = Timeter.StartNew(); //for (var i = 0; i < cnt; i++) //{ // var got = filter.Evaluate(msg); // Aver.AreEqual(expect, got); //} //"Rate {0:n0} ops/sec".Args(cnt / (time.ElapsedMs / 1000d)).See(); }
protected override void DoConfigure(IConfigSectionNode node) { if (node == null) { node = App.ConfigRoot[CONFIG_SERVICE_HOST_SECTION]; } foreach (var snode in node.Children .Where(cn => cn.IsSameName(CONFIG_SERVICE_SECTION)) .OrderBy(cn => cn.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0))) //the order here is needed so that child services get CREATED in order, // not only launched in order { var ignored = snode.AttrByName(CONFIG_IGNORE_THIS_SERVICE_ATTR).ValueAsBool(false); if (ignored) { log(MessageType.Warning, "DoConfigure()", "Service {0} is ignored".Args(snode.AttrByName("name").Value)); continue; } var svc = FactoryUtils.MakeAndConfigure <Service>(snode, args: new object[] { this }); var abort = snode.AttrByName(CONFIG_ABORT_START_ATTR).ValueAsBool(true); RegisterService(svc, snode.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0), abort); } }
protected override void DoInitApplication() { base.DoInitApplication(); var FROM = GetType().FullName + ".DoInitApplication()"; var metabase = m_BootLoader.Metabase; try { m_GDIDProvider = new GdidGenerator(this, "Sky"); foreach (var ah in metabase.GDIDAuthorities) { m_GDIDProvider.AuthorityHosts.Register(ah); WriteLog(MessageType.Info, FROM + "{GDIDProvider init}", "Registered GDID authority host: " + ah.ToString()); } WriteLog(MessageType.Info, FROM, "GDIProvider made"); } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{GDIDProvider init}", error.ToMessageWithType()); try { m_GDIDProvider.Dispose(); } catch { } m_GDIDProvider = null; } var wmSection = ConfigRoot[CONFIG_WEB_MANAGER_SECTION]; if (wmSection.Exists && wmSection.AttrByName(CONFIG_ENABLED_ATTR).ValueAsBool(false)) { try { m_WebManagerServer = new WaveServer(this); m_WebManagerServer.Configure(wmSection); m_WebManagerServer.Start(); } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{WebManagerServer start}", error.ToMessageWithType()); try { m_WebManagerServer.Dispose(); } catch {} m_WebManagerServer = null; } } var lockSection = ConfigRoot[CONFIG_LOCK_MANAGER_SECTION]; try { m_LockManager = FactoryUtils.MakeAndConfigure <ILockManagerImplementation>(lockSection, typeof(LockManager)); WriteLog(MessageType.Info, FROM, "Lock Manager made"); if (m_LockManager is Daemon) { ((Daemon)m_LockManager).Start(); WriteLog(MessageType.Info, FROM, "Lock Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{LockManager start}", error.ToMessageWithType()); try { m_LockManager.Dispose(); } catch {} m_LockManager = null; } var procSection = ConfigRoot[CONFIG_PROCESS_MANAGER_SECTION]; try { m_ProcessManager = FactoryUtils.MakeAndConfigure <IProcessManagerImplementation>(procSection, typeof(ProcessManager), new object[] { this }); WriteLog(MessageType.Info, FROM, "Process Manager made"); if (m_ProcessManager is Daemon) { ((Daemon)m_ProcessManager).Start(); WriteLog(MessageType.Info, FROM, "Process Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{ProcessManager start}", error.ToMessageWithType()); try { m_ProcessManager.Dispose(); } catch {} m_ProcessManager = null; } var hostSection = ConfigRoot[CONFIG_HOST_MANAGER_SECTION]; try { m_DynamicHostManager = FactoryUtils.MakeAndConfigure <IHostManagerImplementation>(procSection, typeof(HostManager), new object[] { this }); WriteLog(MessageType.Info, FROM, "Dynamic Host Manager made"); if (m_DynamicHostManager is Daemon) { ((Daemon)m_DynamicHostManager).Start(); WriteLog(MessageType.Info, FROM, "Dynamic Host Manager STARTED"); } } catch (Exception error) { WriteLog(MessageType.CatastrophicError, FROM + "{HostManager start}", error.ToMessageWithType()); try { m_DynamicHostManager.Dispose(); } catch {} m_DynamicHostManager = null; } }
protected override void DoConfigure(Environment.IConfigSectionNode node) { base.DoConfigure(node); m_Sink = FactoryUtils.MakeAndConfigure <MailerSink>(node[CONFIG_SINK_SECTION], typeof(SMTPMailerSink), args: new object[] { this }); }
protected override void DoConfigure(IConfigSectionNode node) { base.DoConfigure(node); m_Config = node; m_PasswordManager = FactoryUtils.MakeAndConfigure <IPasswordManagerImplementation>(node[CONFIG_PASSWORD_MANAGER_SECTION], typeof(DefaultPasswordManager), new object[] { this }); }
/// <summary> /// Factory method that creates new Signal based on provided Type, PID and Configuration /// </summary> public static Signal MakeNew(IApplication app, Type type, PID pid, IConfigSectionNode args) { return(makeDefault(app.AsSky(), FactoryUtils.MakeAndConfigure <Signal>(args, type), pid)); }
/// <summary> /// Factory method that creates new Process based on provided Type, PID and Configuration /// </summary> public static Process MakeNew(IApplication app, Type type, PID pid, IConfigSectionNode args) => makeDefault(app.AsSky(), FactoryUtils.MakeAndConfigure <Process>(args, type), pid);
public static TParam Make <TParam>(IConfigSectionNode node) where TParam : FileSystem { string name = node.AttrByName(CONFIG_NAME_ATTR).ValueAsString(); return(FactoryUtils.MakeAndConfigure <TParam>(node, typeof(TParam), args: new object[] { name })); }
protected virtual void DoInitApplication() { ExecutionContext.__SetApplicationLevelContext(this, null, null, NOPSession.Instance); const string FROM = "app.init"; ConfigAttribute.Apply(this, m_ConfigRoot); m_Name = m_ConfigRoot.AttrByName(CONFIG_APP_NAME_ATTR).ValueAsString(GetType().FullName); Debugging.DefaultDebugAction = Debugging.ReadDefaultDebugActionFromConfig(); Debugging.TraceDisabled = Debugging.ReadTraceDisableFromConfig(); var node = m_ConfigRoot[CONFIG_LOG_SECTION]; if (node.Exists) { try { m_Log = FactoryUtils.MakeAndConfigure(node, typeof(LogService)) as ILogImplementation; if (m_Log == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Log made"); BeforeLogStart(m_Log); if (m_Log is Service) { ((Service)m_Log).Start(); WriteLog(MessageType.Info, FROM, "Log started, msg times are localized of machine-local time until time source starts"); } } catch (Exception error) { throw new NFXException(StringConsts.APP_LOG_INIT_ERROR + error); } } node = m_ConfigRoot[CONFIG_TIMESOURCE_SECTION]; if (node.Exists) { try { m_TimeSource = FactoryUtils.MakeAndConfigure(node, null) as ITimeSourceImplementation; if (m_TimeSource == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "TimeSource made"); BeforeTimeSourceStart(m_TimeSource); if (m_TimeSource is Service) { ((Service)m_TimeSource).Start(); WriteLog(MessageType.Info, FROM, "TimeSource started"); } WriteLog(MessageType.Info, FROM, "Log msg time is time source-supplied now"); } catch (Exception error) { throw new NFXException(StringConsts.APP_TIMESOURCE_INIT_ERROR + error); } } try { m_StartTime = LocalizedTime; WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime)); } catch (Exception error) { throw new NFXException(StringConsts.APP_TIMESOURCE_INIT_ERROR + error); } node = m_ConfigRoot[CONFIG_EVENT_TIMER_SECTION]; if (node.Exists) { try { m_EventTimer = FactoryUtils.MakeAndConfigure(node, typeof(EventTimer)) as IEventTimerImplementation; if (m_EventTimer == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "EventTimer made"); BeforeEventTimerStart(m_EventTimer); if (m_EventTimer is Service) { ((Service)m_EventTimer).Start(); WriteLog(MessageType.Info, FROM, "EventTimer started"); } } catch (Exception error) { throw new NFXException(StringConsts.APP_EVENT_TIMER_INIT_ERROR + error); } } node = m_ConfigRoot[CONFIG_SECURITY_SECTION]; if (node.Exists) { try { m_SecurityManager = FactoryUtils.MakeAndConfigure(node, typeof(ConfigSecurityManager)) as ISecurityManagerImplementation; if (m_SecurityManager == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Security Manager made"); BeforeSecurityManagerStart(m_SecurityManager); if (m_SecurityManager is Service) { ((Service)m_SecurityManager).Start(); WriteLog(MessageType.Info, FROM, "Security Manager started"); } } catch (Exception error) { var msg = StringConsts.APP_SECURITY_MANAGER_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } try { Behavior.ApplyConfiguredBehaviors(this, m_ConfigRoot); } catch (Exception error) { var msg = StringConsts.APP_APPLY_BEHAVIORS_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg, error); } node = m_ConfigRoot[CONFIG_INSTRUMENTATION_SECTION]; if (node.Exists) { try { m_Instrumentation = FactoryUtils.MakeAndConfigure(node, typeof(InstrumentationService)) as IInstrumentationImplementation; if (m_Instrumentation == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Instrumentation made"); BeforeInstrumentationStart(m_Instrumentation); if (m_Instrumentation is Service) { ((Service)m_Instrumentation).Start(); WriteLog(MessageType.Info, FROM, "Instrumentation started"); } } catch (Exception error) { var msg = StringConsts.APP_INSTRUMENTATION_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } node = m_ConfigRoot[CONFIG_THROTTLING_SECTION]; if (node.Exists) { try { m_Throttling = FactoryUtils.MakeAndConfigure(node, typeof(ThrottlingService)) as IThrottlingImplementation; if (m_Throttling == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Throttling made"); BeforeThrottlingStart(m_Throttling); if (m_Throttling is Service) { ((Service)m_Throttling).Start(); WriteLog(MessageType.Info, FROM, "Throttling started"); } } catch (Exception error) { var msg = StringConsts.APP_THROTTLING_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } node = m_ConfigRoot[CONFIG_DATA_STORE_SECTION]; if (node.Exists) { try { m_DataStore = FactoryUtils.MakeAndConfigure(node) as IDataStoreImplementation; if (m_DataStore == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "DataStore made"); BeforeDataStoreStart(m_DataStore); if (m_DataStore is Service) { ((Service)m_DataStore).Start(); WriteLog(MessageType.Info, FROM, "DataStore started"); } } catch (Exception error) { var msg = StringConsts.APP_DATA_STORE_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } node = m_ConfigRoot[CONFIG_OBJECT_STORE_SECTION]; if (node.Exists) { try { m_ObjectStore = FactoryUtils.MakeAndConfigure(node, typeof(ObjectStoreService)) as IObjectStoreImplementation; if (m_ObjectStore == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "ObjectStore made"); BeforeObjectStoreStart(m_ObjectStore); if (m_ObjectStore is Service) { ((Service)m_ObjectStore).Start(); WriteLog(MessageType.Info, FROM, "ObjectStore started"); } } catch (Exception error) { var msg = StringConsts.APP_OBJECT_STORE_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } node = m_ConfigRoot[CONFIG_GLUE_SECTION]; if (node.Exists) { try { m_Glue = FactoryUtils.MakeAndConfigure(node, typeof(NFX.Glue.Implementation.GlueService)) as IGlueImplementation; if (m_Glue == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Glue made"); BeforeGlueStart(m_Glue); if (m_Glue is Service) { ((Service)m_Glue).Start(); WriteLog(MessageType.Info, FROM, "Glue started"); } } catch (Exception error) { var msg = StringConsts.APP_GLUE_INIT_ERROR + error; WriteLog(MessageType.Error, FROM, msg); throw new NFXException(msg); } } WriteLog(MessageType.Info, FROM, "Common application initialized"); WriteLog(MessageType.Info, FROM, "Time localization information follows"); WriteLog(MessageType.Info, FROM, " Application: " + this.TimeLocation.ToString()); WriteLog(MessageType.Info, FROM, " Log: " + this.Log.TimeLocation.ToString()); WriteLog(MessageType.Info, FROM, " Glue: " + this.Glue.TimeLocation.ToString()); WriteLog(MessageType.Info, FROM, " Instrumentation: " + this.Instrumentation.TimeLocation.ToString()); WriteLog(MessageType.Info, FROM, " ObjStore: " + this.ObjectStore.TimeLocation.ToString()); }
protected virtual void DoInitApplication() { const string FROM = "app.init"; ConfigAttribute.Apply(this, m_ConfigRoot); m_Name = m_ConfigRoot.AttrByName(CONFIG_APP_NAME_ATTR).ValueAsString(GetType().FullName); Debugging.DefaultDebugAction = Debugging.ReadDefaultDebugActionFromConfig(); Debugging.TraceDisabled = Debugging.ReadTraceDisableFromConfig(); var node = m_ConfigRoot[CONFIG_LOG_SECTION]; if (node.Exists) { try { m_Log = FactoryUtils.MakeAndConfigure(node, typeof(LogService)) as ILogImplementation; if (m_Log == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Log made"); BeforeLogStart(m_Log); if (m_Log is Service) { if (((Service)m_Log).StartByApplication()) { WriteLog(MessageType.Info, FROM, "Log started, msg times are localized of machine-local time until time source starts"); } } } catch (Exception error) { throw new NFXException(StringConsts.APP_LOG_INIT_ERROR + error.ToMessageWithType(), error); } } node = m_ConfigRoot[CONFIG_TIMESOURCE_SECTION]; if (node.Exists) { try { m_TimeSource = FactoryUtils.MakeAndConfigure(node, null) as ITimeSourceImplementation; if (m_TimeSource == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "TimeSource made"); BeforeTimeSourceStart(m_TimeSource); if (m_TimeSource is Service) { if (((Service)m_TimeSource).StartByApplication()) { WriteLog(MessageType.Info, FROM, "TimeSource started"); } } WriteLog(MessageType.Info, FROM, "Log msg time is time source-supplied now"); m_StartTime = LocalizedTime; WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime)); } catch (Exception error) { var msg = StringConsts.APP_TIMESOURCE_INIT_ERROR + error.ToMessageWithType(); WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } else { WriteLog(MessageType.Info, FROM, "Using default time source"); m_StartTime = LocalizedTime; WriteLog(MessageType.Info, FROM, "App start time is {0}".Args(m_StartTime)); } node = m_ConfigRoot[CONFIG_EVENT_TIMER_SECTION]; //20150827 DKh event timer must allocate even if it is absent in config //// if (node.Exists) { try { m_EventTimer = FactoryUtils.MakeAndConfigure(node, typeof(EventTimer)) as IEventTimerImplementation; if (m_EventTimer == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "EventTimer made"); BeforeEventTimerStart(m_EventTimer); if (m_EventTimer is Service) { if (((Service)m_EventTimer).StartByApplication()) { WriteLog(MessageType.Info, FROM, "EventTimer started"); } } } catch (Exception error) { var msg = StringConsts.APP_EVENT_TIMER_INIT_ERROR + error.ToMessageWithType(); WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } node = m_ConfigRoot[CONFIG_SECURITY_SECTION]; if (node.Exists) { try { m_SecurityManager = FactoryUtils.MakeAndConfigure(node, typeof(ConfigSecurityManager)) as ISecurityManagerImplementation; if (m_SecurityManager == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Security Manager made"); BeforeSecurityManagerStart(m_SecurityManager); if (m_SecurityManager is Service) { if (((Service)m_SecurityManager).StartByApplication()) { WriteLog(MessageType.Info, FROM, "Security Manager started"); } } } catch (Exception error) { var msg = StringConsts.APP_SECURITY_MANAGER_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } try { Behavior.ApplyConfiguredBehaviors(this, m_ConfigRoot); } catch (Exception error) { var msg = StringConsts.APP_APPLY_BEHAVIORS_ERROR + error; WriteLog(MessageType.Error, FROM, msg, error); throw new NFXException(msg, error); } node = m_ConfigRoot[CONFIG_INSTRUMENTATION_SECTION]; if (node.Exists) { try { m_Instrumentation = FactoryUtils.MakeAndConfigure(node, typeof(InstrumentationService)) as IInstrumentationImplementation; if (m_Instrumentation == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Instrumentation made"); BeforeInstrumentationStart(m_Instrumentation); if (m_Instrumentation is Service) { if (((Service)m_Instrumentation).StartByApplication()) { WriteLog(MessageType.Info, FROM, "Instrumentation started"); } } } catch (Exception error) { var msg = StringConsts.APP_INSTRUMENTATION_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } node = m_ConfigRoot[CONFIG_THROTTLING_SECTION]; if (node.Exists) { try { m_Throttling = FactoryUtils.MakeAndConfigure(node, typeof(ThrottlingService)) as IThrottlingImplementation; if (m_Throttling == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Throttling made"); BeforeThrottlingStart(m_Throttling); if (m_Throttling is Service) { if (((Service)m_Throttling).StartByApplication()) { WriteLog(MessageType.Info, FROM, "Throttling started"); } } } catch (Exception error) { var msg = StringConsts.APP_THROTTLING_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } node = m_ConfigRoot[CONFIG_DATA_STORE_SECTION]; if (node.Exists) { try { m_DataStore = FactoryUtils.MakeAndConfigure(node) as IDataStoreImplementation; if (m_DataStore == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "DataStore made"); BeforeDataStoreStart(m_DataStore); if (m_DataStore is Service) { if (((Service)m_DataStore).StartByApplication()) { WriteLog(MessageType.Info, FROM, "DataStore started"); } } } catch (Exception error) { var msg = StringConsts.APP_DATA_STORE_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } node = m_ConfigRoot[CONFIG_OBJECT_STORE_SECTION]; if (node.Exists) { try { m_ObjectStore = FactoryUtils.MakeAndConfigure(node, typeof(ObjectStoreService)) as IObjectStoreImplementation; if (m_ObjectStore == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "ObjectStore made"); BeforeObjectStoreStart(m_ObjectStore); if (m_ObjectStore is Service) { if (((Service)m_ObjectStore).StartByApplication()) { WriteLog(MessageType.Info, FROM, "ObjectStore started"); } } } catch (Exception error) { var msg = StringConsts.APP_OBJECT_STORE_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } node = m_ConfigRoot[CONFIG_GLUE_SECTION]; if (node.Exists) { try { m_Glue = FactoryUtils.MakeAndConfigure(node, typeof(NFX.Glue.Implementation.GlueService)) as IGlueImplementation; if (m_Glue == null) { throw new NFXException(StringConsts.APP_INJECTION_TYPE_MISMATCH_ERROR + node .AttrByName(FactoryUtils.CONFIG_TYPE_ATTR) .ValueAsString(CoreConsts.UNKNOWN)); } WriteLog(MessageType.Info, FROM, "Glue made"); BeforeGlueStart(m_Glue); if (m_Glue is Service) { if (((Service)m_Glue).StartByApplication()) { WriteLog(MessageType.Info, FROM, "Glue started"); } } } catch (Exception error) { var msg = StringConsts.APP_GLUE_INIT_ERROR + error; WriteLog(MessageType.CatastrophicError, FROM, msg, error); throw new NFXException(msg, error); } } WriteLog(MessageType.Info, FROM, "Common application initialized in '{0}' time location".Args(this.TimeLocation)); WriteLog(MessageType.Info, FROM, "Component dump:"); foreach (var cmp in ApplicationComponent.AllComponents) { WriteLog(MessageType.Info, FROM, " -> Component: {0} '{1}' '{2}' ".Args(cmp.ComponentSID, cmp.GetType().FullName, cmp.ComponentCommonName)); } }
public static TSystem Make <TSystem>(string name, IConfigSectionNode node) where TSystem : CloudSystem { return(FactoryUtils.MakeAndConfigure <TSystem>(node, typeof(TSystem), new object[] { name, node })); }
public static TPaySystem Make <TPaySystem>(string name, IConfigSectionNode node) where TPaySystem : PaySystem { WebSettings.RequireInitializedSettings(); return(FactoryUtils.MakeAndConfigure <TPaySystem>(node, typeof(TPaySystem), new object[] { name, node })); }
public static TParams Make <TParams>(IConfigSectionNode node) where TParams : FileSystemSessionConnectParams { return(FactoryUtils.MakeAndConfigure <TParams>(node, typeof(TParams), args: new object[] { node })); }
/// <summary> /// Makes an instance of remote terminal which is configured under app/remote-terminal section. /// If section is not defined then makes AppRemoteTerminal instance /// </summary> public static AppRemoteTerminal MakeNewTerminal(IApplication app) { var result = FactoryUtils.MakeAndConfigure<AppRemoteTerminal>(app.ConfigRoot[CONFIG_APP_REMOTE_TERMINAL_SECTION], typeof(AppRemoteTerminal)); app.InjectInto(result); return result; }