Ejemplo n.º 1
0
        internal static bool Initialize()
        {
            LogProviderBase log = null;

            if (LogManager.Instance.State == RunState.Running)
            {
                log = LogManager.Instance.GetProvider(typeof(OncorServer));
            }
            if (log == null)
            {
                log = new NullLogger(typeof(OncorServer));
            }

            ConfigurationProviderBase prov = ConfigurationManager.Instance.GetProvider();

            if (prov != null)
            {
                ConfigurationParameter param      = prov.Get(typeof(HttpListenerServerListener), "listenerUrls");
                List <string>          listenUrls = new List <string>();
                if (param != null)
                {
                    string[] tmp = (string[])param.Value;
                    listenUrls.AddRange(tmp);

                    List <IHandlerMapper> handlers = new List <IHandlerMapper>();
                    handlers.Add(InitApi(prov));
                    handlers.Add(InitFiles(prov));
                    Server = InitServer(listenUrls, handlers);
                    return(Server != null);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        protected sealed override void StartImpl()
        {
            LogProviderBase logger = LogManager.Instance.GetProvider(this.GetType());

            if (logger == null)
            {
                logger = new NullLogger(this.GetType());
            }
            logger.Log(0, "Start: Called");
            if (this.State == RunState.Starting) //set by base class
            {
                this.runningTask = new Task(this.Run);
                this.runningTask.Start();
                while (this.runningTask.Status == TaskStatus.WaitingForActivation || this.runningTask.Status == TaskStatus.WaitingToRun)
                {
                    Thread.Sleep(0); //wait to allow the start to actually get started
                }
                if (this.State == RunState.Starting)
                {
                    this.State = RunState.Running;
                }
                else if (this.runningTask.Status == TaskStatus.Faulted)
                {
                    this.State = RunState.FailedStarting;
                    logger.Log(0, "Start: Failed on startup, task thread faulted");
                }
            }
            else
            {
                logger.Log(0, "Start: Called from improper state: " + this.State.ToString());
            }
        }
Ejemplo n.º 3
0
 protected override void Shutdown()
 {
     lock (syncRoot)
     {
         if (writer != null)
         {
             try
             {
                 if (log == null || log is NullLogger)
                 {
                     log = LogManager.Instance.GetProvider(typeof(FlatFileLogFactory));
                 }
                 log.Log(0, "Shutdown: Flushing and closing log");
                 writer.Flush();
                 writer.Dispose();
                 try
                 {
                     writer.Dispose();
                 }
                 catch
                 { }
                 writer = null;
             }
             catch
             {
                 log.Log(1000, "Shutdown: Failed flushing and closing log");
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Tries to intialize by configuration, if no configuartion parameter is found, tries to use local static configuration property.
        /// If that is not found, initialization fails.
        /// </summary>
        /// <returns></returns>
        protected override bool Initialize()
        {
            lock (syncRoot)
            {
                LogProviderBase logger = LogManager.Instance.GetProvider(typeof(FlatFileLogFactory));
                if (logger == null)
                {
                    logger = new NullLogger(typeof(FlatFileLogFactory));
                }

                ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                if (config != null)
                {
                    ConfigurationParameter param = config.Get(typeof(FlatFileLogFactory), "fileName");
                    if (param != null)
                    {
                        try
                        {
                            string fileName = (string)param.Value;
                            if (Init(fileName))
                            {
                                logger = null; //make sure to clear it out
                                return(true);
                            }
                            else
                            {
                                logger.Log(1000, "InitImpl: Failed to get or create log file: " + fileName);
                            }
                        }
                        catch
                        {
                            logger.Log(1000, "InitImpl: Failed to get configuration param");
                        }
                    }
                    else
                    {
                        if (Init(Configuration))
                        {
                            logger = null; //make sure to clear it out
                            return(true);
                        }

                        logger.Log(1000, "InitImpl: Failed to get config parameter: fileName");
                    }
                }
                else
                {
                    logger.Log(1000, "InitImpl: Failed to get config provider");
                    if (Init(Configuration))
                    {
                        logger = null; //make sure to clear it out
                        return(true);
                    }
                }
                logger = null; //make sure to clear it out
                return(false);
            }
        }
Ejemplo n.º 5
0
 public Hosted2()
 {
     if (instance == null)
     {
         instance    = this;
         this.logger = LogManager.Instance.GetProvider(typeof(Hosted2));
         this.State  = RunState.Created;
     }
 }
Ejemplo n.º 6
0
 private void GetLogger()
 {
     this.logger = LogManager.Instance.GetProvider(typeof(HostingManager));
     if (this.logger == null)
     {
         this.logger = new NullLogger(typeof(HostingManager));
     }
     if (LogManager.Instance.State != RunState.Running)
     {
         LogManager.Instance.Start(); //try to enable logging while we shut down
     }
 }
Ejemplo n.º 7
0
        private static void Log(string method, LogLevel level, string message)
        {
            if (logger == null)
            {
                logger = LogManager.Instance.GetProvider(typeof(OncorServer));
            }

            if (logger != null)
            {
                logger.Log(method, LogLevel.Info, message);
            }
        }
Ejemplo n.º 8
0
        public void Bootstrap()
        {
            lock (instance)
            {
                if (RuntimeUtils.Bootstrappable(this.State))
                {
                    string meth = "Bootstrap";
                    this.State  = RunState.Bootstrapping;
                    this.logger = LogManager.Instance.GetProvider(typeof(IdentityManager));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(IdentityManager), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    IdentityConfiguration iConfig = new IdentityConfiguration();
                                    iConfig.FactoryTypeName = typeName;
                                    Bootstrap(iConfig);
                                    return;
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse 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");
                    }


                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
Ejemplo n.º 9
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(InstrumentManager));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(InstrumentManager), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    this.Initialize(typeName);
                                    return;
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse role provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get role provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get role provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }


                    this.State = RunState.FailedInitializing;
                }
            }
        }
Ejemplo n.º 10
0
        protected sealed override void StopImpl()
        {
            LogProviderBase logger = LogManager.Instance.GetProvider(this.GetType());

            if (logger == null)
            {
                logger = new NullLogger(this.GetType());
            }
            logger.Log(0, "Stop: Called");
            if (this.State == RunState.Stopping)
            {
                logger.Log(0, "Stop: stopping");
                if (this.runningTask != null)
                {
                    int i = 0;
                    while (this.runningTask.Status == TaskStatus.Running)
                    {
                        if ((i % 10) == 0)
                        {
                            logger.Log(0, "Stop: waiting for thread to stop " + i.ToString());
                        }
                        Thread.Sleep(5); //this is an issue if the task isn't well behaved
                        i++;
                    }
                    if (this.runningTask.Status == TaskStatus.Canceled || this.runningTask.Status == TaskStatus.RanToCompletion)
                    {
                        this.runningTask = null;
                    }
                    else
                    {
                        logger.Log(0, "Stop: thread stopped into an unexpected state " + this.runningTask.Status.ToString());
                    }
                }
                if (this.State == RunState.Stopping)
                {
                    this.State = RunState.Stopped;
                    logger.Log(0, "Stop: succeeded");
                }
                else
                {
                    logger.Log(0, "Stop: unexpected final state " + this.State.ToString());
                }
            }
            else
            {
                logger.Log(0, "Stop: Called from improper state: " + this.State.ToString());
            }
        }
Ejemplo n.º 11
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;
                }
            }
        }
Ejemplo n.º 12
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(EntityBundleManager));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(EntityBundleProvider), "connectionString");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                if (NpgSqlCommandUtils.TestConnection(tName))
                                {
                                    Db.ConnectionString = tName;
                                    Log(meth, LogLevel.Info, "Succeeded");
                                    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;
                }
            }
        }
Ejemplo n.º 13
0
 public void Start()
 {
     if (this.State == RunState.Stopped || this.State == RunState.Initialized)
     {
         LogProviderBase pp = LogManager.Instance.GetProvider(typeof(OncorHostShim));
         pp.Log(0, "Start: " + svr.State.ToString());
         if (svr.Start())
         {
             this.State = RunState.Running;
         }
         else
         {
             this.State = RunState.FailedStarting;
         }
     }
 }
Ejemplo n.º 14
0
 public void Initialize()
 {
     if (this.State == RunState.Created || this.State == RunState.FailedInitializing)
     {
         this.State = RunState.Initializing;
         LogProviderBase pp = LogManager.Instance.GetProvider(typeof(OncorHostShim));
         pp.Log(0, "Init: " + svr.State.ToString());
         if (svr.Init())
         {
             this.State = RunState.Initialized;
         }
         else
         {
             this.State = RunState.FailedInitializing;
         }
     }
 }
Ejemplo n.º 15
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;
                }
            }
        }
Ejemplo n.º 16
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;
                }
            }
        }
Ejemplo n.º 17
0
        protected override bool Initialize()
        {
            lock (instance)
            {
                if (!this.initialized)
                {
                    string meth = "Initialize";
                    this.logger = LogManager.Instance.GetProvider(myType);
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(myType, "connectionString");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                if (NpgSqlCommandUtils.TestConnection(tName))
                                {
                                    Db.ConnectionString = tName;
                                    this.initialized    = true;
                                    return(true);
                                }
                            }
                            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");
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 18
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;
                }
            }
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            ConfigurationManager.Instance.Bootstrap();
            ConfigurationManager.Instance.Initialize();
            ConfigurationManager.Instance.Start();

            LogManager.Instance.Bootstrap();
            LogManager.Instance.Initialize();
            LogManager.Instance.Start();

            if (LogManager.Instance.State == Osrs.Runtime.RunState.Running)
            {
                LogProviderBase prov = LogManager.Instance.GetProvider(typeof(Program));
                if (prov != null)
                {
                    prov.Log("Hi there", LogLevel.Info);
                }
            }
        }
Ejemplo n.º 20
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(DetProcessorManager));
                    Log(meth, LogLevel.Info, "Called");
                    if (DetRegistry.Instance.Init())
                    {
                        this.State = RunState.Initialized;
                        return;
                    }

                    this.State = RunState.FailedInitializing;
                }
            }
        }
Ejemplo n.º 21
0
        internal bool Init()
        {
            string meth = "Initialize";

            this.logger = LogManager.Instance.GetProvider(typeof(DetRegistry));
            Log(meth, LogLevel.Info, "Called");

            ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();

            if (config != null)
            {
                ConfigurationParameter param = config.Get(typeof(DetRegistry), "connectionString");
                if (param != null)
                {
                    string tName = param.Value as string;
                    if (!string.IsNullOrEmpty(tName))
                    {
                        if (NpgSqlCommandUtils.TestConnection(tName))
                        {
                            this.connString = tName;
                            Log(meth, LogLevel.Info, "Succeeded");
                            return(true);
                        }
                    }
                    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");
            }
            return(false);
        }
Ejemplo n.º 22
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());
                }
            }
        }
Ejemplo n.º 23
0
        protected override void BootstrapImpl()
        {
            lock (instance)
            {
                if (this.State == RunState.Created)
                {
                    string meth = "Bootstrap";
                    this.State  = RunState.Bootstrapping;
                    this.logger = LogManager.Instance.GetProvider(typeof(AuthenticationManager));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(AuthenticationManager), "authenticationProvider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    param = config.Get(typeof(AuthenticationManager), "credentialProvider");
                                    if (param != null)
                                    {
                                        tName = param.Value as string;
                                        if (!string.IsNullOrEmpty(tName))
                                        {
                                            TypeNameReference credName = TypeNameReference.Parse(tName);
                                            if (credName != null)
                                            {
                                                this.Bootstrap(typeName, credName);
                                                return;
                                            }
                                            else
                                            {
                                                Log(meth, LogLevel.Error, "Failed to parse credential provider param value");
                                            }
                                        }
                                        else
                                        {
                                            Log(meth, LogLevel.Error, "Failed to get credential provider param value");
                                        }
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to get credential provider param");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse authentication provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get authentication provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get authentication provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }

                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
        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);
        }
Ejemplo n.º 25
0
        public void Initialize()
        {
            if (this.State == RunState.Created || this.State == RunState.FailedInitializing)
            {
                this.State = RunState.Initializing;
                if (ConfigurationManager.Instance.State == RunState.Created)
                {
                    ConfigurationManager.Instance.Bootstrap();
                    ConfigurationManager.Instance.Initialize();
                }
                if (ConfigurationManager.Instance.State == RunState.Initialized)
                {
                    ConfigurationManager.Instance.Start();
                }

                if (ConfigurationManager.Instance.State == Osrs.Runtime.RunState.Running)
                {
                    if (LogManager.Instance.State == RunState.Created)
                    {
                        LogManager.Instance.Bootstrap();
                        LogManager.Instance.Initialize();
                    }
                    if (LogManager.Instance.State == RunState.Initialized)
                    {
                        LogManager.Instance.Start();
                    }

                    if (LogManager.Instance.State == Osrs.Runtime.RunState.Running)
                    {
                        logger = LogManager.Instance.GetProvider(typeof(HostServiceProxy));
                        if (logger == null)
                        {
                            logger = new NullLogger(typeof(HostServiceProxy));
                        }

                        ConfigurationProviderBase cfg = ConfigurationManager.Instance.GetProvider();
                        if (cfg != null)
                        {
                            ConfigurationParameter parm = cfg.Get(typeof(HostServiceProxy), "appListFileName");
                            if (parm != null)
                            {
                                try
                                {
                                    this.fileName = (string)parm.Value;
                                    if (!string.IsNullOrEmpty(this.fileName))
                                    {
                                        if (File.Exists(this.fileName))
                                        {
                                            this.logger.Log(0, "Init(Constructor): Succeeded");
                                            this.State = RunState.Initialized;
                                            return;
                                        }
                                    }
                                }
                                catch
                                { }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        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;
                }
            }
        }
Ejemplo n.º 27
0
 public void SaveLog <TType>(LogProviderBase <TType> logProvider)
 {
     SaveLog(logProvider.Provide());
 }
Ejemplo n.º 28
0
        static void Init()
        {
            lock (syncRoot)
            {
                HostMessage m = new HostMessage();
                m.Command = HostCommand.Init;

                if (state == RunState.Created)
                {
                    IEnumerable <TypeNameReference> names = null;
                    m.Message = "";

                    LogProviderBase log = null;
                    try
                    {
                        ConfigurationManager.Instance.Bootstrap();
                        ConfigurationManager.Instance.Initialize();
                        ConfigurationManager.Instance.Start();
                        if (ConfigurationManager.Instance.State == RunState.Running)
                        {
                            LogManager.Instance.Bootstrap();
                            LogManager.Instance.Initialize();
                            LogManager.Instance.Start();
                            if (LogManager.Instance.State == RunState.Running)
                            {
                                log = LogManager.Instance.GetProvider(typeof(Program));
                            }
                            if (log == null)
                            {
                                log = new NullLogger(typeof(Program));
                            }

                            ConfigurationProviderBase prov = ConfigurationManager.Instance.GetProvider();
                            if (prov != null)
                            {
                                ConfigurationParameter param = prov.Get(typeof(Program), "hostList");
                                if (param != null)
                                {
                                    string[] values = param.Value as string[];
                                    if (values != null && values.Length > 0)
                                    {
                                        HashSet <TypeNameReference> tps = new HashSet <TypeNameReference>();
                                        foreach (string s in values)
                                        {
                                            TypeNameReference cur = TypeNameReference.Parse(s);
                                            if (cur != null)
                                            {
                                                tps.Add(cur);
                                            }
                                            else
                                            {
                                                log.Log(5, "Failed to parse TypeName for: " + s);
                                            }
                                        }
                                        if (tps.Count > 0)
                                        {
                                            names = tps;
                                        }
                                    }
                                    else
                                    {
                                        m.Message = "Failed to get configuration value";
                                        log.Log(1000, m.Message);
                                    }
                                }
                                else
                                {
                                    m.Message = "Failed to get configuration parameter: hostList";
                                    log.Log(1000, m.Message);
                                }
                            }
                            else
                            {
                                m.Message = "Failed to get configuration provider";
                                log.Log(1000, m.Message);
                            }
                        }
                        else
                        {
                            m.Message = "Failed to initialize using local file, quitting (" + AppContext.BaseDirectory + ")";
                            if (log != null)
                            {
                                log.Log(1000, m.Message);
                            }
                        }
                    }
                    catch
                    {
                        m.Message = "Failed to initialize using config, falling back to local file";
                        if (log != null)
                        {
                            log.Log(1000, m.Message);
                        }
                    }

                    if (names != null)
                    {
                        HostingManager.Instance.Initialize(names);
                        state = HostingManager.Instance.State;
                        if (state == RunState.Initialized)
                        {
                            m.Message = "success " + m.Message;
                            if (log != null)
                            {
                                log.Log(0, m.Message);
                            }
                        }
                        else
                        {
                            m.Message = "failed " + m.Message;
                            if (log != null)
                            {
                                log.Log(1000, m.Message);
                            }
                        }
                    }
                    else
                    {
                        state     = HostingManager.Instance.State;
                        m.Message = "failed " + m.Message;
                        if (log != null)
                        {
                            log.Log(1000, m.Message);
                        }
                    }
                }
                else
                {
                    state     = HostingManager.Instance.State;
                    m.Message = "ignored";
                }

                comms.Send(m);
            }
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
0
 private HostingManager()
 {
     this.logger = new NullLogger(typeof(HostingManager));
 }