public virtual async Task DeleteConnectionStringAsync(TenantConnectionGetByNameInputDto tenantConnectionGetByName)
        {
            var tenant = await TenantRepository.GetAsync(tenantConnectionGetByName.Id);

            tenant.RemoveConnectionString(tenantConnectionGetByName.Name);
            await TenantRepository.UpdateAsync(tenant);
        }
        public virtual async Task DeleteDefaultConnectionStringAsync(Guid id)
        {
            var tenant = await TenantRepository.GetAsync(id);

            tenant.RemoveDefaultConnectionString();
            await TenantRepository.UpdateAsync(tenant);
        }
示例#3
0
        public virtual async Task <ListResultDto <TenantConnectionStringDto> > GetConnectionStringAsync(Guid id)
        {
            var tenant = await TenantRepository.GetAsync(id);

            return(new ListResultDto <TenantConnectionStringDto>(
                       ObjectMapper.Map <List <TenantConnectionString>, List <TenantConnectionStringDto> >(tenant.ConnectionStrings)));
        }
        public virtual async Task UpdateDefaultConnectionStringAsync(Guid id, string defaultConnectionString)
        {
            var tenant = await TenantRepository.GetAsync(id);

            tenant.SetDefaultConnectionString(defaultConnectionString);
            await TenantRepository.UpdateAsync(tenant);
        }
示例#5
0
 public virtual async Task<TenantDto> UpdateAsync(Guid id, TenantUpdateDto input)
 {
     var tenant = await TenantRepository.GetAsync(id);
     await TenantManager.ChangeNameAsync(tenant, input.Name);
     input.MapExtraPropertiesTo(tenant);
     await TenantRepository.UpdateAsync(tenant);
     return ObjectMapper.Map<Tenant, TenantDto>(tenant);
 }
示例#6
0
        public async Task GetTenantByTenantsId()
        {
            await tenantRepository.AddAsync(tenant);

            var dtoTenant = await tenantRepository.GetAsync(tenant.TenantId);

            Assert.Equal(tenant, dtoTenant);
        }
示例#7
0
    public virtual async Task <TenantDto> UpdateAsync(string id, TenantEditInput input)
    {
        var tenant = await TenantRepository.GetAsync(id);

        await TenantManager.ChangeNameAsync(tenant, input.Name);

        await TenantRepository.UpdateAsync(tenant);

        return(tenant.MapTo <TenantDto>());
    }
示例#8
0
        public async Task <TenantDto> UpdateAsync(Guid id, TenantUpdateDto input)
        {
            var tenant = await TenantRepository.GetAsync(id);

            await TenantManager.ChangeNameAsync(tenant, input.Name);

            await TenantRepository.UpdateAsync(tenant);

            return(ObjectMapper.Map <Tenant, TenantDto>(tenant));
        }
        public virtual async Task <SaasTenantDto> UpdateAsync(Guid id, SaasTenantUpdateDto input)
        {
            var tenant = await TenantRepository.GetAsync(id);

            await TenantManager.ChangeNameAsync(tenant, input.Name);

            tenant.SetEdition(input.EditionId);
            await TenantRepository.UpdateAsync(tenant);

            return(ObjectMapper.Map <SaasTenant, SaasTenantDto>(tenant));
        }
        public virtual async Task <TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdateDto tenantConnectionStringCreateOrUpdate)
        {
            var tenant = await TenantRepository.GetAsync(id);

            tenant.SetConnectionString(tenantConnectionStringCreateOrUpdate.Name, tenantConnectionStringCreateOrUpdate.Value);

            return(new TenantConnectionStringDto
            {
                Name = tenantConnectionStringCreateOrUpdate.Name,
                Value = tenantConnectionStringCreateOrUpdate.Value
            });
        }
示例#11
0
        public virtual async Task <TenantConnectionStringDto> GetConnectionStringAsync(Guid id, string name)
        {
            var tenant = await TenantRepository.GetAsync(id);

            var tenantConnectionString = tenant.FindConnectionString(name);

            return(new TenantConnectionStringDto
            {
                Name = name,
                Value = tenantConnectionString
            });
        }
示例#12
0
        public virtual async Task <TenantConnectionStringDto> GetConnectionStringAsync(TenantConnectionGetByNameInputDto tenantConnectionGetByName)
        {
            var tenant = await TenantRepository.GetAsync(tenantConnectionGetByName.Id);

            var tenantConnectionString = tenant.FindConnectionString(tenantConnectionGetByName.Name);

            return(new TenantConnectionStringDto
            {
                Name = tenantConnectionGetByName.Name,
                Value = tenantConnectionString
            });
        }
示例#13
0
        public virtual async Task <TenantDto> UpdateAsync(Guid id, TenantUpdateDto input)
        {
            var tenant = await TenantRepository.GetAsync(id);

            await TenantManager.ChangeNameAsync(tenant, input.Name);

            tenant.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);
            input.MapExtraPropertiesTo(tenant);

            await TenantRepository.UpdateAsync(tenant);

            return(ObjectMapper.Map <Tenant, TenantDto>(tenant));
        }
示例#14
0
        public virtual async Task DeleteConnectionStringAsync(Guid id, string name)
        {
            var tenant = await TenantRepository.GetAsync(id);

            tenant.RemoveConnectionString(name);

            var updateEventData = new UpdateEventData
            {
                Id         = tenant.Id,
                OriginName = tenant.Name,
                Name       = tenant.Name
            };
            await EventBus.PublishAsync(updateEventData);

            await TenantRepository.UpdateAsync(tenant);
        }
示例#15
0
        public virtual async Task <TenantDto> UpdateAsync(Guid id, TenantUpdateDto input)
        {
            var tenant = await TenantRepository.GetAsync(id, false);

            var updateEventData = new UpdateEventData
            {
                Id         = tenant.Id,
                OriginName = tenant.Name,
                Name       = input.Name
            };
            await TenantManager.ChangeNameAsync(tenant, input.Name);

            input.MapExtraPropertiesTo(tenant);
            await TenantRepository.UpdateAsync(tenant);

            await EventBus.PublishAsync(updateEventData);

            return(ObjectMapper.Map <Tenant, TenantDto>(tenant));
        }
示例#16
0
        public virtual async Task <TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdateDto tenantConnectionStringCreateOrUpdate)
        {
            var tenant = await TenantRepository.GetAsync(id);

            tenant.SetConnectionString(tenantConnectionStringCreateOrUpdate.Name, tenantConnectionStringCreateOrUpdate.Value);
            var updateEventData = new UpdateEventData
            {
                Id         = tenant.Id,
                OriginName = tenant.Name,
                Name       = tenant.Name
            };
            // abp当前版本(3.0.0)在EntityChangeEventHelper中存在一个问题,无法发送框架默认的Eto,预计3.1.0修复
            // 发送自定义的事件数据来确保缓存被更新
            await EventBus.PublishAsync(updateEventData);

            return(new TenantConnectionStringDto
            {
                Name = tenantConnectionStringCreateOrUpdate.Name,
                Value = tenantConnectionStringCreateOrUpdate.Value
            });
        }
示例#17
0
        public async Task <Tenant> GetTenantAsync(Guid tenantId, CancellationToken cancellationToken = default)
        {
            NullCheckHelpers.EnsureArgumentIsNotNullOrEmpty(tenantId);

            var dtoTenant = await tenantRepository.GetAsync(tenantId, cancellationToken);

            var dtoAddress = await addressRepository.GetAsync(dtoTenant.AddressId, cancellationToken);

            if (dtoAddress == null)
            {
                throw new SqlEntityNullReferenceException(nameof(dtoAddress), dtoAddress.AddressId.ToString());
            }

            if (dtoTenant == null)
            {
                throw new SqlEntityNullReferenceException(nameof(dtoAddress), dtoTenant.TenantId.ToString());
            }

            var tenant = TenantMapping.ConvertDtoTenantToTenant(dtoTenant);

            tenant.Address = AddressMapping.ConvertDtoAddressToAddress(dtoAddress);

            return(tenant);
        }
示例#18
0
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.
        public static async Task ProcessQueueMessage([QueueTrigger("tenant-queue")] Tenant tenant)
        {
            TenantRepository tenantRepo = new TenantRepository(tenant.TenantID);

            data.ITenant t = await tenantRepo.GetAsync();

            if (t == null || string.IsNullOrEmpty(t.Server) == false || string.IsNullOrEmpty(t.Database) == false)
            {
                Console.WriteLine("[{0}] Tenant already configured or something when wrong.", tenant.TenantID);
                return;
            }


            var credentials = SdkContext.AzureCredentialsFactory
                              .FromServicePrincipal(CloudConfigurationManager.GetSetting("az:clientId"),     //clientId,
                                                    CloudConfigurationManager.GetSetting("az:clientSecret"), //clientSecret,
                                                    CloudConfigurationManager.GetSetting("az:tenantId"),     //tenantId,
                                                    AzureEnvironment.AzureGlobalCloud);

            var azure = Microsoft.Azure.Management.Fluent.Azure
                        .Configure()
                        .Authenticate(credentials)
                        .WithDefaultSubscription();

            string startAddress = "0.0.0.0";
            string endAddress   = "255.255.255.255";

            var servers = await azure.SqlServers.ListAsync();

            var avaibleServers = servers.Where(x => x.Databases.List().Count < 150 && x.ResourceGroupName == "ssas-demo");

            ISqlServer sqlServer;

            if (avaibleServers.Any())
            {
                sqlServer = avaibleServers.FirstOrDefault();
            }
            else
            {
                string sqlServerName = SdkContext.RandomResourceName("saas-", 8);
                // Create the SQL server instance
                sqlServer = azure.SqlServers.Define(sqlServerName)
                            .WithRegion(Region.USEast)
                            .WithExistingResourceGroup("ssas-demo")
                            .WithAdministratorLogin(CloudConfigurationManager.GetSetting("sqlserver:username"))
                            .WithAdministratorPassword(CloudConfigurationManager.GetSetting("sqlserver:password"))
                            .WithNewFirewallRule(startAddress, endAddress)
                            .Create();
            }

            string dbName = SdkContext.RandomResourceName("saas-", 8);

            // Create the database
            ISqlDatabase sqlDb = sqlServer.Databases.Define(dbName)
                                 .WithEdition(DatabaseEditions.Standard)
                                 .WithServiceObjective(ServiceObjectiveName.S0)
                                 .Create();


            Console.WriteLine(sqlServer.FullyQualifiedDomainName);
            Console.WriteLine(sqlDb.Name);

            await tenantRepo.UpdateAsync(sqlDb.SqlServerName, sqlDb.Name);

            if (string.IsNullOrEmpty(tenant.Email) == false)
            {
                await SendEmailNotification(tenant.Email, tenant.Organization);
            }
        }
示例#19
0
    /// <summary>
    /// 获取租户
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public virtual async Task <TenantDto> GetAsync(string id)
    {
        var tenant = await TenantRepository.GetAsync(id);

        return(tenant.MapTo <TenantDto>());
    }
        public virtual async Task <SaasTenantDto> GetAsync(Guid id)
        {
            var tenant = await TenantRepository.GetAsync(id);

            return(ObjectMapper.Map <Tenant, SaasTenantDto>(tenant));
        }
 public virtual async Task <SaasTenantDto> GetAsync(Guid id)
 {
     return(ObjectMapper.Map <SaasTenant, SaasTenantDto>(
                await TenantRepository.GetAsync(id)));
 }
示例#22
0
 public async Task <TenantDto> GetAsync(Guid id)
 {
     return(ObjectMapper.Map <Tenant, TenantDto>(
                await TenantRepository.GetAsync(id)
                ));
 }
        public virtual async Task <string> GetDefaultConnectionStringAsync(Guid id)
        {
            var tenant = await TenantRepository.GetAsync(id);

            return(tenant?.FindDefaultConnectionString());
        }
示例#24
0
 public virtual async Task <TenantDto> GetAsync(Guid id)
 {
     return(ObjectMapper.Map <Tenant, TenantDto>(
                await TenantRepository.GetAsync(id).ConfigureAwait(false)));
 }