/// <summary>
 /// Handle OnAfterSave event of the UI form.
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event argument</param>
 protected void Control_OnAfterSave(object sender, EventArgs e)
 {
     // Run site again if it was previously running
     if ((siteInfo != null) && runAfterSave)
     {
         string  domainName = ValidationHelper.GetString(Control.GetFieldValue("SiteDomainAliasName"), String.Empty);
         DataSet ds         = SiteInfoProvider.CheckDomainNameForCollision(domainName, siteInfo.SiteID);
         if (!DataHelper.DataSourceIsEmpty(ds))
         {
             SiteInfo runningSite = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0));
             if (runningSite != null)
             {
                 string collisionSite   = runningSite.DisplayName;
                 string collisionDomain = ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], "");
                 Control.ShowError(String.Format(ResHelper.GetString("SiteDomain.RunError"), collisionSite, collisionDomain, siteInfo.DisplayName));
             }
         }
         else
         {
             // Try to re-run the site
             try
             {
                 SiteInfoProvider.RunSite(siteInfo.SiteName);
             }
             catch (RunningSiteException ex)
             {
                 Control.ShowError(ex.Message);
             }
         }
     }
 }
    /// <summary>
    /// Handles OnAfterValidate event of the UI form.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Control_OnAfterValidate(object sender, EventArgs e)
    {
        // Check for domain name collision
        if (siteInfo.Status == SiteStatusEnum.Running)
        {
            string  domainName = ValidationHelper.GetString(Control.GetFieldValue("SiteDomainName"), String.Empty);
            DataSet ds         = SiteInfoProvider.CheckDomainNameForCollision(domainName, siteInfo.SiteID);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int      collisionSiteID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0);
                SiteInfo collisionSite   = SiteInfoProvider.GetSiteInfo(collisionSiteID);

                if (collisionSite != null)
                {
                    Control.StopProcessing = true;

                    // Hide error message because user gets informed via confirmation
                    Control.MessagesPlaceHolder.Visible = false;

                    string postBackRef = ControlsHelper.GetPostBackEventReference(Control.ObjectManager.HeaderActions, "StopSite;");
                    string script      = "if (confirm('" + ScriptHelper.GetString(ResHelper.GetStringFormat("sitedomain.proceedwithcollision", collisionSite.DisplayName), false) + "')) { " + postBackRef + "; } ";
                    ScriptHelper.RegisterStartupScript(Control.Page, typeof(string), "DomainCollisionMessage", ScriptHelper.GetScript(script));
                }
            }
        }

        // Remember the state of the site
        runSite = (siteInfo.Status == SiteStatusEnum.Running);
    }
    public string GetCallbackResult()
    {
        if (si != null)
        {
            DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(domainName, si.SiteID);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                return("running");
            }
        }

        return("ok");
    }
    /// <summary>
    /// Handles OnAfterSave event of the UI Form.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Control_OnAfterSave(object sender, EventArgs e)
    {
        string newSiteCodeName = ValidationHelper.GetString(Control.GetFieldValue("SiteName"), String.Empty);

        if (newSiteCodeName.ToLowerCSafe() != siteInfo.SiteName.ToLowerCSafe())
        {
            // Clear settings if sitename changes
            SettingsKeyInfoProvider.ClearCachedValues(true);

            // Reindex hashtable with sessions if SiteName changes and change info message
            SessionManager.ReindexSessionsInfosHashtable(formerCodeName, siteInfo.SiteName);
            if (SearchIndexInfoProvider.SearchEnabled)
            {
                Control.ShowInformation(String.Format(ResHelper.GetString("general.changessaved") + " " + ResHelper.GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + ControlsHelper.GetPostBackEventReference(Control.ObjectManager.HeaderActions, "RebuildSiteIndex;") + "\">" + ResHelper.GetString("General.clickhere") + "</a>"));
            }
        }

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

        // Run the site if it was running previously
        try
        {
            if (runSite)
            {
                DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(siteInfo.DomainName, siteInfo.SiteID);
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    SiteInfo runningSiteInfo = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0));
                    if (runningSiteInfo != null)
                    {
                        string collisionSite   = HTMLHelper.HTMLEncode(runningSiteInfo.DisplayName);
                        string collisionDomain = HTMLHelper.HTMLEncode(ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], ""));

                        Control.ShowWarning(String.Format(ResHelper.GetString("SiteDomain.RunError"), collisionSite, collisionDomain, HTMLHelper.HTMLEncode(siteInfo.DisplayName)));
                    }
                }
                else
                {
                    // Run current site
                    SiteInfoProvider.RunSite(siteInfo.SiteName);
                }
            }
        }
        catch (RunningSiteException ex)
        {
            Control.ShowError(ex.Message);
        }
    }
    /// <summary>
    /// Save or update domain alias.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string result = new Validator().NotEmpty(txtDomainName.Text, GetString("Site_Edit.AliasRequired")).Result;

        if (result == "")
        {
            // Check site of this domain alias
            if (si == null)
            {
                return;
            }

            // Stop the site before adding alias
            bool wasRunning = false;
            if (si.Status == SiteStatusEnum.Running)
            {
                SiteInfoProvider.StopSite(si.SiteName);
                si.Status  = SiteStatusEnum.Stopped;
                wasRunning = true;
            }

            string redirect = String.Empty;

            // Correct domain name and return it to textbox
            txtDomainName.Text = URLHelper.RemoveProtocol(txtDomainName.Text);

            // Insert new
            if (alias == null)
            {
                // Check duplicity
                if (!SiteDomainAliasInfoProvider.DomainAliasExists(txtDomainName.Text, siteId))
                {
                    SiteDomainAliasInfo sdai = new SiteDomainAliasInfo();
                    sdai.SiteID = si.SiteID;
                    sdai.SiteDomainAliasName        = txtDomainName.Text.Trim();
                    sdai.SiteDefaultVisitorCulture  = ValidationHelper.GetString(cultureSelector.Value, "");
                    sdai.SiteDomainDefaultAliasPath = pageSelector.Value.ToString().Trim();
                    sdai.SiteDomainRedirectUrl      = txtRedirectUrl.Text.Trim();

                    SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(sdai);

                    redirect = "Site_Edit_DomainAlias_Edit.aspx?siteId=" + sdai.SiteID + "&domainaliasid=" + sdai.SiteDomainAliasID + "&saved=1";
                }
                else
                {
                    ShowError(GetString("Site_Edit.AliasExists"));
                }
            }
            // Update
            else
            {
                // Check duplicity
                SiteDomainAliasInfo existing = SiteDomainAliasInfoProvider.GetSiteDomainAliasInfo(txtDomainName.Text, siteId);
                if ((existing == null) || (existing.SiteDomainAliasID == alias.SiteDomainAliasID))
                {
                    string originalDomainAlias = alias.SiteDomainAliasName;
                    alias.SiteDomainAliasName        = txtDomainName.Text.Trim();
                    alias.SiteDefaultVisitorCulture  = ValidationHelper.GetString(cultureSelector.Value, "");
                    alias.SiteDomainDefaultAliasPath = pageSelector.Value.ToString().Trim();
                    alias.SiteDomainRedirectUrl      = txtRedirectUrl.Text.Trim();

                    SiteDomainAliasInfoProvider.SetSiteDomainAliasInfo(alias, originalDomainAlias);

                    // Update breadcrumbs
                    CurrentMaster.Title.Breadcrumbs[1, 0] = alias.SiteDomainAliasName;


                    ShowChangesSaved();
                }
                else
                {
                    ShowError(GetString("Site_Edit.AliasExists"));
                }
            }

            // Run site again
            if (wasRunning)
            {
                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   = runningsi.DisplayName;
                        string collisionDomain = ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], "");

                        if (String.IsNullOrEmpty(redirect))
                        {
                            redirect = "Site_Edit_DomainAlias_Edit.aspx?siteId=" + alias.SiteID + "&domainaliasid=" + alias.SiteDomainAliasID + "&saved=1";
                        }

                        // Add parameter indicating run problem
                        redirect = URLHelper.AddParameterToUrl(redirect, "runerror", collisionSite + ";" + collisionDomain);
                    }
                }
                else
                {
                    // Seems to be ok, run the site
                    try
                    {
                        SiteInfoProvider.RunSite(si.SiteName);
                    }
                    catch (Exception ex)
                    {
                        ShowError(ex.Message);
                        redirect = "";
                    }
                }
            }

            // Redirect
            if (redirect != "")
            {
                URLHelper.Redirect(redirect);
            }
        }
        else
        {
            ShowError(result);
        }
    }
Beispiel #6
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);
        }
    }