예제 #1
0
    /// <summary>
    /// Save edited site.
    /// </summary>
    private bool SaveSite(SiteInfo oldSi)
    {
        // Correct domain name and return it to textbox
        txtDomainName.Text = URLHelper.RemoveProtocol(txtDomainName.Text);

        // Get SiteInfo with the given siteID
        SiteInfo si = oldSi.Clone();

        if (siteId > 0)
        {
            try
            {
                // Keep information about running status
                bool runSite = (si.Status == SiteStatusEnum.Running);

                if (si.DisplayName != txtDisplayName.Text)
                {
                    // Refresh the breadcrumb
                    ScriptHelper.RefreshTabHeader(Page, null);
                }

                // Update SiteInfo parameters
                si.SiteName              = txtCodeName.Text;
                si.Description           = txtDescription.Text;
                si.DisplayName           = txtDisplayName.Text;
                si.DomainName            = txtDomainName.Text;
                si.DefaultVisitorCulture = ValidationHelper.GetString(cultureSelector.Value, "");
                si.SiteID = siteId;
                si.SiteDefaultStylesheetID     = ValidationHelper.GetInteger(ctrlSiteSelectStyleSheet.Value, 0);
                si.SiteDefaultEditorStylesheet = ValidationHelper.GetInteger(ctrlEditorSelectStyleSheet.Value, 0);
                si.Status = SiteStatusEnum.Stopped;

                // Save SiteInfo
                SiteInfoProvider.SetSiteInfo(si);

                // Remove cached cultures for site
                CultureInfoProvider.ClearSiteCultures(true);

                // Clear settings if sitename changes
                if (si.SiteName.ToLower() != txtCodeName.Text.Trim().ToLower())
                {
                    SettingsKeyProvider.Clear(true);
                }

                // Reindex hashtable with sessions if SiteName changes and change info message
                if (oldSi.SiteName != txtCodeName.Text)
                {
                    SessionManager.ReindexSessionsInfosHashtable(oldSi.SiteName, txtCodeName.Text);
                    if (SearchIndexInfoProvider.SearchEnabled)
                    {
                        lblInfo.Text = String.Format(GetString("general.changessaved") + " " + GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>");
                    }
                }

                if (runSite)
                {
                    DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(txtDomainName.Text.Trim(), si.SiteID);
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        SiteInfo runningsi = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0));
                        if (runningsi != null)
                        {
                            string collisionSite   = HTMLHelper.HTMLEncode(runningsi.DisplayName);
                            string collisionDomain = HTMLHelper.HTMLEncode(ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], ""));

                            lblError.Text    = String.Format(GetString("SiteDomain.RunError"), collisionSite, collisionDomain, HTMLHelper.HTMLEncode(si.DisplayName));
                            lblError.Visible = true;
                        }
                    }
                    else
                    {
                        // Run current site
                        SiteInfoProvider.RunSite(si.SiteName);
                    }
                }
            }
            catch (RunningSiteException exc)
            {
                lblError.Visible = true;
                lblError.Text    = exc.Message;
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }