/// <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);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void Start(ISite site)
        {
            // Gets the site
            SiteInfo siteToStart = SiteInfoProvider.GetSiteInfo(site.SiteName);

            if (siteToStart != null)
            {
                // Starts the site
                SiteInfoProvider.RunSite(siteToStart.SiteName);
            }
        }
    /// <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);
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Runs the site. Called when the "Run site" button is pressed.
    /// </summary>
    private bool RunSite()
    {
        // Get the site
        SiteInfo site = SiteInfoProvider.GetSiteInfo("MyNewSite");

        if (site != null)
        {
            // Stop site
            SiteInfoProvider.RunSite(site.SiteName);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void Control_OnAction(string actionName, object actionArgument)
    {
        SiteInfo si = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(actionArgument, 0));

        if (si != null)
        {
            string siteName = si.SiteName;

            switch (actionName)
            {
            case "delete":
                URLHelper.Redirect("~/CMSModules/Sites/Pages/site_delete.aspx?siteid=" + actionArgument);
                break;

            case "editContent":
            {
                // Build URL for site in format 'http(s)://sitedomain/application/admin'
                string sitedomain  = si.DomainName.TrimEnd('/');
                string application = null;

                // Support of multiple web sites on single domain
                if (!sitedomain.Contains("/"))
                {
                    application = URLHelper.ResolveUrl("~/.").TrimEnd('/');
                }

                // Application includes string '/admin'.
                application += "/admin/";
                string url = RequestContext.CurrentScheme + "://" + sitedomain + application;
                ScriptHelper.RegisterStartupScript(Control.Page, typeof(string), "EditContentScript", ScriptHelper.GetScript("window.open('" + url + "');"));
            }
            break;

            case "openLiveSite":
            {
                // Make url for site in form 'http(s)://sitedomain/application'.
                string sitedomain = si.DomainName.TrimEnd('/');

                string application = null;
                // Support of multiple web sites on single domain
                if (!sitedomain.Contains("/"))
                {
                    application = URLHelper.ResolveUrl("~/.").TrimEnd('/');
                }
                string url = RequestContext.CurrentScheme + "://" + sitedomain + application + "/";
                ScriptHelper.RegisterStartupScript(Control.Page, typeof(string), "OpenLiveSiteScript", ScriptHelper.GetScript("window.open('" + url + "');"));
            }
            break;

            case "start":
                try
                {
                    SiteInfoProvider.RunSite(siteName);
                }
                catch (Exception ex)
                {
                    Control.ShowError(ResHelper.GetString("Site_List.ErrorMsg"), ex.Message, null);
                }
                break;

            case "stop":
                SiteInfoProvider.StopSite(siteName);
                SessionManager.Clear(siteName);
                break;

            case "export":
                URLHelper.Redirect(URLHelper.AppendQuery(UIContextHelper.GetElementUrl(ModuleName.CMS, "Export", false), "siteID=" + actionArgument));
                break;
            }
        }
    }
    /// <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);
        }
    }
Ejemplo n.º 7
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);
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void UniGridSites_OnAction(string actionName, object actionArgument)
    {
        SiteInfo si = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(actionArgument, 0));

        if (si != null)
        {
            string siteName = si.SiteName;

            switch (actionName)
            {
            case "editSite":
                URLHelper.Redirect("Site_Edit_Frameset.aspx?siteid=" + actionArgument);
                break;

            case "delete":
                URLHelper.Redirect("site_delete.aspx?siteid=" + actionArgument);
                break;

            case "editContent":
            {
                // Make url for site in form 'http(s)://sitedomain/application/cmsdesk'.
                string sitedomain = si.DomainName.TrimEnd('/');

                string application = null;
                // Support of multiple web sites on single domain
                if (!sitedomain.Contains("/"))
                {
                    application = ResolveUrl("~/.").TrimEnd('/');
                }

                // Application includes string '/cmsdesk'.
                application += "/cmsdesk/";

                string url = URLHelper.Url.Scheme + "://" + sitedomain + application;

                ltlScript.Text = ScriptHelper.GetScript("window.open('" + url + "');");
            }
            break;

            case "openLiveSite":
            {
                // Make url for site in form 'http(s)://sitedomain/application'.
                string sitedomain = si.DomainName.TrimEnd('/');

                string application = null;
                // Support of multiple web sites on single domain
                if (!sitedomain.Contains("/"))
                {
                    application = ResolveUrl("~/.").TrimEnd('/');
                }
                string url = URLHelper.Url.Scheme + "://" + sitedomain + application + "/";

                ltlScript.Text = ScriptHelper.GetScript("window.open('" + url + "');");
            }
            break;

            case "start":
                try
                {
                    SiteInfoProvider.RunSite(siteName);
                }
                catch (Exception ex)
                {
                    lblErrorMsg.Visible = true;
                    lblErrorMsg.Text    = GetString("Site_List.ErrorMsg") + " " + ex.Message;
                }
                break;

            case "stop":
                SiteInfoProvider.StopSite(siteName);
                SessionManager.Clear(siteName);
                break;

            case "export":
                URLHelper.Redirect("~/CMSModules/ImportExport/SiteManager/ExportSite.aspx?siteid=" + actionArgument);
                break;
            }
        }
    }