CreateComment() public method

public CreateComment ( String data ) : XmlComment
data String
return XmlComment
        //////////////////////////////////////////////////////////////////////////
        public bool SaveToXmlFile(string Filename)
        {
            try
            {
                XmlDocument Doc = new XmlDocument();

                // header
                XmlDeclaration Decl = Doc.CreateXmlDeclaration("1.0", "utf-8", null);

                Assembly A = Assembly.GetExecutingAssembly();
                XmlComment Comment1 = Doc.CreateComment("Generated by: " + A.GetName());
                XmlComment Comment2 = Doc.CreateComment("Generated on: " + DateTime.Now.ToString());

                // root
                XmlNode RootNode = SaveToXmlNode(Doc);
                Doc.InsertBefore(Decl, Doc.DocumentElement);
                Doc.AppendChild(Comment1);
                Doc.AppendChild(Comment2);
                Doc.AppendChild(RootNode);

                // save to file
                XmlTextWriter Writer = new XmlTextWriter(Filename, null);
                Writer.Formatting = Formatting.Indented;
                Doc.Save(Writer);
                Writer.Close();

                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// Generates a capabilities file from a map object for use in WMS services
        /// </summary>
        /// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks>
        /// <param name="map">The map to create capabilities for</param>
        /// <param name="description">Additional description of WMS</param>
        /// <param name="request">An abstraction of the <see cref="HttpContext"/> request</param>
        /// <returns>Returns XmlDocument describing capabilities</returns>
        public static XmlDocument GetCapabilities(Map map, WmsServiceDescription description, IContextRequest request)
        {
            XmlDocument capabilities = new XmlDocument();

            // Insert XML tag
            capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", String.Empty), capabilities.DocumentElement);
            string format = String.Format("Capabilities generated by SharpMap v. {0}", Assembly.GetExecutingAssembly().GetName().Version);
            capabilities.AppendChild(capabilities.CreateComment(format));

            // Create root node
            XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", WmsNamespaceUri);
            rootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities));

            XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
            attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
            rootNode.Attributes.Append(attr);

            rootNode.Attributes.Append(CreateAttribute("xmlns:xlink", XlinkNamespaceUri, capabilities));
            XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation",
                                                              "http://www.w3.org/2001/XMLSchema-instance");
            attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
            rootNode.Attributes.Append(attr2);

            // Build Service node
            rootNode.AppendChild(GenerateServiceNode(ref description, capabilities));

            // Build Capability node
            XmlNode capabilityNode = GenerateCapabilityNode(map, capabilities, description.PublicAccessURL, request);
            rootNode.AppendChild(capabilityNode);

            capabilities.AppendChild(rootNode);

            //TODO: Validate output against schema
            return capabilities;
        }
Beispiel #3
0
        /// <summary>
        /// write layout data in xml-file for list of object
        /// </summary>
        /// <param name="fileName">name of xml-file</param>
        /// <param name="stores">list of object for writing layout data</param>
        public static void WriteXml(string fileName, IList<ILayoutDataStore> stores)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement element;
            IList<ILayoutDataStore> controls = stores;
            // create a comment/pi and append
            if (controls == null) return;
            XmlNode node = doc.CreateComment(string.Format("Saved layout information for {0} controls of form", controls.Count));
            doc.AppendChild(node);
            node = doc.CreateElement(LayoutControlsElement);
            doc.AppendChild(node);

            foreach (ILayoutDataStore control in controls)
            {
                element = CreateElement(doc, ControlElement, NameElement, control.Name);
                node.AppendChild(element);
                element.AppendChild(CreateElement(doc, CheckElement, control.CheckCode));
                element.AppendChild(CreateCDataSection(doc, DataElement, control.Save()));
            }

            XmlTextWriter tw = new XmlTextWriter(FileUtils.MakeValidFilePath(fileName), null);
            tw.Formatting = Formatting.Indented;
            doc.Save(tw);
            tw.Close();
        }
Beispiel #4
0
        public bool Save(string path)
        {
            bool saved = true;
            XmlDocument m_Xdoc = new XmlDocument();
            try
            {
                m_Xdoc.RemoveAll();

                XmlNode node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateComment($" Profile Configuration Data. {DateTime.Now} ");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateWhitespace("\r\n");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null);

                m_Xdoc.AppendChild(node);

                m_Xdoc.Save(path);
            }
            catch
            {
                saved = false;
            }

            return saved;
        }
Beispiel #5
0
        //Add a node
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the XML document
            XmlDocument document = new XmlDocument();
            document.Load("../../Books.xml");

            //Get the root element
            XmlElement root = document.DocumentElement;


            //Create the new nodes
            XmlElement newBook = document.CreateElement("book");
            XmlElement newTitle = document.CreateElement("title");
            XmlElement newAuthor = document.CreateElement("author");
            XmlElement newCode = document.CreateElement("code");
            XmlText title = document.CreateTextNode("Beginning Visual C# 3rd Edition");  
            XmlText author = document.CreateTextNode("Karli Watson C# 3rd Edition");
            XmlText code = document.CreateTextNode("1234567890");
            XmlComment comment = document.CreateComment("This book is the book you are reading");

            //Insert the elements
            newBook.AppendChild(comment);
            newBook.AppendChild(newTitle);
            newBook.AppendChild(newAuthor);
            newBook.AppendChild(newCode);
            newTitle.AppendChild(title);
            newAuthor.AppendChild(author);
            newCode.AppendChild(code);
            root.InsertAfter(newBook, root.LastChild);

            document.Save("../../Books.xml");

            listBoxXmlNodes.Items.Clear();
            RecurseXmlDocument((XmlNode)document.DocumentElement, 0);  
        }
		public void GetReady ()
		{
			document = new XmlDocument ();
			document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
			document.NodeChanging += new XmlNodeChangedEventHandler (this.EventNodeChanging);
			comment = document.CreateComment ("foo");
		}
Beispiel #7
0
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
            doc.AppendChild(declaration);

            XmlComment comment = doc.CreateComment("my first xml document");
            doc.AppendChild(comment);

            XmlElement Employee = doc.CreateElement("Employee");
            doc.AppendChild(Employee);
            Employee.SetAttribute("ID", "48090");

            XmlElement Fname = doc.CreateElement("Fname");
            Fname.InnerXml = "naynish";
            Employee.AppendChild(Fname);

            XmlElement Lname = doc.CreateElement("Lname");
            Lname.InnerXml = "chaughule";
            Employee.AppendChild(Lname);

            XmlElement Salary = doc.CreateElement("Salary");
            Salary.InnerXml = "85000";
            Employee.AppendChild(Salary);

            doc.Save("FirstXml");
            Console.WriteLine("{0}", File.ReadAllText("FirstXml"));
            Console.WriteLine();
            SimpleXmlUsingLinq();
            Traverse();
            Update();
            Console.ReadLine();
        }
        public void SerializeTypes(IEnumerable<Type> types, TextWriter output) {
            var groupedByAssembly = from type in types
                                    group type by type.Module into groupedByModule
                                    group groupedByModule by groupedByModule.Key.Assembly;

            XmlDocument doc = new XmlDocument();
            doc.AppendChild(doc.CreateComment(MvcResources.TypeCache_DoNotModify));

            XmlElement typeCacheElement = doc.CreateElement("typeCache");
            doc.AppendChild(typeCacheElement);
            typeCacheElement.SetAttribute("lastModified", CurrentDate.ToString());
            typeCacheElement.SetAttribute("mvcVersionId", _mvcVersionId.ToString());

            foreach (var assemblyGroup in groupedByAssembly) {
                XmlElement assemblyElement = doc.CreateElement("assembly");
                typeCacheElement.AppendChild(assemblyElement);
                assemblyElement.SetAttribute("name", assemblyGroup.Key.FullName);

                foreach (var moduleGroup in assemblyGroup) {
                    XmlElement moduleElement = doc.CreateElement("module");
                    assemblyElement.AppendChild(moduleElement);
                    moduleElement.SetAttribute("versionId", moduleGroup.Key.ModuleVersionId.ToString());

                    foreach (Type type in moduleGroup) {
                        XmlElement typeElement = doc.CreateElement("type");
                        moduleElement.AppendChild(typeElement);
                        typeElement.AppendChild(doc.CreateTextNode(type.FullName));
                    }
                }
            }

            doc.Save(output);
        }
Beispiel #9
0
        private void buttonCreateNode_Click(object sender, RoutedEventArgs e)
        {
            // Load the XML document.
              XmlDocument document = new XmlDocument();
              document.Load(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");

              // Get the root element.
              XmlElement root = document.DocumentElement;

              // Create the new nodes.
              XmlElement newBook = document.CreateElement("book");
              XmlElement newTitle = document.CreateElement("title");
              XmlElement newAuthor = document.CreateElement("author");
              XmlElement newCode = document.CreateElement("code");
              XmlText title = document.CreateTextNode("Beginning Visual C# 2010");
              XmlText author = document.CreateTextNode("Karli Watson et al");
              XmlText code = document.CreateTextNode("1234567890");
              XmlComment comment = document.CreateComment("The previous edition");

              // Insert the elements.
              newBook.AppendChild(comment);
              newBook.AppendChild(newTitle);
              newBook.AppendChild(newAuthor);
              newBook.AppendChild(newCode);
              newTitle.AppendChild(title);
              newAuthor.AppendChild(author);
              newCode.AppendChild(code);
              root.InsertAfter(newBook, root.FirstChild);

              document.Save(@"C:\Beginning Visual C# 2012\Chapter 22\Books.xml");
        }
Beispiel #10
0
        /// <summary>
        /// XML Documentに変換。
        /// </summary>
        /// <param name="xmlText"></param>
        /// <returns></returns>
        public XmlDocument Perform(
            MemoryGloballistconfig moGlcnf,
            Log_Reports log_Reports
            )
        {
            XmlDocument doc = new XmlDocument();

            XmlElement rootElm = doc.CreateElement("global-list-config");
            doc.AppendChild(rootElm);

            rootElm.AppendChild(doc.CreateComment(" 変数の型名を、グローバルリストに並んでいる順番に並べてください "));

            // 変数の型名の追加
            foreach (GloballistconfigTypesection typeSection in moGlcnf.TypesectionList.List_Item)
            {
                XmlElement typeElm = doc.CreateElement("type");
                typeElm.SetAttribute(SrsAttrName.S_NAME, typeSection.Name_Type);
                rootElm.AppendChild(typeElm);
            }

            rootElm.AppendChild(doc.CreateComment(" 担当者の情報を記述してください。担当者名、変数の型名、変数番号のそれぞれ、順不同です。 "));
            // 担当者情報の追加
            foreach (GloballistconfigHuman human in moGlcnf.Dictionary_Human.Values)
            {
                XmlElement humanElm = doc.CreateElement("human");
                humanElm.SetAttribute(SrsAttrName.S_NAME, human.Name);
                rootElm.AppendChild(humanElm);

                // 担当変数の型の情報の追加
                foreach (GloballistconfigVariable var in human.Dictionary_Variable.Values)
                {
                    XmlElement varElm = doc.CreateElement("variable");
                    varElm.SetAttribute("type", var.Name_Type);
                    humanElm.AppendChild(varElm);

                    // 担当変数の情報の追加
                    foreach (GloballistconfigNumber num in var.Dictionary_Number.Values)
                    {
                        XmlElement numElm = doc.CreateElement("number");
                        numElm.SetAttribute("range", num.Text_Range);
                        numElm.SetAttribute("priority", num.Priority.Text);
                        varElm.AppendChild(numElm);
                    }
                }
            }
            return doc;
        }
Beispiel #11
0
 public XMLDocInstance(ObjectInstance prototype, string path)
     : this(prototype)
 {
     _doc = new XmlDocument();
     _path = path;
     _doc.AppendChild(_doc.CreateXmlDeclaration("1.0", null, null));
     _doc.AppendChild(_doc.CreateComment("Generated by Sphere SFML XML Content Serializer v1.0"));
 }
Beispiel #12
0
        public static void CreateEmptyComment()
        {
            var xmlDocument = new XmlDocument();
            var comment = xmlDocument.CreateComment(String.Empty);

            Assert.Equal("<!---->", comment.OuterXml);
            Assert.Equal(String.Empty, comment.InnerText);
            Assert.Equal(comment.NodeType, XmlNodeType.Comment);
        }
Beispiel #13
0
        public static void Save()
        {
            string filepath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            string FileName = Path.Combine(filepath, "Options.xml");

            XmlDocument dom = new XmlDocument();
            XmlDeclaration decl = dom.CreateXmlDeclaration("1.0", "utf-8", null);
            dom.AppendChild(decl);
            XmlElement sr = dom.CreateElement("Options");

            XmlComment comment = dom.CreateComment("LogPath is the default path to check for log files when you press the Parse Button");
            sr.AppendChild(comment);
            XmlElement elem = dom.CreateElement("LogPath");
            elem.InnerText = Program.opt.DefaultLogPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("OutputPath is the default path to use when you press the Save Button after parsing");
            sr.AppendChild(comment);
            elem = dom.CreateElement("OutputPath");
            elem.InnerText = Program.opt.DefaultOutputPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("POLPath is the default path to use for the POL Parsing Tools in the Tools Menu");
            sr.AppendChild(comment);
            elem = dom.CreateElement("POLPath");
            elem.InnerText = Program.opt.DefaultPOLPath.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("LastUsedList is the last Keyword List used when Options was last saved");
            sr.AppendChild(comment);
            elem = dom.CreateElement("LastUsedList");
            elem.InnerText = Program.Keys.CurrentList.ToString();
            sr.AppendChild(elem);

            comment = dom.CreateComment("Case decides if to use Case Sensitive searches based on Keywords in the main Parser");
            sr.AppendChild(comment);
            elem = dom.CreateElement("Case");
            elem.InnerText = Program.opt.CaseParse.ToString();
            sr.AppendChild(elem);

            dom.AppendChild(sr);
            dom.Save(FileName);
        }
        public static XmlDocument ToXml(this OrganizationSnapshot[] matrix)
        {
            var document = new XmlDocument();

            document.AppendChild(document.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
            document.AppendChild(document.CreateComment("Comparison matrix"));

            var root = document.CreateElement("matrix");
            document.AppendChild(root);

            XmlElement element;
            XmlAttribute attribute;

            var solutions = document.CreateElement(Constants.Xml.SOLUTIONS);
            root.AppendChild(solutions);

            foreach (var solution in matrix[0].Solutions)
            {
                element = document.CreateElement(Constants.Xml.SOLUTION);

                attribute = document.CreateAttribute(Constants.Xml.UNIQUE_NAME);
                attribute.Value = solution.UniqueName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.FRIENDLY_NAME);
                attribute.Value = solution.FriendlyName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.VERSION);
                attribute.Value = solution.Version.ToString();
                element.Attributes.Append(attribute);

                solutions.AppendChild(element);
            }

            var assemblies = document.CreateElement(Constants.Xml.ASSEMBLIES);
            root.AppendChild(assemblies);

            foreach (var assembly in matrix[0].Assemblies)
            {
                element = document.CreateElement(Constants.Xml.ASSEMBLY);

                attribute = document.CreateAttribute(Constants.Xml.FRIENDLY_NAME);
                attribute.Value = assembly.FriendlyName;
                element.Attributes.Append(attribute);

                attribute = document.CreateAttribute(Constants.Xml.VERSION);
                attribute.Value = assembly.Version.ToString();
                element.Attributes.Append(attribute);

                assemblies.AppendChild(element);
            }

            return document;
        }
        public static void CreateEmptyResourceFile(string path)
        {
            XmlDocument document = new XmlDocument();
            XmlElement root = document.CreateElement("Resources");
            XmlComment comment = document.CreateComment("Here you can define resources used by Speech Sequencer");

            root.AppendChild(comment);
            document.AppendChild(root);
            document.DocumentElement.SetAttribute("xmlns:var", VariableNamespace);

            document.Save(path);
        }
		public static string ConvertIniStringToXmlString(string iniString)
		{
			var xmlDoc = new XmlDocument();
			var root = xmlDoc.CreateElement("root");
			var ini = Ini.FromString(iniString);

			foreach (var section in ini.Sections)
			{
				if (section.Comment != null)
				{
					root.AppendChild(xmlDoc.CreateComment(section.Comment));
				}

				var node = xmlDoc.CreateElement(section.SectionStart.SectionName);				
				foreach (var i in section.Elements)
				{
					XmlNode ele = null;
					if (i is IniBlankLine)
					{					
					}
					else if (i is IniCommentary)
					{
						ele = xmlDoc.CreateComment((i as IniCommentary).Comment);
					}
					else if (i is IniValue)
					{
						ele = xmlDoc.CreateElement((i as IniValue).Key);
						ele.InnerText = (i as IniValue).Value;
					}
					if(ele!=null)
						node.AppendChild(ele);
				}
				root.AppendChild(node);
			}
			return root.InnerXml;
		}
        public static void ImportDocumentFragment()
        {
            var tempDoc = new XmlDocument();
            var nodeToImport = tempDoc.CreateDocumentFragment();

            nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
            nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
            nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));

            var xmlDocument = new XmlDocument();
            var node = xmlDocument.ImportNode(nodeToImport, true);

            Assert.Equal(xmlDocument, node.OwnerDocument);
            Assert.Equal(XmlNodeType.DocumentFragment, node.NodeType);
            Assert.Equal(nodeToImport.OuterXml, node.OuterXml);
        }
        public static void OwnerDocumentOnImportedTree()
        {
            var tempDoc = new XmlDocument();
            var nodeToImport = tempDoc.CreateDocumentFragment();

            nodeToImport.AppendChild(tempDoc.CreateElement("A1"));
            nodeToImport.AppendChild(tempDoc.CreateComment("comment"));
            nodeToImport.AppendChild(tempDoc.CreateProcessingInstruction("PI", "donothing"));

            var xmlDocument = new XmlDocument();
            var node = xmlDocument.ImportNode(nodeToImport, true);

            Assert.Equal(xmlDocument, node.OwnerDocument);

            foreach (XmlNode child in node.ChildNodes)
                Assert.Equal(xmlDocument, child.OwnerDocument);
        }
Beispiel #19
0
        /// <summary>
        /// Generates a capabilities file from a map object for use in WMS services
        /// </summary>
        /// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks>
        /// <param name="map">The map to create capabilities for</param>
        /// <param name="serviceDescription">Additional description of WMS</param>
        /// <param name="request">An abstraction of the <see cref="HttpContext"/> request</param>
        /// <returns>Returns XmlDocument describing capabilities</returns>
        public static XmlDocument GetCapabilities(Map map, WmsServiceDescription serviceDescription, IContextRequest request)
        {
            XmlDocument capabilities = new XmlDocument();


            //Set XMLSchema
            //capabilities.Schemas.Add(GetCapabilitiesSchema());

            //Instantiate an XmlNamespaceManager object.
            //System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(capabilities.NameTable);
            //xmlnsManager.AddNamespace(xlinkNamespaceURI, "urn:Books");

            //Insert XML tag
            capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", string.Empty),
                                      capabilities.DocumentElement);
            capabilities.AppendChild(
                capabilities.CreateComment("Capabilities generated by SharpMap v. " +
                                           Assembly.GetExecutingAssembly().GetName().Version));
            //Create root node
            XmlNode RootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", wmsNamespaceURI);
            RootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities));

            XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
            attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
            RootNode.Attributes.Append(attr);

            RootNode.Attributes.Append(CreateAttribute("xmlns:xlink", xlinkNamespaceURI, capabilities));
            XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation",
                                                              "http://www.w3.org/2001/XMLSchema-instance");
            attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
            RootNode.Attributes.Append(attr2);

            //Build Service node
            RootNode.AppendChild(GenerateServiceNode(ref serviceDescription, capabilities));

            //Build Capability node
            XmlNode capabilityNode = GenerateCapabilityNode(map, capabilities, serviceDescription.PublicAccessURL, request);
            RootNode.AppendChild(capabilityNode);

            capabilities.AppendChild(RootNode);

            //TODO: Validate output against schema

            return capabilities;
        }
Beispiel #20
0
        public static void SaveSettingsFile()
        {
            XmlDocument doc = new XmlDocument();
            XmlNode settings = doc.CreateElement("Settings");
            doc.AppendChild(settings);

            // "credentials" node

            XmlNode creds = doc.CreateElement("Credentials");
            settings.AppendChild(creds);
            settings.InsertBefore(doc.CreateComment(" Fill in your Twitter Credentials here to have TweetPly auto-load them. "), creds);

            XmlNode consumerKey = doc.CreateElement("ConsumerKey");
            consumerKey.InnerText = ConsumerKey; // <node></node> instead of <node />
            creds.AppendChild(consumerKey);

            XmlNode consumerSecret = doc.CreateElement("ConsumerSecret");
            consumerSecret.InnerText = ConsumerSecret; // <node></node> instead of <node />
            creds.AppendChild(consumerSecret);

            XmlNode accessToken = doc.CreateElement("AccessToken");
            accessToken.InnerText = AccessToken; // <node></node> instead of <node />
            creds.AppendChild(accessToken);

            XmlNode accessTokenSecret = doc.CreateElement("AccessTokenSecret");
            accessTokenSecret.InnerText = AccessTokenSecret; // <node></node> instead of <node />
            creds.AppendChild(accessTokenSecret);

            XmlNode tweets = doc.CreateElement("Tweets");
            tweets.InnerText = Tweets.ToString(); // <node></node> instead of <node />
            settings.AppendChild(tweets);
            settings.InsertBefore(doc.CreateComment(" Number of Tweets to fetch (1-1500) "), tweets);

            using (StringWriter sw = new StringWriter())
            using (XmlTextWriter xtw = new XmlTextWriter(sw))
            {
                xtw.Formatting = Formatting.Indented; // for pretty code
                xtw.Indentation = 4;
                settings.WriteTo(xtw);
                File.WriteAllText(SettingsFile, sw.ToString(), Encoding.UTF8);
            }
        }
Beispiel #21
0
 //NOTE: XmlDocument.ImportNode munges "xmlns:asmv2" to "xmlns:d1p1" for some reason, use XmlUtil.CloneElementToDocument instead
 public static XmlElement CloneElementToDocument(XmlElement element, XmlDocument document, string namespaceURI)
 {
     XmlElement newElement = document.CreateElement(element.Name, namespaceURI);
     foreach (XmlAttribute attribute in element.Attributes)
     {
         XmlAttribute newAttribute = document.CreateAttribute(attribute.Name);
         newAttribute.Value = attribute.Value;
         newElement.Attributes.Append(newAttribute);
     }
     foreach (XmlNode node in element.ChildNodes)
         if (node.NodeType == XmlNodeType.Element)
         {
             XmlElement childElement = CloneElementToDocument((XmlElement)node, document, namespaceURI);
             newElement.AppendChild(childElement);
         }
         else if (node.NodeType == XmlNodeType.Comment)
         {
             XmlComment childComment = document.CreateComment(((XmlComment)node).Data);
             newElement.AppendChild(childComment);
         }
     return newElement;
 }
Beispiel #22
0
        public static XmlNode CreateNode(XmlDocument doc, XmlNodeType nodeType)
        {
            Assert.NotNull(doc);

            switch (nodeType)
            {
                case XmlNodeType.CDATA:
                    return doc.CreateCDataSection(@"&lt; &amp; <tag> < ! > & </tag> 	 ");
                case XmlNodeType.Comment:
                    return doc.CreateComment(@"comment");
                case XmlNodeType.Element:
                    return doc.CreateElement("E");
                case XmlNodeType.Text:
                    return doc.CreateTextNode("text");
                case XmlNodeType.Whitespace:
                    return doc.CreateWhitespace(@"	  ");
                case XmlNodeType.SignificantWhitespace:
                    return doc.CreateSignificantWhitespace("	");
                default:
                    throw new ArgumentException("Wrong XmlNodeType: '" + nodeType + "'");
            }
        }
Beispiel #23
0
        public void TestIsValidNode()
        {
            EcellXmlReader reader = new EcellXmlReader();
            Assert.IsNotNull(reader, "Constructor of type, EcellXmlReader failed to create instance.");
            Type type = reader.GetType();
            MethodInfo methodInfo = type.GetMethod("IsValidNode", BindingFlags.NonPublic | BindingFlags.Instance);

            bool expected = true;
            XmlDocument eml = new XmlDocument();
            eml.Load(TestConstant.Model_RBC);
            XmlNode node = eml.ChildNodes[0];
            bool result = (bool)methodInfo.Invoke(reader, new object[] { node });

            Assert.AreEqual(expected, result, "IsValidNode method returned unexpected value.");

            node = eml.CreateComment("");
            expected = false;
            result = (bool)methodInfo.Invoke(reader, new object[] { node });
            Assert.AreEqual(expected, result, "IsValidNode method returned unexpected value.");

            result = (bool)methodInfo.Invoke(reader, new object[] { null });
            Assert.AreEqual(expected, result, "IsValidNode method returned unexpected value.");
        }
 public static XmlElement CloneElementToDocument(XmlElement element, XmlDocument document, string namespaceURI)
 {
     XmlElement element2 = document.CreateElement(element.Name, namespaceURI);
     foreach (XmlAttribute attribute in element.Attributes)
     {
         XmlAttribute attribute2 = document.CreateAttribute(attribute.Name);
         attribute2.Value = attribute.Value;
         element2.Attributes.Append(attribute2);
     }
     foreach (XmlNode node in element.ChildNodes)
     {
         if (node.NodeType == XmlNodeType.Element)
         {
             XmlElement newChild = CloneElementToDocument((XmlElement) node, document, namespaceURI);
             element2.AppendChild(newChild);
         }
         else if (node.NodeType == XmlNodeType.Comment)
         {
             XmlComment comment = document.CreateComment(((XmlComment) node).Data);
             element2.AppendChild(comment);
         }
     }
     return element2;
 }
        private void BSave_Click(object sender, EventArgs e)
        {
            //----------------- Save Configfile and set Settings ----------------
            XmlDocument xml;
            XmlElement root;
            XmlElement element;
            XmlText text;
            XmlComment xmlComment;

            // ---------- Check Plausibility of the Config ----------------------------

            //Pull Spell
            if (!CBPull.Checked && !(SpellManager.HasSpell(TBPull.Text)))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller Part Spells: Don't have your configured Pull Spell - setting to Default");
                CBPull.Checked = true;
                TBPull.Text = "";
            }
            if (!CBPull.Checked && (TBPull.Text == ""))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You must insert Pullspell");
                CBPull.Checked = true;
            }
            if (Convert.ToInt32(TBRange.Text) > 40)
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Set Range to 25, over 40 is impossible");
                TBRange.Text = "25";
            }
            if (CBPull.Checked && SpellManager.HasSpell("Crusader Strike") && (Convert.ToInt32(TBRange.Text) > 3))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Set Range to 3 because of Low Range of Default Pull Spell Crusader Strike");
                TBRange.Text = "3";
            }
            if (CBPull.Checked && SpellManager.HasSpell("Sinister Strike") && (Convert.ToInt32(Rarekiller.Settings.Range) > 3))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Set Range to 3 because of Low Range of Default Spell Sinister Strike");
                TBRange.Text = "3";
            }
            if ((CBWotlk.Checked || CBBC.Checked || CBCata.Checked || CBLowRAR.Checked || CBHuntByID.Checked
                || CBDormus.Checked || CBAeonaxx.Checked || CBTestWelpTargeting.Checked)
                && CBPull.Checked && !(SpellManager.HasSpell(Rarekiller.Spells.LowPullspell)))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller Part Spells: Don't have your Pull Spell - please config one");
                CBWotlk.Checked = false;
                CBBC.Checked = false;
                CBCata.Checked = false;
                CBHuntByID.Checked = false;
                CBLowRAR.Checked = false;
                CBDormus.Checked = false;
                CBAeonaxx.Checked = false;
            }
            if (CBTLPD.Checked && CBPull.Checked
                && !(SpellManager.HasSpell(Rarekiller.Spells.FastPullspell)))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller Part Spells: Don't have a valid Pull Spell for TLPD - please check your Config");
                CBTLPD.Checked = false;
            }

            //Hunt and Tame by ID
            if (CBHuntByID.Checked && (TBHuntByID.Text == ""))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You must insert the ID of the Mob you want to hunt");
                CBHuntByID.Checked = false;
            }
            if (CBTameByID.Checked && (TBTameID.Text == ""))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You must insert the ID of the Mob you want to tame");
                CBTameByID.Checked = false;
            }

            //Slowfall
            if (CBItem.Checked && (TBSlowfallItem.Text == ""))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You must insert a Slowfall Item");
                CBItem.Checked = false;
            }
            if (CBSpell.Checked && (TBSlowfallSpell.Text == ""))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You must insert a Slowfall Spell");
                CBSpell.Checked = false;
            }
            if (CBUseSlowfall.Checked && CBSpell.Checked && !(SpellManager.HasSpell(TBSlowfallSpell.Text)))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Don't have your Slowfall Spell - please check your Config");
                CBSpell.Checked = false;
                TBSlowfallSpell.Text = "";
            }
            if (CBTLPD.Checked && !CBUseSlowfall.Checked)
                Logging.Write(System.Drawing.Color.Red, "Rarekiller Warning: You will probably die, hunting the TLPD without Slowfall.");
            if (CBWotlk.Checked && CBVyragosa.Checked && !CBUseSlowfall.Checked)
                Logging.Write(System.Drawing.Color.Red, "Rarekiller Warning: You will probably die, hunting Vyragosa without Slowfall. Please Check - don't kill Vyragosa");
            if (TBFalltimer.Text == "")
                TBFalltimer.Text = "10";
            //Diverses
            if (CBTestShootDown.Checked && (!SpellManager.HasSpell("Lightning Bolt")))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You don't have Lightning Bolt to use this");
                CBTestShootDown.Checked = false;
            }
            if (CBShotVyra.Checked && (!SpellManager.HasSpell("Shoot") || !SpellManager.HasSpell("Throw")))
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You don't have Shoot or Throw to use this");
                CBShotVyra.Checked = false;
            }

            if (CBContinentChange.Checked && !RBKillWoW.Checked && !RBLogOut.Checked && !RBJustAlert.Checked)
                RBJustAlert.Checked = true;
            if (CBAeonaxx.Checked && CBGroundMount.Checked)
            {
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Can't hunt Aeonaxx in GroundMountMode");
                CBAeonaxx.Checked = false;
            }
            if (!CBContinentChange.Checked)
            {
                RBKillWoW.Checked = false;
                RBLogOut.Checked = false;
                RBJustAlert.Checked = false;
            }
            if (CBBlacklistCheck.Checked && (TBBlacklistTime.Text == ""))
            {
                TBBlacklistTime.Text = "180";
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: Set Blacklist Time to Default");
            }
            if (CBTagged.Checked && !CBBlacklistTagged.Checked && !CBWinnerTagged.Checked)
            {
                Logging.Write(System.Drawing.Color.Red, "You have to define what he should do instead of killing tagged Mobs, set these Settings to default");
                CBWinnerTagged.Checked = true;
            }
            if (CBBloodseekerKill.Checked && !CBUseSlowfall.Checked)
            {
                CBBloodseekerKill.Checked = false;
                Logging.Write(System.Drawing.Color.Red, "Rarekiller: You can't hunt Bloodseeker without Slowfall (Setup in Tap 2).");
            }

            // Variablen nach Settings übernehmen
            // Addons
            Rarekiller.Settings.CATA = CBCata.Checked;
            Rarekiller.Settings.WOTLK = CBWotlk.Checked;
            Rarekiller.Settings.BC = CBBC.Checked;
            Rarekiller.Settings.LowRAR = CBLowRAR.Checked;
            Rarekiller.Settings.TLPD = CBTLPD.Checked;
            Rarekiller.Settings.Poseidus = CBPoseidus.Checked;
            Rarekiller.Settings.RaptorNest = CBRaptorNest.Checked;
            // Hunt by ID
            Rarekiller.Settings.HUNTbyID = CBHuntByID.Checked;
            Rarekiller.Settings.MobID = TBHuntByID.Text;
            Rarekiller.Settings.BlacklistCheck = CBBlacklistCheck.Checked;
            Rarekiller.Settings.BlacklistTime = TBBlacklistTime.Text;
            Rarekiller.Settings.ZoneSave = CBZoneSave.Checked;
            //Tamer
            Rarekiller.Settings.TameDefault = CBTameDefault.Checked;
            Rarekiller.Settings.TameByID = CBTameByID.Checked;
            Rarekiller.Settings.NotKillTameable = CBNotKillTameable.Checked;
            Rarekiller.Settings.TameMobID = TBTameID.Text;
            // Slowfall
            Rarekiller.Settings.UseSlowfall = CBUseSlowfall.Checked;
            Rarekiller.Settings.Cloak = RBCloak.Checked;
            Rarekiller.Settings.Item = CBItem.Checked;
            Rarekiller.Settings.SlowfallItem = TBSlowfallItem.Text;
            Rarekiller.Settings.Spell = CBSpell.Checked;
            Rarekiller.Settings.SlowfallSpell = TBSlowfallSpell.Text;
            Rarekiller.Settings.Falltimer = TBFalltimer.Text;
            // Pullspell
            Rarekiller.Settings.DefaultPull = CBPull.Checked;
            Rarekiller.Settings.Pull = TBPull.Text;
            Rarekiller.Settings.Range = TBRange.Text;
            Rarekiller.Settings.Vyragosa = CBVyragosa.Checked;
            Rarekiller.Settings.ShotVyra = CBShotVyra.Checked;
            Rarekiller.Settings.Blazewing = CBBlazewing.Checked;
            Rarekiller.Settings.BloodseekerSearch = CBBloodseekerSearch.Checked;
            Rarekiller.Settings.BloodseekerKill = CBBloodseekerKill.Checked;
            //Testpart
            Rarekiller.Settings.Aeonaxx = CBAeonaxx.Checked;
            Rarekiller.Settings.TestKillAeonaxx = CBTestKillAeonaxx.Checked;
            Rarekiller.Settings.Camel = CBCamel.Checked;
            Rarekiller.Settings.Collect = CBCollect.Checked;
            Rarekiller.Settings.Dormus = CBDormus.Checked;
            //Alert etc
            Rarekiller.Settings.GroundMountMode = CBGroundMount.Checked;
            Rarekiller.Settings.Alert = CBAlert.Checked;
            Rarekiller.Settings.BlacklistTagged = CBBlacklistTagged.Checked;
            Rarekiller.Settings.WinnerTagged = CBWinnerTagged.Checked;
            Rarekiller.Settings.DontKillTagged = CBTagged.Checked;
            Rarekiller.Settings.Wisper = CBWisper.Checked;
            Rarekiller.Settings.Guild = CBGuild.Checked;
            Rarekiller.Settings.Keyer = CBKeyer.Checked;
            Rarekiller.Settings.SoundfileWisper = TBSoundfileWisper.Text;
            Rarekiller.Settings.SoundfileGuild = TBSoundfileGuild.Text;
            Rarekiller.Settings.SoundfileFoundRare = TBSoundfileFoundRare.Text;
            //Security
            Rarekiller.Settings.KillWoW = RBKillWoW.Checked;
            Rarekiller.Settings.LogOut = RBLogOut.Checked;
            Rarekiller.Settings.JustAlert = RBJustAlert.Checked;
            Rarekiller.Settings.Message1 = TBMessage1.Text;
            Rarekiller.Settings.Message2 = TBMessage2.Text;
            Rarekiller.Settings.PlayerFollows = CBPlayerFollow.Checked;
            Rarekiller.Settings.PlayerFollowsLogout = CBPlayerFollowLogout.Checked;
            Rarekiller.Settings.PlayerFollowsTime = TBPlayerFollows.Text;
            Rarekiller.Settings.ContinentChange = CBContinentChange.Checked;
            Rarekiller.Settings.LootSuccess = CBLootSuccess.Checked;
            //Screenshot
            Rarekiller.Settings.ScreenAeonaxx = CBScreenAeonaxx.Checked;
            Rarekiller.Settings.ScreenCamel = CBScreenCamel.Checked;
            Rarekiller.Settings.ScreenRarekiller = CBScreenRarekiller.Checked;
            Rarekiller.Settings.ScreenTamer = CBScreenTamer.Checked;
            Rarekiller.Settings.ScreenFound = CBScreenFound.Checked;
            Rarekiller.Settings.ScreenSuccess = CBScreenSuccess.Checked;
            //Developer Box
            Rarekiller.Settings.TestRaptorNest = CBTestRaptorNest.Checked;
            Rarekiller.Settings.TestFigurineInteract = CBTestCamel.Checked;
            Rarekiller.Settings.TestKillDormus = CBTestDormus.Checked;
            Rarekiller.Settings.TestMountAeonaxx = CBTestAeonaxx.Checked;
            Rarekiller.Settings.TestWelpTargeting = CBTestWelpTargeting.Checked;
            Rarekiller.Settings.TestShootMob = CBTestShootDown.Checked;
            Rarekiller.Settings.TestLogoutItem = CBTestLogoutItem.Checked;

            // Rarekiller
            Logging.WriteDebug("Rarekiller Save: CATA = {0}", CBCata.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: WOTLK = {0}", CBWotlk.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: BC = {0}", CBBC.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: LowRare = {0}", CBLowRAR.Checked.ToString());
            // Mount Rares
            Logging.WriteDebug("Rarekiller Save: TLPD = {0}", CBTLPD.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Poseidus = {0}", CBPoseidus.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Aeonaxx = {0}", CBAeonaxx.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Testcase Rota Aeonaxx = {0}", CBTestKillAeonaxx.Checked.ToString());
            // Collector
            Logging.WriteDebug("Rarekiller Save: Camel = {0}", CBCamel.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: CollectOnce = {0}", CBCollect.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Dormus = {0}", CBDormus.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: RaptorNest = {0}", CBRaptorNest.Checked.ToString());
            // Problem Mobs
            Logging.WriteDebug("Rarekiller Save: Vyragosa = {0}", CBVyragosa.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ShotVyra = {0}", CBShotVyra.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Blazewing = {0}", CBBlazewing.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: BloodseekerSearch = {0}", CBBloodseekerSearch.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: BloodseekerKill = {0}", CBBloodseekerKill.Checked.ToString());
            // Hunt by ID
            Logging.WriteDebug("Rarekiller Save: HuntByID = {0}", CBHuntByID.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: MobID = {0}", TBHuntByID.Text.ToString());
            // Tamer
            Logging.WriteDebug("Rarekiller Save: TameDefault = {0}", CBTameDefault.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: TameByID = {0}", CBTameByID.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: NotKillTameable = {0}", CBNotKillTameable.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: TameID = {0}", TBTameID.Text.ToString());
            // Pullspell
            Logging.WriteDebug("Rarekiller Save: DefaultPull = {0}", CBPull.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Spell = {0}", TBPull.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: Range = {0}", TBRange.Text.ToString());
            // Slowfall
            Logging.WriteDebug("Rarekiller Save: UseSlowfall = {0}", CBUseSlowfall.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Cloak = {0}", RBCloak.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: UseSlowfallItem = {0}", CBItem.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: SlowfallItem = {0}", TBSlowfallItem.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: UseSlowfallSpell = {0}", CBSpell.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: SlowfallSpell = {0}", TBSlowfallSpell.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: Falltimer = {0}", TBFalltimer.Text.ToString());
            // Miscs
            Logging.WriteDebug("Rarekiller Save: BlacklistCheck = {0}", CBBlacklistCheck.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: BlacklistTime = {0}", TBBlacklistTime.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: ZoneSafe = {0}", CBZoneSave.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: GroundmountMode = {0}", CBGroundMount.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: MoveAround = {0}", CBKeyer.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: DontKillTagged = {0}", CBTagged.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: BlacklistTagged = {0}", CBBlacklistTagged.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: WinnerTagged = {0}", CBWinnerTagged.Checked.ToString());
            // Screenshot
            Logging.WriteDebug("Rarekiller Save: ScreenAeonaxx = {0}", CBScreenAeonaxx.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ScreenCamel = {0}", CBScreenCamel.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ScreenRarekiller = {0}", CBScreenRarekiller.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ScreenTamer = {0}", CBScreenTamer.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ScreenFound = {0}", CBScreenFound.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: ScreenSuccess = {0}", CBScreenSuccess.Checked.ToString());
            // Alerts
            Logging.WriteDebug("Rarekiller Save: Alert = {0}", CBAlert.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Wisper = {0}", CBWisper.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Guild = {0}", CBGuild.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: FileWisper = {0}", TBSoundfileWisper.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: FileGuild = {0}", TBSoundfileGuild.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: FileFound = {0}", TBSoundfileFoundRare.Text.ToString());
            // Security
            Logging.WriteDebug("Rarekiller Save: ContinentChange = {0}", CBContinentChange.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: JustAlert = {0}", RBJustAlert.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: KillWoW = {0}", RBKillWoW.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: LogOut = {0}", RBLogOut.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: Message1 = {0}", TBMessage1.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: Message2 = {0}", TBMessage2.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: PlayerFollowedHeart = {0}", CBPlayerFollow.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: PlayerFollowLogout = {0}", CBPlayerFollowLogout.Checked.ToString());
            Logging.WriteDebug("Rarekiller Save: PlayerFollowsTime = {0}", TBPlayerFollows.Text.ToString());
            Logging.WriteDebug("Rarekiller Save: LootSuccess = {0}", CBLootSuccess.Checked.ToString());

            // ---------- Save ----------------------------

            string sPath = Path.Combine(Rarekiller.FolderPath, "config\\");

            if (!Directory.Exists(sPath))
            {
                Logging.WriteDebug("Rarekiller: Creating config directory");
                Directory.CreateDirectory(sPath);
            }

            sPath = Path.Combine(sPath, "Rarekiller.config");

            Logging.WriteDebug("Rarekiller: Saving config file: {0}", sPath);
            Logging.Write("Rarekiller: Settings Saved");
            xml = new XmlDocument();
            XmlDeclaration dc = xml.CreateXmlDeclaration("1.0", "utf-8", null);
            xml.AppendChild(dc);

            xmlComment = xml.CreateComment(
                "=======================================================================\n" +
                ".CONFIG  -  This is the Config File For Rarekiller\n\n" +
                "XML file containing settings to customize in the Rarekiller Plugin\n" +
                "It is STRONGLY recommended you use the Configuration UI to change this\n" +
                "file instead of direct changein it here.\n" +
                "========================================================================");

            //let's add the root element
            root = xml.CreateElement("Rarekiller");
            root.AppendChild(xmlComment);

            //Rarekiller
            //let's add another element (child of the root)
            element = xml.CreateElement("CATA");
            text = xml.CreateTextNode(CBCata.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("WOTLK");
            text = xml.CreateTextNode(CBWotlk.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BC");
            text = xml.CreateTextNode(CBBC.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("LowRAR");
            text = xml.CreateTextNode(CBLowRAR.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Rare Mounts
            //let's add another element (child of the root)
            element = xml.CreateElement("TLPD");
            text = xml.CreateTextNode(CBTLPD.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Poseidus");
            text = xml.CreateTextNode(CBPoseidus.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Aeonaxx");
            text = xml.CreateTextNode(CBAeonaxx.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("AeonaxxTestcaseTrainingDummy");
            text = xml.CreateTextNode(CBTestKillAeonaxx.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Collector
            //let's add another element (child of the root)
            element = xml.CreateElement("Camel");
            text = xml.CreateTextNode(CBCamel.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Collect");
            text = xml.CreateTextNode(CBCollect.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Dormus");
            text = xml.CreateTextNode(CBDormus.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("RaptorNest");
            text = xml.CreateTextNode(CBRaptorNest.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Problem Mobs
            //let's add another element (child of the root)
            element = xml.CreateElement("Blazewing");
            text = xml.CreateTextNode(CBBlazewing.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Vyragosa");
            text = xml.CreateTextNode(CBVyragosa.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ShootVyra");
            text = xml.CreateTextNode(CBShotVyra.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BloodseekerSearch");
            text = xml.CreateTextNode(CBBloodseekerSearch.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BloodseekerKill");
            text = xml.CreateTextNode(CBBloodseekerKill.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Hunt by ID
            //let's add another element (child of the root)
            element = xml.CreateElement("HuntByID");
            text = xml.CreateTextNode(CBHuntByID.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("MobID");
            text = xml.CreateTextNode(TBHuntByID.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Tamer
            //let's add another element (child of the root)
            element = xml.CreateElement("NotKillTameable");
            text = xml.CreateTextNode(CBNotKillTameable.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("TameDefault");
            text = xml.CreateTextNode(CBTameDefault.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("TameByID");
            text = xml.CreateTextNode(CBTameByID.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("TameMobID");
            text = xml.CreateTextNode(TBTameID.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Pullspell
            //let's add another element (child of the root)
            element = xml.CreateElement("DefaultPull");
            text = xml.CreateTextNode(CBPull.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Pull");
            text = xml.CreateTextNode(TBPull.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Range");
            text = xml.CreateTextNode(TBRange.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Slowfall
            //let's add another element (child of the root)
            element = xml.CreateElement("UseSlowfall");
            text = xml.CreateTextNode(CBUseSlowfall.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Spell");
            text = xml.CreateTextNode(CBSpell.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("SlowfallSpell");
            text = xml.CreateTextNode(TBSlowfallSpell.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Cloak");
            text = xml.CreateTextNode(RBCloak.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Item");
            text = xml.CreateTextNode(CBItem.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("SlowfallItem");
            text = xml.CreateTextNode(TBSlowfallItem.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Falltimer");
            text = xml.CreateTextNode(TBFalltimer.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Miscs
            //let's add another element (child of the root)
            element = xml.CreateElement("GroundMountMode");
            text = xml.CreateTextNode(CBGroundMount.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Keyer");
            text = xml.CreateTextNode(CBKeyer.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Tagged
            //let's add another element (child of the root)
            element = xml.CreateElement("DontKillTagged");
            text = xml.CreateTextNode(CBTagged.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BlacklistTagged");
            text = xml.CreateTextNode(CBBlacklistTagged.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("WinnerTagged");
            text = xml.CreateTextNode(CBWinnerTagged.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Blacklist Mobs
            //let's add another element (child of the root)
            element = xml.CreateElement("ZoneSave");
            text = xml.CreateTextNode(CBZoneSave.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BlacklistCheck");
            text = xml.CreateTextNode(CBBlacklistCheck.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("BlacklistTime");
            text = xml.CreateTextNode(TBBlacklistTime.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Screens
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenAeonaxx");
            text = xml.CreateTextNode(CBScreenAeonaxx.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenCamel");
            text = xml.CreateTextNode(CBScreenCamel.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenRarekiller");
            text = xml.CreateTextNode(CBScreenRarekiller.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenTamer");
            text = xml.CreateTextNode(CBScreenTamer.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenFound");
            text = xml.CreateTextNode(CBScreenFound.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("ScreenSuccess");
            text = xml.CreateTextNode(CBScreenSuccess.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Alerts
            //let's add another element (child of the root)
            element = xml.CreateElement("Alert");
            text = xml.CreateTextNode(CBAlert.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Wisper");
            text = xml.CreateTextNode(CBWisper.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("GuildChat");
            text = xml.CreateTextNode(CBGuild.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("SoundfileFoundRare");
            text = xml.CreateTextNode(TBSoundfileFoundRare.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("SoundfileWisper");
            text = xml.CreateTextNode(TBSoundfileWisper.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("SoundfileGuild");
            text = xml.CreateTextNode(TBSoundfileGuild.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            //Security
            //let's add another element (child of the root)
            element = xml.CreateElement("ContinentChange");
            text = xml.CreateTextNode(CBContinentChange.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("KillWoW");
            text = xml.CreateTextNode(RBKillWoW.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("JustAlert");
            text = xml.CreateTextNode(RBJustAlert.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("LogOut");
            text = xml.CreateTextNode(RBLogOut.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Message1");
            text = xml.CreateTextNode(TBMessage1.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("Message2");
            text = xml.CreateTextNode(TBMessage2.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("PlayerFollows");
            text = xml.CreateTextNode(CBPlayerFollow.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("PlayerFollowsLogout");
            text = xml.CreateTextNode(CBPlayerFollowLogout.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("PlayerFollowsTime");
            text = xml.CreateTextNode(TBPlayerFollows.Text.ToString());
            element.AppendChild(text);
            root.AppendChild(element);
            //let's add another element (child of the root)
            element = xml.CreateElement("LootSuccess");
            text = xml.CreateTextNode(CBLootSuccess.Checked.ToString());
            element.AppendChild(text);
            root.AppendChild(element);

            xml.AppendChild(root);

            System.IO.FileStream fs = new System.IO.FileStream(@sPath, System.IO.FileMode.Create,
                                                               System.IO.FileAccess.Write);
            try
            {
                xml.Save(fs);
                fs.Close();
            }
            catch (Exception np)
            {
                Logging.Write(System.Drawing.Color.Red, np.Message);
            }
        }
Beispiel #26
0
        private CacheInfo TrySaveToDisk(XmlDocument doc, string url, DateTime utcExpiry)
        {
            string fileName = null;

            if (_directoryOnDisk != null)
            {
                XmlComment comment = doc.CreateComment(string.Format(CultureInfo.InvariantCulture, "{0}@{1}", utcExpiry.ToBinary(), url));
                doc.InsertBefore(comment, doc.DocumentElement);

                fileName = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}_{1:x8}.feed",
                    GetTempFileNamePrefixFromUrl(url),
                    Guid.NewGuid().GetHashCode());

                try
                {
                    doc.Save(Path.Combine(_directoryOnDisk, fileName));
                }
                catch
                {
                    // can't save to disk - not a problem
                    fileName = null;
                }
            }

            return new CacheInfo(doc, utcExpiry, fileName);
        }
Beispiel #27
0
        string addCheckSum(string xmlFileName, string chksum)
        {
            XmlDocument xmlDoc = new XmlDocument();

              xmlDoc.Load(xmlFileName);

              XmlComment chkSumComment;
              chkSumComment = xmlDoc.CreateComment("Checksum:" + chksum);

              XmlElement root = xmlDoc.DocumentElement;
              xmlDoc.InsertAfter(chkSumComment, root);
              xmlDoc.Save(xmlFileName);
              return chksum;
        }
Beispiel #28
0
        /// <summary>
        /// return an Xml document containing camera calibration parameters
        /// </summary>
        /// <param name="device_name"></param>
        /// <param name="focal_length_pixels"></param>
        /// <param name="baseline_mm"></param>
        /// <param name="fov_degrees"></param>
        /// <param name="image_width"></param>
        /// <param name="image_height"></param>
        /// <param name="lens_distortion_curve"></param>
        /// <param name="centre_of_distortion_x"></param>
        /// <param name="centre_of_distortion_y"></param>
        /// <param name="rotation"></param>
        /// <param name="scale"></param>
        /// <param name="lens_distortion_image_filename"></param>
        /// <param name="curve_fit_image_filename"></param>
        /// <param name="offset_x"></param>
        /// <param name="offset_y"></param>
        /// <param name="pan_curve"></param>
        /// <param name="pan_offset_x"></param>
        /// <param name="pan_offset_y"></param>
        /// <param name="tilt_curve"></param>
        /// <param name="tilt_offset_x"></param>
        /// <param name="tilt_offset_y"></param>
        /// <returns></returns>
        private static XmlDocument getXmlDocument(
            string device_name,
            float focal_length_pixels,
            float baseline_mm,
            float fov_degrees,
            int image_width, int image_height,
            polynomial[] lens_distortion_curve,
            double[] centre_of_distortion_x, double[] centre_of_distortion_y,
            double[] rotation, double[] scale,
            string[] lens_distortion_image_filename,
            string[] curve_fit_image_filename,
            float offset_x, float offset_y,
            polynomial pan_curve, float pan_offset_x, float pan_offset_y,
            polynomial tilt_curve, float tilt_offset_x, float tilt_offset_y)
        {
            // Create the document.
            XmlDocument doc = new XmlDocument();

            // Insert the xml processing instruction and the root node
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);
            doc.PrependChild(dec);

            XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System");
            doc.AppendChild(commentnode);

            XmlElement nodeCalibration = doc.CreateElement("Sentience");
            doc.AppendChild(nodeCalibration);

            xml.AddComment(doc, nodeCalibration, "Sentience");

            XmlElement elem = getXml(doc, nodeCalibration,
                device_name,
                focal_length_pixels,
                baseline_mm,
                fov_degrees,
                image_width, image_height,
                lens_distortion_curve,
                centre_of_distortion_x, centre_of_distortion_y,
                rotation, scale,
                lens_distortion_image_filename,
                curve_fit_image_filename,
                offset_x, offset_y,
                pan_curve, pan_offset_x, pan_offset_y,
                tilt_curve, tilt_offset_x, tilt_offset_y);
            doc.DocumentElement.AppendChild(elem);

            return (doc);
        }
Beispiel #29
0
        /// <summary>
        /// Сохранить настройки приложения в файле
        /// </summary>
        public bool Save(string fileName, out string errMsg)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();

                XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmlDoc.AppendChild(xmlDecl);

                XmlElement rootElem = xmlDoc.CreateElement("ScadaCommSvcConfig");
                xmlDoc.AppendChild(rootElem);

                // Общие параметры
                rootElem.AppendChild(xmlDoc.CreateComment(
                    Localization.UseRussian ? "Общие параметры" : "Common Parameters"));
                XmlElement paramsElem = xmlDoc.CreateElement("CommonParams");
                rootElem.AppendChild(paramsElem);
                paramsElem.AppendParamElem("ServerUse", Params.ServerUse,
                    "Использовать SCADA-Сервер", "Use SCADA-Server");
                paramsElem.AppendParamElem("ServerHost", Params.ServerHost,
                    "Имя компьютера или IP-адрес SCADA-Сервера", "SCADA-Server host or IP address");
                paramsElem.AppendParamElem("ServerPort", Params.ServerPort,
                    "Номер TCP-порта SCADA-Сервера", "SCADA-Server TCP port number");
                paramsElem.AppendParamElem("ServerUser", Params.ServerUser,
                    "Имя пользователя для подключения к SCADA-Серверу",
                    "User name for the connection to SCADA-Server");
                paramsElem.AppendParamElem("ServerPwd", Params.ServerPwd,
                    "Пароль пользователя для подключения к SCADA-Серверу",
                    "User password for the connection to SCADA-Server");
                paramsElem.AppendParamElem("ServerTimeout", Params.ServerTimeout,
                    "Таймаут ожидания ответа SCADA-Сервера, мс", "SCADA-Server response timeout, ms");
                paramsElem.AppendParamElem("WaitForStop", Params.WaitForStop,
                    "Ожидание остановки линий связи, мс", "Waiting for the communication lines temrination, ms");
                paramsElem.AppendParamElem("RefrParams", Params.RefrParams,
                    "Период передачи всех данных КП, с", "Sending all device data period, sec");

                // Линии связи
                rootElem.AppendChild(xmlDoc.CreateComment(
                    Localization.UseRussian ? "Линии связи" : "Communication Lines"));
                XmlElement linesElem = xmlDoc.CreateElement("CommLines");
                rootElem.AppendChild(linesElem);

                foreach (CommLine commLine in CommLines)
                {
                    linesElem.AppendChild(xmlDoc.CreateComment(
                        (Localization.UseRussian ? "Линия " : "Line ") + commLine.Number));

                    // соединение
                    XmlElement lineElem = xmlDoc.CreateElement("CommLine");
                    lineElem.SetAttribute("active", commLine.Active);
                    lineElem.SetAttribute("bind", commLine.Bind);
                    lineElem.SetAttribute("number", commLine.Number);
                    lineElem.SetAttribute("name", commLine.Name);
                    linesElem.AppendChild(lineElem);

                    XmlElement connElem = xmlDoc.CreateElement("Connection");
                    lineElem.AppendChild(connElem);

                    XmlElement connTypeElem = xmlDoc.CreateElement("ConnType");
                    connTypeElem.SetAttribute("value", commLine.ConnType);
                    connTypeElem.SetAttribute("descr", Localization.UseRussian ?
                        "Тип подключения: ComPort или None" : "Connection type: ComPort or None");
                    connElem.AppendChild(connTypeElem);

                    XmlElement portElem = xmlDoc.CreateElement("ComPortSettings");
                    portElem.SetAttribute("portName", commLine.PortName);
                    portElem.SetAttribute("baudRate", commLine.BaudRate);
                    portElem.SetAttribute("dataBits", commLine.DataBits);
                    portElem.SetAttribute("parity", commLine.Parity);
                    portElem.SetAttribute("stopBits", commLine.StopBits);
                    portElem.SetAttribute("dtrEnable", commLine.DtrEnable);
                    portElem.SetAttribute("rtsEnable", commLine.RtsEnable);
                    connElem.AppendChild(portElem);

                    // параметры
                    paramsElem = xmlDoc.CreateElement("LineParams");
                    lineElem.AppendChild(paramsElem);
                    paramsElem.AppendParamElem("ReqTriesCnt", commLine.ReqTriesCnt,
                        "Количество попыток перезапроса КП при ошибке", "Device request retries count on error");
                    paramsElem.AppendParamElem("CycleDelay", commLine.CycleDelay,
                        "Задержка после цикла опроса, мс", "Delay after request cycle, ms");
                    paramsElem.AppendParamElem("MaxCommErrCnt", commLine.MaxCommErrCnt,
                        "Количество неудачных сеансов связи до объявления КП неработающим",
                        "Failed session count for setting device error state");
                    paramsElem.AppendParamElem("CmdEnabled", commLine.CmdEnabled,
                        "Команды ТУ разрешены", "Commands enabled");

                    // пользовательские параметры
                    paramsElem = xmlDoc.CreateElement("UserParams");
                    lineElem.AppendChild(paramsElem);
                    foreach (UserParam param in commLine.UserParams)
                        paramsElem.AppendParamElem(param.Name, param.Value, param.Descr);

                    // последовательность опроса
                    XmlElement reqSeqElem = xmlDoc.CreateElement("ReqSequence");
                    lineElem.AppendChild(reqSeqElem);

                    foreach (KP kp in commLine.ReqSequence)
                    {
                        XmlElement kpElem = xmlDoc.CreateElement("KP");
                        kpElem.SetAttribute("active", kp.Active);
                        kpElem.SetAttribute("bind", kp.Bind);
                        kpElem.SetAttribute("number", kp.Number);
                        kpElem.SetAttribute("name", kp.Name);
                        kpElem.SetAttribute("dll", kp.Dll);
                        kpElem.SetAttribute("address", kp.Address);
                        kpElem.SetAttribute("callNum", kp.CallNum);
                        kpElem.SetAttribute("timeout", kp.Timeout);
                        kpElem.SetAttribute("delay", kp.Delay);
                        kpElem.SetAttribute("time", kp.Time.ToString("T", DateTimeFormatInfo.InvariantInfo));
                        kpElem.SetAttribute("period", kp.Period);
                        kpElem.SetAttribute("cmdLine", kp.CmdLine);
                        reqSeqElem.AppendChild(kpElem);
                    }
                }

                // сохранение XML-документа в файле
                string bakName = fileName + ".bak";
                File.Copy(fileName, bakName, true);
                xmlDoc.Save(fileName);

                errMsg = "";
                return true;
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.SaveAppSettingsError + ":\r\n" + ex.Message;
                return false;
            }
        }
Beispiel #30
0
        /// <summary>
		/// This method will save the collection to the file specified
		/// </summary>
		/// <param name="fileName">File that will contain the data</param>
		/// <returns>True if successful</returns>
		public bool Save( string fileName, string encoding )
		{
			bool res = false;
			if (fileName == null || encoding == null)
			{
				throw ( new ArgumentException( Workshare.Reports.Properties.Resources.CANNOTSAVE ) );
			}
			// Check that the file can be saved to
			if (CheckFile( fileName ))
			{
				XmlDocument xmlDoc = new XmlDocument();
				try
				{
					XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration( "1.0", encoding, "no" );                    
                    StringBuilder cmt = new StringBuilder();
					cmt.AppendFormat( Workshare.Reports.Properties.Resources.COMMENT1, DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString() );
					XmlComment xmlCmt1 = xmlDoc.CreateComment( cmt.ToString() );
					XmlNode xmlRoot = xmlDoc.ImportNode( Node, true );
                    XmlSchemaSet xss = new XmlSchemaSet();
                    StringBuilder xsd = new StringBuilder();
                    xsd.AppendFormat("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory,
                        (AppDomain.CurrentDomain.BaseDirectory.EndsWith("\\") ? "" : "\\"),
                        "TraceScan.xsd");
                    xss.Add("urn:www.workshare.com/trace/1.0", xsd.ToString());
                    xmlDoc.Schemas.Add(xss);                    
					xmlDoc.InsertBefore( xmlDec, xmlDoc.DocumentElement );
					xmlDoc.InsertAfter( xmlCmt1, xmlDec );
					xmlDoc.InsertAfter( xmlRoot, xmlCmt1 );
					xmlDoc.Save( fileName );
                    m_scanSaved = true;
					res = true;
				}
				catch (XmlException e)
				{
					StringBuilder sb = new StringBuilder();
					sb.AppendFormat( Workshare.Reports.Properties.Resources.XMLERROR, Environment.NewLine, e.Message );
					throw ( new InvalidOperationException( sb.ToString() ) );
				}
			}
			return res;
		}
Beispiel #31
0
        private void btnDump_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Multiselect = true;
            DialogResult msgFileSelectResult = this.openFileDialog1.ShowDialog();

            if (msgFileSelectResult == DialogResult.OK)
            {
                string targetFolder = this.openFileDialog1.FileNames[0];
                targetFolder = System.IO.Directory.GetParent(targetFolder).FullName;
                foreach (string msgfile in this.openFileDialog1.FileNames)
                {
                    bool   attachGenerated = false;
                    string fileName        = null;
                    using (Stream messageStream = File.Open(msgfile, FileMode.Open, FileAccess.Read))
                    {
                        fileName = string.Empty;
                        OutlookStorage.Message message = new OutlookStorage.Message(messageStream);
                        messageStream.Close();
                        try
                        {
                            //获取comment#
                            //Comment has been added as: 34227
                            string comment = null;
                            string body    = message.BodyText;
                            comment = body.Substring(body.IndexOf("Comment has been added as:") + 26).Trim();
                            //Insurer: Aggressive Insurance Texas Elite
                            string insurer = null;
                            string state   = null;
                            string title   = message.Subject;
                            if (title.Contains("Reminder Email for debugging purpose"))
                            {
                                //CarrierName: Progressive Auto
                                insurer = ExtractHtml(body, "CarrierName:", "\r\n");
                                if (string.IsNullOrEmpty(insurer))
                                {
                                    throw new Exception("Failed to extract CarrierName");
                                }
                                insurer = insurer.Trim().Split(' ')[0];
                                //Quoting State: VT
                                state = body.Substring(body.IndexOf("Quoting State:") + 14).Trim();
                                state = state.Substring(0, state.IndexOf("\r\n"));
                            }
                            else
                            {
                                //insurer = body.Substring(body.IndexOf("Insurer:")+8).Trim();
                                //insurer = insurer.Substring(0, insurer.IndexOf("\r\n"));
                                //insurer = insurer.Substring(0, insurer.IndexOf(" "));
                                //qpquote\stdInsurers\HartfordScrape.vb
                                insurer = body.Substring(body.LastIndexOf("qpquote\\stdInsurers\\") + 20);
                                if (insurer.Contains(".vb"))
                                {
                                    insurer = insurer.Substring(0, insurer.IndexOf(".vb"));
                                    if (insurer.Contains("Scrape"))
                                    {
                                        //insurer = insurer.Replace("Scrape", "");
                                        insurer = insurer.Substring(0, insurer.IndexOf("Scrape"));
                                    }
                                }
                                else
                                {
                                    //Insurer: Progressive Insurance Company
                                    insurer = ExtractHtml(insurer, "Insurer:", "Insurer Web Login:"******"Failed to extract Insurer Company Name");
                                    }
                                    insurer = insurer.Trim().Split(' ')[0];
                                }
                                //State Quoted: MA

                                state = body.Substring(body.IndexOf("State Quoted:") + 13).Trim();
                                state = state.Substring(0, state.IndexOf("\r\n"));
                            }
                            //2017-08-10,iimax:state rule changed
                            if (state.StartsWith("State"))
                            {
                                state = state.Substring(5);
                            }
                            fileName = string.Format("#{0}-{1} ({2}).txt", comment, insurer, state);
                            //附件
                            if (message.Attachments.Count > 0)
                            {
                                OutlookStorage.Attachment file = message.Attachments[0];
                                string fileContent             = System.Text.Encoding.UTF8.GetString(file.Data);
                                //2016-06-29:修改last name为 testing,修改 effdate
                                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                                doc.PreserveWhitespace = true;
                                doc.LoadXml(fileContent);
                                if (fileContent.Contains("<AutoQuote>"))
                                {
                                    var CusLastName = doc.DocumentElement.SelectSingleNode("/AutoQuote/Quotation/CusLastName");
                                    if (CusLastName != null)
                                    {
                                        //Create a comment.
                                        XmlComment newComment = doc.CreateComment(CusLastName.OuterXml);
                                        CusLastName.ParentNode.InsertAfter(newComment, CusLastName);
                                        CusLastName.InnerText = "Testing";
                                    }
                                    var EffDate = doc.DocumentElement.SelectSingleNode("/AutoQuote/Quotation/EffDate");
                                    if (EffDate != null)
                                    {
                                        string   eff = EffDate.InnerText;
                                        DateTime dt  = DateTime.Today;
                                        DateTime.TryParse(eff, out dt);
                                        if (dt < DateTime.Today)
                                        {
                                            XmlComment newComment = doc.CreateComment(EffDate.OuterXml);
                                            EffDate.ParentNode.InsertAfter(newComment, EffDate);
                                            EffDate.InnerText = DateTime.Today.ToString("MM/dd/yyyy");
                                        }
                                    }
                                    var drivers = doc.DocumentElement.SelectNodes("/AutoQuote/Quotation/Drivers/Driver");
                                    if (drivers != null)
                                    {
                                        foreach (XmlNode item in drivers)
                                        {
                                            var LastName = item.SelectSingleNode("LastName");
                                            if (LastName != null)
                                            {
                                                XmlComment newComment = doc.CreateComment(LastName.OuterXml);
                                                LastName.ParentNode.InsertAfter(newComment, LastName);
                                                LastName.InnerText = "Testing";
                                            }
                                        }
                                    }
                                }
                                else if (fileContent.Contains("<HomeQuote>"))
                                {
                                    var CusLastName = doc.DocumentElement.SelectSingleNode("/HomeQuote/InsuredInfo/CusLastName");
                                    if (CusLastName != null)
                                    {
                                        //Create a comment.
                                        XmlComment newComment = doc.CreateComment(CusLastName.OuterXml);
                                        CusLastName.ParentNode.InsertAfter(newComment, CusLastName);
                                        CusLastName.InnerText = "Testing";
                                    }
                                    var hEffDate = doc.DocumentElement.SelectSingleNode("/HomeQuote/InsuredInfo/hEffDate");
                                    if (hEffDate != null)
                                    {
                                        string   eff = hEffDate.InnerText;
                                        DateTime dt  = DateTime.Today;
                                        if (DateTime.TryParse(eff, out dt))
                                        {
                                        }
                                        if (dt < DateTime.Today)
                                        {
                                            XmlComment newComment = doc.CreateComment(hEffDate.OuterXml);
                                            hEffDate.ParentNode.InsertAfter(newComment, hEffDate);
                                            hEffDate.InnerText = DateTime.Today.ToString("MM/dd/yyyy");

                                            var hExpDate = doc.DocumentElement.SelectSingleNode("/HomeQuote/InsuredInfo/hExpDate");
                                            if (hExpDate != null)
                                            {
                                                XmlComment hExpDateComment = doc.CreateComment(hExpDate.OuterXml);
                                                hExpDate.ParentNode.InsertAfter(hExpDateComment, hExpDate);
                                                hExpDate.InnerText = DateTime.Today.AddYears(1).ToString("MM/dd/yyyy");
                                            }
                                            //修改 RiskInfo
                                            var EffDate = doc.DocumentElement.SelectSingleNode("/HomeQuote/RiskInfo/ThisRisk/EffDate");
                                            var ExpDate = doc.DocumentElement.SelectSingleNode("/HomeQuote/RiskInfo/ThisRisk/ExpDate");
                                            if (EffDate != null)
                                            {
                                                XmlComment xComment = doc.CreateComment(EffDate.OuterXml);
                                                EffDate.ParentNode.InsertAfter(xComment, EffDate);
                                                EffDate.InnerText = DateTime.Today.ToString("MM/dd/yyyy");
                                            }

                                            if (ExpDate != null)
                                            {
                                                XmlComment xComment = doc.CreateComment(ExpDate.OuterXml);
                                                ExpDate.ParentNode.InsertAfter(xComment, ExpDate);
                                                ExpDate.InnerText = DateTime.Today.AddYears(1).ToString("MM/dd/yyyy");
                                            }
                                        }
                                    }
                                }
                                fileContent = doc.OuterXml;
                                System.IO.File.WriteAllText(Path.Combine(targetFolder, fileName), fileContent);
                            }
                            attachGenerated = true;
                            //MessageBox.Show(fileName);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        finally
                        {
                            message.Dispose();
                        }

                        if (attachGenerated)
                        {
                            //重命名msg
                            FileInfo fi = new FileInfo(msgfile);
                            //目标文件名
                            string msgfileName = fi.Name;
                            string ourfileName = fi.Name.Replace(".msg", string.Format("{0}.msg", fileName));
                            ourfileName = ourfileName.Replace("comment#", "#").Replace(".txt.", ".");
                            System.IO.File.Move(msgfile, Path.Combine(fi.DirectoryName, ourfileName));
                        }
                    }
                }
            }
        }
        private XmlNode LoadNode(bool skipOverWhitespace)
        {
            XmlReader      r      = this.reader;
            XmlNode        parent = null;
            XmlElement     element;
            IXmlSchemaInfo schemaInfo;

            do
            {
                XmlNode node = null;
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    bool fEmptyElement = r.IsEmptyElement;
                    element         = doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI);
                    element.IsEmpty = fEmptyElement;

                    if (r.MoveToFirstAttribute())
                    {
                        XmlAttributeCollection attributes = element.Attributes;
                        do
                        {
                            XmlAttribute attr = LoadAttributeNode();
                            attributes.Append(attr);       // special case for load
                        }while(r.MoveToNextAttribute());
                        r.MoveToElement();
                    }

                    // recursively load all children.
                    if (!fEmptyElement)
                    {
                        if (parent != null)
                        {
                            parent.AppendChildForLoad(element, doc);
                        }
                        parent = element;
                        continue;
                    }
                    else
                    {
                        schemaInfo = r.SchemaInfo;
                        if (schemaInfo != null)
                        {
                            element.XmlName = doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                        }
                        node = element;
                        break;
                    }

                case XmlNodeType.EndElement:
                    if (parent == null)
                    {
                        return(null);
                    }
                    Debug.Assert(parent.NodeType == XmlNodeType.Element);
                    schemaInfo = r.SchemaInfo;
                    if (schemaInfo != null)
                    {
                        element = parent as XmlElement;
                        if (element != null)
                        {
                            element.XmlName = doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
                        }
                    }
                    if (parent.ParentNode == null)
                    {
                        return(parent);
                    }
                    parent = parent.ParentNode;
                    continue;

                case XmlNodeType.EntityReference:
                    node = LoadEntityReferenceNode(false);
                    break;

                case XmlNodeType.EndEntity:
                    Debug.Assert(parent == null);
                    return(null);

                case XmlNodeType.Attribute:
                    node = LoadAttributeNode();
                    break;

                case XmlNodeType.Text:
                    node = doc.CreateTextNode(r.Value);
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = doc.CreateSignificantWhitespace(r.Value);
                    break;

                case XmlNodeType.Whitespace:
                    if (preserveWhitespace)
                    {
                        node = doc.CreateWhitespace(r.Value);
                        break;
                    }
                    else if (parent == null && !skipOverWhitespace)
                    {
                        // if called from LoadEntityReferenceNode, just return null
                        return(null);
                    }
                    else
                    {
                        continue;
                    }

                case XmlNodeType.CDATA:
                    node = doc.CreateCDataSection(r.Value);
                    break;


                case XmlNodeType.XmlDeclaration:
                    node = LoadDeclarationNode();
                    break;

                case XmlNodeType.ProcessingInstruction:
                    node = doc.CreateProcessingInstruction(r.Name, r.Value);
                    break;

                case XmlNodeType.Comment:
                    node = doc.CreateComment(r.Value);
                    break;

                case XmlNodeType.DocumentType:
                    node = LoadDocumentTypeNode();
                    break;

                default:
                    throw UnexpectedNodeType(r.NodeType);
                }

                Debug.Assert(node != null);
                if (parent != null)
                {
                    parent.AppendChildForLoad(node, doc);
                }
                else
                {
                    return(node);
                }
            }while (r.Read());

            return(null);
        }
Beispiel #33
0
    //
    //createListElement
    //
    private static void createListElement(
        ref System.Xml.XmlDocument pdoc,
        string pname,
        string pcore,
        System.Collections.Generic.List <pvMetadata.ListtemplateContenttype> ptypestable,
        System.Collections.Generic.List <pvMetadata.ListtemplateColumn> pfieldstable)
    {
        //
        // Insert ContentTypeRef
        //
        System.Xml.XmlNode contenttypes = pdoc.SelectSingleNode("//mha:List/mha:MetaData/mha:ContentTypes", s_nsMgr);
        foreach (ListtemplateContenttype typ in ptypestable)
        {
            string ContentTypeID;
            switch (typ.BasedOn)
            {
            case "Element":
                ContentTypeID = "0x01" + "00" + typ.typeGUID;
                break;

            case "Annoncering":
                ContentTypeID = "0x0104" + "00" + typ.typeGUID;
                break;

            case "Hyperlink":
                ContentTypeID = "0x0105" + "00" + typ.typeGUID;
                break;

            case "'Kontaktperson":
                ContentTypeID = "0x0106" + "00" + typ.typeGUID;
                break;

            case "'Meddelelse":
                ContentTypeID = "0x0107" + "00" + typ.typeGUID;
                break;

            case "'Opgave":
                ContentTypeID = "0x0108" + "00" + typ.typeGUID;
                break;

            case "'Problem":
                ContentTypeID = "0x0103" + "00" + typ.typeGUID;
                break;

            default:
                ContentTypeID = "Error" + "00" + typ.typeGUID;
                break;
            }

            System.Xml.XmlElement contenttyperef      = pdoc.CreateElement("", "ContentTypeRef", s_ns);
            System.Xml.XmlComment contenttypescomment = pdoc.CreateComment(typ.SysName);
            contenttyperef.SetAttribute("ID", ContentTypeID);

            System.Xml.XmlNode ContentTypeRef0x01 = pdoc.SelectSingleNode("//mha:List/mha:MetaData/mha:ContentTypes/mha:ContentTypeRef[@ID=\"0x01\"]", s_nsMgr);
            if (ContentTypeRef0x01 == null)
            {
                System.Xml.XmlNode lastContentTypeRef = contenttypes.AppendChild(contenttyperef);
                contenttypes.InsertBefore(contenttypescomment, lastContentTypeRef);
            }
            else
            {
                System.Xml.XmlNode Folder = pdoc.SelectSingleNode("//mha:List/mha:MetaData/mha:ContentTypes/mha:ContentTypeRef[@ID=\"0x01\"]/mha:Folder", s_nsMgr);
                if (Folder != null)
                {
                    System.Xml.XmlNode copyFolder = Folder.CloneNode(true);
                    contenttyperef.AppendChild(copyFolder);
                }
                contenttypes.InsertBefore(contenttypescomment, ContentTypeRef0x01);
                contenttypes.ReplaceChild(contenttyperef, ContentTypeRef0x01);
            }
        }


        System.Collections.Generic.SortedDictionary <string, ListtemplateColumn> scol = new System.Collections.Generic.SortedDictionary <string, ListtemplateColumn>();
        foreach (ListtemplateColumn col in pfieldstable)
        {
            scol.Add(col.Seqnr, col);
        }

        //
        // Insert Field in Fields
        //
        System.Xml.XmlNode fields = pdoc.SelectSingleNode("//mha:List/mha:MetaData/mha:Fields", s_nsMgr);
        foreach (ListtemplateColumn col in scol.Values)
        {
            if (!col.SysCol)
            {
                System.Xml.XmlElement fieldref = pdoc.CreateElement("", "Field", s_ns);
                fieldref.SetAttribute("Name", col.SysName);
                fieldref.SetAttribute("ID", col.colGUID);

                fieldref.SetAttribute("DisplayName", "$Resources:" + pcore + "," + col.SysName + ";");
                switch (col.KolonneType)
                {
                case "Text":
                    fieldref.SetAttribute("Type", "Text");
                    break;

                case "Note":
                    fieldref.SetAttribute("Type", "Note");
                    fieldref.SetAttribute("NumLines", "3");
                    fieldref.SetAttribute("RichText", "TRUE");
                    break;

                case "Choice":
                    fieldref.SetAttribute("Type", "Choice");
                    break;

                case "Number":
                    fieldref.SetAttribute("Type", "Number");
                    fieldref.SetAttribute("Decimals", "0");
                    break;

                case "Percentage":
                    fieldref.SetAttribute("Type", "Number");
                    fieldref.SetAttribute("Percentage", "TRUE");
                    fieldref.SetAttribute("Min", "0");
                    fieldref.SetAttribute("Max", "1");
                    break;

                case "Currency":
                    fieldref.SetAttribute("Type", "Currency");
                    fieldref.SetAttribute("Decimals", "2");
                    break;

                case "DateOnly":
                    fieldref.SetAttribute("Type", "DateTime");
                    fieldref.SetAttribute("Format", "DateOnly");
                    break;

                case "DateTime":
                    fieldref.SetAttribute("Type", "DateTime");
                    break;

                case "Boolean":
                    fieldref.SetAttribute("Type", "Boolean");
                    break;

                case "Counter":
                    fieldref.SetAttribute("Type", "Counter");
                    break;

                case "Picture":
                    fieldref.SetAttribute("Type", "Picture");
                    break;

                case "Hyperlink":
                    fieldref.SetAttribute("Type", "Hyperlink");
                    break;

                default:
                    break;
                }

                fields.AppendChild(fieldref);
            }
        }


        //
        // Insert FieldsRef in ViewFields
        //
        System.Xml.XmlNode viewfields = pdoc.SelectSingleNode("//mha:List/mha:MetaData/mha:Views/mha:View[@BaseViewID=\"1\"]/mha:ViewFields", s_nsMgr);
        foreach (ListtemplateColumn col in scol.Values)
        {
            if (!col.SysCol)
            {
                System.Xml.XmlElement fieldref = pdoc.CreateElement("", "FieldRef", s_ns);
                fieldref.SetAttribute("ID", col.colGUID);
                fieldref.SetAttribute("Name", col.SysName);
                viewfields.AppendChild(fieldref);
            }
        }
    }