Exemple #1
0
        public void Save()
        {
            if (File.Exists(DefaultFile))
            {
                File.Delete(DefaultFile);
            }

            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
            using (XmlWriter writer = XmlWriter.Create(DefaultFile))
            {
                xml.Writer = writer;
                xml.WriteObject(this, typeof(XConfig), null);
            }
        }
Exemple #2
0
        public void Save()
        {
            if (!String.IsNullOrEmpty(HeadTemplate))
            {
                HeadTemplate = HeadTemplate.Replace("\n", Environment.NewLine);
            }

            if (File.Exists(DefaultFile))
            {
                File.Delete(DefaultFile);
            }

            //XmlSerializer xml = new XmlSerializer(typeof(XConfig));
            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();

            using (XmlWriter writer = XmlWriter.Create(DefaultFile))
            {
                xml.Writer = writer;
                xml.WriteObject(this, typeof(XConfig), null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 启动Xml序列化到磁盘的进程
        /// </summary>
        private static void StartXmlWriterThread()
        {
            Thread thread = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(3000);

                    if (s_needWriteToDisk) // 如果需要序列化
                    {
                        try
                        {
                            if (File.Exists(s_xmlFilePath))
                            {
                                File.Delete(s_xmlFilePath);
                            }

                            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
                            using (XmlWriter writer = XmlWriter.Create(s_xmlFilePath))
                            {
                                xml.Writer = writer;
                                xml.WriteObject(s_dictAssemblyType, typeof(Dictionary <String, AssemblyType>), null);
                            }
                            s_needWriteToDisk = false;

                            XTrace.WriteLine("已将代理程序集和端口类列表序列化到磁盘上AssemblyType.xml。");
                        }
                        catch (Exception ex)
                        {
                            XTrace.WriteException(ex);
                        }
                    }
                }
            });

            thread.Start();
        }
Exemple #4
0
        public void Save()
        {
            if (File.Exists(DefaultFile)) File.Delete(DefaultFile);

            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
            using (XmlWriter writer = XmlWriter.Create(DefaultFile))
            {
                xml.Writer = writer;
                xml.WriteObject(this, typeof(XConfig), null);
            }
        }
Exemple #5
0
        public void Save()
        {
            if (!String.IsNullOrEmpty(HeadTemplate)) HeadTemplate = HeadTemplate.Replace("\n", Environment.NewLine);

            if (File.Exists(DefaultFile)) File.Delete(DefaultFile);

            //XmlSerializer xml = new XmlSerializer(typeof(XConfig));
            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();

            using (XmlWriter writer = XmlWriter.Create(DefaultFile))
            {
                xml.Writer = writer;
                xml.WriteObject(this, typeof(XConfig), null);
            }
        }
Exemple #6
0
        /// <summary>
        /// 启动Xml序列化到磁盘的进程
        /// </summary>
        private static void StartXmlWriterThread()
        {
            Thread thread = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(3000);

                    if (s_needWriteToDisk) // 如果需要序列化
                    {
                        try
                        {
                            if (File.Exists(s_xmlFilePath)) File.Delete(s_xmlFilePath);

                            NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
                            using (XmlWriter writer = XmlWriter.Create(s_xmlFilePath))
                            {
                                xml.Writer = writer;
                                xml.WriteObject(s_dictAssemblyType, typeof(Dictionary<String, AssemblyType>), null);
                            }
                            s_needWriteToDisk = false;

                            XTrace.WriteLine("已将代理程序集和端口类列表序列化到磁盘上AssemblyType.xml。");
                        }
                        catch (Exception ex)
                        {
                            XTrace.WriteException(ex);
                        }
                    }
                }
            });
            thread.Start();
        }
Exemple #7
0
 public static void SaveRules(RuleInfo[] ruleList, string fileName)
 {
     //保存规则
     if (File.Exists(fileName)) File.Delete(fileName);
     NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
     //写入格式控制
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.Indent = true;
     settings.OmitXmlDeclaration = true;
     settings.NewLineOnAttributes = true;
     using (XmlWriter writer = XmlWriter.Create(fileName,settings ))
     {                 
         xml.Writer = writer;
         xml.WriteObject(ruleList, typeof(RuleInfo[]), null);
     }
 }
Exemple #8
0
 /// <summary>
 /// 保存配置信息
 /// </summary>
 public void Save()
 {
     if (File.Exists(DefaultXmlFileName)) File.Delete(DefaultXmlFileName);           
     NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX();
     using (XmlWriter writer = XmlWriter.Create(DefaultXmlFileName))
     {
         xml.Writer = writer;
         Dictionary<string, string> dic = ReadFromDgv();
         ConfigDictionary temp = new ConfigDictionary();
         temp.Items = dic;
         xml.WriteObject(temp , typeof(ConfigDictionary ), null);
     }
 }