Пример #1
0
        public IHttpActionResult Post(
            [FromBody] CreateTenantModel command)
        {
            if (command == null || !ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("Tenant body parameters missing"));
            }

            var dbProviderConfig = CreateDBProviderConfiguration(command);

            var tenant = Tenant.Create(0, command.Name, command.DefaultTheme, dbProviderConfig);

            _tenantsRepository.Add(tenant);
            _tenantsRepository.SaveChanges();

            return(Ok(_mapper.Map <TenantModel>(tenant)));
        }
Пример #2
0
        /// <summary>
        /// Registers the new shard.
        /// Verify if shard exists for the tenant. If not then create new shard and add tenant details to Tenants table in catalog
        /// </summary>
        /// <param name="tenantName">Name of the tenant.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        /// <param name="tenantServerConfig">The tenant server configuration.</param>
        /// <param name="databaseConfig">The database configuration.</param>
        /// <param name="catalogConfig">The catalog configuration.</param>
        public static bool RegisterNewShard(string tenantName, int tenantId, TenantServerConfig tenantServerConfig, DatabaseConfig databaseConfig, CatalogConfig catalogConfig)
        {
            try
            {
                Shard         shard;
                ShardLocation shardLocation = new ShardLocation(tenantServerConfig.TenantServer, tenantName, databaseConfig.SqlProtocol, databaseConfig.DatabaseServerPort);

                if (!ShardMap.TryGetShard(shardLocation, out shard))
                {
                    //create shard if it does not exist
                    shard = ShardMap.CreateShard(shardLocation);
                }


                // Register the mapping of the tenant to the shard in the shard map.
                // After this step, DDR on the shard map can be used
                PointMapping <int> mapping;
                if (!ShardMap.TryGetMappingForKey(tenantId, out mapping))
                {
                    var pointMapping = ShardMap.CreatePointMapping(tenantId, shard);

                    //convert from int to byte[] as tenantId has been set as byte[] in Tenants entity
                    var key = _helper.ConvertIntKeyToBytesArray(pointMapping.Value);

                    //add tenant to Tenants table
                    var tenant = new Tenants
                    {
                        ServicePlan = catalogConfig.ServicePlan,
                        TenantId    = key,
                        TenantName  = tenantName
                    };

                    _tenantsRepository.Add(tenant);
                }
                return(true);
            }
            catch (Exception ex)
            {
                // _logger.LogError(0, ex, "Error in registering new shard.");
                //throw new ApplicationException("Error in registering new shard.");
                return(false);
            }
        }
        public void AddTenantTest()
        {
            var result = _tenantsRepository.Add(SetTenant());

            Assert.IsTrue(result);
        }
 public void Setup()
 {
     _tenantsRepository = new MockTenantsRepository();
     _tenantsRepository.Add(SetTenant());
 }
Пример #5
0
 public Tenant Add(Tenant model)
 {
     _tenantsRepository.Add(model);
     return(model);
 }