简体   繁体   English

如何同时由多个用户更新.xsl文件?

[英]How to update .xsl file by multiple users at the same time?

I am working on an application on an aplication in which multiple users update a xsl during their processing.This file is placed on a folder on server where web application is deployed. 我正在开发一个应用程序,其中多个用户在处理过程中会更新xsl。此文件位于部署了Web应用程序的服务器上的文件夹中。

Following code is used to update the xsl file. 以下代码用于更新xsl文件。

XmlDocument doc = new XmlDocument();
doc.Load(ConfigurationManager.AppSettings["XSLPdfDimensions"]);
XmlNode root = doc.DocumentElement;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");

root.SelectSingleNode(marginTop, nsmgr).Attributes["select"].Value = Convert.ToString(top);
root.SelectSingleNode(marginBottom, nsmgr).Attributes["select"].Value = Convert.ToString(bottom);

doc.Save(ConfigurationManager.AppSettings["XSLPdfDimensions"]);

When users access this file concurrently following exception occurs 当用户同时访问此文件时,发生以下异常

"The process cannot access the file 'C:\XSL\Dimensions.xsl'because it is being used by another process"

How to resolve this issue by minimum delay in functionality or there is some alternative approach for updating xsl file ? 如何以最小的功能延迟解决此问题,或者有其他替代方法来更新xsl文件?

or there is some alternative approach for updating xsl file ? 还是有一些替代方法来更新xsl文件?

Why not pass in the marginTop and marginBottom through code as parameters. 为什么不通过代码将marginTop和marginBottom作为参数传递。 That way you have one XSL, no modifications are required and all users get what they want. 这样,您就可以拥有一个XSL,无需进行任何修改,所有用户都可以得到他们想要的东西。

Or modify the XML to pass in those values and rewrite the XSL to use those values from the XML. 或修改XML以传递这些值,然后重写XSL以使用XML中的那些值。 There should be no reason for user modification of the XSL in a well designed system. 在设计良好的系统中,用户无需修改XSL。 Either the XML or a parameter passed to the transformation can handle that variable information. XML或传递给转换的参数都可以处理该变量信息。

Since I see you are trying to pass PDF dimensions, you should look at the code here at http://www.cloudformatter.com/CSS2Pdf.APIDoc.Usage . 由于我看到您正在尝试传递PDF尺寸,因此您应该在http://www.cloudformatter.com/CSS2Pdf.APIDoc.Usage查看代码。 If you look into that code you can get to the XSL behind that conversion. 如果您查看该代码,则可以找到该转换背后的XSL。 All of the appropriate page dimensions -- page size, all margins and many, many more things are all passed into that XSL from the XML (derived from the HTML div and/or specified in the Javascript and attached to the XML sent to the XSL). 所有适当的页面尺寸-页面大小,所有页边距以及很多很多东西都已从XML传递到该XSL(派生自HTML div和/或在Javascript中指定,并附加到发送给XSL的XML上) )。

There is no need for anyone to edit that XSL to get all kinds of things -- page sizes, margins, background images, page borders, page background colors, etc. 无需任何人来编辑XSL即可获得各种内容-页面大小,边距,背景图像,页面边框,页面背景颜色等。

I would guess that you see this error when two or more users try to call doc.Save method. 我猜您将在两个或多个用户尝试调用doc.Save方法时看到此错误。 When one user starts writing to a file, operating system locks it preventing others from changing at same time. 当一个用户开始写入文件时,操作系统将其锁定,以防止其他用户同时更改。 You might need to use it inside lock - them you'll make sure that only one thread would attempt to write to it at the same moment of time. 您可能需要在内部使用它-它们将确保只有一个线程会在同一时间尝试对其进行写入。

Another option is to redesign your application to avoid concurrently writing to a file system - it's a risky business exactly because of the concurrency issues. 另一种选择是重新设计应用程序,以避免同时写入文件系统-正是由于并发性问题,这是一项冒险的业务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM