Example #1
0
        private void Initialize()
        {
            if (!initialized)
            {
                lock (locker)
                {
                    if (!initialized)
                    {
                        initialized = true;

                        var find = false;
                        foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings)
                        {
                            if (cs.Name.StartsWith(dbid + "."))
                            {
                                var name = cs.Name.Substring(dbid.Length + 1);
                                regions[name] = new HostedSolution(cs, name);
                                find          = true;
                            }
                        }
                        if (find)
                        {
                            regions[dbid] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                            if (!regions.ContainsKey(string.Empty))
                            {
                                regions[string.Empty] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                            }
                        }
                        else
                        {
                            try
                            {
                                using (var db = new DbManager(dbid))
                                {
                                    var q = new SqlQuery("regions")
                                            .Select("region")
                                            .Select("connection_string")
                                            .Select("provider");
                                    db.ExecuteList(q)
                                    .ForEach(r =>
                                    {
                                        var cs = new ConnectionStringSettings((string)r[0], (string)r[1], (string)r[2]);
                                        if (!DbRegistry.IsDatabaseRegistered(cs.Name))
                                        {
                                            DbRegistry.RegisterDatabase(cs.Name, cs);
                                        }
                                        regions[cs.Name] = new HostedSolution(cs, cs.Name);
                                    });
                                }
                            }
                            catch (DbException) { }
                        }
                    }
                }
            }
        }
Example #2
0
        private void Initialize()
        {
            var connectionStrings   = Configuraion.GetConnectionStrings();
            var dbConnectionStrings = Configuraion.GetConnectionStrings(dbid);

            if (Convert.ToBoolean(Configuraion["core.multi-hosted.config-only"] ?? "false"))
            {
                foreach (var cs in Configuraion.GetConnectionStrings())
                {
                    if (cs.Name.StartsWith(dbid + "."))
                    {
                        var name = cs.Name.Substring(dbid.Length + 1);
                        regions[name] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, cs, TariffServiceStorage, Options, name);
                    }
                }

                regions[dbid] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, dbConnectionStrings, TariffServiceStorage, Options);
                if (!regions.ContainsKey(string.Empty))
                {
                    regions[string.Empty] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, dbConnectionStrings, TariffServiceStorage, Options);
                }
            }
            else
            {
                var find = false;
                foreach (var cs in connectionStrings)
                {
                    if (cs.Name.StartsWith(dbid + "."))
                    {
                        var name = cs.Name.Substring(dbid.Length + 1);
                        regions[name] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, cs, TariffServiceStorage, Options, name);
                        find          = true;
                    }
                }
                if (find)
                {
                    regions[dbid] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, dbConnectionStrings, TariffServiceStorage, Options);
                    if (!regions.ContainsKey(string.Empty))
                    {
                        regions[string.Empty] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, dbConnectionStrings, TariffServiceStorage, Options);
                    }
                }
                else
                {
                    foreach (var connectionString in connectionStrings)
                    {
                        try
                        {
                            using var db = DbOptions.Get(connectionString.Name);
                            var q = new SqlQuery("regions")
                                    .Select("region")
                                    .Select("connection_string")
                                    .Select("provider");
                            db.ExecuteList(q)
                            .ForEach(r =>
                            {
                                var cs = new System.Configuration.ConnectionStringSettings((string)r[0], (string)r[1], (string)r[2]);
                                if (!DbRegistry.IsDatabaseRegistered(cs.Name))
                                {
                                    DbRegistry.RegisterDatabase(cs.Name, cs);
                                }

                                if (!regions.ContainsKey(string.Empty))
                                {
                                    regions[string.Empty] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, cs, TariffServiceStorage, Options, cs.Name);
                                }

                                regions[cs.Name] = new HostedSolution(Configuraion, TenantDomainValidator, TimeZoneConverter, DbRegistry, cs, TariffServiceStorage, Options, cs.Name);
                            });
                        }
                        catch (DbException) { }
                    }
                }
            }
        }
        private void Initialize()
        {
            if (!initialized)
            {
                lock (locker)
                {
                    if (!initialized)
                    {
                        initialized = true;


                        if (Convert.ToBoolean(ConfigurationManager.AppSettings["core.multi-hosted.config-only"] ?? "false"))
                        {
                            foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings)
                            {
                                if (cs.Name.StartsWith(dbid + "."))
                                {
                                    var name = cs.Name.Substring(dbid.Length + 1);
                                    regions[name] = new HostedSolution(cs, name);
                                }
                            }

                            regions[dbid] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                            if (!regions.ContainsKey(string.Empty))
                            {
                                regions[string.Empty] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                            }
                        }
                        else
                        {

                            var find = false;
                            foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings)
                            {
                                if (cs.Name.StartsWith(dbid + "."))
                                {
                                    var name = cs.Name.Substring(dbid.Length + 1);
                                    regions[name] = new HostedSolution(cs, name);
                                    find = true;
                                }
                            }
                            if (find)
                            {
                                regions[dbid] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                                if (!regions.ContainsKey(string.Empty))
                                {
                                    regions[string.Empty] = new HostedSolution(ConfigurationManager.ConnectionStrings[dbid]);
                                }
                            }
                            else
                            {
                                try
                                {
                                    using (var db = new DbManager(dbid))
                                    {
                                        var q = new SqlQuery("regions")
                                            .Select("region")
                                            .Select("connection_string")
                                            .Select("provider");
                                        db.ExecuteList(q)
                                            .ForEach(r =>
                                            {
                                                var cs = new ConnectionStringSettings((string)r[0], (string)r[1], (string)r[2]);
                                                if (!DbRegistry.IsDatabaseRegistered(cs.Name))
                                                {
                                                    DbRegistry.RegisterDatabase(cs.Name, cs);
                                                }
                                                regions[cs.Name] = new HostedSolution(cs, cs.Name);
                                            });
                                    }
                                }
                                catch (DbException) { }
                            }
                        }
                    }
                }
            }
        }
        private void Initialize()
        {
            var connectionStrings   = Configuraion.GetConnectionStrings();
            var dbConnectionStrings = Configuraion.GetConnectionStrings(dbid);

            if (Convert.ToBoolean(Configuraion["core.multi-hosted.config-only"] ?? "false"))
            {
                foreach (var cs in Configuraion.GetConnectionStrings())
                {
                    if (cs.Name.StartsWith(dbid + "."))
                    {
                        var name = cs.Name.Substring(dbid.Length + 1);
                        regions[name] = new HostedSolution(Configuraion, cs, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(cs.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(cs.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(cs.ConnectionString)), name);
                    }
                }

                regions[dbid] = new HostedSolution(Configuraion, dbConnectionStrings, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(dbConnectionStrings.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(dbConnectionStrings.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(dbConnectionStrings.ConnectionString)));
                if (!regions.ContainsKey(string.Empty))
                {
                    regions[string.Empty] = new HostedSolution(Configuraion, dbConnectionStrings, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(dbConnectionStrings.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(dbConnectionStrings.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(dbConnectionStrings.ConnectionString)));
                }
            }
            else
            {
                var find = false;
                foreach (var cs in connectionStrings)
                {
                    var dbContextOptionsBuilder = new DbContextOptionsBuilder <DbContext>();
                    var options = dbContextOptionsBuilder
                                  .UseMySql(cs.ConnectionString)
                                  .UseLoggerFactory(LoggerFactory)
                                  .Options;

                    using var dbContext = new DbContext(options);

                    if (cs.Name.StartsWith(dbid + "."))
                    {
                        var name = cs.Name.Substring(dbid.Length + 1);
                        regions[name] = new HostedSolution(Configuraion, cs, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(dbConnectionStrings.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(dbConnectionStrings.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(dbConnectionStrings.ConnectionString)), name);
                        find          = true;
                    }
                }
                if (find)
                {
                    regions[dbid] = new HostedSolution(Configuraion, dbConnectionStrings, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(dbConnectionStrings.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(dbConnectionStrings.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(dbConnectionStrings.ConnectionString)));
                    if (!regions.ContainsKey(string.Empty))
                    {
                        regions[string.Empty] = new HostedSolution(Configuraion, dbConnectionStrings, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(dbConnectionStrings.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(dbConnectionStrings.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(dbConnectionStrings.ConnectionString)));
                    }
                }
                else
                {
                    foreach (var connectionString in connectionStrings)
                    {
                        try
                        {
                            var dbContextOptionsBuilder = new DbContextOptionsBuilder <DbContext>();
                            var options = dbContextOptionsBuilder
                                          .UseMySql(connectionString.ConnectionString)
                                          .UseLoggerFactory(LoggerFactory)
                                          .Options;

                            using var dbContext = new DbContext(options);

                            var q = dbContext.Regions.ToList();

                            foreach (var r in q)
                            {
                                var cs = new System.Configuration.ConnectionStringSettings(r.Region, r.ConnectionString, r.Provider);

                                if (!regions.ContainsKey(string.Empty))
                                {
                                    regions[string.Empty] = new HostedSolution(Configuraion, cs, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(cs.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(cs.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(cs.ConnectionString)), cs.Name);
                                }

                                regions[cs.Name] = new HostedSolution(Configuraion, cs, TariffServiceStorage, Options, TenantUtil, TenantDomainValidator, new TenantDbContext(GetOptions <TenantDbContext>(cs.ConnectionString)), new UserDbContext(GetOptions <UserDbContext>(cs.ConnectionString)), new CoreDbContext(GetOptions <CoreDbContext>(cs.ConnectionString)), cs.Name);
                            }
                        }
                        catch (DbException) { }
                    }
                }
            }
        }