public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var resolveResult = _tenantResolver.ResolveTenantIdOrName();

            _tenantResolveResultAccessor.Result = resolveResult;

            TenantConfiguration tenant = null;

            if (resolveResult.TenantIdOrName != null)
            {
                tenant = await FindTenantAsync(resolveResult.TenantIdOrName);

                if (tenant == null)
                {
                    //TODO: A better exception?
                    throw new AbpException(
                              "There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName
                              );
                }
            }

            using (_currentTenant.Change(tenant?.Id, tenant?.Name))
            {
                await next(context);
            }
        }
Esempio n. 2
0
        public async Task InvokeAsync(HttpContext httpContext, ITenantStore tenantStore)
        {
            async Task <TenantInfo> FindTenantAsync(string tenantIdOrName)
            {
                return(await tenantStore.FindAsync(tenantIdOrName));
            }

            var resolveResult = _tenantResolver.ResolveTenantIdOrName();

            _tenantResolveResultAccessor.Result = resolveResult;

            TenantInfo tenant = null;

            if (resolveResult.TenantIdOrName != null)
            {
                tenant = await FindTenantAsync(resolveResult.TenantIdOrName);

                if (tenant == null)
                {
                    //TODO: A better exception?
                    throw new LinFxException("There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName);
                }
            }

            using (_currentTenant.Change(tenant?.Id, tenant?.Name))
            {
                await _next(httpContext);
            }
        }
Esempio n. 3
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var resolveResult = _tenantResolver.ResolveTenantIdOrName();

            _tenantResolveResultAccessor.Result = resolveResult;

            TenantConfiguration tenant = null;

            if (resolveResult.TenantIdOrName != null)
            {
                tenant = await FindTenantAsync(resolveResult.TenantIdOrName);

                if (tenant == null)
                {
                    throw new BusinessException(
                              code: "PlusIo.MultiTenancy:010001",
                              message: "Tenant not found!",
                              details: "There is no tenant with the tenant id or name: " + resolveResult.TenantIdOrName
                              );
                }
            }

            using (_currentTenant.Change(tenant?.Id, tenant?.Name))
            {
                await next(context);
            }
        }
Esempio n. 4
0
        public async Task Invoke(HttpContext httpContext)
        {
            //TODO: Try-catch and return "unknown tenant" if found tenant is not in the store..?

            var tenantIdOrName = _tenantResolver.ResolveTenantIdOrName();

            if (tenantIdOrName == null)
            {
                await _next(httpContext);

                return;
            }

            var tenant = await FindTenantAsync(tenantIdOrName);

            if (tenant == null)
            {
                throw new AbpException("There is no tenant with given tenant id or name: " + tenantIdOrName);
            }

            using (SetCurrent(tenant))
            {
                await _next(httpContext);
            }
        }
Esempio n. 5
0
        private async Task <TenantInfo> ResolveCurrentTenantAsync()
        {
            var tenantIdOrName = _tenantResolver.ResolveTenantIdOrName();

            if (tenantIdOrName == null)
            {
                return(null);
            }

            var tenant = await FindTenantAsync(tenantIdOrName);

            if (tenant == null)
            {
                throw new AbpException("There is no tenant with given tenant id or name: " + tenantIdOrName);
            }

            return(tenant);
        }
Esempio n. 6
0
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var resolveResult = tenantResolver.ResolveTenantIdOrName();

            TenantConfiguration tenant = null;

            if (resolveResult.TenantIdOrName != null)
            {
                tenant = await FindTenantAsync(resolveResult.TenantIdOrName);

                if (tenant == null)
                {
                    throw new StructureException("There is no tenant with given tenant id or name: " + resolveResult.TenantIdOrName);
                }
            }

            using (currentTenant.Change(tenant?.Id, tenant?.Name))
            {
                await next(context);
            }
        }