/// <summary>
 /// Builds the common data node info.
 /// </summary>
 /// <param name="commonDataNode">The common data node.</param>
 protected virtual void BuildCommonDataNodeInfo(XElement commonDataNode)
 {
     commonDataNode.SetElementValue("TaskCompletedMessage", LocalizedObjectHelper.GetLocalizedStringFrom("TaskCompletedMessageFormatter"));
     commonDataNode.SetElementValue("TaskCompleteWithZeroMessage", LocalizedObjectHelper.GetLocalizedStringFrom("TaskCompleteWithZeroMessage"));
     commonDataNode.SetElementValue("DefaultCurrency", AppSetting.Instance.DefaultCurrency);
     commonDataNode.SetElementValue("AppName", AppSetting.Instance.AppName.IsNullOrEmpty() ? "ACCOUNTBOOK" : AppSetting.Instance.AppName);
     commonDataNode.SetElementValue("Weekends", AppSetting.Weekends.ToStringLine<string>(","));
 }
Пример #2
0
 public static void addDatabase(GeispDatabase db)
 {
     XElement asocs = doc;
     XElement xmlDb = new XElement("asoc");
     xmlDb.SetAttributeValue("name", db.name);
     xmlDb.SetElementValue("name", db.name);
     xmlDb.SetElementValue("mdb", db.mdb);
     xmlDb.SetElementValue("excel", db.excel);
     xmlDb.SetElementValue("mdb2", db.mdb2);
     asocs.Add(xmlDb);
     doc.Save(directory + "GEISP\\GEISP.xml");
 }
Пример #3
0
 public static void SetElementValueConditional(this SXL.XElement el, SXL.XName name, string value)
 {
     if (value != null)
     {
         el.SetElementValue(name, value);
     }
 }
Пример #4
0
 public static void SetElementValueConditionalBool(this SXL.XElement el, SXL.XName name, bool?value)
 {
     if (value != null)
     {
         el.SetElementValue(name, value.Value ? "1" : "0");
     }
 }
Пример #5
0
        public static XElement ObjToXElement(PObject obj)
        {
            XElement x = new XElement("obj");

            XElement xAttrs = new XElement("attrs");
            foreach (string attr in obj._attrs.Keys)
            {
                xAttrs.SetElementValue(attr, obj._attrs[attr]);
            }
            x.Add(xAttrs);

            XElement xColls = new XElement("colls");
            x.Add(xColls);
            foreach (PCollection coll in obj._collections.Values)
            {
                XElement xColl = new XElement("coll");
                xColl.SetAttributeValue("name", coll.Name);
                xColls.Add(xColl);
                int cnt = coll.Count;
                for (int i = 0; i < cnt; i++)
                {
                    XElement xi = ObjToXElement(coll._items[i]);
                    xi.SetAttributeValue("num", i);
                    xColl.Add(xi);
                }
            }
            return x;
        }
Пример #6
0
 public static void SetElementValueConditional <T>(this SXL.XElement el, SXL.XName name, T?value) where T : struct
 {
     if (value != null)
     {
         el.SetElementValue(name, value.ToString());
     }
 }
Пример #7
0
 public static void SetElementValueConditional <T, TDest>(this SXL.XElement el, SXL.XName name, T?value, System.Func <T, TDest> xfrm) where T : struct
 {
     if (value != null)
     {
         var v = xfrm(value.Value);
         el.SetElementValue(name, v.ToString());
     }
 }
Пример #8
0
 internal void SaveUserData(XElement node)
 {
     node.SetElementValue("ShowMessages", this.buttonMessages.Checked);
     node.SetElementValue("ShowWarnings", this.buttonWarnings.Checked);
     node.SetElementValue("ShowErrors", this.buttonErrors.Checked);
     node.SetElementValue("ShowCore", this.buttonCore.Checked);
     node.SetElementValue("ShowEditor", this.buttonEditor.Checked);
     node.SetElementValue("ShowGame", this.buttonGame.Checked);
     node.SetElementValue("AutoClear", this.checkAutoClear.Checked);
     node.SetElementValue("PauseOnError", this.buttonPauseOnError.Checked);
 }
    protected void AddNode()
    {
        XElement parentXElement = null;
        XElement refXElement = null;
        XElement newXElement = null;
        int nodescount = CountNodes();

        parentXElement = xmlDoc.XPathSelectElement("customers");

        //newXElement.SetAttributeValue("url", parent_url_txt.Text);
        //newXElement.SetAttributeValue("src", "");

        if (nodescount == 0)
        {
            //refXElement = xmlDoc.XPathSelectElement("customers/customer[@id = '1']");
            //refXElement.SetElementValue("name",NameTextBox.Text);
            //refXElement.SetElementValue("designation", DesignationTextBox.Text);

            newXElement = new XElement("customer");
            newXElement.SetAttributeValue("id", (nodescount + 1).ToString());
            newXElement.SetElementValue("name", NameTextBox.Text);
            newXElement.SetElementValue("phone", ContactTextBox.Text);
            newXElement.SetElementValue("country", country.SelectedItem.Text);
            newXElement.SetElementValue("email", MailTextBox.Text);
            newXElement.SetElementValue("subject", SubjectTextBox.Text);
            parentXElement.AddFirst(newXElement);
        }
        else if (nodescount > 0)
        {
            newXElement = new XElement("customer");
            newXElement.SetAttributeValue("id", (nodescount + 1).ToString());
            newXElement.SetElementValue("name", NameTextBox.Text);
            newXElement.SetElementValue("phone", ContactTextBox.Text);
            newXElement.SetElementValue("country", country.SelectedItem.Text);
            newXElement.SetElementValue("email", MailTextBox.Text);
            newXElement.SetElementValue("subject", SubjectTextBox.Text);
            parentXElement.LastNode.AddAfterSelf(newXElement);
        }

        xmlDoc.Save(UpPath);
        string message = "New parent menu added successfully";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "customalert", "<script type='text/javascript'>customalert('" + message + "')</script>");
    }
Пример #10
0
        public static void SetElementValueConditionalDateTime(this SXL.XElement el, SXL.XName name, System.DateTimeOffset?date)
        {
            const string datefmt = "yyyy-MM-ddTHH:mm:ss";

            if (date != null)
            {
                var    culture = System.Globalization.CultureInfo.InvariantCulture;
                string datestr = date.Value.ToString(datefmt, culture);
                el.SetElementValue(name, datestr);
            }
        }
        public void CreateXElementElementaryDataTypes()
        {
            var person = new Person()
            {
                Name = "Peter",
                Birthday = new DateTime(2015, 7, 7),
                Height = 180,
                Weight = 80
            };

            var expectedElement = new XElement("Person");
            expectedElement.SetElementValue("Name", "Peter");
            expectedElement.SetElementValue("Birthday", "2015-07-07T00:00:00");
            expectedElement.SetElementValue("Weight", "80");
            expectedElement.SetElementValue("Height", "180");

            var dataStore = new PersonDataStore();
            var xElement = dataStore.CreateXElement(person);

            var guid = xElement.GetGuid();
            expectedElement.SetAttributeValue("ref", guid);

            Assert.AreEqual(expectedElement.Value, xElement.Value);
        }
Пример #12
0
        static void GenerateManifestFile(AddInElements data)
        {
            Xml.XElement addin = new Xml.XElement(
                "Addin", new Xml.XAttribute("Type", data.Type));
            Type type = data.GetType();

            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object value = prop.GetValue(data);
                if (null != value)
                {
                    addin.SetElementValue(prop.Name, (string)value);
                }
            }
            Xml.XElement    xmlTree = new Xml.XElement("RevitAddIns", addin);
            IO.StreamWriter sw      = IO.File.CreateText(
                IO.Path.GetFileName(data.Assembly)
                .Replace(IO.Path.GetExtension(data.Assembly), ".addin"));
            sw.Write(xmlTree);
            sw.Close();
            Console.WriteLine(xmlTree);
        }
        static void Main(string[] args)
        {
            XDocument document = new XDocument();
            //第三个参数为yes,说明这个xml是单纯的xml无任何规定,能随意写标签
            XDeclaration delaration = new XDeclaration("1.0", "utf-8", "yes");
            //文档声明写入文档
            document.Declaration = delaration;

            //XElement rootNode = new XElement("根节点", "这是根节点的内容,但是一般不放文字");
            XElement rootNode = new XElement("根节点");

            //在根节点内加入两个有内容的子节点
            XElement sonNode1 = new XElement("子节点1", "我是有文字内容的");
            rootNode.Add(sonNode1);
            XElement sonNode2 = new XElement("子节点2", "我是有文字内容的");
            rootNode.Add(sonNode2);

            //加入有子节点的子节点
            XElement sonNode3 = new XElement("子节点3");
            //这个节点加入子节点
            XElement sunNode1 = new XElement("孙节点", "我有文字内容和属性");
            //给这个节点设置属性
            sunNode1.SetAttributeValue("id", "孙节点1好");
            sonNode3.Add(sunNode1);
            rootNode.Add(sonNode3);

            //直接在根节点添加子节点,但是这样拿不到子节点对象
            rootNode.SetElementValue("子节点4", "我有文字内容");
            //设置属性
            rootNode.SetAttributeValue("id", "唯一的根节点");

            document.Add(rootNode);
            document.Save("xml文档.xml");
            Console.WriteLine("ok");
            Console.ReadKey();
        }
Пример #14
0
 internal void SaveUserData(XElement node)
 {
     node.SetElementValue("ShowComponents", this.buttonShowComponents.Checked);
 }
Пример #15
0
 public void SetCapabilities(XElement options)
 {
     const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
     options.SetElementValue(XName.Get("supportsKeywords", manifestUri), "Yes");
     options.SetElementValue(XName.Get("supportsGetTags", manifestUri), "Yes");
     options.SetElementValue(XName.Get("keywordsAsTags", manifestUri), "Yes");
 }
Пример #16
0
        public XElement AsXml()
        {
            XElement carXml = new XElement(IsIngame ? "Car" : "DisabledCar");

            carXml.SetAttributeValue("Name", Name);
            carXml.SetAttributeValue("ABS", ABS);
            carXml.SetAttributeValue("AT", AT);

            carXml.SetElementValue("DisplayName", DisplayName);
            carXml.SetElementValue("Description", Description);
            carXml.SetElementValue("Author", Author);

            return carXml;
        }
        bool WriteTexture(XElement texturesElement, string textureType, string texturePath)
        {
            if (texturePath == null)
                return false;

            var element = texturesElement.Elements("Texture").FirstOrDefault(x => x.Attribute("Map").Value == textureType);
            if (element == null)
            {
                element = new XElement("Texture");

                element.SetAttributeValue("Map", textureType);
                element.SetAttributeValue("File", texturePath);
            }
            else
            {
                element.SetAttributeValue("File", texturePath);

                texturesElement.SetElementValue("Texture", element);
            }

            return true;
        }
Пример #18
0
        private string GetOutline(int indentLevel, XElement element)
        {
            StringBuilder result = new StringBuilder();
            // TODO
            if (element.Attribute("id") != null)
            {
                //result = result.AppendLine(new string(' ', indentLevel * 2) + element.Attribute("id").Value);
                //foreach (var item in element.Descendants())
                //{
                //    result = result.AppendLine(new string(' ', indentLevel * 2) + item.Value);
                //}
                var test = element.Attribute("id").Value;
                result = result.AppendLine(element.Attribute("id").Value);
                try
                {
                    foreach (var item in element.Descendants())
                    {
                        element.SetElementValue("from", "test");
                        result = result.AppendLine(new string(' ', 4) + item.Name.ToString() + " " + item.Value);
                    }
                }
                catch (Exception e)
                {
            #if DEBUG
                    Console.WriteLine(e.Message);
            #endif
            #if RELEASE
                    Console.WriteLine(e.Message);
                    Logger.Log(e.Message);
            #endif
                }
            }

            foreach (XElement childElement in element.Elements())
            {
                result.Append(GetOutline(indentLevel + 1, childElement));
            }

            return result.ToString();
        }
        private XElement ConverterJogoEmXml(Jogo jogo)
        {
            XElement jogoXml = new XElement("jogo");
            jogoXml.SetAttributeValue("id", jogo.Id);
            jogoXml.SetElementValue("nome", jogo.Nome);
            //jogoXml.SetElementValue("preco", jogo.Preco);
            jogoXml.SetElementValue("categoria", jogo.Categoria.ToString());
            //jogoXml.SetElementValue("id_cliente_locacao", jogo.IdClienteLocacao.HasValue ? jogo.IdClienteLocacao.Value.ToString() : "");
            jogoXml.SetElementValue("selo", jogo.Selo);
            jogoXml.SetElementValue("descricao", jogo.Descricao);
            jogoXml.SetElementValue("iamgem", jogo.Imagem);
            jogoXml.SetElementValue("video", jogo.Video);

            return jogoXml;
        }
Пример #20
0
 private XElement GenerateXElement(Student student)
 {
     XElement newStudEl = new XElement(STUD_EL);
     newStudEl.SetAttributeValue(STUD_NAME_ATT, student.name);
     newStudEl.SetAttributeValue(ID_ATT, student.id);
     newStudEl.SetElementValue(STUD_GRADE_EL, student.grade);
     newStudEl.SetElementValue(STUD_HEIGHT_EL, student.height);
     return newStudEl;
 }
Пример #21
0
 public void ExecuteValueVariation(XElement content, object newValue)
 {
     int count = content.Nodes().Count();
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, newValue);
             // First all contents are removed and then new element with the value is added.
             xElem.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Пример #22
0
		private void ReplaceSegmentReference(XElement rt, string propName, XElement otherReference)
		{
			rt.SetElementValue(propName, otherReference.ToString());
		}
Пример #23
0
        // <?xml version="1.0"?>
        // <?order alpha ascending?>
        // <art xmlns='urn:art-org:art'>
        //   <period name='Renaissance' xmlns:a='urn:art-org:artists'>
        //     <a:artist>Leonardo da Vinci</a:artist>
        //     <a:artist>Michelangelo</a:artist>
        //     <a:artist><![CDATA[Donatello]]></a:artist>
        //   </period>
        //   <!-- 在此处插入 period -->
        // </art>
        public static XDocument CreateDocumentVerbose()
        {
            XNamespace nsArt = "urn:art-org:art";
            XNamespace nsArtists = "urn:art-org:artists";

            // 创建文档
            XDocument document = new XDocument();

            // 创建 xml 声明,并在
            // 文档中对其进行设置
            document.Declaration = new XDeclaration("1.0", null, null);

            // 创建 art 元素,并将其
            // 添加到文档中
            XElement art = new XElement(nsArt + "art");
            document.Add(art);

            // 创建顺序处理指令,并将其
            // 添加到 art 元素之前
            XProcessingInstruction pi = new XProcessingInstruction("order", "alpha ascending");
            art.AddBeforeSelf(pi);

            // 创建 period 元素,并将其
            // 添加到 art 元素中
            XElement period = new XElement(nsArt + "period");
            art.Add(period);

            // 向 period 元素中添加 name 特性
            period.SetAttributeValue("name", "Renaissance");

            // 创建命名空间声明 xmlns:a,并将其
            // 添加到 period 元素中
            XAttribute nsdecl = new XAttribute(XNamespace.Xmlns + "a", nsArtists);
            period.Add(nsdecl);

            // 创建 artist 元素和
            // 基础文本节点
            period.SetElementValue(nsArtists + "artist", "Michelangelo");

            XElement artist = new XElement(nsArtists + "artist", "Leonardo ", "da ", "Vinci");
            period.AddFirst(artist);

            artist = new XElement(nsArtists + "artist");
            period.Add(artist);
            XText cdata = new XText("Donatello");
            artist.Add(cdata);

            // 创建注释,并将其
            // 添加到 art 元素中
            XComment comment = new XComment("insert period here");
            art.Add(comment);

            return document;
        }
Пример #24
0
        public void XLinq72()
        {
            XElement elem = new XElement("customer",
                                         new XElement("name", "jack"),
                                         "this is an XElement",
                                         new XComment("new customer"),
                                         new XAttribute("id", "abc"));
            Console.WriteLine("Original element {0}", elem);

            elem.SetElementValue("name", "David");
            Console.WriteLine("Updated element {0}", elem);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="wikiDocument"></param>
        /// <returns></returns>
        private XElement SerializeXml(BsonDocument wikiDocument) {
            var xml = new XElement("WikiPage");

            foreach (var el in wikiDocument.Elements) {
                xml.SetElementValue(el.Name, el.Value.ToString());
            }

            return xml;
        }
Пример #26
0
        /// <summary>
        /// Convert RandomMapper task name and property names
        /// Author: Martin Milota
        /// </summary>
        public static string Convert1To2(string xml)
        {
            xml = xml.Replace("MyRandomMappertask", "MyRandomMapperTask");

            XDocument document = XDocument.Parse(xml);

            if (document.Root == null)
                return xml;

            List<XElement> toRemove = new List<XElement>();

            foreach (var mapper in document.Root.Descendants("MyRandomMapper"))
            {
                // Move the DoDecoding property from the only task to the node
                {
                    string doDecoding = "false";

                    foreach (var task in mapper.Descendants("Task"))
                    {
                        if (task.Attributes().Any(prop => prop.Value.Contains("MyRandomMapperTask")))
                        {
                            foreach (var decoding in task.Descendants("DoDecoding"))
                            {
                                doDecoding = decoding.Value;
                                toRemove.Add(decoding);
                            }
                        }
                    }

                    mapper.AddFirst(new XElement("DoDecoding", doDecoding));
                }

                // Add a new task that is enabled by default
                foreach (var tasks in mapper.Descendants("Tasks"))
                {
                    XElement generateTask = new XElement("Task");
                    generateTask.SetAttributeValue("Enabled", "True");
                    generateTask.SetAttributeValue("PropertyName", "InitTask");

                    XNamespace yaxlib = "http://www.sinairv.com/yaxlib/";
                    XName realtype = yaxlib + "realtype";
                    generateTask.SetAttributeValue(realtype, "BrainSimulator.VSA.MyRandomMapper+MyGenerateMatrixTask");

                    generateTask.SetElementValue("AxisToNormalize", "yDim");

                    tasks.AddFirst(generateTask);
                }

                // Replace the Orthonormalize property by VectorMode
                foreach (var ortho in mapper.Descendants("Orthonormalize"))
                {
                    ortho.AddBeforeSelf(new XElement("VectorMode", ortho.Value == "True" ? "Orthonormalize" : "Normal"));
                    toRemove.Add(ortho);
                }
            }

            foreach (var xElement in toRemove)
            {
                xElement.Remove();
            }

            return document.ToString();
        }
Пример #27
0
 public static void set_element(XElement root,
                                string element_name, string el_val)
 {
     var el = root.Element(element_name);
     if (el == null)
     {
         el = new XElement(element_name);
         root.Add(el);
     }
     if (el_val != null)
         root.SetElementValue(element_name, el_val);
 }
Пример #28
0
        public void AddSimpleCollection(XElement tagOrSimple, string name, IEnumerable values)
        {
            foreach (object value in values)
              {
            XElement simpleElement = new XElement("Simple");
            simpleElement.SetElementValue("Name", name);
            simpleElement.SetElementValue("String", value);

            tagOrSimple.Add(simpleElement);
              }
        }
Пример #29
0
 public void ExecuteRemoveVariation(XElement content)
 {
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, null);
             xElem.Verify();
             eHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Пример #30
0
        private XElement LoadDBConfig(string newcfg)
        {

            //retrieve all the names
            string CommandText = "select id,value from data where grp='" + newcfg + "' and tbl='" + this.sql_tbl + "'";
            SQLiteDataAdapter DB2 = new SQLiteDataAdapter(CommandText, sql_con);
            DataSet DS2 = new DataSet();
            DS2.Reset();
            DB2.Fill(DS2);
            XElement xe = new XElement("Item");
            foreach (string reg in regs)
            {
                xe.Add(reg, "0");
            }
            foreach (DataRow dr in DS2.Tables[0].Rows)
            {
                foreach (string reg in regs)
                {
                    if (reg == dr[0].ToString())
                        xe.SetElementValue(dr[0].ToString(), dr[1].ToString());
                }
            }
            //sql_con.Close();
            return xe;           

        }
Пример #31
0
                /// <summary>
                /// Validate enumeration of the SetElementValue method on element/
                /// </summary>
                /// <param name="contextValue"></param>
                /// <returns></returns>
                //[Variation(Desc = "ElementSetElementValue")]
                public void ElementSetElementValue()
                {
                    XElement e1 = new XElement("x");

                    // Removal of non-existant element
                    e1.SetElementValue("foo", null);
                    Validate.Count(e1.Elements(), 0);

                    // Add of non-existant element
                    e1.SetElementValue("foo", "foo-value");
                    Validate.EnumeratorDeepEquals(
                        e1.Elements(),
                        new XElement[] { new XElement("foo", "foo-value") });

                    // Overwriting of existing element
                    e1.SetElementValue("foo", "noo-value");
                    Validate.EnumeratorDeepEquals(
                        e1.Elements(),
                        new XElement[] { new XElement("foo", "noo-value") });

                    // Effective removal of existing element
                    e1.SetElementValue("foo", null);
                    Validate.Count(e1.Elements(), 0);
                }
Пример #32
0
		internal void SaveUserData(XElement node)
		{
			Camera nativeCamera = this.nativeCamObj.GetComponent<Camera>();

			node.SetElementValue("Perspective", nativeCamera.Perspective);
			node.SetElementValue("FocusDist", nativeCamera.FocusDist);
			XElement bgColorElement = new XElement("BackgroundColor");
			{
				bgColorElement.SetElementValue("R", nativeCamera.ClearColor.R);
				bgColorElement.SetElementValue("G", nativeCamera.ClearColor.G);
				bgColorElement.SetElementValue("B", nativeCamera.ClearColor.B);
				bgColorElement.SetElementValue("A", nativeCamera.ClearColor.A);
			}
			node.Add(bgColorElement);

			XElement snapToGridSizeElement = new XElement("SnapToGridSize");
			node.Add(snapToGridSizeElement);
			snapToGridSizeElement.SetElementValue("X", this.editingUserGuides.GridSize.X);
			snapToGridSizeElement.SetElementValue("Y", this.editingUserGuides.GridSize.Y);
			snapToGridSizeElement.SetElementValue("Z", this.editingUserGuides.GridSize.Z);

			if (this.activeState != null) 
				node.SetElementValue("ActiveState", this.activeState.GetType().GetTypeId());

			XElement stateListNode = new XElement("States");
			foreach (var pair in this.availStates)
			{
				XElement stateNode = new XElement("State");
				stateNode.SetAttributeValue("type", pair.Key.GetTypeId());
				pair.Value.SaveUserData(stateNode);
				if (!stateNode.IsEmpty)
					stateListNode.Add(stateNode);
			}
			if (!stateListNode.IsEmpty)
				node.Add(stateListNode);

			XElement layerListNode = new XElement("Layers");
			foreach (var pair in this.availLayers)
			{
				XElement layerNode = new XElement("Layer");
				layerNode.SetAttributeValue("type", pair.Key.GetTypeId());
				pair.Value.SaveUserData(layerNode);
				if (!layerListNode.IsEmpty)
					layerListNode.Add(layerNode);
			}
			if (!layerListNode.IsEmpty)
				node.Add(layerListNode);
		}
Пример #33
0
        public void ElementSetElementValue()
        {
            XElement e1 = new XElement("x");

            // Removal of non-existant element
            e1.SetElementValue("foo", null);
            Assert.Empty(e1.Elements());

            // Add of non-existant element
            e1.SetElementValue("foo", "foo-value");
            Assert.Equal(new XElement[] { new XElement("foo", "foo-value") }, e1.Elements(), XNode.EqualityComparer);

            // Overwriting of existing element
            e1.SetElementValue("foo", "noo-value");
            Assert.Equal(new XElement[] { new XElement("foo", "noo-value") }, e1.Elements(), XNode.EqualityComparer);

            // Effective removal of existing element
            e1.SetElementValue("foo", null);
            Assert.Empty(e1.Elements());
        }
Пример #34
0
 protected void AddValue(XElement element, string name, object value)
 {
     //Recurise through the value(s)
     if (value != null && value.GetType().HasElementType && value is System.Collections.IEnumerable)
     {
         //Recurse through the values
         foreach (object item in (System.Collections.IEnumerable)value)
             AddValue(element, name, item);
     }
     else
     {
         element.SetElementValue(name, StringEx.ToString(value));
     }
 }
        public void CreateXElementMultipleReferenceDataTypes()
        {
            var father = new Person()
            {
                Name = "Father",
                Birthday = new DateTime(1970, 7, 7),
                Height = 180,
                Weight = 80
            };

            var mother = new Person()
            {
                Name = "Mother",
                Birthday = new DateTime(1975, 7, 7),
                Height = 175,
                Weight = 72
            };

            var child = new Child()
            {
                Father = father,
                Mother = mother
            };

            var child2 = new Child()
            {
                Father = father,
                Mother = mother
            };

            var children = new Children()
            {
                ChildOne = child,
                ChildTwo = child2
            };

            var expectedFather = new XElement("Person");
            expectedFather.SetElementValue("Name", "Father");
            expectedFather.SetElementValue("Birthday", "1970-07-07T00:00:00");
            expectedFather.SetElementValue("Weight", "80");
            expectedFather.SetElementValue("Height", "180");

            var expectedMother = new XElement("Person");
            expectedMother.SetElementValue("Name", "Mother");
            expectedMother.SetElementValue("Birthday", "1975-07-07T00:00:00");
            expectedMother.SetElementValue("Weight", "72");
            expectedMother.SetElementValue("Height", "175");

            var expectedChild1 = new XElement("ChildOne", expectedFather, expectedMother);
            var expectedChild2 = new XElement("ChildTwo", expectedFather, expectedMother);
            var expectedChildren = new XElement("Children", expectedChild1, expectedChild2);

            var dataStore = new ChildrenDataStore();
            var actualElement = dataStore.CreateXElement(children);

            var guid = actualElement.GetGuid();
            expectedChildren.SetAttributeValue("ref", guid);

            guid = actualElement.Elements().ElementAt(0).GetGuid();
            expectedChild1.SetAttributeValue("ref", guid);

            guid = actualElement.Elements().ElementAt(1).GetGuid();
            expectedChild2.SetAttributeValue("ref", guid);

            guid = actualElement.Elements().ElementAt(0).Elements().ElementAt(0).GetGuid();
            expectedFather.SetAttributeValue("ref", guid);

            guid = actualElement.Elements().ElementAt(0).Elements().ElementAt(1).GetGuid();
            expectedMother.SetAttributeValue("ref", guid);

            Assert.AreEqual(expectedChildren.Value, actualElement.Value);
        }
Пример #36
0
		internal void SaveUserData(XElement node)
		{
			node.SetElementValue("AutoRefresh", this.buttonAutoRefresh.Checked);
			node.SetElementValue("Locked", this.buttonLock.Checked);
			node.SetElementValue("TitleText", this.Text);
			node.SetElementValue("DebugMode", this.buttonDebug.Checked);
		}