コード例 #1
0
        public Task ExecutePostRegistrationStep(IDIContainer container, CancellationToken cancellationToken = default(CancellationToken))
        {
            var config = container.Resolve <IConfiguration>();
            var server = container.Resolve <IServer>();

            server.Location = container.Resolve <ILocation>();

            server.Location.Lat.Point = config.GetValueOrDefault("Server:Location:Lat", 0.0);
            server.Location.Lon.Point = config.GetValueOrDefault("Server:Location:Lon", 0.0);

            if (server.Location.Lat.Point != 0 && server.Location.Lon.Point != 0)
            {
                var ss = container.Resolve <ISunriseSunset>();
                server.Sunrise = ss.GetSunrise(server.Location.Lat.Point, server.Location.Lon.Point);
                server.Sunrset = ss.GetSunset(server.Location.Lat.Point, server.Location.Lon.Point);
            }

            if (container.IsRegistered <IScheduler>())
            {
                var scheduler = container.Resolve <IScheduler>();
                var updateJob = container.Resolve <IUpdateServerPropertiesJob>();
                var cron      = container.Resolve <ICronExpressions>();

                scheduler.RecurringJobAddOrUpdate(() => updateJob.UpdateServerProperties(), cron.Daily(12), TimeZoneInfo.Local);
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
 public Type GetType(string actorName)
 {
     if (_container.IsRegistered <IActorRef>(actorName))
     {
         return(_container.Resolve <IActorRef>(actorName)?.GetType());
     }
     return(null);
 }
コード例 #3
0
 private ICache <TKey, TValue> GetCache <TKey, TValue>(string name)
 {
     if (_container.IsRegistered <ICache <TKey, TValue> >(name))
     {
         return(_container.Resolve <ICache <TKey, TValue> >(name));
     }
     return(default(ICache <TKey, TValue>));
 }
コード例 #4
0
        public void Register(IDIContainer container)
        {
            if (!container.IsRegistered <ISerialize>())
            {
                new CoreServicesRegistrationContainer().Register(container);
            }
            if (!container.IsRegistered <ILogFactory>())
            {
                new LoggingRegistrationContainer().Register(container);
            }
            if (!container.IsRegistered <ICacheFactory>())
            {
                new CacheRegistrationContainer().Register(container);
            }

            container.Register <IResourceCompiler, ResourceCompiler>();
            container.Register <INeonTetraResources, NeonTetraResourceCache>();
            container.Register <ISpecificCultureTranslations, SpecificCultureTranslations>("DEFAULT");
        }
コード例 #5
0
 public void Register(IDIContainer container)
 {
     if (!container.IsRegistered <IConfiguration>())
     {
         container.Register <IConfiguration, Configuration>();
         var config = container.Resolve <IConfiguration>();
         config.Build();
         container.RegisterInstance(config, typeof(IConfiguration));
     }
 }
コード例 #6
0
        public Task ExecutePostRegistrationStep(IDIContainer container,
                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            Dictionary <string, string> loggingContext;

            if (container.IsRegistered <Dictionary <string, string> >("LoggingContext"))
            {
                loggingContext = container.Resolve <Dictionary <string, string> >("LoggingContext");
            }
            else
            {
                loggingContext = new Dictionary <string, string>();
                container.RegisterInstance(loggingContext, "LoggingContext");
            }

            loggingContext["Command Line"]      = Environment.CommandLine;
            loggingContext["Current Directory"] = Environment.CurrentDirectory;
            loggingContext["User Domain Name"]  = Environment.UserDomainName;
            loggingContext["User Name"]         = Environment.UserName;
            loggingContext["OS Version"]        = Environment.OSVersion.ToString();
            loggingContext["Machine Name"]      = Environment.MachineName;

            var host = Environment.GetEnvironmentVariable("Host");

            loggingContext["Host"] = host;

            if (container.IsRegistered <IConfiguration>())
            {
                var config = container.Resolve <IConfiguration>();
                loggingContext["Host Environment"]   = config.HostEnvironment;
                loggingContext["Entry Point"]        = config.EntryPoint;
                loggingContext["Environment"]        = config.Environment;
                loggingContext["Version"]            = config.Version;
                loggingContext["App Data Directory"] = config.AppDataDirectory.ToString();
                loggingContext["Debug Mode"]         = config.DebugMode.ToString().ToLowerInvariant();
                loggingContext["Root Directory"]     = config.RootDirectory.ToString();
            }

            return(Task.CompletedTask);
        }
            private void CheckDependencies()
            {
                foreach (var t in unregisteredTypesWeAreDependingOn.ToList())
                {
                    if (diContainer.IsRegistered(t))
                    {
                        unregisteredTypesWeAreDependingOn.Remove(t);
                    }
                }

                if (!unregisteredTypesWeAreDependingOn.Any())
                {
                    diContainer.NewTypesRegistered -= diContainer_NewTypesRegistered;
                }
            }
コード例 #8
0
        public override JsonContract ResolveContract(Type type)
        {
            if (type.GetTypeInfo().IsInterface)
            {
                if (_container.IsRegistered(type))
                {
                    var t = _container.Resolve(type);
                    if (t != null)
                    {
                        var i = t.GetType();
                        return(base.ResolveContract(i));
                    }
                }
                else
                {
                    _log.Error("JSON contract resolver failed to resolve type {0}.", type.FullName);
                }
            }

            return(base.ResolveContract(type));
        }
コード例 #9
0
        public async Task <IDeployment> Start(IDIContainer rootContainer, IDictionary <string, object> environment = null)
        {
            var id = Guid.NewGuid().ToString();

            if (environment != null)
            {
                if (environment.ContainsKey("id"))
                {
                    id = environment["id"].ToString();
                }
            }

            rootContainer.RegisterInstance(rootContainer);
            rootContainer.RegisterInstance(rootContainer as IRegister);
            rootContainer.RegisterInstance(rootContainer as IResolve);

            if (environment != null)
            {
                rootContainer.RegisterInstance(environment, "environment");
                foreach (var key in environment.Keys)
                {
                    rootContainer.RegisterInstance(environment[key], "environment." + key);
                }
            }

            IDeployment deployment = null;

            if (environment != null && environment.ContainsKey("Deployment"))
            {
                deployment = environment["Deployment"] as IDeployment;
            }
            else if (rootContainer.IsRegistered <IConfiguration>())
            {
                var config       = rootContainer.Resolve <IConfiguration>();
                var deployConfig = config.GetValue <string>("Deployment");
                if (!string.IsNullOrEmpty(deployConfig))
                {
                    var type = rootContainer.GetTypeByModuleName(deployConfig);
                    if (type != null)
                    {
                        deployment = type.Assembly.CreateInstance(type.FullName, false) as IDeployment;
                    }
                }
            }

            if (deployment == null)
            {
                deployment = new DefaultDeployment();
            }

            await deployment.Start(rootContainer, environment);

            while (!_activeDeployments.TryAdd(id, deployment))
            {
                await Task.Delay(1);
            }
            rootContainer.RegisterInstance(deployment);

            Started = true;
            return(deployment);
        }