Пример #1
0
    /// <summary>
    /// Creates new variant and raises "Add" event if specified.
    /// </summary>
    /// <param name="name">Name of new variant</param>
    /// <param name="issueId">ID of source issue on which the new variant will be based</param>
    private void RaiseOnAddEvent(string name, int issueId)
    {
        // Get main issue (original)
        int       currentIssuedId = IssueID;
        IssueInfo parentIssue     = IssueInfoProvider.GetOriginalIssue(currentIssuedId);

        // Allow modifying issues in idle state only
        if ((parentIssue == null) || (parentIssue.IssueStatus != IssueStatusEnum.Idle))
        {
            return;
        }

        // Get issue content specified by ID (if not found use original)
        IssueInfo contentIssue = null;

        if (issueId > 0)
        {
            if (issueId == parentIssue.IssueID)
            {
                contentIssue = parentIssue;
            }
            else
            {
                contentIssue = IssueInfoProvider.GetIssueInfo(issueId);
            }
        }

        NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(parentIssue.IssueNewsletterID);

        // ID of the first child (if new A/B test is being created (i.e. parent and 2 children)
        int origVariantId = 0;

        // Check if current issue is variant issue
        if (!parentIssue.IssueIsABTest)
        {
            // Variant issue has not been created yet => create original and 2 child variants
            parentIssue.IssueIsABTest = true;

            // Create 1st variant based on parent issue, the 2nd variant will be created as ordinary variant below
            IssueInfo issueOrigVariant = parentIssue.Clone(true);
            issueOrigVariant.IssueVariantOfIssueID = parentIssue.IssueID;
            issueOrigVariant.IssueVariantName      = GetString("newsletter.abvariantoriginal");
            issueOrigVariant.IssueScheduledTaskID  = 0;
            IssueInfoProvider.SetIssueInfo(issueOrigVariant);
            // Create scheduled task for variant mail-out and update issue variant
            issueOrigVariant.IssueScheduledTaskID = CreateScheduledTask(issueOrigVariant);
            IssueInfoProvider.SetIssueInfo(issueOrigVariant);
            // Update parent issue
            IssueInfoProvider.SetIssueInfo(parentIssue);
            try
            {
                ObjectVersionManager.DestroyObjectHistory(parentIssue.ObjectType, parentIssue.IssueID);
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("Newsletter-AddVariant", "EXCEPTION", ex);
            }

            origVariantId = issueOrigVariant.IssueID;
        }

        // Variant issue has been created => create new variant only
        IssueInfo issueVariant = (contentIssue != null ? contentIssue.Clone(true) : parentIssue.Clone(true));

        issueVariant.IssueVariantName      = name;
        issueVariant.IssueVariantOfIssueID = parentIssue.IssueID;

        // Prepare content with empty regions if empty content will be used
        string[] regions = null;
        if ((contentIssue == null) && (newsletter != null))
        {
            EmailTemplateInfo template = EmailTemplateInfoProvider.GetEmailTemplateInfo(newsletter.NewsletterTemplateID);
            if (template != null)
            {
                bool          isValidRegionName;
                List <string> regionNames = new List <string>();
                EmailTemplateHelper.ValidateEditableRegions(template.TemplateBody, out isValidRegionName, out isValidRegionName, regionNames);
                for (int i = regionNames.Count - 1; i >= 0; i--)
                {
                    regionNames[i] = regionNames[i] + "::";
                }
                regions = regionNames.ToArray();
                // Set template ID (i.e. this template with these regions is used for current issue)
                issueVariant.IssueTemplateID = template.TemplateID;
            }
        }

        issueVariant.IssueText            = (contentIssue != null ? contentIssue.IssueText : IssueHelper.GetContentXML(regions));
        issueVariant.IssueScheduledTaskID = 0;
        IssueInfoProvider.SetIssueInfo(issueVariant);

        // Duplicate attachments and replace old guids with new guids in issue text if current variant issue is based on content of another
        if (contentIssue != null)
        {
            List <Guid> guids = new List <Guid>();
            MetaFileInfoProvider.CopyMetaFiles(contentIssue.IssueID, issueVariant.IssueID,
                                               (contentIssue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE),
                                               ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, guids);
            if (guids.Count > 0)
            {
                for (int i = 0; i < guids.Count; i += 2)
                {
                    issueVariant.IssueText = LinkConverter.ReplaceInLink(issueVariant.IssueText, guids[i].ToString(), guids[i + 1].ToString());
                }
            }
        }

        // Create scheduled task for variant mail-out
        issueVariant.IssueScheduledTaskID = CreateScheduledTask(issueVariant);
        // Update issue variant
        IssueInfoProvider.SetIssueInfo(issueVariant);

        if (origVariantId > 0)
        {
            // New A/B test issue created => create new A/B test info
            ABTestInfo abi = new ABTestInfo
            {
                TestIssueID = parentIssue.IssueID, TestSizePercentage = 50, TestWinnerOption = ABTestWinnerSelectionEnum.OpenRate, TestSelectWinnerAfter = 60
            };
            ABTestInfoProvider.SetABTestInfo(abi);

            // Move attachments (meta files) from parent issue to first variant
            MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE);
            MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE);
        }

        if (OnAddVariant != null)
        {
            VariantEventArgs args = new VariantEventArgs(name, issueVariant.IssueID);
            OnAddVariant(this, args);
        }
    }
Пример #2
0
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWebPartName.Text        = txtWebPartName.Text.Trim();
        txtWebPartDisplayName.Text = txtWebPartDisplayName.Text.Trim();
        txtWebPartFileName.Text    = txtWebPartFileName.Text.Trim();

        // Validate the text box fields
        string errorMessage = new Validator()
                              .NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage)
                              .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage)
                              .IsCodeName(txtWebPartName.Text, GetString("WebPart_Clone.InvalidCodeName"))
                              .Result;

        // Validate file name
        if (string.IsNullOrEmpty(errorMessage) && chckCloneWebPartFiles.Checked)
        {
            errorMessage = new Validator()
                           .NotEmpty(txtWebPartFileName.Text, rfvWebPartFileName.ErrorMessage)
                           .IsFileName(Path.GetFileName(txtWebPartFileName.Text.Trim('~')), GetString("WebPart_Clone.InvalidFileName")).Result;
        }

        // Check if webpart with same name exists
        if (WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text) != null)
        {
            errorMessage = GetString(String.Format("Development-WebPart_Clone.WebPartExists", txtWebPartName.Text));
        }

        // Check if webpart is not cloned to the root category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

        if (wci.CategoryID == ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1))
        {
            errorMessage = GetString("Development-WebPart_Clone.cannotclonetoroot");
        }

        if (errorMessage != "")
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }

        // get web part info object
        WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wi == null)
        {
            lblError.Text    = GetString("WebPart_Clone.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Create new webpart with all properties from source webpart
        WebPartInfo nwpi = new WebPartInfo(wi, false);

        nwpi.WebPartID   = 0;
        nwpi.WebPartGUID = Guid.NewGuid();

        // Modify clone info
        nwpi.WebPartName        = txtWebPartName.Text;
        nwpi.WebPartDisplayName = txtWebPartDisplayName.Text;
        nwpi.WebPartCategoryID  = ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1);

        if (nwpi.WebPartParentID <= 0)
        {
            nwpi.WebPartFileName = txtWebPartFileName.Text;
        }

        string path     = String.Empty;
        string filename = String.Empty;
        string inher    = String.Empty;

        try
        {
            // Copy file if needed and webpart is not ihnerited
            if (chckCloneWebPartFiles.Checked && (wi.WebPartParentID == 0))
            {
                // Get source file path
                string srcFile = GetWebPartPhysicalPath(wi.WebPartFileName);

                // Get destination file path
                string dstFile = GetWebPartPhysicalPath(nwpi.WebPartFileName);

                // Ensure directory
                DirectoryHelper.EnsureDiskPath(Path.GetDirectoryName(DirectoryHelper.EnsurePathBackSlash(dstFile)), URLHelper.WebApplicationPhysicalPath);

                // Check if source and target file path are different
                if (File.Exists(dstFile))
                {
                    throw new Exception(GetString("general.fileexists"));
                }

                // Get file name
                filename = Path.GetFileName(dstFile);
                // Get path to the partial class name replace
                string wpPath = nwpi.WebPartFileName;

                if (!wpPath.StartsWith("~/"))
                {
                    wpPath = WebPartInfoProvider.WebPartsDirectory + "/" + wpPath.TrimStart('/');
                }
                path = Path.GetDirectoryName(wpPath);

                inher = path.Replace('\\', '_').Replace('/', '_') + "_" + Path.GetFileNameWithoutExtension(filename).Replace('.', '_');
                inher = inher.Trim('~');
                inher = inher.Trim('_');

                // Read .aspx file, replace classname and save as new file
                string text = File.ReadAllText(srcFile);
                File.WriteAllText(dstFile, ReplaceASCX(text, DirectoryHelper.CombinePath(path, filename), inher));

                // Read .aspx file, replace classname and save as new file
                if (File.Exists(srcFile + ".cs"))
                {
                    text = File.ReadAllText(srcFile + ".cs");
                    File.WriteAllText(dstFile + ".cs", ReplaceASCXCS(text, inher));
                }

                if (File.Exists(srcFile + ".vb"))
                {
                    text = File.ReadAllText(srcFile + ".vb");
                    File.WriteAllText(dstFile + ".vb", ReplaceASCXVB(text, inher));
                }

                // Copy web part subfolder
                string srcDirectory = srcFile.Remove(srcFile.Length - Path.GetFileName(srcFile).Length) + Path.GetFileNameWithoutExtension(srcFile) + "_files";
                if (Directory.Exists(srcDirectory))
                {
                    string dstDirectory = dstFile.Remove(dstFile.Length - Path.GetFileName(dstFile).Length) + Path.GetFileNameWithoutExtension(dstFile) + "_files";
                    if (srcDirectory.ToLower() != dstDirectory.ToLower())
                    {
                        DirectoryHelper.EnsureDiskPath(srcDirectory, URLHelper.WebApplicationPhysicalPath);
                        DirectoryHelper.CopyDirectory(srcDirectory, dstDirectory);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Add new web part to database
        WebPartInfoProvider.SetWebPartInfo(nwpi);

        try
        {
            // Get and duplicate all webpart layouts associated to webpart
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts(webPartId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo(dr);
                    wpli.WebPartLayoutID                    = 0;              // Create new record
                    wpli.WebPartLayoutWebPartID             = nwpi.WebPartID; // Associate layout to new webpart
                    wpli.WebPartLayoutGUID                  = Guid.NewGuid();
                    wpli.WebPartLayoutCheckedOutByUserID    = 0;
                    wpli.WebPartLayoutCheckedOutFilename    = "";
                    wpli.WebPartLayoutCheckedOutMachineName = "";

                    // Replace classname and inherits attribut
                    wpli.WebPartLayoutCode = ReplaceASCX(wpli.WebPartLayoutCode, DirectoryHelper.CombinePath(path, filename), inher);
                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                }
            }

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(webPartId, nwpi.WebPartID, PortalObjectType.WEBPART, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);
        }
        catch (Exception ex)
        {
            lblError.Text    = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Close clone window
        // Refresh web part tree and select/edit new widget
        string script      = String.Empty;
        string refreshLink = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?webpartid=" + nwpi.WebPartID + "&reload=true");

        if (QueryHelper.Contains("reloadAll"))
        {
            script += "wopener.parent.parent.frames['webparttree'].location.href ='" + refreshLink + "';";
        }
        else
        {
            script = "wopener.location = '" + refreshLink + "';";
        }
        script += "window.close();";

        ltlScript.Text = ScriptHelper.GetScript(script);
    }
Пример #3
0
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWidgetName.Text        = TextHelper.LimitLength(txtWidgetName.Text.Trim(), 100, "");
        txtWidgetDisplayName.Text = TextHelper.LimitLength(txtWidgetDisplayName.Text.Trim(), 100, "");

        // Validate the text box fields
        string errorMessage = new Validator()
                              .NotEmpty(txtWidgetName.Text, rfvWidgetName.ErrorMessage)
                              .NotEmpty(txtWidgetDisplayName.Text, rfvWidgetDisplayName.ErrorMessage)
                              .IsCodeName(txtWidgetName.Text, GetString("general.InvalidCodeName"))
                              .Result;

        // Check if widget with same name exists
        if (WidgetInfoProvider.GetWidgetInfo(txtWidgetName.Text) != null)
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (errorMessage == "")
        {
            // Clone widget info
            WidgetInfo nwi = new WidgetInfo(wi, false);

            // Modify info data
            nwi.WidgetID          = 0;
            nwi.WidgetGUID        = Guid.NewGuid();
            nwi.WidgetName        = txtWidgetName.Text;
            nwi.WidgetDisplayName = txtWidgetDisplayName.Text;
            nwi.WidgetCategoryID  = ValidationHelper.GetInteger(categorySelector.Value, 0);

            // Add new web part to database
            WidgetInfoProvider.SetWidgetInfo(nwi);

            // Clone widget security
            DataSet ds = WidgetRoleInfoProvider.GetWidgetRoles("WidgetID = " + wi.WidgetID, null, 0, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WidgetRoleInfo nwri = new WidgetRoleInfo(dr);
                    nwri.WidgetID = nwi.WidgetID;
                    WidgetRoleInfoProvider.SetWidgetRoleInfo(nwri);
                }
            }

            // Update widget category counts
            WidgetCategoryInfoProvider.UpdateCategoryWidgetChildCount(0, nwi.WidgetCategoryID);

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(wi.WidgetID, nwi.WidgetID, PortalObjectType.WIDGET, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);

            string script      = String.Empty;
            string refreshLink = URLHelper.ResolveUrl("~/CMSModules/Widgets/UI/WidgetTree.aspx?widgetid=" + nwi.WidgetID + "&reload=true");
            if (QueryHelper.GetBoolean("reloadAll", true))
            {
                // Refresh web part tree and select/edit new widget
                script = "wopener.location = '" + refreshLink + "';";
            }
            else
            {
                script += "wopener.parent.parent.frames['widgettree'].location.href ='" + refreshLink + "';";
            }
            script += "window.close();";

            ltlScript.Text = ScriptHelper.GetScript(script);
        }
        else
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
        }
    }
    /// <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 uniGrid_OnAction(string actionName, object actionArgument)
    {
        string templateId = actionArgument.ToString();

        switch (actionName.ToLower())
        {
        // Edit the template
        case "edit":
            URLHelper.Redirect("NewsletterTemplate_Edit.aspx?templateid=" + templateId);
            break;

        // Delete the template
        case "delete":
            // Check 'Manage templates' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "managetemplates"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "managetemplates");
            }

            // Check if the template is used in a newsletter
            string where = string.Format("(NewsletterTemplateID={0}) OR (NewsletterSubscriptionTemplateID={0}) OR (NewsletterUnsubscriptionTemplateID={0}) OR (NewsletterOptInTemplateID={0})", templateId);

            DataSet newsByEmailtempl = NewsletterProvider.GetNewsletters(where, null, 1, "NewsletterID");
            if (DataHelper.DataSourceIsEmpty(newsByEmailtempl))
            {
                // Check if the template is used in an issue
                DataSet newsletterIssues = IssueProvider.GetIssues("IssueTemplateID = " + templateId, null, 1, "IssueID");
                if (DataHelper.DataSourceIsEmpty(newsletterIssues))
                {
                    // Delete EmailTemplate object from database
                    EmailTemplateProvider.DeleteEmailTemplate(ValidationHelper.GetInteger(templateId, 0));
                }
                else
                {
                    ShowError(GetString("NewsletterTemplate_List.TemplateInUseByNewsletterIssue"));
                }
            }
            else
            {
                ShowError(GetString("NewsletterTemplate_List.TemplateInUseByNewsletter"));
            }
            break;

        // Clone the template
        case "clone":
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.newsletter", "managetemplates"))
            {
                RedirectToCMSDeskAccessDenied("cms.newsletter", "managetemplates");
            }

            int           tmpId = ValidationHelper.GetInteger(templateId, 0);
            EmailTemplate oldet = EmailTemplateProvider.GetEmailTemplate(tmpId);
            if (oldet != null)
            {
                EmailTemplate et = new EmailTemplate();
                et.TemplateBody           = oldet.TemplateBody;
                et.TemplateDisplayName    = oldet.TemplateDisplayName;
                et.TemplateSubject        = oldet.TemplateSubject;
                et.TemplateFooter         = oldet.TemplateFooter;
                et.TemplateHeader         = oldet.TemplateHeader;
                et.TemplateID             = 0;
                et.TemplateName           = oldet.TemplateName;
                et.TemplateSiteID         = oldet.TemplateSiteID;
                et.TemplateStylesheetText = oldet.TemplateStylesheetText;
                et.TemplateType           = oldet.TemplateType;

                string templateName        = et.TemplateName;
                string templateDisplayName = et.TemplateDisplayName;

                while (EmailTemplateProvider.GetEmailTemplate(templateName, et.TemplateSiteID) != null)
                {
                    templateName        = Increment(templateName, "_", "");
                    templateDisplayName = Increment(templateDisplayName, "(", ")");
                }

                et.TemplateName        = templateName;
                et.TemplateDisplayName = templateDisplayName;

                // Get new ID
                using (CMSActionContext context = new CMSActionContext())
                {
                    // Disable versioning to prevent creating new version on first set
                    context.CreateVersion = false;

                    EmailTemplateProvider.SetEmailTemplate(et);
                }

                List <Guid> convTable = new List <Guid>();

                try
                {
                    MetaFileInfoProvider.CopyMetaFiles(tmpId, et.TemplateID, NewsletterObjectType.NEWSLETTERTEMPLATE, MetaFileInfoProvider.OBJECT_CATEGORY_TEMPLATE, convTable);
                }
                catch (Exception e)
                {
                    ShowError(e.Message);
                    EmailTemplateProvider.DeleteEmailTemplate(et);
                    return;
                }

                for (int i = 0; i < convTable.Count; i += 2)
                {
                    et.TemplateBody = et.TemplateBody.Replace(convTable[i].ToString(), convTable[i + 1].ToString());
                }

                EmailTemplateProvider.SetEmailTemplate(et);
            }
            break;
        }
    }
Пример #5
0
    /// <summary>
    /// Clones the given report (including attachment files).
    /// </summary>
    /// <param name="reportId">Report id</param>
    protected void Clone(int reportId)
    {
        // Check 'Modify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.reporting", "Modify"))
        {
            RedirectToAccessDenied("cms.reporting", "Modify");
        }

        // Try to get report info
        ReportInfo oldri = ReportInfoProvider.GetReportInfo(reportId);

        if (oldri == null)
        {
            return;
        }

        DataSet graph_ds = ReportGraphInfoProvider.GetGraphs(reportId);
        DataSet table_ds = ReportTableInfoProvider.GetTables(reportId);
        DataSet value_ds = ReportValueInfoProvider.GetValues(reportId);

        // Duplicate report info object
        ReportInfo ri = new ReportInfo(oldri, false);

        ri.ReportID   = 0;
        ri.ReportGUID = Guid.NewGuid();

        // Duplicate report info
        string reportName    = ri.ReportName;
        string oldReportName = ri.ReportName;

        string reportDispName = ri.ReportDisplayName;

        while (ReportInfoProvider.GetReportInfo(reportName) != null)
        {
            reportName     = Increment(reportName, "_", "", 100);
            reportDispName = Increment(reportDispName, "(", ")", 450);
        }

        ri.ReportName        = reportName;
        ri.ReportDisplayName = reportDispName;

        // Used to eliminate version from create object task
        using (CMSActionContext context = new CMSActionContext())
        {
            context.CreateVersion = false;
            ReportInfoProvider.SetReportInfo(ri);
        }

        string name;

        // Duplicate graph data
        if (!DataHelper.DataSourceIsEmpty(graph_ds))
        {
            foreach (DataRow dr in graph_ds.Tables[0].Rows)
            {
                // Duplicate the graph
                ReportGraphInfo rgi = new ReportGraphInfo(dr);
                rgi.GraphID       = 0;
                rgi.GraphGUID     = Guid.NewGuid();
                rgi.GraphReportID = ri.ReportID;
                name = rgi.GraphName;

                // Replace layout based on HTML or regular graph type
                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, rgi.GraphIsHtml ? REP_HTMLGRAPH_MACRO : REP_GRAPH_MACRO, rgi.GraphName, name, oldReportName, reportName);
                rgi.GraphName   = name;

                ReportGraphInfoProvider.SetReportGraphInfo(rgi);
            }
        }

        // Duplicate table data
        if (!DataHelper.DataSourceIsEmpty(table_ds))
        {
            foreach (DataRow dr in table_ds.Tables[0].Rows)
            {
                // Duplicate the table
                ReportTableInfo rti = new ReportTableInfo(dr);
                rti.TableID       = 0;
                rti.TableGUID     = Guid.NewGuid();
                rti.TableReportID = ri.ReportID;
                name = rti.TableName;

                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_TABLE_MACRO, rti.TableName, name, oldReportName, reportName);
                rti.TableName   = name;

                ReportTableInfoProvider.SetReportTableInfo(rti);
            }
        }

        // Duplicate value data
        if (!DataHelper.DataSourceIsEmpty(value_ds))
        {
            foreach (DataRow dr in value_ds.Tables[0].Rows)
            {
                // Duplicate the value
                ReportValueInfo rvi = new ReportValueInfo(dr);
                rvi.ValueID       = 0;
                rvi.ValueGUID     = Guid.NewGuid();
                rvi.ValueReportID = ri.ReportID;
                name = rvi.ValueName;

                ri.ReportLayout = ReplaceMacro(ri.ReportLayout, REP_VALUE_MACRO, rvi.ValueName, name, oldReportName, reportName);
                rvi.ValueName   = name;

                ReportValueInfoProvider.SetReportValueInfo(rvi);
            }
        }

        List <Guid> convTable = new List <Guid>();

        try
        {
            MetaFileInfoProvider.CopyMetaFiles(reportId, ri.ReportID, ReportingObjectType.REPORT, MetaFileInfoProvider.OBJECT_CATEGORY_LAYOUT, convTable);
        }
        catch (Exception e)
        {
            lblError.Visible = true;
            lblError.Text    = e.Message;
            ReportInfoProvider.DeleteReportInfo(ri);
            return;
        }

        for (int i = 0; i < convTable.Count; i += 2)
        {
            Guid oldGuid = convTable[i];
            Guid newGuid = convTable[i + 1];
            ri.ReportLayout = ri.ReportLayout.Replace(oldGuid.ToString(), newGuid.ToString());
        }

        ReportInfoProvider.SetReportInfo(ri);

        // Refresh tree
        ltlScript.Text += "<script type=\"text/javascript\">";
        ltlScript.Text += @"if (parent.frames['reportcategorytree'])
                                {
                                    parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"';
                                }    
                                if (parent.parent.frames['reportcategorytree'])
                                {
                                    parent.parent.frames['reportcategorytree'].location.href = 'ReportCategory_tree.aspx?reportid=" + ri.ReportID + @"';
                                }                           
                 this.location.href = 'Report_Edit.aspx?reportId=" + Convert.ToString(ri.ReportID) + @"&saved=1&categoryID=" + categoryId + @"'
                </script>";
    }