示例#1
0
        public void Shutdown()
        {
            lock (this.syncRoot)
            {
                GetLogger();

                this.logger.Log(0, "Shutdown: Called");
                this.State = RunState.Stopping;
                while (this.monitoring)
                {
                    Thread.Sleep(5); //just try to let it finish a round of restarts
                }
                foreach (IHostedService cur in this.hostedServices)
                {
                    cur.Shutdown();
                    if (cur.State != RunState.Shutdown)
                    {
                        this.logger.Log(0, "Shutdown: Failed to shutdown " + NameReflectionUtils.GetName(cur).ToString());
                    }
                }
                LogManager.Instance.Shutdown();
                if (LogManager.Instance.State != RunState.Shutdown)
                {
                    this.logger.Log(0, "Shutdown: Failed to shutdown " + NameReflectionUtils.GetName(LogManager.Instance).ToString());
                }
                ConfigurationManager.Instance.Shutdown();
                if (ConfigurationManager.Instance.State != RunState.Shutdown)
                {
                    this.logger.Log(0, "Shutdown: Failed to shutdown " + NameReflectionUtils.GetName(ConfigurationManager.Instance).ToString());
                }

                this.logger.Log(0, "Shutdown: Succeeded");
                this.State = RunState.Shutdown;
            }
        }
 public void Bootstrap(TypeNameReference configSource, ConfigurationProviderBase initialConfig)
 {
     lock (this.syncRoot)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             this.State = RunState.Bootstrapping;
             if (configSource != null)
             {
                 this.initialProv = initialConfig;
                 ConfigurationFactoryBase configFinal = NameReflectionUtils.CreateInstance <ConfigurationFactoryBase>(configSource);
                 if (configFinal != null)
                 {
                     if (configFinal.Initialize())
                     {
                         this.provider = configFinal;
                         this.State    = RunState.Bootstrapped;
                         return;
                     }
                     else
                     {
                         this.provider = null;
                     }
                 }
             }
             this.State = RunState.FailedBootstrapping;
         }
     }
 }
示例#3
0
 public void Resume() //we left the monitor running, so we may not need to restart it
 {
     lock (this.syncRoot)
     {
         if (LogManager.Instance.State != RunState.Running)
         {
             LogManager.Instance.Start();
         }
         this.logger.Log(0, "Resume: Called");
         if (this.State == RunState.Paused)
         {
             this.State = RunState.Starting;
             foreach (IHostedService cur in this.hostedServices)
             {
                 cur.Resume();
                 if (cur.State != RunState.Running)
                 {
                     this.logger.Log(0, "Resume: Failed to resume " + NameReflectionUtils.GetName(cur).ToString());
                 }
             }
             this.logger.Log(0, "Resume: Succeeded, restarting monitoring");
             this.State = RunState.Running;
             if (!this.monitoring)
             {
                 Task t = new Task(this.MonitorServices);
                 t.Start();
             }
         }
         else
         {
             this.logger.Log(0, "Resume: Called from improper state: " + this.State.ToString());
         }
     }
 }
示例#4
0
 public void Pause() //leave the monitor running and never stop the logger -- just in case
 {
     lock (this.syncRoot)
     {
         this.logger.Log(0, "Pause: Called");
         if (this.State == RunState.Running)
         {
             this.State = RunState.Stopping;
             foreach (IHostedService cur in this.hostedServices)
             {
                 cur.Pause();
                 if (cur.State != RunState.Paused)
                 {
                     this.logger.Log(0, "Pause: Failed to pause " + NameReflectionUtils.GetName(cur).ToString());
                 }
             }
             this.logger.Log(0, "Pause: Succeeded");
             this.State = RunState.Paused;
         }
         else
         {
             this.logger.Log(0, "Pause: Called from improper state: " + this.State.ToString());
         }
     }
 }
示例#5
0
 protected NonSubclassableSingletonBase()
     : base()
 {
     lock (syncRoot)
     {
         if (created != null)
         {
             throw new SingletonException("Singleton instance already exists: " + created);
         }
         created = NameReflectionUtils.GetName(this);
     }
 }
 public ObjectToStringBuilder(object thing)
 {
     if (thing == null)
     {
         this.sb.Append(ObjectToStringBuilder.NullLiteral);
         this.sb.Append(ObjectToStringBuilder.StartObject);
     }
     else
     {
         this.sb.Append(NameReflectionUtils.GetBaseName(thing));
         this.sb.Append(ObjectToStringBuilder.StartObject);
     }
 }
示例#7
0
        protected override void InitializeImpl()
        {
            lock (instance)
            {
                if (RuntimeUtils.Initializable(this.State))
                {
                    string meth = "Initialize";
                    this.State  = RunState.Initializing;
                    this.logger = LogManager.Instance.GetProvider(typeof(UserAffilationSecurityManager));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(NameReflectionUtils.GetType(TypeNameReference.Parse("Osrs.WellKnown.FieldActivities.Providers.PgFieldActivityProviderFactory, Osrs.WellKnown.FieldActivities.Providers.Postgres")), "connectionString");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                if (NpgSqlCommandUtils.TestConnection(tName))
                                {
                                    Db.ConnectionString = tName;
                                    this.initialized    = true;
                                    this.State          = RunState.Initialized;
                                    return;
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get connectionString param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get connectionString param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }


                    this.State = RunState.FailedInitializing;
                }
            }
        }
示例#8
0
        public void Start()
        {
            lock (this.syncRoot)
            {
                GetLogger();
                this.logger.Log(0, "Start: Called");
                if (this.State == RunState.Initialized || this.State == RunState.Stopped)
                {
                    this.State = RunState.Starting;
                    if (ConfigurationManager.Instance.State != RunState.Running)
                    {
                        ConfigurationManager.Instance.Start();
                        if (ConfigurationManager.Instance.State != RunState.Running)
                        {
                            this.logger.Log(0, "Start: Failed to start " + NameReflectionUtils.GetName(ConfigurationManager.Instance).ToString());
                        }
                    }
                    if (LogManager.Instance.State != RunState.Running)
                    {
                        LogManager.Instance.Start();
                        if (LogManager.Instance.State != RunState.Running)
                        {
                            this.logger.Log(0, "Start: Failed to start " + NameReflectionUtils.GetName(LogManager.Instance).ToString());
                        }
                    }

                    foreach (IHostedService cur in this.hostedServices)
                    {
                        cur.Start();
                        if (cur.State != RunState.Running)
                        {
                            this.logger.Log(0, "Start: Failed to start " + NameReflectionUtils.GetName(cur).ToString());
                        }
                    }
                    this.logger.Log(0, "Start: Succeeded, starting monitoring");
                    this.State = RunState.Running;

                    Task t = new Task(this.MonitorServices);
                    t.Start();
                }
                else
                {
                    this.logger.Log(0, "Start: Called from improper state: " + this.State.ToString());
                }
            }
        }
示例#9
0
 public void Bootstrap(TypeNameReference logfactory)
 {
     lock (this.syncRoot)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             this.State = RunState.Bootstrapping;
             if (logfactory != null)
             {
                 this.provider = new MemoryLoggerFactory();
                 this.provider.Initialize();
                 if (!logfactory.Equals(TypeNameReference.Create(typeof(MemoryLoggerFactory)))) //confirm we're not just using memory logger
                 {
                     LogProviderFactory configFinal = NameReflectionUtils.CreateInstance <LogProviderFactory>(logfactory);
                     if (configFinal != null)
                     {
                         if (configFinal.Initialize())
                         {
                             this.provider = configFinal; //for the time being
                             foreach (LogItem cur in MemoryLoggerFactory.Items)
                             {
                                 LogProviderBase log = this.provider.GetLogger(NameReflectionUtils.GetType(cur.TypeName));
                                 if (log != null)
                                 {
                                     log.Log(cur.Severity, cur.Message);
                                 }
                             }
                             MemoryLoggerFactory.Items.Clear();
                             this.State = RunState.Bootstrapped;
                             return;
                         }
                     }
                 }
                 else //permanent logger is memory logger, so do nothing else
                 {
                     this.State = RunState.Bootstrapped;
                     return;
                 }
             }
             this.provider = null;
             this.State    = RunState.FailedBootstrapping;
         }
     }
 }
示例#10
0
        public void Bootstrap(TypeNameReference authFactoryType, TypeNameReference credFactoryType)
        {
            lock (instance)
            {
                if (this.State == RunState.Created || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(AuthenticationManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (authFactoryType != null && credFactoryType != null)
                    {
                        this.credFactory = NameReflectionUtils.CreateInstance <CredentialStoreFactory>(credFactoryType);
                        if (this.credFactory != null)
                        {
                            this.authFactory = NameReflectionUtils.CreateInstance <AuthenticationProviderFactory>(authFactoryType);
                            if (this.authFactory != null)
                            {
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Bootstrapped;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create authentication factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to create credential factory instance");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No typename provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
示例#11
0
        public void Initialize(TypeNameReference providerFactory)
        {
            lock (instance)
            {
                if (RuntimeUtils.Initializable(this.State) || this.State == RunState.Initializing)
                {
                    this.State = RunState.Initializing;
                    string meth = "Initialize";
                    if (this.logger == null)                     //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(InstrumentManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (providerFactory != null)
                    {
                        this.factory = NameReflectionUtils.CreateInstance <InstrumentProviderFactoryBase>(providerFactory);
                        if (this.factory != null)
                        {
                            if (this.factory.Initialize())
                            {
                                this.factory.LocalContext = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Initialized;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to initialize provider factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to create permission factory instance");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No typename provided");
                    }
                    this.State = RunState.FailedInitializing;
                }
            }
        }
示例#12
0
        public void Bootstrap(IdentityConfiguration config)
        {
            lock (instance)
            {
                if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(IdentityManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (config != null)
                    {
                        TypeNameReference typ = config.FactoryTypeName;
                        if (typ != null)
                        {
                            this.factory = NameReflectionUtils.CreateInstance <IdentityProviderFactory>(typ);
                            if (this.factory != null)
                            {
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Bootstrapped;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to extract typename");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No config provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
示例#13
0
        public void Stop()
        {
            lock (this.syncRoot)
            {
                GetLogger();
                this.logger.Log(0, "Stop: Called");
                if (this.State == RunState.Running || this.State == RunState.Paused)
                {
                    this.State = RunState.Stopping;
                    while (this.monitoring)
                    {
                        Thread.Sleep(5); //just try to let it finish a round of restarts
                    }
                    foreach (IHostedService cur in this.hostedServices)
                    {
                        cur.Stop();
                        if (cur.State != RunState.Stopped)
                        {
                            this.logger.Log(0, "Stop: Failed to stop " + NameReflectionUtils.GetName(cur).ToString());
                        }
                    }

                    ConfigurationManager.Instance.Stop();
                    if (ConfigurationManager.Instance.State != RunState.Stopped)
                    {
                        this.logger.Log(0, "Stop: Failed to stop " + NameReflectionUtils.GetName(ConfigurationManager.Instance).ToString());
                    }

                    this.logger.Log(0, "Stop: Succeeded"); //try to make sure we can log this event before we kill the logger
                    LogManager.Instance.Stop();
                    if (LogManager.Instance.State != RunState.Stopped)
                    {
                        this.logger.Log(0, "Stop: Failed to stop " + NameReflectionUtils.GetName(LogManager.Instance).ToString()); //ha! may or may not actually log
                    }
                    this.State = RunState.Stopped;
                }
                else
                {
                    this.logger.Log(0, "Stop: Called from improper state: " + this.State.ToString());
                }
            }
        }
示例#14
0
 public void Bootstrap(TypeNameReference factoryType, uint sessionDuration)
 {
     lock (instance)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             if (factoryType != null)
             {
                 SessionProviderFactory fact = NameReflectionUtils.CreateInstance <SessionProviderFactory>(factoryType);
                 if (fact != null)
                 {
                     this.factory         = fact;
                     this.SessionDuration = sessionDuration;
                     this.State           = RunState.Bootstrapped;
                     return;
                 }
             }
             this.State = RunState.FailedBootstrapping;
         }
     }
 }
示例#15
0
 public bool Initialize(UserPasswordConfig config)
 {
     lock (this)
     {
         if (config != null && !this.initialized)
         {
             if (config.HistoryProvider != null)
             {
                 this.HistoryProvider = this.HistoryProvider = NameReflectionUtils.CreateInstance <UserPasswordHistoryProviderFactory>(config.HistoryProvider);
                 if (this.HistoryProvider != null)
                 {
                     if (this.HistoryProvider.Initialize())
                     {
                         this.MaxHistory = config.MaxHistory;
                         if (config.MinChar < config.MaxChar)
                         {
                             try
                             {
                                 this.Shaker = new SaltShaker((char)config.MinChar, (char)config.MaxChar, config.HashLength, SaltCreationModel.Repeatable, SaltEmbeddingModel.Randomized, -1);
                                 foreach (PasswordComplexityRule curRule in config.Rules)
                                 {
                                     if (curRule != null)
                                     {
                                         this.ComplexityChecker.Rules.Add(curRule);
                                     }
                                 }
                                 this.initialized = true;
                                 return(true);
                             }
                             catch
                             { }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
        protected override bool Initialize()
        {
            lock (instance)
            {
                if (!this.initialized)
                {
                    string meth = "Initialize";
                    this.logger = LogManager.Instance.GetProvider(typeof(CachingPermissionProviderFactory));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(CachingPermissionProviderFactory), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    innerFact = NameReflectionUtils.CreateInstance <PermissionProviderFactory>(typeName);
                                    if (innerFact != null)
                                    {
                                        if (InitializeOther(innerFact))
                                        {
                                            //ok preload the cache
                                            LocalSystemUser     u    = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
                                            IPermissionProvider prov = this.GetProviderOther(this.innerFact, new UserSecurityContext(u));
                                            if (prov != null)
                                            {
                                                IEnumerable <Permission> perms = prov.GetPermissions();
                                                if (perms != null)
                                                {
                                                    foreach (Permission p in perms)
                                                    {
                                                        PermissionMemorySet.RegisterPermission(p);
                                                    }

                                                    this.initialized = true;
                                                    return(true);
                                                }
                                                else
                                                {
                                                    Log(meth, LogLevel.Error, "Failed to get existing permissions");
                                                }
                                            }
                                            else
                                            {
                                                Log(meth, LogLevel.Error, "Failed to get inner provider for preload");
                                            }
                                        }
                                        else
                                        {
                                            Log(meth, LogLevel.Error, "Failed to initialize inner provider");
                                        }
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create inner provider factory");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse permission provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }
                }
            }
            return(false);
        }
        public void Bootstrap(AuthorizationConfiguration config)
        {
            lock (instance)
            {
                if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(AuthorizationManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (config != null)
                    {
                        TypeNameReference typ = config.PermissionFactoryTypeName;
                        if (typ != null)
                        {
                            this.permissionFactory = NameReflectionUtils.CreateInstance <PermissionProviderFactory>(typ);
                            if (this.permissionFactory != null)
                            {
                                typ = config.RoleFactoryTypeName;
                                if (typ != null)
                                {
                                    this.roleFactory = NameReflectionUtils.CreateInstance <RoleProviderFactory>(typ);
                                    if (this.roleFactory != null)
                                    {
                                        this.roleFactory.LocalContext       = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                        this.permissionFactory.LocalContext = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                        Log(meth, LogLevel.Info, "Succeeded");
                                        this.State = RunState.Bootstrapped;
                                        return;
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create role factory instance");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to extract role typename");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create permission factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to extract permission typename");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No config provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
示例#18
0
        protected override bool Initialize()
        {
            lock (instance)
            {
                if (!this.initialized)
                {
                    string meth = "Initialize";
                    this.logger = LogManager.Instance.GetProvider(typeof(CachingRoleProviderFactory));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(CachingRoleProviderFactory), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    innerFact = NameReflectionUtils.CreateInstance <RoleProviderFactory>(typeName);
                                    if (innerFact != null)
                                    {
                                        if (InitializeOther(innerFact))
                                        {
                                            //ok preload the cache
                                            LocalSystemUser u    = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
                                            IRoleProvider   prov = this.GetProviderOther(this.innerFact, new UserSecurityContext(u));
                                            if (prov != null)
                                            {
                                                if (RoleMemorySet.Reset(prov))
                                                {
                                                    if (RoleMembershipMemorySet.Reset(prov))
                                                    {
                                                        this.initialized = true;
                                                        scavengeTimer    = new Timer(this.Scavenge, null, 0, 300000); //5 minutes
                                                        return(true);
                                                    }
                                                    else
                                                    {
                                                        Log(meth, LogLevel.Error, "Failed to initialize caching");
                                                    }
                                                }
                                                else
                                                {
                                                    Log(meth, LogLevel.Error, "Failed to initialize caching");
                                                }
                                            }
                                            else
                                            {
                                                Log(meth, LogLevel.Error, "Failed to get inner provider for preload");
                                            }
                                        }
                                        else
                                        {
                                            Log(meth, LogLevel.Error, "Failed to initialize inner provider");
                                        }
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create inner provider factory");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse permission provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get permission provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }
                }
            }
            return(false);
        }
示例#19
0
        public void Initialize(IEnumerable <TypeNameReference> typeList)
        {
            lock (this.syncRoot)
            {
                if (this.State == RunState.Created)
                {
                    if (ConfigurationManager.Instance.State == RunState.Created)
                    {
                        ConfigurationManager.Instance.Bootstrap();
                        ConfigurationManager.Instance.Initialize();
                    }
                    if (ConfigurationManager.Instance.State == RunState.Initialized)
                    {
                        ConfigurationManager.Instance.Start();
                    }
                    if (LogManager.Instance.State == RunState.Created)
                    {
                        LogManager.Instance.Bootstrap();
                        LogManager.Instance.Initialize();
                    }
                    if (LogManager.Instance.State == RunState.Initialized)
                    {
                        LogManager.Instance.Start(); //make sure we have something to log to
                    }
                    this.logger = null;

                    GetLogger();
                    this.logger.Log(0, "Initialize: Called");
                    //at this point, the logging and configuration services are running

                    if (typeList == null)
                    {
                        this.logger.Log(0, "Initialize: Null typeList, exiting");
                        return;
                    }

                    if (ConfigurationManager.Instance.State != RunState.Running)
                    {
                        this.logger.Log(100, "Initialize: ConfigurationManager failed to initialize");
                    }
                    if (LogManager.Instance.State != RunState.Running)
                    {
                        this.logger.Log(100, "Initialize: LogManager failed to initialize");
                    }

                    foreach (TypeNameReference cur in typeList)
                    {
                        try
                        {
                            IHostedService b = ReflectionUtils.Get <IHostedService>(cur);
                            if (b != null)
                            {
                                this.hostedServices.Add(b);
                                b.Initialize();
                                if (b.State != RunState.Initialized)
                                {
                                    this.logger.Log(5, "Initialize: Init failed for " + NameReflectionUtils.GetName(b).ToString());
                                }
                            }
                            else
                            {
                                this.logger.Log(5, "Initialize: Load failed for " + cur);
                            }
                        }
                        catch
                        { }
                    }

                    this.logger.Log(0, "Initialize: Succeeded");
                    this.State = RunState.Initialized;
                }
                else
                {
                    this.logger.Log(0, "Initialize: Called from improper state: " + this.State.ToString());
                }
            }
        }
示例#20
0
 private void MonitorServices()
 {
     this.monitoring = true;
     while (this.State == RunState.Running)
     {
         foreach (IHostedService cur in this.hostedServices)
         {
             if (cur.State == RunState.FailedRunning) //only try to restart failed services
             {
                 try
                 {
                     this.logger.Log(1000, "MonitorServices: Discovered failed service, attempting restart: " + NameReflectionUtils.GetName(cur).ToString());
                     cur.Start();
                     if (cur.State == RunState.FailedStarting)
                     {
                         this.logger.Log(1000, "MonitorServices: restart failed: " + NameReflectionUtils.GetName(cur).ToString());
                     }
                 }
                 catch
                 { } //suck it up and keep going
             }
         }
         Thread.Sleep(5000); //5 seconds
     }
     this.monitoring = false;
 }