zoukankan      html  css  js  c++  java
  • XML操作

    string filename = System.Windows.Forms.Application.ExecutablePath + ".config";
                    XmlDocument doc = new XmlDocument();
                    doc.Load(filename);
    
                    XmlElement element = doc.SelectSingleNode("//appSettings/add[@key='Lang']") as XmlElement;
                    if (element == null)
                    {
                        var appElement = doc.SelectSingleNode("//appSettings");
                        if (appElement == null)
                        {
                            appElement = doc.CreateElement("appSettings");
                            doc.SelectSingleNode("/configuration").AppendChild(appElement);
                        }
    
                        element = doc.CreateElement("add");
                        var key = doc.CreateAttribute("key");
                        key.Value = "Lang";
    
                        var value = doc.CreateAttribute("value");
                        element.AppendChild(key);
                        element.AppendChild(value);
                        appElement.AppendChild(element);
                    }
                    element.GetAttributeNode("value").Value = CurrentLang.CultureInfo.Name;
                    doc.Save(filename);
    
     var configDir = new DirectoryInfo("./Config/Language/ServiceUri");
                FileInfo[] configFiles = configDir.Exists ? configDir.GetFiles() : new FileInfo[0];
    
                FileInfo item = null;
    
                if (languageName == "中文")
                {
                    item = configFiles.FirstOrDefault(f => System.IO.Path.GetFileNameWithoutExtension(f.Name) == "serviceuri_zh");
                }
                else
                {
                    item = configFiles.FirstOrDefault(f => System.IO.Path.GetFileNameWithoutExtension(f.Name) == "serviceuri_us");
                }
    
                if (item != null)
                {
                    var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName + ".config");
                    File.Copy(item.FullName, fileName, true);
                    ConfigurationManager.RefreshSection("system.serviceModel");
                    ConfigurationManager.RefreshSection("appSettings");
                }
    
  • 相关阅读:
    获取其他线程的数据用 queue, 多进程Q
    self: 限制并发量asyncio
    asyncio 中给running 的loop 动态添加 Future Task
    雾里看花之 Python Asyncio
    python协程之动态添加任务
    异步IO( asyncio) 协程
    加快phpstorm、rubymine、pycharm系列IDE运行速度的方法
    scrapy 'fcntl' has no attribute 'F_GETFD
    sitemap index
    Django模板系统 运算
  • 原文地址:https://www.cnblogs.com/wywnet/p/4790706.html
Copyright © 2011-2022 走看看