Beispiel #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();

            var mixed = Lifestyle.CreateHybrid(new AsyncScopedLifestyle(), new ThreadScopedLifestyle());
            var style = Lifestyle.CreateHybrid(new WebRequestLifestyle(), mixed);

            container.Options.DefaultScopedLifestyle = style;

            container.Register <IDbContextInfoProvider, DbContextInfoProvider>(Lifestyle.Scoped);
            container.Register <IUnitOfWork, UnitOfWork>(Lifestyle.Scoped);
            container.Register <IClientService, ClientService>(Lifestyle.Scoped);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));

            InitialiseShardMapManager();
            ShardHelper.RegisterAllTenantShard(DatabaseConfigHelper.GetServerNameFull());
        }
Beispiel #2
0
        /// <summary>
        /// Initialises the shard map manager and shard map
        /// <para>Also does all tasks related to sharding</para>
        /// </summary>
        private void InitialiseShardMapManager()
        {
            var basicConnectionString = ConnectionStringHelper.GetBasicSqlConnectionString();
            SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder(basicConnectionString)
            {
                DataSource     = "tcp:" + DatabaseConfigHelper.GetServerNameFull() + "," + DatabaseConfigHelper.GetServerPort(),
                InitialCatalog = CatalogConfigHelper.GetDatabase()
            };

            var sharding = new Sharding(CatalogConfigHelper.GetDatabase(), connectionString.ConnectionString);
        }
Beispiel #3
0
        // DELETE: Tenant
        public ActionResult Delete(string tenantName)
        {
            HttpContext.Server.ScriptTimeout = 600;

            tenantName = tenantName.ToLower();

            var db     = new CatalogDbContext();
            var tenant = db.Tenants.FirstOrDefault(t => t.TenantName == tenantName);

            if (tenant != null)
            {
                ShardHelper.DeleteTenantShard(DatabaseConfigHelper.GetServerNameFull(), tenantName);
                DeleteDb(tenantName);

                db.Tenants.Remove(tenant);
                db.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
Beispiel #4
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                HttpContext.Server.ScriptTimeout = 600;

                var tenantName = collection.Get("tenantName");
                if (string.IsNullOrEmpty(tenantName))
                {
                    ViewBag.ErrorMsg = "Tenant name is invalid";
                    return(View());
                }

                tenantName = tenantName.ToLower();

#if DEBUG
                if (!tenantName.ToLower().StartsWith("dev-"))
                {
                    ViewBag.ErrorMsg = "Tenant name need to start with dev-";
                    return(View());
                }
#endif

                var db     = new CatalogDbContext();
                var tenant = db.Tenants.FirstOrDefault(t => t.TenantName == tenantName);
                if (tenant == null)
                {
                    CopyDbTemplate(tenantName);
                    ShardHelper.RegisterTenantShard(DatabaseConfigHelper.GetServerNameFull(), tenantName);
                }

                return(RedirectToAction("List"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMsg = ex.Message;
                return(View());
            }
        }