コード例 #1
1
        public void CreateDumpFile()
        {            
            try
            {
                System.Xml.Linq.XDocument doc = new System.Xml.Linq.XDocument();
                System.Xml.Linq.XElement xel = new System.Xml.Linq.XElement("DumpList");

                foreach (var item in EquipmentManagerInstance.EquipmentList)
                {
                    var list = new List<object>();
                    var xml = Utility.UtilityClass.ObjectToXml(item.Value);
                    if (xml != null)
                    {
                        var equipXml = new System.Xml.Linq.XElement("Equipment");
                        var name = new System.Xml.Linq.XElement("Name");
                        name.Value = item.Key;

                        var value = new System.Xml.Linq.XElement("Value");
                        value.Add(xml);

                        equipXml.Add(name);
                        equipXml.Add(value);

                        xel.Add(equipXml);
                    }
                }

                doc.Add(xel);

                string filename = DateTime.Now.ToString("yyyy-MM-dd_HHmmss") + ".xml";
                string path = System.IO.Path.Combine(ConfigClasses.GlobalConst.ROOT_PATH, "DumpFile");
                if (System.IO.Directory.Exists(path) == false)
                    System.IO.Directory.CreateDirectory(path);

                string pathAndFilename = System.IO.Path.Combine(path, filename);

                doc.Save(pathAndFilename);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.ToString());
            }
        }
コード例 #2
0
        public static void MergeXml(System.Xml.Linq.XDocument dst, string pathsrc)
        {
            System.Xml.Linq.XDocument src = null;
            try
            {
                src = System.Xml.Linq.XDocument.Load(pathsrc);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
            if (src == null)
            {
                return;
            }

            if (dst.Root == null)
            {
                dst.Add(new System.Xml.Linq.XElement(src.Root));
            }
            else
            {
                MergeXml(dst.Root, src.Root);
            }
        }
コード例 #3
0
ファイル: DatabaseServer.cs プロジェクト: eoehen/nHydrate
        private static void LoadSql(string fileName, string sql, long elapsed)
        {
            try
            {
                System.Xml.Linq.XDocument xmlDoc      = null;
                System.Xml.Linq.XElement  rootElement = null;
                const string RootName = "SQL";
                if (File.Exists(fileName))
                {
                    xmlDoc      = System.Xml.Linq.XDocument.Load(fileName);
                    rootElement = xmlDoc.Element(RootName);
                }
                else
                {
                    xmlDoc      = new System.Xml.Linq.XDocument();
                    rootElement = new System.Xml.Linq.XElement(RootName);
                    xmlDoc.Add(rootElement);
                }

                var parentElement = new System.Xml.Linq.XElement("Entry",
                                                                 new System.Xml.Linq.XAttribute("datetime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")),
                                                                 new System.Xml.Linq.XAttribute("elapsed", elapsed.ToString()));
                parentElement.Add(new System.Xml.Linq.XElement("sql", new System.Xml.Linq.XCData(sql)));
                rootElement.Add(parentElement);
                xmlDoc.Save(fileName);
            }
            catch (Exception ex)
            {
                //Do Nothing
            }
        }
コード例 #4
0
 public void Save(string fileName)
 {
     // 创建文件对象。
     System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
     // 如果文件对象所在目录不存在,则创建。
     if (!System.IO.Directory.Exists(fileInfo.DirectoryName))
     {
         System.IO.Directory.CreateDirectory(fileInfo.DirectoryName);
     }
     // 创建Xml文档。
     System.Xml.Linq.XDocument xDocument = new System.Xml.Linq.XDocument(new System.Xml.Linq.XDeclaration("1.0", "utf-8", ""));
     // 添加Xml根节点。
     xDocument.Add(new System.Xml.Linq.XElement(XmlRootName));
     // 遍历配置文件中的配置组集合。
     foreach (ConfigurationGroup configurationGroup in _ConfigurationGroupDictionary.Values)
     {
         // 创建并添加Xml组节点。
         System.Xml.Linq.XElement xGroup = new System.Xml.Linq.XElement(XmlGroupNodeName);
         xGroup.SetAttributeValue(XmlKeyAttributeName, configurationGroup.Key);
         xDocument.Root.Add(xGroup);
         // 遍历配置组中的配置项集合。
         foreach (ConfigurationItem configurationItem in configurationGroup)
         {
             // 创建并添加Xml项节点。
             System.Xml.Linq.XElement xItem = new System.Xml.Linq.XElement(XmlItemNodeName);
             xItem.SetAttributeValue(XmlKeyAttributeName, configurationItem.Key);
             xItem.SetAttributeValue(XmlValueAttributeName, configurationItem.Encrypted ? Studio.Security.DESManager.Encrypt(configurationItem.Value) : configurationItem.Value);
             xItem.SetAttributeValue(XmlEncryptedAttributeName, configurationItem.Encrypted);
             xGroup.Add(xItem);
         }
     }
     // 保存到文件。
     xDocument.Save(fileInfo.FullName);
 }
コード例 #5
0
 public static void SaveBlogConnectionInfo(MP.BlogConnectionInfo coninfo, string filename)
 {
     var doc = new System.Xml.Linq.XDocument();
     var p = new System.Xml.Linq.XElement("blogconnectioninfo");
     doc.Add(p);
     p.Add(new System.Xml.Linq.XElement("blogurl", coninfo.BlogUrl));
     p.Add(new System.Xml.Linq.XElement("blogid", coninfo.BlogId));
     p.Add(new System.Xml.Linq.XElement("metaweblog_url", coninfo.MetaWeblogUrl));
     p.Add(new System.Xml.Linq.XElement("username", coninfo.Username));
     p.Add(new System.Xml.Linq.XElement("password", coninfo.Password));
     doc.Save(filename);
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: Injac/MetaWeblogPortable
        public static void SaveBlogConnectionInfo(MP.BlogConnectionInfo coninfo, string filename)
        {
            var doc = new System.Xml.Linq.XDocument();
            var p   = new System.Xml.Linq.XElement("blogconnectioninfo");

            doc.Add(p);
            p.Add(new System.Xml.Linq.XElement("blogurl", coninfo.BlogUrl));
            p.Add(new System.Xml.Linq.XElement("blogid", coninfo.BlogId));
            p.Add(new System.Xml.Linq.XElement("metaweblog_url", coninfo.MetaWeblogUrl));
            p.Add(new System.Xml.Linq.XElement("username", coninfo.Username));
            p.Add(new System.Xml.Linq.XElement("password", coninfo.Password));
            doc.Save(filename);
        }
コード例 #7
0
        public void Save(string filename)
        {
            var doc = new System.Xml.Linq.XDocument();
            var p   = new System.Xml.Linq.XElement("blogconnectioninfo");

            doc.Add(p);
            p.Add(new System.Xml.Linq.XElement("blogurl", this.BlogURL));
            p.Add(new System.Xml.Linq.XElement("blogid", this.BlogID));
            p.Add(new System.Xml.Linq.XElement("metaweblog_url", this.MetaWeblogURL));
            p.Add(new System.Xml.Linq.XElement("username", this.Username));
            p.Add(new System.Xml.Linq.XElement("password", this.Password));
            doc.Save(filename);
        }
コード例 #8
0
        /// <summary>
        /// Converts the setting object to <see cref="System.Xml.Linq.XDocument"/>
        /// </summary>
        /// <param name="setting">Setting object to convert</param>
        /// <returns></returns>
        protected virtual System.Xml.Linq.XDocument ConvertSettingObjectToXDocument(AppSetting setting)
        {
            if (setting.SettingItem == null)
            {
                return(System.Xml.Linq.XDocument.Parse(@"<settings>Empty setting object</settings>"));
            }

            StringBuilder xmlBuilder  = new StringBuilder();
            var           xDoc        = new System.Xml.Linq.XDocument();
            var           rootElement = new System.Xml.Linq.XElement(setting.SettingItem.Name);

            xDoc.Add(rootElement);
            this.WriteSettingObjectRecursively(rootElement, setting.SettingItem);

            return(xDoc);
        }
コード例 #9
0
ファイル: Fault.cs プロジェクト: csantero/MetaWeblogPortable
        public System.Xml.Linq.XDocument CreateDocument()
        {
            var doc = new System.Xml.Linq.XDocument();
            var root = new System.Xml.Linq.XElement("methodResponse");

            doc.Add(root);

            var f = new System.Xml.Linq.XElement("fault");

            root.Add(f);

            var struct_ = new XmlRpc.Struct();
            struct_["faultCode"] = new XmlRpc.IntegerValue(this.FaultCode);
            struct_["faultString"] = new XmlRpc.StringValue(this.FaultString);
            struct_.AddXmlElement(f);

            return doc;
        }
コード例 #10
0
ファイル: Fault.cs プロジェクト: Injac/MetaWeblogPortable
        public System.Xml.Linq.XDocument CreateDocument()
        {
            var doc  = new System.Xml.Linq.XDocument();
            var root = new System.Xml.Linq.XElement("methodResponse");

            doc.Add(root);

            var f = new System.Xml.Linq.XElement("fault");

            root.Add(f);


            var struct_ = new XmlRpc.Struct();

            struct_["faultCode"]   = new XmlRpc.IntegerValue(this.FaultCode);
            struct_["faultString"] = new XmlRpc.StringValue(this.FaultString);
            struct_.AddXmlElement(f);

            return(doc);
        }
コード例 #11
0
        static void Main()
        {
            // Try to load the config, if it doesn't exist then simply create a default
            // config and add some standard keys to it.
            Config c = null;

            try {
                c = new Config("appconfig.xml");
            } catch (FileNotFoundException e) {
                System.Xml.Linq.XDocument xdoc = new System.Xml.Linq.XDocument();
                xdoc.Add(new System.Xml.Linq.XElement("configfile"));
                xdoc.Save("appconfig.xml");

                c = new Config("appconfig.xml", xdoc);
                c.setConfig("ActicationPoint", (10).ToString());
                c.setConfig("SamlePeriod", (2000).ToString());
                c.setConfig("Cooldown", (5000).ToString());
            }

            // Load the values from the config file.
            int act_point     = c.getConfig <int>("ActivationPoint", 10);
            int sample_period = c.getConfig <int>("SamplePeriod", 2000);
            int cooldown      = c.getConfig <int>("Cooldown", 5000);

            // Set up a trigger on N keys pressed in less than M seconds
            // and set up a handler for reaching the activation point that
            // mutes the microphone.
            mRateTrigger = new RateTrigger(act_point, sample_period);
            MicrophoneHandling mic = new MicrophoneHandling(cooldown);

            mRateTrigger.ActivationPointReached += mic.TriggeredLimit;

            // Set up hooks and stuff for the application.
            _hookID = SetHook(_proc);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            UnhookWindowsHookEx(_hookID);
        }
コード例 #12
0
        public System.Xml.Linq.XDocument ToXML()
        {
            var dom        = new System.Xml.Linq.XDocument();
            var devinfo_el = new System.Xml.Linq.XElement("DeviceInfo");

            dom.Add(devinfo_el);


            this.WriteStringSafe(devinfo_el, "OutputFormat", this.OutputFormat);

            devinfo_el.SetElementValue("Toolbar", this.Capitalize(this.Toolbar.ToString()));

            this.WriteStringSafe(devinfo_el, "PageWidth", this.PageWidth);
            this.WriteStringSafe(devinfo_el, "PageHeight", this.PageHeight);
            this.WriteStringSafe(devinfo_el, "MarginTop", this.MarginTop);
            this.WriteStringSafe(devinfo_el, "MarginBottom", this.MarginBottom);
            this.WriteStringSafe(devinfo_el, "MarginLeft", this.MarginLeft);
            this.WriteStringSafe(devinfo_el, "MarginRight", this.MarginRight);

            if (this.PrintDpiX.HasValue)
            {
                devinfo_el.SetElementValue("PrintDpiX", this.PrintDpiX.ToString());
            }
            if (this.PrintDpiY.HasValue)
            {
                devinfo_el.SetElementValue("PrintDpiY", this.PrintDpiY.ToString());
            }
            if (this.DpiX.HasValue)
            {
                devinfo_el.SetElementValue("DpiX", this.DpiX.ToString());
            }
            if (this.DpiY.HasValue)
            {
                devinfo_el.SetElementValue("DpiY", this.DpiY.ToString());
            }


            return(dom);
        }
コード例 #13
0
ファイル: DeviceInfo.cs プロジェクト: saveenr/saveenr
        public System.Xml.Linq.XDocument ToXML()
        {
            var dom = new System.Xml.Linq.XDocument();
            var devinfo_el = new System.Xml.Linq.XElement("DeviceInfo");
            dom.Add(devinfo_el);


            this.WriteStringSafe(devinfo_el, "OutputFormat", this.OutputFormat);

            devinfo_el.SetElementValue("Toolbar", this.Capitalize(this.Toolbar.ToString()));

            this.WriteStringSafe(devinfo_el, "PageWidth", this.PageWidth);
            this.WriteStringSafe(devinfo_el, "PageHeight", this.PageHeight);
            this.WriteStringSafe(devinfo_el, "MarginTop", this.MarginTop);
            this.WriteStringSafe(devinfo_el, "MarginBottom", this.MarginBottom);
            this.WriteStringSafe(devinfo_el, "MarginLeft", this.MarginLeft);
            this.WriteStringSafe(devinfo_el, "MarginRight", this.MarginRight);

            if (this.PrintDpiX.HasValue)
            {
                devinfo_el.SetElementValue("PrintDpiX", this.PrintDpiX.ToString());
            }
            if (this.PrintDpiY.HasValue)
            {
                devinfo_el.SetElementValue("PrintDpiY", this.PrintDpiY.ToString());
            }
            if (this.DpiX.HasValue)
            {
                devinfo_el.SetElementValue("DpiX", this.DpiX.ToString());
            }
            if (this.DpiY.HasValue)
            {
                devinfo_el.SetElementValue("DpiY", this.DpiY.ToString());
            }


            return dom;
        }