English 中文(简体)
书写Xml文档——多种用户需要的模式
原标题:write xml file - pattern for multiple users needed
  • 时间:2011-03-04 11:24:43
  •  标签:
  • c#
  • xml

My web site writes to XML files.
This is an example of the write to: a task xml .

/// <summary>
/// The name of the xml file containing the tasks data.
/// </summary>
private string tasksFile;

/// <summary>
/// The Xml Document that stores the contents of the tasks
/// xml file in memory once loaded.
/// </summary>
private XDocument tasksXml;

........

/// <summary>
/// Writes the xml task file to the disk
/// </summary>
private void SaveTask()
{
    this.tasksXml.Save(this.tasksFile);
}

<代码>tasXml>载荷,然后处理,然后使用<代码>Save方法予以节省。

由于不止一名用户可以同时试图在档案中书写,因此用户A可能会超越用户B所做的改动。

Edit: Trying to avoid User A opens, user B opens, both edit, then both save their changes (so only one wins)

  • A. How do I ensure that multiple users do not overwrite each other s work?

  • B. Would the term singleton be correct - if so how is it implemented?

最佳回答

我发现的唯一选择与我如何认为应该做的工作一致,在以下网站作了解释:link on SO。 它使用临时档案表明XML档案是否“锁定”。

问题回答

Hum,

I cheat, my xml 载有一个日期,并锁定了点名。 为了避免僵局和过度使用这些因素。 如果它被锁定,它就会回到“仅仅”的位置。 所有ed都有使用日邮票。 有许多缺陷,其中至少是ed在记录上,不能落到实地。

现在对我的申请作了解释。 这是一个管理办公室出勤的制度。 它监测所有电梯活动门,记录 s。 这是一种低纬度和活跃的习俗解决办法。 因此,在运作过程中,僵局并不严重。 超过99%的数据完整性是一种奖金。 因此,它在这些参数范围内运作良好。 如果要吸引更多的交易压力,则可能需要一个作为交通工具的子系统。

这对我来说都是如此:

单一州只是想要存在一个目标。 在这种情况下,你只想一个用户在某一时间可以查阅的物体。

B是否希望确保它获得A在开始处理之前所写的最新信息?

事实是,你不需要不断阅读和向档案系统撰写这份文件。 如果你们想要确保用户能够查阅,那么,答案可能是你的答复,你可以制造一个单一吨标语,保持记忆中XML的提及,并为其提供查阅机会(视需要作书面发言)。

A singleton is an easy pattern; you make the constructor private and create a "getter" that returns a reference to it. There s a good description here: http://www.dofactory.com/Patterns/PatternSingleton.aspx

My suggestion is that you create a class whose responsibility is to control access to the files. You don t make this a singleton, because you need an instance for each file your application edits. It would keep a reference to the file and a Queue of update requests. You then create a singleton "library" which keeps a collection of these document objects. You need that, because without it you could instantiate two instances pointing to the same file. The application interacts only with the library, not with the file access objects. The application tells the library what content it wants to put in what file. The library looks for an instance handling that file, and if it doesn t exist, the library creates it. Then it adds the request into the queue for that object, where it will come up in FIFO order.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签