Esempio n. 1
0
        public Task <TenantShell <Tenant> > Get(TenantDistinguisher distinguisher)
        {
            // If cookie was present, then scheme will be our own custom one.
            if (distinguisher.Uri.Scheme == "tenant")
            {
                var tenant = distinguisher.Uri.Host.ToLowerInvariant();
                switch (tenant)
                {
                case "moogle":
                    return(CreateMoogleTenant());

                case "gicrosoft":
                    return(CreateGicrosoftTenant());
                }
            }

            // Otherwise, just pick tenant based on port.
            if (distinguisher.Uri.Port == 5000 || distinguisher.Uri.Port == 5001)
            {
                return(CreateMoogleTenant());
            }

            if (distinguisher.Uri.Port == 5002)
            {
                return(CreateGicrosoftTenant());
            }


            throw new NotImplementedException("Please make request on ports 5000 - 5003 to see various behaviour.");
        }
Esempio n. 2
0
        public async Task <TenantShell <Tenant> > Get(TenantDistinguisher distinguisher)
        {
            if (distinguisher.Key == "http://localhost:5004")
            {
                Guid tenantId = Guid.Parse("b17fcd22-0db1-47c0-9fef-1aa1cb09605e");
                var  tenant   = new Tenant(tenantId)
                {
                    Name = "Foo"
                };
                var result = new TenantShell <Tenant>(tenant);
                return(result);
            }

            if (distinguisher.Key.Contains(":5000") || distinguisher.Key.Contains(":5001"))
            {
                Guid tenantId = Guid.Parse("049c8cc4-3660-41c7-92f0-85430452be22");
                var  tenant   = new Tenant(tenantId)
                {
                    Name = "Bar"
                };
                var result = new TenantShell <Tenant>(tenant, "http://localhost:5000", "http://localhost:5001"); // additional distinguishers to map this same tenant shell instance too.
                return(result);
            }

            // for an unknown tenant, we can either create the tenant shell as a NULL tenant by returning a TenantShell<TTenant>(null),
            // which results in the TenantShell being created, and will explicitly have to be reloaded() in order for this method to be called again.
            if (distinguisher.Key.Contains("5002"))
            {
                var result = new TenantShell <Tenant>(null);
                return(result);
            }

            if (distinguisher.Key.Contains("5003"))
            {
                // or we can return null - which means we wil keep attempting to resolve the tenant on every subsequent request until a result is returned in future.
                // (i.e allows tenant to be created in backend in a few moments time).
                return(null);
            }

            throw new NotImplementedException("Please make request on ports 5000 - 5003 to see various behaviour. Can also use 63291 when launching under IISExpress");
        }
        public ITenantContainerAccessor <TTenant> WithTenant(TenantDistinguisher tenantDistinguisher)
        {
            TenantContainer = new Lazy <Task <ITenantContainerAdaptor> >(async() =>
            {
                var tenantShell = await _tenantShellAccessor.WithTenant(tenantDistinguisher).CurrentTenantShell.Value;

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

                var tenant = tenantShell?.Tenant;
                var lazy   = tenantShell.GetOrAddContainer(() =>
                {
                    return(_containerFactory.Get(tenant));
                });

                return(await lazy.Value);
            });

            return(this);
        }
        public Task <TenantShell <Tenant> > Get(TenantDistinguisher distinguisher)
        {
            if (distinguisher.Uri.Port == 5000 || distinguisher.Uri.Port == 5001)
            {
                Guid tenantId = Guid.Parse("049c8cc4-3660-41c7-92f0-85430452be22");
                var  tenant   = new Tenant(tenantId, "Moogle");
                // Also adding any additional Uri's that should be mapped to this same tenant.
                var result = new TenantShell <Tenant>(tenant, new Uri("http://localhost:5000"),
                                                      new Uri("http://localhost:5001"));
                return(Task.FromResult(result));
            }

            if (distinguisher.Uri.Port == 5002)
            {
                Guid tenantId = Guid.Parse("b17fcd22-0db1-47c0-9fef-1aa1cb09605e");
                var  tenant   = new Tenant(tenantId, "Gicrosoft");
                var  result   = new TenantShell <Tenant>(tenant);
                return(Task.FromResult(result));
            }


            throw new NotImplementedException("Please make request on ports 5000 - 5003 to see various behaviour.");
        }