コード例 #1
0
        public virtual async Task InitializeAsync()
        {
            var tenantName  = Guid.NewGuid().ToString("n");
            var tablePrefix = await TablePrefixGenerator.GeneratePrefixAsync();

            var createModel = new Tenants.ViewModels.CreateApiViewModel
            {
                DatabaseProvider = DatabaseProvider,
                TablePrefix      = tablePrefix,
                ConnectionString = ConnectionString,
                RecipeName       = RecipeName,
                Name             = tenantName,
                RequestUrlPrefix = tenantName
            };

            var createResult = await DefaultTenantClient.PostAsJsonAsync("api/tenants/create", createModel);

            createResult.EnsureSuccessStatusCode();

            var content = await createResult.Content.ReadAsStringAsync();

            var url = new Uri(content.Trim('"'));

            url = new Uri(url.Scheme + "://" + url.Authority + url.LocalPath + "/");

            var setupModel = new Tenants.ViewModels.SetupApiViewModel
            {
                SiteName         = "Test Site",
                DatabaseProvider = DatabaseProvider,
                TablePrefix      = tablePrefix,
                ConnectionString = ConnectionString,
                RecipeName       = RecipeName,
                UserName         = "******",
                Password         = "******",
                Name             = tenantName,
                Email            = "Nick@Orchard"
            };

            var setupResult = await DefaultTenantClient.PostAsJsonAsync("api/tenants/setup", setupModel);

            setupResult.EnsureSuccessStatusCode();

            lock (Site)
            {
                Client     = Site.CreateDefaultClient(url);
                TenantName = tenantName;
            }

            if (PermissionsContext != null)
            {
                var permissionContextKey = Guid.NewGuid().ToString();
                SiteStartup.PermissionsContexts.TryAdd(permissionContextKey, PermissionsContext);
                Client.DefaultRequestHeaders.Add("PermissionsContext", permissionContextKey);
            }

            GraphQLClient = new OrchardGraphQLClient(Client);
        }
コード例 #2
0
        public virtual async Task InitializeAsync()
        {
            var tenantName = Guid.NewGuid().ToString().Replace("-", "");

            var createModel = new Tenants.ViewModels.CreateApiViewModel
            {
                DatabaseProvider = "Sqlite",
                RecipeName       = "Blog",
                Name             = tenantName,
                RequestUrlPrefix = tenantName
            };

            var createResult = await DefaultTenantClient.PostAsJsonAsync("api/tenants/create", createModel);

            createResult.EnsureSuccessStatusCode();

            var content = await createResult.Content.ReadAsStringAsync();

            var url = new Uri(content.Trim('"'));

            url = new Uri(url.Scheme + "://" + url.Authority + url.LocalPath + "/");

            var setupModel = new Tenants.ViewModels.SetupApiViewModel
            {
                SiteName         = "Test Site",
                DatabaseProvider = "Sqlite",
                RecipeName       = "Blog",
                UserName         = "******",
                Password         = "******",
                Name             = tenantName,
                Email            = "Nick@Orchard"
            };

            var setupResult = await DefaultTenantClient.PostAsJsonAsync("api/tenants/setup", setupModel);

            setupResult.EnsureSuccessStatusCode();

            // Track if Lucene needs more time to update its indexes.
            await Task.Delay(100);

            Client        = Site.CreateDefaultClient(url);
            GraphQLClient = new OrchardGraphQLClient(Client);
        }