public ServicesConfiguration Clone()
        {
            ServicesConfiguration configuration = new ServicesConfiguration();

            //
            // 序列化信息
            //

            StringBuilder outString = new StringBuilder();

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(outString, xmlWriterSettings))
            {
                // WriteXml(writer);
                writer.Flush();

                writer.Close();
            }

            //
            // 赋值
            //

            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.CloseInput = true;

            using (StringReader sr = new StringReader(outString.ToString()))
            {
                using (XmlReader reader = XmlReader.Create(sr, xmlReaderSettings))
                {
                    // configuration.ReadXml(reader);
                    reader.Close();
                }

                sr.Close();
            }

            return(configuration);
        }
示例#2
0
        /// <summary>加载配置信息</summary>
        private void Load(string path)
        {
            if (File.Exists(path))
            {
                ServicesConfiguration configuration = new ServicesConfiguration();

                using (XmlTextReader reader = new XmlTextReader(path))
                {
                    XmlDocument doc = new XmlDocument();

                    doc.Load(reader);

                    // 加载集合:Keys
                    XmlNodeList nodes = doc.SelectNodes(string.Format(@"configuration/{0}/keys/add", ServicesConfiguration.SectionName));

                    foreach (XmlNode node in nodes)
                    {
                        configuration.Keys.Add(new NameValueConfigurationElement(node.Attributes["name"].Value, node.Attributes["value"].Value));
                    }

                    // 加载集合:SpecialWords
                    nodes = doc.SelectNodes(string.Format(@"configuration/{0}/services/add", ServicesConfiguration.SectionName));

                    foreach (XmlNode node in nodes)
                    {
                        configuration.Services.Add(new NameTypeConfigurationElement(node.Attributes["name"].Value, node.Attributes["type"].Value));
                    }

                    // 加载集合:SpecialWords
                    nodes = doc.SelectNodes(string.Format(@"configuration/{0}/observers/add", ServicesConfiguration.SectionName));

                    foreach (XmlNode node in nodes)
                    {
                        configuration.Observers.Add(new ServiceObserverConfigurationElement(node.Attributes["name"].Value, node.Attributes["type"].Value, node.Attributes["args"].Value, node.Attributes["nextRunTime"].Value));
                    }

                    reader.Close();
                }

                this.configuration = configuration;
            }
        }