public async Task Invoke(HttpContext context) { if (!context.Items.ContainsKey(TenantConstants.TenantInfoContextKey)) { ITenantInfo tenantInfo = null; var hostString = context.Request.Host; string host = null; if (hostString.HasValue) { host = hostString.Host; tenantInfo = _tenantDataProvider.LookupTenantByHost(host); } if (tenantInfo == null) { // we could not find any tenant _logger.LogError($"No tenant found for host {hostString}"); throw new NotFoundApiException(NotFoundApiException.TenantNotFound, $"The tenant for host {host} was not found", host); } context.Items.Add(TenantConstants.TenantInfoContextKey, tenantInfo); } await _next.Invoke(context).ConfigureAwait(false); }
private void EnrichTenantInfo <TModel>(TModel model, ITenantInfo tenantInfo) where TModel : TemplateViewModel { if (_tenantInfoAccessor != null && tenantInfo == null) { tenantInfo = _tenantInfoAccessor.TenantInfo; } if (tenantInfo == null) { return; } model.TenantName = tenantInfo.Name; model.TenantLogoSvgUrl = tenantInfo.LogoSvgUrl; model.TenantLogoPngUrl = tenantInfo.LogoPngUrl; model.TenantPrimaryColor = tenantInfo.PrimaryColorHex; model.TenantSecondaryColor = tenantInfo.SecondaryColorHex; model.TenantTextOnPrimaryColor = tenantInfo.TextOnPrimaryColorHex; model.TenantTextOnSecondaryColor = tenantInfo.TextOnSecondaryColorHex; model.TenantSupportEmail = tenantInfo.SupportEmail; model.TenantProductName = tenantInfo.ProductName; model.TenantDefaultCulture = tenantInfo.DefaultCulture; model.TenantDefaultCurrency = tenantInfo.DefaultCurrency; }
public Task <bool> UpdateTenantInfo(ITenantInfo tenantInfo, CancellationToken cancellationToken = default) { bool result = true; _dic.TryGetValue(tenantInfo.TenantId, out var existValue); if (existValue != null) { result = _dic.TryUpdate(tenantInfo.TenantId, tenantInfo, existValue); } return(Task.FromResult(result)); }
public async Task Invoke(HttpContext context) { if (!context.Items.ContainsKey(TenantConstants.TenantInfoContextKey)) { ITenantInfo tenantInfo = null; var hostString = context.Request.Host; string host = null; if (hostString.HasValue) { host = hostString.Host; tenantInfo = _tenantDataProvider.LookupTenantByHost(host); } if (tenantInfo == null) { // we could not find any tenant // check if we have a health check running here var healthCheckPort = _tenantDataProvider.HealthCheckPort; if (healthCheckPort != null && context.Request.Host.Port == healthCheckPort) { var healthCheckTenantHost = _tenantDataProvider.HealthCheckTenantHost; if (!string.IsNullOrEmpty(healthCheckTenantHost)) { tenantInfo = _tenantDataProvider.LookupTenantByHost(healthCheckTenantHost); } } if (tenantInfo == null) { _logger.LogError($"No tenant found for host {hostString}"); throw new NotFoundApiException(NotFoundApiException.TenantNotFound, $"The tenant for host {host} was not found", host); } } context.Items.Add(TenantConstants.TenantInfoContextKey, tenantInfo); } await _next.Invoke(context).ConfigureAwait(false); }
public virtual async Task <TenantContext?> Run(TContext context, CancellationToken cancellationToken = default) { TenantContext?tenantContext = null; var identity = await _identityHandler.GetIdentity(context, cancellationToken); if (string.IsNullOrWhiteSpace(identity)) { _logger.LogWarning("The application is config multi-tenant,but current context is not found tenant-id."); await CurrentInterceptorOperator.IdentityFalid(context, TenantOptions, cancellationToken); return(tenantContext); } await CurrentInterceptorOperator.IdentitySucceed(identity, context, TenantOptions, cancellationToken); ITenantInfo tenantInfo = null; if (TenantOptions.MultiTenantType != MultiTenantModeType.Table) { await CurrentInterceptorOperator.BeforeGetTenantInfo(identity, context, TenantOptions, cancellationToken); // get identity info from store. tenantInfo = await _store.GetTenantInfo(identity, cancellationToken); if (tenantInfo == null) { _logger.LogWarning($"The application is config multi-tenant,but cannot find tenant info from store with tenant-id:[{identity}]."); await CurrentInterceptorOperator.TenantInfoFailed(identity, context, TenantOptions, cancellationToken); return(tenantContext); } await CurrentInterceptorOperator.TenantInfoSucceed(tenantInfo, context, TenantOptions, cancellationToken); } // generate tenant-context tenantContext = new TenantContext() { TenantInfo = tenantInfo, Options = TenantOptions }; return(tenantContext); }
/// <summary> /// Exec <see cref="ITenantInfoRetrieveInterceptor.TenantInfoRetrieveSucceed(Abstractions.ITenantInfo, TenantInfoRetrieveContext, CancellationToken)"/> of all registed interceptors. /// </summary> /// <param name="tenantInfo"></param> /// <param name="context"></param> /// <param name="options"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task TenantInfoSucceed(ITenantInfo tenantInfo, object context, MultiTenantOptions options, CancellationToken cancellationToken = default) { var infoInterceptors = _interceptors.Find <ITenantInfoRetrieveInterceptor>(); if (infoInterceptors.Count() == 0) { return; } var retrieveContext = new TenantInfoRetrieveContext() { TenantId = tenantInfo.TenantId, Context = context, Options = options }; foreach (var infoInterceptor in infoInterceptors) { await infoInterceptor.TenantInfoRetrieveSucceed(tenantInfo, retrieveContext, cancellationToken); } }
public MultiTenantEntitiesContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
protected MultiTenantIdentityDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
public ApplicationDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
public ApplicationDbContext(ITenantInfo tenantInfo, DbContextOptions <ApplicationDbContext> options) : base(tenantInfo, options) { }
protected MultiTenantDbContext(ITenantInfo tenantInfo, DbContextOptions options) : base(options) { this.TenantInfo = tenantInfo; }
public TestIdentityDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
public ToDoDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
public BloggingDbContext(ITenantInfo tenantInfo, DbContextOptions <BloggingDbContext> options) : base(tenantInfo, options) { }
public Task <bool> DeleteTenantInfo(ITenantInfo tenantInfo, CancellationToken cancellationToken = default) { return(Task.FromResult(_dic.TryRemove(tenantInfo.TenantId, out _))); }
public MultiTenantEntitiesContext(ITenantInfo tenantInfo, DbContextOptions <MultiTenantEntitiesContext> options) : base(tenantInfo, options) { }
public Task <bool> AddTenantInfo(ITenantInfo tenantInfo, CancellationToken cancellationToken = default) { return(Task.FromResult(_dic.TryAdd(tenantInfo.TenantId, tenantInfo))); }
public SqlServerApplicationDbContext(ITenantInfo tenantInfo, DbContextOptions <SqlServerApplicationDbContext> options) : base(tenantInfo, options) { }
public SqlServerApplicationDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
protected MultiTenantIdentityDbContext(ITenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options) { }
public BloggingDbContext(ITenantInfo tenantInfo) : base(tenantInfo) { }
public FinbuckleSqlServerToDoIdentityDbContext(ITenantInfo tenantInfo, DbContextOptions <FinbuckleSqlServerToDoIdentityDbContext> options) : base(tenantInfo, options) { }
public async Task <MemoryStream> RenderPdfAsync <TModel>(string viewName, TModel model, ITenantInfo tenantInfo = null) where TModel : TemplateViewModel { if (_renderService == null) { throw new Exception("JSReport render service is not available"); } var htmlContent = await RenderViewAsync(viewName, model, tenantInfo).ConfigureAwait(false); var pdf = await _renderService.RenderAsync(new RenderRequest() { Template = new Template() { Content = htmlContent, Engine = Engine.None, Recipe = Recipe.ChromePdf, Chrome = new Chrome() { DisplayHeaderFooter = true, MarginTop = "2cm", MarginLeft = "2cm", MarginRight = "2cm", MarginBottom = "2cm", HeaderTemplate = "", FooterTemplate = "<span style='color:black; font-size:8pt; font-family: sans-serif !important; width:100%;text-align:right;margin-right:2cm;'>" + Messages.page + " <span class=\"pageNumber\"></span> " + Messages.of + " <span class=\"totalPages\"></span></span>" } } }).ConfigureAwait(false); var ms = new MemoryStream(); pdf.Content.CopyTo(ms); return(ms); }
protected MultiTenantDbContext(ITenantInfo tenantInfo) { this.TenantInfo = tenantInfo; }
public TestDbContext(Action <ModelBuilder>?config, ITenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options) { this._config = config; }
public async Task InvokeAsync(HttpContext context) { if (!context.Items.ContainsKey(TenantConstants.TenantInfoContextKey)) { string matchedSubDomain = null; ITenantInfo tenantInfo = null; var hostString = context.Request.Host; string host = null; if (hostString.HasValue) { host = hostString.Host; (matchedSubDomain, tenantInfo) = await _tenantDataProvider.GetTenantByHostAsync(host, context).ConfigureAwait(false); if (tenantInfo != null && tenantInfo.RequiresDevAdminSsoReplacement) { if (_devAdminSsoReplacementWhitelistIpAddresses != null && _devAdminSsoReplacementWhitelistIpAddresses.Count > 0) { var ipAddress = context.Connection?.RemoteIpAddress?.ToString(); if (_devAdminSsoReplacementWhitelistIpAddresses.Contains(ipAddress)) { tenantInfo = tenantInfo.Clone(); if (!string.IsNullOrEmpty(tenantInfo.DevAdminSsoReplacementSamlPeerEntityId)) { tenantInfo.SamlPeerEntityId = tenantInfo.DevAdminSsoReplacementSamlPeerEntityId; } if (!string.IsNullOrEmpty(tenantInfo.DevAdminSsoReplacementSamlPeerIdpMetadataLocation)) { tenantInfo.SamlPeerIdpMetadataLocation = tenantInfo.DevAdminSsoReplacementSamlPeerIdpMetadataLocation; tenantInfo.SamlPeerIdpMetadata = null; } tenantInfo.AdditionalCacheKey = "devAdminSsoReplacement"; } } } } if (tenantInfo == null) { // we could not find any tenant // check if we have a health check running here var healthCheckPort = _tenantDataProvider.HealthCheckPort; if (healthCheckPort != null && context.Request.Host.Port == healthCheckPort) { var healthCheckTenantHost = _tenantDataProvider.HealthCheckTenantHost; if (!string.IsNullOrEmpty(healthCheckTenantHost)) { (matchedSubDomain, tenantInfo) = await _tenantDataProvider.GetTenantByHostAsync(healthCheckTenantHost).ConfigureAwait(false); } } if (tenantInfo == null) { _logger.LogInformation($"No tenant found for host {hostString}"); throw new NotFoundApiException(NotFoundApiException.TenantNotFound, $"The tenant for host {host} was not found", host); } } context.Items.Add(TenantConstants.TenantInfoContextKey, tenantInfo); context.Items.Add(TenantConstants.MatchedSubDomainContextKey, matchedSubDomain); } await _next.Invoke(context).ConfigureAwait(false); }
public MultiTenantConfigurationDbContext(ITenantInfo tenantInfo, DbContextOptions <MultiTenantConfigurationDbContext> options, ConfigurationStoreOptions storeOptions) : base(options, storeOptions) { TenantInfo = tenantInfo; }
public ToDoDbContext(ITenantInfo tenantInfo, DbContextOptions <ToDoDbContext> options) : base(tenantInfo, options) { }
public async Task <string> RenderViewAsync <TModel>(string viewName, TModel model, ITenantInfo tenantInfo = null) where TModel : TemplateViewModel { EnrichTenantInfo(model, tenantInfo); var actionContext = GetActionContext(); var view = FindView(actionContext, viewName); using (var output = new StringWriter()) { var viewContext = new ViewContext( actionContext, view, new ViewDataDictionary <TModel>( metadataProvider: new EmptyModelMetadataProvider(), modelState: new ModelStateDictionary()) { Model = model }, new TempDataDictionary( actionContext.HttpContext, _tempDataProvider), output, new HtmlHelperOptions()); viewContext.RouteData = _context?.GetRouteData() ?? new RouteData(); await view.RenderAsync(viewContext).ConfigureAwait(false); return(output.ToString()); } }