示例#1
0
        private async Task <bool> SetupCloudscribeCore(HttpResponse response)
        {
            bool result = true;

            if (!schemaHasBeenCreated)
            {
                if (canAlterSchema)
                {
                    schemaHasBeenCreated = await CreateInitialSchema(response, "cloudscribe-core");

                    if (schemaHasBeenCreated)
                    {
                        //recheck
                        needCoreSchemaUpgrade = setupManager.NeedsUpgrade("cloudscribe-core");
                    }
                }
            }

            if (
                (schemaHasBeenCreated) &&
                (needCoreSchemaUpgrade) &&
                (canAlterSchema)
                )
            {
                needCoreSchemaUpgrade = await UpgradeSchema(response, "cloudscribe-core");
            }

            if (!CoreSystemIsReady())
            {
                return(false);
            }

            existingSiteCount = setupManager.ExistingSiteCount();

            if (existingSiteCount == 0)
            {
                await WritePageContent(response,
                                       "CreatingSite" //SetupResources.CreatingSiteMessage
                                       , true);

                SiteSettings newSite = await siteManager.CreateNewSite(true);

                await WritePageContent(response,
                                       "CreatingRolesAndAdminUser" //SetupResources.CreatingRolesAndAdminUserMessage
                                       , true);

                result = await siteManager.CreateRequiredRolesAndAdminUser(newSite);
            }

            //TODO dbSiteSettingsEx.EnsureSettings(); add to ISiteRepository


            return(result);
        }
        private async Task <bool> SetupCloudscribeCore(HttpResponse response)
        {
            bool result = true;

            if (!schemaHasBeenCreated)
            {
                if (canAlterSchema)
                {
                    schemaHasBeenCreated = await CreateInitialSchema(response, "cloudscribe-core");

                    if (schemaHasBeenCreated)
                    {
                        //recheck
                        needCoreSchemaUpgrade = setupManager.NeedsUpgrade("cloudscribe-core");
                    }
                }
            }

            if (
                (schemaHasBeenCreated) &&
                (needCoreSchemaUpgrade) &&
                (canAlterSchema)
                )
            {
                needCoreSchemaUpgrade = await UpgradeSchema(response, "cloudscribe-core");
            }

            if (!CoreSystemIsReady())
            {
                return(false);
            }

            existingSiteCount = await siteManager.ExistingSiteCount();

            if (existingSiteCount == 0)
            {
                await WritePageContent(response,
                                       "CreatingSite" //SetupResources.CreatingSiteMessage
                                       , true);

                SiteSettings newSite = await siteManager.CreateNewSite(true);

                await WritePageContent(response,
                                       "CreatingRolesAndAdminUser" //SetupResources.CreatingRolesAndAdminUserMessage
                                       , true);

                result = await siteManager.CreateRequiredRolesAndAdminUser(newSite);
            }
            else
            {
                // check here if count of users is 0
                // if something went wrong with creating admin user
                // setup page should try to correct it on subsequent runs
                // ie create an admin user if no users exist
                if (response.HttpContext.Request.Host.HasValue)
                {
                    ISiteSettings site = await siteManager.Fetch(response.HttpContext.Request.Host.Value);

                    if (site != null)
                    {
                        int roleCount = await siteManager.GetRoleCount(site.SiteId);

                        bool roleResult = true;
                        if (roleCount == 0)
                        {
                            roleResult = await siteManager.EnsureRequiredRoles(site);
                        }

                        if (roleResult)
                        {
                            int userCount = await siteManager.GetUserCount(site.SiteId);

                            if (userCount == 0)
                            {
                                await siteManager.CreateAdminUser(site);
                            }
                        }
                    }
                }
            }



            //TODO dbSiteSettingsEx.EnsureSettings(); add to ISiteRepository


            return(result);
        }
        public async Task <ActionResult> NewSite(SiteBasicSettingsViewModel model)
        {
            ViewData["Title"] = "Create New Site";

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool addHostName = false;

            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                if (string.IsNullOrEmpty(model.SiteFolderName))
                {
                    ModelState.AddModelError("foldererror", "Folder name is required.");

                    return(View(model));
                }

                ISiteFolder folder = await siteManager.GetSiteFolder(model.SiteFolderName);

                if (folder != null)
                {
                    ModelState.AddModelError("foldererror", "The selected folder name is already in use on another site.");

                    return(View(model));
                }
            }
            else
            {
                ISiteHost host;

                if (!string.IsNullOrEmpty(model.HostName))
                {
                    model.HostName = model.HostName.Replace("https://", string.Empty).Replace("http://", string.Empty);

                    host = await siteManager.GetSiteHost(model.HostName);

                    if (host != null)
                    {
                        ModelState.AddModelError("hosterror", "The selected host/domain name is already in use on another site.");

                        return(View(model));
                    }

                    addHostName = true;
                }
            }

            SiteSettings newSite = new SiteSettings();

            // only the first site created by setup page should be a server admin site
            newSite.IsServerAdminSite = false;

            newSite.SiteName = model.SiteName;

            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                newSite.SiteFolderName = model.SiteFolderName;
            }
            else if (addHostName)
            {
                newSite.PreferredHostName = model.HostName;
            }

            newSite.SiteIsClosed        = model.IsClosed;
            newSite.SiteIsClosedMessage = model.ClosedMessage;

            //Site.SiteRepository.Save(newSite);
            bool result = await siteManager.CreateNewSite(newSite);

            result = await siteManager.CreateRequiredRolesAndAdminUser(newSite);

            if ((result) && (multiTenantOptions.Mode == MultiTenantMode.FolderName))
            {
                bool folderResult = await siteManager.EnsureSiteFolder(newSite);

                // for folder sites we need routes that match the folder
                // which are normally created during app startup
                // can we add routes here? or do we need to force the app to recycle?
                // this seems to work, but we really do need to restart
                // so that the per folder authentication gets setup too
                //cloudscribe.Web.Routing.RouteRegistrar.AddDefaultRouteForNewSiteFolder(folder.FolderName);

                //startup.TriggerStartup();
                //http://stackoverflow.com/questions/31339896/replacement-httpruntime-unloadappdomain-in-asp-net-5
            }

            if (result && addHostName)
            {
                bool hostResult = await siteManager.AddHost(
                    newSite.SiteGuid,
                    newSite.SiteId,
                    model.HostName);
            }

            if (result)
            {
                this.AlertSuccess(string.Format("Basic site settings for <b>{0}</b> were successfully created.",
                                                newSite.SiteName), true);
            }

            return(RedirectToAction("SiteList", new { pageNumber = model.ReturnPageNumber }));
        }