protected void btnSaveAll_Click(object sender, EventArgs e)
    {
        try
        {
            // Save all the document transformations
            DataSet ds = DataClassInfoProvider.GetAllDataClass();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    classId        = ValidationHelper.GetInteger(dr["ClassID"], 0);
                    string className      = ValidationHelper.GetString(dr["ClassName"], "");
                    bool   isDocumentType = ValidationHelper.GetBoolean(dr["ClassIsDocumentType"], false);

                    if (isDocumentType)
                    {
                        ProcessTransformations(classId, className);
                    }
                }
            }

            // Save all the custom table transformations
            ds = DataClassInfoProvider.GetCustomTableClasses(null, null, 0, "ClassID,ClassName,ClassIsCustomTable");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    classId       = ValidationHelper.GetInteger(dr["ClassID"], 0);
                    string className     = ValidationHelper.GetString(dr["ClassName"], "");
                    bool   isCustomTable = ValidationHelper.GetBoolean(dr["ClassIsCustomTable"], false);

                    if (isCustomTable)
                    {
                        ProcessTransformations(classId, className);
                    }
                }
            }

            // Save all the layouts
            ds = LayoutInfoProvider.GetAllLayouts();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string layoutName = ValidationHelper.GetString(dr["LayoutCodeName"], "");
                    string layoutCode = ValidationHelper.GetString(dr["LayoutCode"], "");

                    int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["LayoutCheckedOutByUserID"], 0);
                    string checkedOutMachineName = ValidationHelper.GetString(dr["LayoutCheckedOutMachineName"], "");

                    if ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower()))
                    {
                        string filename = LayoutInfoProvider.GetLayoutUrl(layoutName, null);

                        // Prepare the code
                        string code = layoutCode;
                        code = LayoutInfoProvider.AddLayoutDirectives(code);

                        SiteManagerFunctions.SaveCodeFile(filename, code);
                    }
                }
            }

            // Save all the page template layouts
            ds = PageTemplateInfoProvider.GetAllTemplates();
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string templateName   = ValidationHelper.GetString(dr["PageTemplateCodeName"], "");
                    string templateLayout = ValidationHelper.GetString(dr["PageTemplateLayout"], "");
                    bool   isReusable     = ValidationHelper.GetBoolean(dr["PageTemplateIsReusable"], false);

                    int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["PageTemplateLayoutCheckedOutByUserID"], 0);
                    string checkedOutMachineName = ValidationHelper.GetString(dr["PageTemplateLayoutCheckedOutMachineName"], "");
                    bool   isPortalTemplate      = ValidationHelper.GetBoolean(dr["PageTemplateIsPortal"], false);
                    string pageTemplateType      = ValidationHelper.GetString(dr["PageTemplateType"], "");
                    bool   isDashboard           = pageTemplateType.Equals(PageTemplateInfoProvider.GetPageTemplateTypeCode(PageTemplateTypeEnum.Dashboard));

                    if ((isPortalTemplate || isDashboard) && !String.IsNullOrEmpty(templateLayout) && ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower())))
                    {
                        string filename = null;
                        if (isReusable)
                        {
                            filename = PageTemplateInfoProvider.GetLayoutUrl(templateName, null);
                        }
                        else
                        {
                            filename = PageTemplateInfoProvider.GetAdhocLayoutUrl(templateName, null);
                        }

                        // Prepare the code
                        string code = templateLayout;
                        code = LayoutInfoProvider.AddLayoutDirectives(code);

                        SiteManagerFunctions.SaveCodeFile(filename, code);
                    }
                }
            }

            // Save all the web part layouts
            ds = WebPartLayoutInfoProvider.GetWebPartLayouts(null, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    string webPartLayoutCodeName = ValidationHelper.GetString(dr["WebPartLayoutCodeName"], "");
                    string webPartLayoutCode     = ValidationHelper.GetString(dr["WebPartLayoutCode"], "");

                    WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(dr["WebPartLayoutWebPartID"], 0));

                    if (wpi != null)
                    {
                        int    checkedOutByUserId    = ValidationHelper.GetInteger(dr["WebPartLayoutCheckedOutByUserID"], 0);
                        string checkedOutMachineName = ValidationHelper.GetString(dr["WebPartLayoutCheckedOutMachineName"], "");

                        if (!String.IsNullOrEmpty(webPartLayoutCode) && ((checkedOutByUserId == 0) || (checkedOutMachineName.ToLower() != HTTPHelper.MachineName.ToLower())))
                        {
                            // Get layout filename
                            string filename = WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, webPartLayoutCodeName, "");
                            // Get path to the code file
                            string codeFilePath = URLHelper.GetVirtualPath(filename) + ".cs";

                            // Get path to the original code behind file
                            string originalCodeFilePath = String.Empty;
                            if (codeFileRegex.IsMatch(webPartLayoutCode, 0))
                            {
                                originalCodeFilePath = codeFileRegex.Match(webPartLayoutCode).Result("$1");
                            }

                            // Get original class name
                            string originalClassName = String.Empty;
                            if (inheritsRegex.IsMatch(webPartLayoutCode))
                            {
                                originalClassName = inheritsRegex.Match(webPartLayoutCode).Result("$1");
                            }

                            if (codeFileRegex.IsMatch(webPartLayoutCode))
                            {
                                webPartLayoutCode = codeFileRegex.Replace(webPartLayoutCode, "CodeFile=\"" + codeFilePath + "\"");
                            }

                            if (inheritsRegex.IsMatch(webPartLayoutCode))
                            {
                                webPartLayoutCode = inheritsRegex.Replace(webPartLayoutCode, "Inherits=\"$1_Web_Deployment\"");
                            }

                            // Read original codefile and change classname
                            string codeFileCode = String.Empty;
                            if (!String.IsNullOrEmpty(originalCodeFilePath) && FileHelper.FileExists(originalCodeFilePath))
                            {
                                codeFileCode = File.ReadAllText(Server.MapPath(originalCodeFilePath));
                                codeFileCode = codeFileCode.Replace(originalClassName, originalClassName + "_Web_Deployment");

                                // Save code file
                                SiteManagerFunctions.SaveCodeFile(filename, webPartLayoutCode);

                                // Save code behind file
                                SiteManagerFunctions.SaveCodeFile(codeFilePath, codeFileCode);
                            }
                        }
                    }
                }
            }

            lblResult.Text = GetString("Deployment.ObjectsSaved");
        }
        catch (Exception ex)
        {
            CMS.EventLog.EventLogProvider ep = new CMS.EventLog.EventLogProvider();
            ep.LogEvent("System deployment", "E", ex);

            lblError.Visible = true;
            lblError.Text    = ex.Message;
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Raises the <see cref="E:PreRender"/> event.
    /// </summary>
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        bool editingEnabled = true;

        // Disable items when virtual path provider is disabled
        if (!SettingsKeyProvider.UsingVirtualPathProvider && (pti != null))
        {
            this.lblVirtualInfo.Text     = String.Format(GetString("TemplateLayout.VirtualPathProviderNotRunning"), PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null));
            this.plcVirtualInfo.Visible  = true;
            this.pnlCheckOutInfo.Visible = false;

            editingEnabled             = false;
            this.txtCustomCSS.ReadOnly = true;
            this.drpType.Enabled       = false;
        }

        string info = null;

        // Setup the information and code type
        bool isAscx = (this.drpType.SelectedValue.ToLower() == "ascx");

        if (isAscx)
        {
            txtCustom.Editor.Language = LanguageEnum.ASPNET;
            txtCustom.UseAutoComplete = false;

            info = GetString("Administration-PageLayout_New.Hint");

            // Check the edit code permission
            if (!user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                editingEnabled = false;
                info           = ResHelper.GetString("EditCode.NotAllowed");
            }
        }
        else
        {
            txtCustom.Editor.Language = LanguageEnum.HTMLMixed;
            txtCustom.UseAutoComplete = true;

            info = GetString("EditLayout.HintHtml");
        }

        this.ltlHint.Text       = info;
        this.txtCustom.ReadOnly = !editingEnabled;

        this.plcDirectives.Visible = isAscx;

        this.plcCssLink.Visible = String.IsNullOrEmpty(txtCustomCSS.Text.Trim());
        this.lnkStyles.Visible  = radCustom.Checked;
    }
Esempio n. 3
0
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        bool editingEnabled = true;

        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        // Layout save button script
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "LayoutSave", ScriptHelper.GetScript(
                                                   "function SaveDocument() { layoutChanged = true; " + this.Page.ClientScript.GetPostBackEventReference(this.btnSaveLayout, "") + "; } \n"
                                                   ));

        string tmpLayoutCode = "";
        int    tmpCheckUser  = 0;
        string tmpMachine    = "";
        string tmpFilename   = "";
        string tmpLayoutUrl  = "";
        string layoutUrl     = "";

        LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx;

        if (li != null)
        {
            tmpLayoutCode = li.LayoutCode;

            tmpCheckUser = li.LayoutCheckedOutByUserID;
            tmpMachine   = li.LayoutCheckedOutMachineName;
            tmpFilename  = li.LayoutCheckedOutFilename;
            tmpLayoutUrl = LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, null, li.LayoutType);

            layoutUrl  = tmpLayoutUrl;
            layoutType = li.LayoutType;
        }

        // Get layout information
        if ((li == null) && (pti != null))
        {
            tmpLayoutCode = pti.PageTemplateLayout;

            tmpCheckUser = pti.PageTemplateLayoutCheckedOutByUserID;
            tmpMachine   = pti.PageTemplateLayoutCheckedOutMachineName;
            tmpFilename  = pti.PageTemplateLayoutCheckedOutFileName;

            layoutUrl  = PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType);
            layoutType = pti.PageTemplateLayoutType;

            if (pti.IsReusable)
            {
                tmpLayoutUrl = PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType);
            }
            else
            {
                tmpLayoutUrl = PageTemplateInfoProvider.GetAdhocLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType);
            }
        }

        if (!RequestHelper.IsPostBack())
        {
            drpType.SelectedIndex = (layoutType == LayoutTypeEnum.Html ? 1 : 0);

            this.txtLayout.Text = tmpLayoutCode;
        }

        this.plcUndoCheckOut.Visible = false;
        this.plcCheckOut.Visible     = false;
        this.plcCheckIn.Visible      = false;

        // Check checked-out status
        if (tmpCheckUser > 0)
        {
            this.txtLayout.ReadOnly = true;

            string   username = null;
            UserInfo ui       = UserInfoProvider.GetUserInfo(tmpCheckUser);
            if (ui != null)
            {
                username = HTMLHelper.HTMLEncode(ui.FullName);
            }

            // Checked out by current machine
            if ((HttpContext.Current != null) && (tmpMachine.ToLower() == HTTPHelper.MachineName.ToLower()))
            {
                this.plcCheckIn.Visible = true;

                this.lblCheckOutInfo.Text = String.Format(ResHelper.GetString("PageLayout.CheckedOut", culture), HttpContext.Current.Server.MapPath(tmpFilename));
            }
            else
            {
                this.lblCheckOutInfo.Text = String.Format(ResHelper.GetString("PageLayout.CheckedOutOnAnotherMachine", culture), HTMLHelper.HTMLEncode(tmpMachine), HTMLHelper.HTMLEncode(username));
            }
            //this.lblCheckOutInfo.Text = String.Format(ResHelper.GetString("PageLayout.CheckedOutOnAnotherMachine"), li.LayoutCheckedOutMachineName, username);

            if (user.IsGlobalAdministrator)
            {
                this.plcUndoCheckOut.Visible = true;
            }
        }
        else
        {
            if (HttpContext.Current != null)
            {
                this.lblCheckOutInfo.Text = String.Format(ResHelper.GetString("PageLayout.CheckOutInfo", culture), HttpContext.Current.Server.MapPath(tmpLayoutUrl));
            }
            this.plcCheckOut.Visible = true;
            this.txtLayout.ReadOnly  = false;
        }

        bool isAscx = (this.drpType.SelectedValue.ToLower() == "ascx");

        this.btnSaveLayout.Visible = !isAscx || SettingsKeyProvider.UsingVirtualPathProvider;

        // Disable items when virtual path provider is disabled
        if (isAscx && !SettingsKeyProvider.UsingVirtualPathProvider && (pti != null))
        {
            this.lblVirtualInfo.Text     = String.Format(ResHelper.GetString("TemplateLayout.VirtualPathProviderNotRunning", culture), PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null));
            this.plcVirtualInfo.Visible  = true;
            this.pnlCheckOutInfo.Visible = false;

            editingEnabled = false;
        }

        string info = null;

        // Setup the information and code type
        if (isAscx)
        {
            txtLayout.Editor.Language = LanguageEnum.ASPNET;
            txtLayout.UseAutoComplete = false;

            info = ResHelper.GetString("Administration-PageLayout_New.Hint", culture);

            // Check the edit code permission
            if (!user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                editingEnabled = false;
                info           = ResHelper.GetString("EditCode.NotAllowed", culture);
            }
        }
        else
        {
            txtLayout.Editor.Language = LanguageEnum.HTMLMixed;
            txtLayout.UseAutoComplete = true;

            info = ResHelper.GetString("EditLayout.HintHtml", culture);
        }

        if (!String.IsNullOrEmpty(lblLayoutInfo.Text))
        {
            lblLayoutInfo.Text += "&nbsp;&nbsp;";
        }

        lblLayoutInfo.Text += info;

        this.lblLayoutInfo.Visible = (this.lblLayoutInfo.Text != "");

        this.txtLayout.ReadOnly = !editingEnabled;
        this.plcActions.Visible = editingEnabled;

        // Disable editor for layout or template checked out
        if (li != null)
        {
            if (li.LayoutCheckedOutByUserID > 0)
            {
                txtLayout.ReadOnly = true;
            }
        }
        else if (pti != null)
        {
            if (pti.PageTemplateLayoutCheckedOutByUserID > 0)
            {
                txtLayout.ReadOnly = true;
            }
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Reload data.
    /// </summary>
    public void ReloadData()
    {
        if (templateId > 0)
        {
            PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);

            if (pti != null)
            {
                // For ASPX, do not allow to change the layout
                if (pti.PageTemplateType == PageTemplateTypeEnum.Aspx)
                {
                    plcContent.Visible      = false;
                    pnlCheckOutInfo.Visible = false;
                    lblAspxInfo.Visible     = true;
                    lblAspxInfo.Text        = GetString("TemplateLayout.ASPXtemplate");

                    return;
                }

                this.pnlCheckOutInfo.Visible = true;

                if (pti.PageTemplateLayoutCheckedOutByUserID > 0)
                {
                    this.txtCustom.ReadOnly    = true;
                    this.txtCustomCSS.ReadOnly = true;
                    string   username = null;
                    UserInfo ui       = UserInfoProvider.GetUserInfo(pti.PageTemplateLayoutCheckedOutByUserID);
                    if (ui != null)
                    {
                        username = HTMLHelper.HTMLEncode(ui.FullName);
                    }

                    // Checked out by current machine
                    if (pti.PageTemplateLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                    {
                        this.lblCheckOutInfo.Text = String.Format(GetString("PageLayout.CheckedOut"), Server.MapPath(pti.PageTemplateLayoutCheckedOutFileName));
                    }
                    else
                    {
                        this.lblCheckOutInfo.Text = String.Format(GetString("PageLayout.CheckedOutOnAnotherMachine"), pti.PageTemplateLayoutCheckedOutFileName, username);
                    }
                }
                else
                {
                    string url = null;
                    if (pti.IsReusable)
                    {
                        url = Server.MapPath(PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType));
                    }
                    else
                    {
                        url = Server.MapPath(PageTemplateInfoProvider.GetAdhocLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType));
                    }

                    this.lblCheckOutInfo.Text = String.Format(GetString("PageLayout.CheckOutInfo"), url);
                }

                if (ValidationHelper.GetInteger(pti.LayoutID, 0) > 0)
                {
                    // Shared layout
                    pnlCheckOutInfo.Visible = false;

                    radShared.Checked = true;

                    txtCustom.ReadOnly    = true;
                    txtCustomCSS.ReadOnly = true;

                    drpType.Enabled = false;

                    selectShared.Enabled = true;

                    try
                    {
                        // Load layout content
                        selectShared.Value = pti.LayoutID.ToString();

                        LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(pti.LayoutID);
                        if (li != null)
                        {
                            txtCustom.Text    = li.LayoutCode;
                            txtCustomCSS.Text = li.LayoutCSS;

                            drpType.SelectedIndex = (li.LayoutType == LayoutTypeEnum.Html ? 1 : 0);
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    // Custom layout
                    radCustom.Checked  = true;
                    txtCustom.Text     = pti.PageTemplateLayout;
                    txtCustom.ReadOnly = false;

                    txtCustomCSS.Text     = pti.PageTemplateCSS;
                    txtCustomCSS.ReadOnly = false;

                    drpType.SelectedIndex = (pti.PageTemplateLayoutType == LayoutTypeEnum.Html ? 1 : 0);
                    drpType.Enabled       = true;
                    selectShared.Enabled  = false;
                }
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Check out layout event handler.
    /// </summary>
    protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        // Ensure version before check-out
        using (CMSActionContext context = new CMSActionContext())
        {
            context.AllowAsyncActions = false;

            // Save first
            if (!SaveLayout())
            {
                return;
            }
        }

        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            try
            {
                string         filename   = "";
                string         tmpCode    = "";
                LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx;

                if (li != null)
                {
                    filename   = LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, null, li.LayoutType);
                    layoutType = li.LayoutType;

                    tmpCode = li.LayoutCode;
                }
                else
                {
                    filename   = PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType);
                    layoutType = pti.PageTemplateLayoutType;

                    tmpCode = pti.PageTemplateLayout;
                }

                // Write the code to the file
                string fullfilename = "";
                if (HttpContext.Current != null)
                {
                    fullfilename = HttpContext.Current.Server.MapPath(filename);
                    DirectoryHelper.EnsureDiskPath(fullfilename, HttpContext.Current.Server.MapPath("~/"));
                }

                StringBuilder sb = new StringBuilder();
                if (layoutType == LayoutTypeEnum.Ascx)
                {
                    sb.Append(LayoutInfoProvider.GetLayoutDirectives());
                }
                sb.Append(tmpCode);

                string content = HTMLHelper.EnsureLineEnding(sb.ToString(), "\r\n");
                File.WriteAllText(fullfilename, content);

                // Set the layout data
                if (li != null)
                {
                    // Shared layout
                    li.LayoutCheckedOutByUserID    = user.UserID;
                    li.LayoutCheckedOutMachineName = "";
                    if (HttpContext.Current != null)
                    {
                        li.LayoutCheckedOutMachineName = HTTPHelper.MachineName;
                    }
                    li.LayoutCheckedOutFilename = filename;

                    LayoutInfoProvider.SetLayoutInfo(li);
                }
                else
                {
                    // Page template layout
                    pti.PageTemplateLayoutCheckedOutByUserID    = user.UserID;
                    pti.PageTemplateLayoutCheckedOutMachineName = "";
                    if (HttpContext.Current != null)
                    {
                        pti.PageTemplateLayoutCheckedOutMachineName = HTTPHelper.MachineName;
                    }
                    pti.PageTemplateLayoutCheckedOutFileName = filename;

                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
            }
            catch
            {
                return;
            }
        }
    }