예제 #1
0
    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;
        }
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        // Disable items when virtual path provider is disabled
        if (!SettingsKeyProvider.UsingVirtualPathProvider && (wpli != null) && (wpi != null))
        {
            lblVirtualInfo.Text     = String.Format(GetString("WebPartLayout.VirtualPathProviderNotRunning"), WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null));
            plcVirtualInfo.Visible  = true;
            pnlCheckOutInfo.Visible = false;
            etaCode.Enabled         = false;
            tbCSS.Enabled           = false;
        }
    }
    /// <summary>
    /// Loads data of edited layout from DB into TextBoxes.
    /// </summary>
    protected void LoadData()
    {
        // Initialize default flag values
        bool displayCheckIn      = false;
        bool displayUndoCheckOut = false;
        bool displayCheckOut     = false;

        if (wpli != null)
        {
            pnlCheckOutInfo.Visible = true;

            string codeNameOnly = wpli.WebPartLayoutCodeName;
            int    pos          = codeNameOnly.IndexOf('.');
            if (pos >= 0)
            {
                codeNameOnly = codeNameOnly.Substring(pos + 1, codeNameOnly.Length - pos - 1);
            }

            if (!RequestHelper.IsPostBack())
            {
                txtDisplayName.Text = wpli.WebPartLayoutDisplayName;
                txtCodeName.Text    = codeNameOnly;
                txtDescription.Text = wpli.WebPartLayoutDescription;
                etaCode.Text        = wpli.WebPartLayoutCode;
                tbCSS.Text          = wpli.WebPartLayoutCSS;
            }

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.Enabled = false;
                tbCSS.Enabled   = false;

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

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    displayCheckIn = true;

                    lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    displayUndoCheckOut = true;
                }
            }
            else if (wpi != null)
            {
                lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

                displayCheckOut = true;
            }
        }
        else
        {
            lblError.Text    = GetString("WebPartEditLayoutEdit.InvalidLayoutID");
            lblError.Visible = true;
        }

        InitializeMasterPage(displayCheckIn, displayCheckOut, displayUndoCheckOut);

        if (QueryHelper.GetInteger("saved", 0) == 1)
        {
            lblInfo.Text    = GetString("general.changessaved");
            lblInfo.Visible = true;

            // Reload header if changes were saved
            ScriptHelper.RefreshTabHeader(Page, null);
        }
    }
예제 #4
0
    /// <summary>
    /// Sets check out/in/undo panel
    /// </summary>
    protected void SetCheckPanel(WebPartLayoutInfo mwpli)
    {
        WebPartInfo       wpi  = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
        WebPartLayoutInfo wpli = mwpli;

        if (wpi != null)
        {
            if (wpli == null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
            }
        }

        if (wpli != null)
        {
            this.pnlCheckOutInfo.Visible = true;

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.ReadOnly = true;
                etaCSS.ReadOnly  = true;

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

                plcCheckOut.Visible = false;

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    this.plcCheckIn.Visible = true;

                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    this.plcUndoCheckOut.Visible = true;
                }
            }
            else
            {
                wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
                if (wpi != null)
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

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