[已解决]重新加载?启动时的XML资源文件 [英] [Solved] Reload? XML resource file at startup

查看:265
本文介绍了[已解决]重新加载?启动时的XML资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要一些建议...

我有一个带有XML资源文件的WPF C#程序,其中有一些按钮的文本,例如语言文件(我们称其为language.xml),还有2个xml,例如english.xml和spanish.xml. .
我有XmlDataProvider指向language.xml
在启动时,我会在数据库中查找使用哪种语言配置用户,然后用english.xml或spanish.xml中的内容覆盖language.xml

有时程序会正确加载,但是大多数时候它会加载错误的数据,尽管您查看language.xml并且数据是正确的.
(当我说错数据时,我的意思是加载程序并与一个使用某种语言设置的用户一起进入,然后关闭,然后与另一个使用另一种语言的用户一起进入...).

有点令人困惑,但我希望有人尝试过这种方法...

先感谢您. :)

更新:
OP解决了该问题-将其作为答案发布.

Hello, I seek a little bit of advice...

I have an WPF C# program with an XML resource file in which I have text for some buttons, like a language file (let''s call it language.xml), and 2 xml more, for example english.xml and spanish.xml.
I have the XmlDataProvider pointing to language.xml
At startup I seek in a database which language has the user in his/her configuration, and I overwrite language.xml with the content in english.xml or spanish.xml

Sometimes the program loads right, but most of the time it loads the wrong data, although you look in the language.xml and the data is right.
(When I say wrong data I mean loading the program and entering with one user with a language set, closing, and entering with another one with other language...).

It''s a little bit confusing, but I hope someone have tried something like this...

Thank you in advance. :)

UPDATE:
OP resolved it - posted that as an answer.

推荐答案

我怀疑文件系统在报告文件操作实际上已经完成之前就报告了,那么您就可以了"重新请求文件的速度如此之快,以至于它没有获得新版本(它是从缓存或其他内容中提取的).

有两种方法可以解决此问题.

由于您沿着这条路走得足够远,因此我可能建议您在第一种方法中做两件事.
1)在覆盖内容之前检查(并存储)文件的最后修改日期.
2)覆盖内容后,请等待,直到上次修改日期被报告为与原始捕获日期相比有所更改.

另一种方法是使用.NET内置的全球化支持,但是如果您已经构建了自己的版本,那将需要大量的工作.

干杯.
I suspect that the file system is reporting that the file operation is complete before it actually is, then you''re requesting the file so quickly that it doesn''t get the new version (it''s pulling from cache or something).

There are two ways to fix this.

Since you are far enough along this path, I would likely suggest doing two things in the first approach.
1) Check (and store) the last mod date of the file prior to overwriting the contents.
2) After you overwrite the contents, wait until the last mod date is reported as changed from what you originally captured.

The other approach would be to use .NET''s built in globalization support, but that would take a lot of work if you''ve already built out your own version.

Cheers.


好,知道了.我必须在Loaded方法中重新加载XmlDataProvider.
另外,看到必须重新加载XmlDataProvider本身,我将其设置为直接指向正确的.xml文件. :)
Ok, got it. I had to reload the XmlDataProvider in the Loaded method.
In addition, seeing that I had to reload the XmlDataProvider itself, I set it to point directly to the correct .xml file. :)


这篇关于[已解决]重新加载?启动时的XML资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆