Exemplo n.º 1
0
 public CloudService()
 {
     tenant      = App.Context.GetTenantContext().Tenant;
     cloudConfig = ConfigContext.GetConfig <CloudConfig>(tenant.Name, (config, key) =>
     {
         cloudConfig = config;
     });
 }
Exemplo n.º 2
0
        public static IEngine Initialize(bool forceRecreate)
        {
            if (Singleton <IEngine> .Instance == null || forceRecreate)
            {
                Singleton <IEngine> .Instance = new CoreEngine();

                var config = ConfigContext.GetConfig <CoreConfig>(new CoreConfig().SectionName);
                Singleton <IEngine> .Instance.Initialize(config);
            }
            return(Singleton <IEngine> .Instance);
        }
Exemplo n.º 3
0
        public IotWsClient(ILogger <IotWsClient> logger,
                           IHubContext <IotServiceHub> iotServiceHub)
        {
            this.logger        = logger;
            this.iotServiceHub = iotServiceHub;

            this.tenant = App.Context.GetTenantContext().Tenant;
            this.access = ConfigContext.GetConfig <IotConfig>(tenant.Name).Servers["iot"];

            this.Connect();
        }
Exemplo n.º 4
0
        public void ConfigTest()
        {
            _services.AddJsonConfig <TestConfig>(opts =>
            {
                opts.ConfigFile = "test.json";
            })
            .BuildServiceProvider()
            .UseConfigContext();

            var testConfig = ConfigContext.GetConfig <TestConfig>();

            Assert.AreNotEqual(testConfig, null);
            Assert.AreEqual(testConfig.Name, "hello");
        }
Exemplo n.º 5
0
        public void ConfigWithNameTest()
        {
            _services.AddJsonConfig <TestConfig>(opts =>
            {
                opts.Name       = "test";
                opts.ConfigFile = "test.json";
            })
            .BuildServiceProvider()
            .UseConfigContext();

            var testConfig = ConfigContext.GetConfig <TestConfig>("test");

            Assert.AreNotEqual(testConfig, null);
            Assert.AreEqual(testConfig.SubConfig.SubName, "world");
            Assert.AreEqual(testConfig.SubConfig.List[4], 4);
        }
Exemplo n.º 6
0
        public static IServiceCollection AddDataAccess(this IServiceCollection services)
        {
            services.AddSingleton <IStore>(sp =>
            {
                var tenant = sp.GetService <IApplicationContext>().TenantContext.Tenant;

                // get tentant's store config.
                var dataConfig = ConfigContext.GetConfig <DataConfig>(tenant.Name);

                // init store configuration.
                var option = new StoreOption();

                // Disabling query gating as it's failing to improve performance right now
                option.UseDatabase(tenant.Name).UseConfig(dataConfig);

                // create schemas.
                var store = new Store(option);
                if (option.AutoCreateSchema)
                {
                    var storeCreator = sp.GetService <ISchemaCreator>();
                    if (storeCreator != null)
                    {
                        using (var session = store.OpenSession())
                        {
                            storeCreator.CreateSchema(session);
                        }
                    }
                }

                return(store);
            });

            services.AddScoped(sp =>
            {
                var store = sp.GetRequiredService <IStore>();
                return(store.OpenSession());
            });

            return(services);
        }
Exemplo n.º 7
0
        public void ConfigWithTenantTest()
        {
            _services.AddJsonConfig <TestConfig>(opts =>
            {
                opts.IsTenantConfig = true;
                opts.ConfigFile     = "tenant.json";
            })
            .BuildServiceProvider()
            .UseConfigContext();

            var testConfig = ConfigContext.GetConfig <TestConfig>("test");

            Assert.AreNotEqual(testConfig, null);
            Assert.AreEqual(testConfig.SubConfig.SubName, "world");
            Assert.AreEqual(testConfig.SubConfig.List.Count, 5);

            var webConfig = ConfigContext.GetConfig <TestConfig>("web");

            Assert.AreNotEqual(webConfig, null);
            Assert.AreEqual(webConfig.SubConfig.SubName, "web");
            Assert.AreEqual(webConfig.SubConfig.List.Count, 4);
        }
Exemplo n.º 8
0
        public IotClient(ILogger <IotClient> logger, IIotService iotService, ICacheService cacheService)
        {
            this.logger       = logger;
            this.iotService   = iotService;
            this.cacheService = cacheService;

            this.actions = new ConcurrentDictionary <string, IotContext>();
            this.tenant  = App.Context.GetTenantContext().Tenant;
            this.access  = ConfigContext.GetConfig <IotConfig>(tenant.Name).Servers["iot"];

            this.Client = new EasyClient();
            this.Client.Initialize(new IotReceiveFilter(), this.OnReceived);
            this.Client.Closed += (s, e) =>
            {
                if (access.ReconnectClose)
                {
                    var t1 = Open();
                }
            };

            // open
            var t2 = Open();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize components and plugins in the nop environment.
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(CoreConfig config)
        {
            //dependencies
            var builder = new ContainerBuilder();

            builder.RegisterInstance(config).As <CoreConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();

            ITypeFinder typeFinder = new WebAppTypeFinder(config);

            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            //builder = new ContainerBuilder();
            string fullNameCurrentFinder = typeFinder.GetType().FullName;
            var    listTypeFinder        = typeFinder.FindClassesOfType <ITypeFinder>().ToList();
            var    tfInstances           = new List <ITypeFinder>();

            foreach (var tfType in listTypeFinder)
            {
                var ctor = tfType.GetConstructors().FirstOrDefault(c => c.GetParameters().Length == 1);
                if (ctor != null && ctor.GetParameters()[0].ParameterType == typeof(CoreConfig))
                {
                    tfInstances.Add((ITypeFinder)Activator.CreateInstance(tfType, config));
                }
                else
                {
                    tfInstances.Add((ITypeFinder)Activator.CreateInstance(tfType));
                }
            }

            var listConfig = typeFinder.FindClassesOfType <ConfigBase>();

            foreach (var configType in listConfig)
            {
                var configBase     = (ConfigBase)Activator.CreateInstance(configType);
                var instanceConfig = ConfigContext.GetConfig(configBase.SectionName);
                builder.RegisterInstance(instanceConfig).As(configType).SingleInstance();
            }

            //register dependencies provided by other assemblies
            var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar>();
            var drInstances = new List <IDependencyRegistrar>();

            foreach (var drType in drTypes)
            {
                IDependencyRegistrar dependencyRegistrar = (IDependencyRegistrar)Activator.CreateInstance(drType);
                drInstances.Add(dependencyRegistrar);
            }
            //sort
            drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in drInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder, config);
            }

            //controllers
            builder.RegisterControllers(typeFinder.GetAssemblies().ToArray());

            var container = builder.Build();

            _containerManager = new WebContainerManager(container);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }