private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions()
            {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);
            _apiClient  = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());

            _apiClient.SignInWithUserPassword_WithSlug_Async(
                TestUsers.DefaultSiteAdminName, TestUsers.DefaultSiteAdminPass,
                _httpClient, "").Wait();
            _siteAdminUser = await _apiClient.GetCurrentUserAsync();

            _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);

            await _apiClient.SignInWithUserPassword_WithSlug_Async(
                TestUsers.DefaultSiteAdminName, TestUsers.DefaultSiteAdminPass,
                _httpClient, "");

            _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);
        }
コード例 #2
0
    private async Task InitOnce()
    {
      if (_app != null) return;

      _app = new DefaultWebApplicationFactory();
      var options = new WebApplicationFactoryClientOptions()
      {
        AllowAutoRedirect = false
      };
      _httpClient = _app.CreateClient(options);
      _apiClient = new ApiClient(_httpClient, _app.GetLogger<ApiClient>());

      // create tenants here
      await _apiClient.AsSiteAdminAsync(_httpClient);
      _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);
      await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse);
      await TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse);
      await TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse);
      await TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse);
      _gryffindorEmployees = (await _apiClient.GetEmployeesAsync()).ToList();

      await _apiClient.AsSiteAdminAsync(_httpClient);
      _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);
      await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse);
      await TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse);
      await TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse);
      await TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse);
    }
コード例 #3
0
        private void UpdateJobDetails(ServiceRequest mfrServiceRequest)
        {
            mfrServiceRequest.Name        = MfrCustomer.Name;
            mfrServiceRequest.CustomerId  = MfrCustomer.Id;
            mfrServiceRequest.ExternalId  = Auftrag.EindeutigeNummer;
            mfrServiceRequest.Description = "Aufgabenbeschreibung";

            TenantContainer.SaveChanges(); // create the job

            // service objekte hinzufügen

            var serviceObject = mfrServiceRequest.ServiceObjects.Where(s => s.ExternalId == Einsatzort.EindeutigeNummer).FirstOrDefault();

            if (serviceObject == null)
            {
                serviceObject = TenantContainer.ServiceObjects.Where(s => s.ExternalId == Einsatzort.EindeutigeNummer).FirstOrDefault();
                if (serviceObject == null)
                {
                    throw new InvalidOperationException("ServiceObject not found");
                }

                mfrServiceRequest.ServiceObjects.Add(serviceObject);
                TenantContainer.AddLink(mfrServiceRequest, "ServiceObjects", serviceObject);
            }

            // send a user notification and assign the job
            CreateOrUpdateAppointment(mfrServiceRequest);
        }
コード例 #4
0
ファイル: Startup.cs プロジェクト: mhagrelius/MultiTenant
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
            services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
            services.AddSingleton(new TenantMiddlewareConfiguration());
            services.AddHttpContextAccessor();

            SetupHome();
            SetupWork();

            void SetupHome()
            {
                var tenantServices = new ServiceCollection();

                tenantServices.AddSingleton(_ => new WeatherForecastService("Home"));

                var homeContainer = new TenantContainer("home", tenantServices);

                services.AddSingleton(homeContainer);
            }

            void SetupWork()
            {
                var tenantServices = new ServiceCollection();

                tenantServices.AddSingleton(_ => new WeatherForecastService("Work"));
                var workContainer = new TenantContainer("work", tenantServices);

                services.AddSingleton(workContainer);
            }
        }
コード例 #5
0
        private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);

            var apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());

            apiClient.TraceResponseOnException = true;

            _apiClient = apiClient;

            // site admin creates 2 tenants
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);

            await _apiClient.AsSiteAdminAsync(_httpClient);

            _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);

            // Slytherin House admin creates branch office and departments
            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse).Wait();
            TestDepartment.SeedDefaultDepartments(_apiClient, _slytherinHouse).Wait();
            TestPosition.SeedDefaultPosition(_apiClient, _slytherinHouse).Wait();
            TestEmployees.SeedDefaultEmployees(_apiClient, _slytherinHouse).Wait();

            // Gryffindor House admin creates branch office and departments
            await _apiClient.AsGryffindorAdminAsync(_httpClient);

            TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse).Wait();
            TestDepartment.SeedDefaultDepartments(_apiClient, _gryffindorHouse).Wait();
            TestPosition.SeedDefaultPosition(_apiClient, _gryffindorHouse).Wait();
            TestEmployees.SeedDefaultEmployees(_apiClient, _gryffindorHouse).Wait();

            _workDepartmentId = _gryffindorHouse.Department_1_2.Department.Id;
        }
コード例 #6
0
        /// <summary>
        /// Create our serivce provider
        /// </summary>
        /// <param name="containerBuilder"></param>
        /// <returns></returns>
        public IServiceProvider CreateServiceProvider(ContainerBuilder containerBuilder)
        {
            TenantContainer <T> container = null;

            Func <TenantContainer <T> > containerAccessor = () =>
            {
                return(container);
            };

            containerBuilder
            .RegisterInstance(containerAccessor)
            .SingleInstance();

            container = new TenantContainer <T>(containerBuilder.Build(), _tenantSerivcesConfiguration);

            return(new AutofacServiceProvider(containerAccessor()));
        }
コード例 #7
0
        private void CreateOrUpdateAppointment(ServiceRequest mfrServiceRequest)
        {
            if (mfrServiceRequest.ServiceObjects.Count == 0)
            {
                //("ERROR: Job " + mfrServiceRequest.ExternalId + "has no service objects. Appointment could not be created.");
                //mfrServiceRequest.Description = "ERROR: Job " + mfrServiceRequest.ExternalId + "has no service objects. Appointment could not be created.";
                TenantContainer.SaveChanges();
                return;
            }

            var mfrTechnicianContainer = GetTechniciansForAuftrag(Auftrag);

            var appointment = mfrServiceRequest.Appointments.FirstOrDefault() ?? new Appointment()
            {
                Id = 0
            };

            foreach (
                var technician in
                mfrTechnicianContainer.Where(technician => !appointment.ContactIds.Contains(technician.Id)))
            {
                appointment.ContactIds.Add(technician.Id);
            }

            appointment.StartDateTime = Auftrag.TerminBegin;
            appointment.EndDateTime   = Auftrag.TerminEnde;

            if (appointment.StartDateTime.Value.AddMinutes(30) > appointment.EndDateTime.Value)
            {
                appointment.EndDateTime = appointment.StartDateTime.Value.AddHours(1);
            }

            if (appointment.Id == 0)
            {
                mfrServiceRequest.Appointments.Add(appointment);
                TenantContainer.AddRelatedObject(mfrServiceRequest, "Appointments", appointment);
                TenantContainer.SaveChanges();
            }
            else
            {
                TenantContainer.UpdateObject(appointment);
                TenantContainer.SaveChanges();
            }
        }
コード例 #8
0
        private async Task InitOnce()
        {
            if (_app != null)
            {
                return;
            }

            LogHelper.ConfigureConsoleLogger();

            _app = new DefaultWebApplicationFactory();

            var options = new WebApplicationFactoryClientOptions()
            {
                AllowAutoRedirect = false
            };

            _httpClient = _app.CreateClient(options);

            _apiClient = new ApiClient(_httpClient, _app.GetLogger <ApiClient>());
            // admin creates Gryffindor tenant and initializes default branch office
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _siteAdminUser = await _apiClient.GetCurrentUserAsync();

            _gryffindorHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.GryffindorHouse);

            await _apiClient.AsGryffindorAdminAsync(_httpClient);

            await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _gryffindorHouse);

            // admin creates Slytherin tenant and initializes default branch office
            await _apiClient.AsSiteAdminAsync(_httpClient);

            _slytherinHouse = await TestTenants.CreateTenantWithRolesAndUsers(_apiClient, _httpClient, TestTenants.SlytherinHouse);

            await _apiClient.AsSlytherinAdminAsync(_httpClient);

            await TestBranchOffice.SeedDefaultBranchOffice(_apiClient, _httpClient, _slytherinHouse);
        }
コード例 #9
0
        //Provavel deprecated
        public static IServiceProvider UseMultiTenantServiceProvider <T>(this IServiceCollection services, Action <T, ContainerBuilder, IHttpContextAccessor> registerServicesForTenant) where T : Tenant
        {
            ContainerBuilder containerBuilder = new ContainerBuilder();

            //Declare our container and create a accessor function
            //This is to support the Func<MultiTenantContainer<T>> multiTenantContainerAccessor parameter in the middleware
            TenantContainer <T>         container         = null;
            Func <TenantContainer <T> > containerAccessor = () =>
            {
                return(container);
            };

            services.AddSingleton(containerAccessor);

            //Add all the application level services to the builder
            containerBuilder.Populate(services);

            //Create and assign the new multiteant container
            container = new TenantContainer <T>(containerBuilder.Build(), registerServicesForTenant);

            //Return the new IServiceProvider which will be used to replace the standard one
            return(new AutofacServiceProvider(containerAccessor()));
        }
コード例 #10
0
        public void Execute()
        {
            TenantContainer = tenant.CreateApiContainer();

            ServiceRequest mfrServiceRequest = null;

            ServiceObjectsToAdd = new List <ServiceObject>();
            mfrServiceRequest   = TenantContainer.ServiceRequests.Expand(j => j.Customer)
                                  .Expand(j => j.Steps)
                                  .Expand(j => j.Items)
                                  .Expand("Appointments/Contacts")
                                  .Expand(j => j.ServiceObjects)
                                  .Where(c => c.ExternalId == Auftrag.EindeutigeNummer)
                                  .ToList()
                                  .FirstOrDefault();

            if (mfrServiceRequest == null)
            {
                mfrServiceRequest = new ServiceRequest()
                {
                    Name = "Auftragsbeispiel",
                    Id   = 0,
                };

                TenantContainer.AddToServiceRequests(mfrServiceRequest);
            }

            UpdateJobDetails(mfrServiceRequest);
            TenantContainer.SaveChanges(SaveChangesOptions.Batch);

            if (ServiceObjectsToAdd.Count != 0)
            {
                ServiceObjectsToAdd.ForEach(s => mfrServiceRequest.ServiceObjects.Add(s));
                TenantContainer.UpdateObject(mfrServiceRequest);
                TenantContainer.SaveChanges();
            }
        }