【问题标题】:How to revert the changes in text file, if "Save & Close" on a page is not clicked?如果未单击页面上的“保存并关闭”,如何恢复文本文件中的更改?
【发布时间】:2012-07-26 15:24:21
【问题描述】:

我正在使用这个 java 脚本将页面 id 组件 id 和模板 id 作为查询字符串传递给 aspx 页面:

var masterTabControl = $controls.getControl($("#MasterTabControl"),
                                            "Tridion.Controls.TabControl");
p.compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
p.selectedComponentPresentation = p.compPresTab.getSelectedComponentPresentation();

p.selectedComp = p.selectedComponentPresentation.getComponentId();

window.open("http://" + location.hostname + ":path/test.aspx?pgId=" + pageId + 
            "&comId=" + p.selectedComponentPresentation.getComponentId() + 
            "&comTmpId=" + 
            p.selectedComponentPresentation.getComponentTemplateId(), 
            "myWindow", "status = 1, 
            toolbar=no,width=300,height=200,resizable=no,scrollbars=yes");

现在在 test.aspx 页面上,我正在读取 id 并使用用户提供的一些附加信息将其保存到文本文件中。

在一个按钮上单击弹出 test.aspx 页面,我将其保存在文本文件中:

sLogDetails = PageId + "| " + ComponentId + "|" + ComponentTemplateId + 
              "|" + text ;

//Move the contents to the temp file other than the existing one.
using (var sr = new StreamReader(permanentFile))
{
    using (var sw = new StreamWriter(@"" + tempFile , true))
    {
        string line;

        while ((line = sr.ReadLine()) != null)
        {
            string[] parts = line.Split('|');
            PageId = parts[0].Trim();
            ComponentId = parts[1].Trim();
            ComponentTemplateId = parts[2].Trim();

            //Check there exist same record already 
            if (SPageId != PageId.Trim() || SComponentId != ComponentId.Trim() 
                || SComponentTemplateId != ComponentTemplateId.Trim())
                sw.WriteLine(line);
        }

        //Delete the Permanent file & create permanent file from temporary file
        File.Delete(permanentFile);
        File.Move(tempFile, permanentFile);


        // Insert changes to the Permanent file
        using (StreamWriter w = File.AppendText(permanentFile))
        {
            // Close the writer and underlying file.
            w.WriteLine(sLogDetails);
            w.Flush();
            w.Close();
        }

如果 id 已经存在于文本文件中,那么我将其填充到弹出 test.aspx 页面上的文本字段中,例如:

using (StreamReader r = File.OpenText(strPath + "Log.txt"))
{
    string line;

    while ((line = r.ReadLine()) != null)
    {
        // Console.WriteLine(line);
        string[] parts = line.Split('|');
        PageId=parts[0].Trim();
        ComponentId = parts[1].Trim();
        ComponentTemplateId = parts[2].Trim();

        //If there exist a record populate the data fields
       if (SPageId == PageId.Trim() && SComponentId == ComponentId.Trim() 
           && SComponentTemplateId == ComponentTemplateId.Trim())
        {
            txtRuleName.Text = (string)parts[3];
        }

    }
    r.Close();
}

现在我被困在这里了。当它填充在文本字段中时,用户可以在弹出的 test.aspx 页面中编辑文本区域,单击“确定”将保存在文本文件中。如果用户在没有“保存并关闭”的情况下关闭页面窗口,那么他在文本字段中所做的更改不应保存在文本文件中。它应该恢复到旧版本。

知道怎么做吗?

【问题讨论】:

  • 我重新缩进了您的代码块,并将它们分别标记为 JavaScript 和 C#。请检查我所做的更改。如果您同意他们的观点,请声明您下次不要自己做这些事情。
  • 谢谢Puff..我会从下次开始处理这个

标签: tridion tridion-2011


【解决方案1】:

对“没有发生的事情”做出回应是相当困难的。

那么有什么方法可以创建一个用户可以退出该窗口的其他方式的列表?使用该列表,您可以注册相关的事件处理程序(或覆盖相关命令)并在那里实现您的回滚。

或者,您可以考虑从弹出窗口中对临时位置的文件进行更改。然后仅在用户单击“保存并关闭”时将其提交到您的文本文件。


请注意,当您横向扩展 Tridion GUI 和 Content Manager 以在多台机器上运行时,他的基于文件的方法将开始失败。通常,当您在使用企业级软件时,您应该警惕将内容存储在服务器上的文件中。现在的单服务器(并且在您的开发环境中将始终是单服务器)将在未来某个时间变成多服务器,届时您的解决方案将导致问题。

【讨论】:

  • 当我打字时,那个似乎也更可行。我认为 Jaime 在某处发布了有关如何扩展现有命令的信息,因此请看一下。您的其余逻辑应该不受此更改的影响。
  • 你当然坦率..我会看起来..谢谢...如果我遇到任何问题我会回来...
猜你喜欢
  • 1970-01-01
  • 2016-12-31
  • 2020-06-29
  • 1970-01-01
  • 2012-03-18
  • 2015-03-24
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多