Esempio n. 1
0
        public void Save()
        {
            var xmlWriter = new CommonXmlWriter();
            var root      = xmlWriter.CreateRoot("shortcuts");

            ShortcutKeies.ForEach((key, value) => root.Append(xmlWriter.CreateElement("shortcut", CreateAttributeInfo(value))));

            xmlWriter.Write(xmlPath, root);
        }
Esempio n. 2
0
        public void Write(Stream stream)
        {
            var writer         = new CommonXmlWriter();
            var root           = CommonXmlNode.CreateRoot("ServerSettings");
            var configXmlArray = (from config in configs.Values
                                  let configAttributeInfo = CreateConfigAttributeInfos(config)
                                                            select CommonXmlNode.CreateElement("property", configAttributeInfo)).ToArray();

            root.ChildNodes = configXmlArray;

            writer.Write(stream, root);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var xmlReader = new CommonXmlReader("Config/vehicles.xml");
            var elem      = xmlReader.GetAllNodes();
            var elem2     = xmlReader.GetNode("/vehicles/vehicle[@name='vehicleGyrocopter']");

            var xmlWriter = new CommonXmlWriter();

            xmlWriter.Write("test.xml", elem);
            //foreach (var item in items)
            //{
            //    var list = xmlReader.GetAttributes("name", $"/vehicles/vehicle[@name='{item}']/property");
            //    list.ForEach(Console.WriteLine);
            //}
            //Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var writer = new CommonXmlWriter();
            var root   = writer.CreateRoot("ServerSettings");

            var text  = GetInnerXml(File.ReadAllText("serverconfig.xml"));
            var regex = new Regex("^( |\\t)*<property( |\\t)+name=\"(?<name>.*)\"( |\\t)+value=\"(?<value>.*)\"( |\\t)*\\/>( |\\t)*([\r\n])*( |\t)*<!--(?<description>.*)-->",
                                  RegexOptions.Multiline);
            var match = regex.Match(text);

            while (match.Success)
            {
                var name        = match.Groups["name"].ToString();
                var value       = match.Groups["value"].ToString();
                var description = match.Groups["description"].ToString().TrimStart(' ').TrimEnd(' ');

                string selection     = "";
                string selectionType = "string";

                if (int.TryParse(value, out var iresult))
                {
                    selectionType = "integer";
                }
                else if (bool.TryParse(value, out var bresult))
                {
                    selectionType = "combo";
                    selection     = "true/false";
                }

                var attributes = new List <AttributeInfo>
                {
                    new AttributeInfo()
                    {
                        Name = "name", Value = name
                    },
                    new AttributeInfo()
                    {
                        Name = "value", Value = value
                    },
                    new AttributeInfo()
                    {
                        Name = "selection", Value = selection
                    },
                    new AttributeInfo()
                    {
                        Name = "type", Value = selectionType
                    }
                };
                description = AddDescription(attributes, description);

                var elem = writer.CreateElement("property", attributes.ToArray(), description);
                root.Append(elem);

                match = match.NextMatch();
            }

            var memory = new MemoryStream();

            writer.Write(memory, root);
            Console.WriteLine(Encoding.UTF8.GetString(memory.ToArray()));
        }