Exemplo n.º 1
0
        static XmlDocument CreateXmlDocument()
        {
            XmlDocument
                doc = new XmlDocument();

            XmlNode
                node = doc.CreateXmlDeclaration("1.0", "utf-8", null),
                RootNode;

            doc.AppendChild(node);

            RootNode = doc.CreateElement("TestClassSimple");
            doc.AppendChild(RootNode);

            node = doc.CreateElement("FInt");
            node.AppendChild(doc.CreateTextNode("1"));
            RootNode.AppendChild(node);

            node = doc.CreateElement("FDecimal");
            node.AppendChild(doc.CreateTextNode("1.1"));
            RootNode.AppendChild(node);

            node = doc.CreateElement("FDateTime");
            node.AppendChild(doc.CreateTextNode(DateTime.Now.ToString("o")));
            RootNode.AppendChild(node);

            node = doc.CreateElement("FString");
            node.AppendChild(doc.CreateTextNode("TestТест"));
            RootNode.AppendChild(node);

            return(doc);
        }
Exemplo n.º 2
0
        // Create a title section with a string as its title.
        private void CreateTitleSection(string title)
        {
            SectionNode node = CreateSectionNode();

            node.Label = title;
            RootNode.AppendChild(node);
        }
Exemplo n.º 3
0
        /// <summary>  Adds a new zone</summary>
        /// <param name="zoneId">The zone ID
        /// </param>
        /// <param name="zoneUrl">The zone URL
        /// </param>
        /// <param name="templateId">The ID of the zone template
        /// </param>
        public virtual XmlElement AddZone(string zoneId,
                                          string zoneUrl,
                                          string templateId)
        {
            if (zoneId == null || zoneId.Trim().Length == 0)
            {
                throw new AdkConfigException("Zone ID cannot be blank");
            }

            XmlElement zone = GetZoneNode(zoneId);

            if (zone != null)
            {
                throw new AdkConfigException("Zone already defined");
            }

            //  Create a new <zone> element
            zone = Document.CreateElement(XmlConstants.ZONE_ELEMENT);
            RootNode.AppendChild(zone);
            zone.SetAttribute(XmlConstants.ID, zoneId);
            if (zoneUrl != null)
            {
                zone.SetAttribute(XmlConstants.URL, zoneUrl);
            }
            zone.SetAttribute(XmlConstants.TEMPLATE, templateId == null ? "Default" : templateId);

            return(zone);
        }
    /// <summary>
    /// Writes the given match into the match XML file.
    /// </summary>
    public void WriteMatch(Rules match, string name)
    {
        XmlNode n = RootNode.AppendChild(Document.CreateElement("match"));

        XmlAttribute nameAtt = Document.CreateAttribute(name);

        nameAtt.Value = name;
        n.Attributes.Append(nameAtt);

        Document.Save(FullPath);
    }
Exemplo n.º 5
0
        private XmlNode GetSettingsNode(string name)
        {
            XmlNode settingsNode = RootNode.SelectSingleNode(name);

            if (settingsNode == null)
            {
                settingsNode = rootDocument.CreateElement(name);
                RootNode.AppendChild(settingsNode);
            }
            return(settingsNode);
        }
        public void ClearChildTest()
        {
            RootNode root   = new RootNode();
            var      source = new StreamSourceNode <string, string>(
                "topic",
                "source-01",
                new Stream.Internal.ConsumedInternal <string, string>("source-01", new StringSerDes(), new StringSerDes(), null));

            root.AppendChild(source);
            root.ClearChildren();

            Assert.IsTrue(root.IsEmpty);
        }
        public void AppendChildTest()
        {
            RootNode root   = new RootNode();
            var      source = new StreamSourceNode <string, string>(
                "topic",
                "source-01",
                new Stream.Internal.ConsumedInternal <string, string>("source-01", new StringSerDes(), new StringSerDes(), null));

            root.AppendChild(source);

            Assert.IsFalse(root.IsEmpty);
            Assert.AreEqual(new string[] { "ROOT-NODE" }, source.ParentNodeNames());
        }
        public void WriteTopologyTest()
        {
            var builder = new InternalTopologyBuilder();
            List <StreamGraphNode> nodes = new List <StreamGraphNode>();

            RootNode root   = new RootNode();
            var      source = new StreamSourceNode <string, string>(
                "topic",
                "source-01",
                new Stream.Internal.ConsumedInternal <string, string>("source-01", new StringSerDes(),
                                                                      new StringSerDes(), null));

            root.AppendChild(source);
            nodes.Add(source);

            var filterParameters =
                new ProcessorParameters <string, string>(
                    new KStreamFilter <string, string>((k, v) => true, false), "filter-02");
            var filter = new ProcessorGraphNode <string, string>("filter-02", filterParameters);

            source.AppendChild(filter);
            nodes.Add(filter);

            var to = new StreamSinkNode <string, string>(
                new StaticTopicNameExtractor <string, string>("topic2"), "to-03",
                new Stream.Internal.Produced <string, string>(
                    new StringSerDes(),
                    new StringSerDes())
                );

            filter.AppendChild(to);
            nodes.Add(to);

            builder.BuildTopology(root, nodes);

            Assert.IsTrue(root.AllParentsWrittenToTopology);
            Assert.IsTrue(source.AllParentsWrittenToTopology);
            Assert.IsTrue(filter.AllParentsWrittenToTopology);
            Assert.IsTrue(to.AllParentsWrittenToTopology);

            var topology = builder.BuildTopology();

            Assert.IsTrue(topology.SourceOperators.ContainsKey("topic"));
            Assert.IsTrue(topology.ProcessorOperators.ContainsKey("filter-02"));
            Assert.IsTrue(topology.SinkOperators.ContainsKey("topic2"));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Attemps to create a basic XML file to hold configuration data.  It will try to build the tag structure
        /// needed to reach the RootNodePath.  It can only handle simple tag names, if the base path is not
        /// /name/name/name format then it will not be able to create the file.
        /// </summary>
        /// <param name="FileName">Path and name of the XML file to create</param>
        /// <param name="RootNodePath">Simple XPath describing the tag path to create</param>
        /// <param name="DeleteExisting">True to create a new file, false to edit existing file</param>
        static public void CreateBasicXMLConfig(string FileName, string RootNodePath, bool DeleteExisting)
        {
            XmlDocument xdConfig = new XmlDocument();
            XmlNode     RootNode, NextNode;

            string[] TagList;
            string   CurrPath;

            TagList = RootNodePath.Trim(new char[] { '/' }).Split('/');

            if ((File.Exists(FileName) == true) && (DeleteExisting == false))               //File exists and we can't overwrite it
            {
                xdConfig.Load(FileName);
            }
            else if (DeleteExisting == true)
            {
                File.Delete(FileName);
            }

            if (xdConfig.DocumentElement == null)
            {
                xdConfig.AppendChild(xdConfig.CreateElement(TagList[0]));
            }

            RootNode = xdConfig.DocumentElement;
            CurrPath = "";
            foreach (string TagName in TagList)
            {
                CurrPath += "/TagName";

                NextNode = RootNode.SelectSingleNode("/" + TagName);

                if (NextNode == null)
                {
                    NextNode = xdConfig.CreateElement(TagName);

                    RootNode.AppendChild(NextNode);
                }

                RootNode = NextNode;                 //Keep descending into the path
            }

            xdConfig.Save(FileName);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attempts to write configuration tags into an XML file.  It will create or update tags as children to the taf
        /// specified in RootNodePath.
        /// </summary>
        /// <param name="FileName">Path and file name of the XML file to load</param>
        /// <param name="RootNodePath">XPath to the root node of the configuration data</param>
        /// <param name="AttemptUpdates">If true it will attempt to update existing tags, otherwise it will create all tags and new children</param>
        /// <param name="Data">List of configuration data to write to the XML</param>
        /// <returns>True if the XML file is updated successfully, false or exception on error</returns>
        public static bool WriteXMLConfig(string FileName, string RootNodePath, bool AttemptUpdates, IEnumerable <XMLFileData> Data)
        {
            XmlDocument  xdConfig = new XmlDocument();
            XmlNode      RootNode, NewNode;
            XmlAttribute NewAttr;

            try {
                xdConfig.Load(FileName);
            } catch (FileNotFoundException) {             //If the file doesn't exist, create it
                xdConfig.AppendChild(xdConfig.CreateXmlDeclaration("1.0", "UTF-8", null));
            }

            RootNode = xdConfig.SelectSingleNode(RootNodePath);

            if (RootNode == null)               //Root node doesn't exist, create it
            {
                string[] RootParts = RootNodePath.Split(new char[] { '/' });

                foreach (string TagName in RootParts)
                {
                    if (String.IsNullOrWhiteSpace(TagName) == true)
                    {
                        continue;
                    }

                    RootNode = xdConfig.CreateNode(XmlNodeType.Element, TagName, "");

                    if (xdConfig.DocumentElement != null)                       //Append to existing document
                    {
                        xdConfig.DocumentElement.AppendChild(RootNode);
                    }
                    else
                    {
                        xdConfig.AppendChild(RootNode);
                    }
                }
            }

            foreach (XMLFileData NewTag in Data)
            {
                NewNode = RootNode.SelectSingleNode(NewTag.Name);

                if ((AttemptUpdates == false) && (NewNode != null))                   //OVerwrite existing tags
                {
                    RootNode.RemoveChild(NewNode);

                    NewNode = null;
                }

                if (NewNode == null)
                {
                    NewNode = xdConfig.CreateElement(NewTag.Name);

                    RootNode.AppendChild(NewNode);
                }

                NewNode.InnerText = NewTag.Value;

                if (NewTag.Attributes != null)
                {
                    foreach (string AttrName in NewTag.Attributes.Keys)
                    {
                        if (NewNode.Attributes[AttrName] == null)
                        {
                            NewAttr = xdConfig.CreateAttribute(AttrName);

                            NewNode.Attributes.Append(NewAttr);
                        }
                        else
                        {
                            NewAttr = NewNode.Attributes[AttrName];
                        }

                        NewAttr.InnerText = NewTag.Attributes[AttrName];
                    }
                }
            }

            xdConfig.Save(FileName);

            return(true);
        }
Exemplo n.º 11
0
        public void Serialise(object value, string name)
        {
            XmlNode object_node = SerialiseObject(value, name);

            RootNode.AppendChild(object_node);
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            try
            {
                XmlDocument
                    doc = null;

                #if TEST_XML
                doc = new XmlDocument();
                doc.Load("TestConfig.xml");
                #endif

                const string
                    AttrId         = "id",
                    Id             = "TestId",
                    AttrIntId      = "FInt",
                    AttrDateTimeId = "FDateTime";

                doc = new XmlDocument();

                XmlNode
                    node = doc.CreateXmlDeclaration("1.0", "utf-8", null),
                    RootNode;

                XmlNodeList
                    xmlNodeList;

                doc.AppendChild(node);
                RootNode = doc.CreateElement("root");

                XmlAttribute
                    attr = doc.CreateAttribute(AttrId);

                attr.Value = Id;

                RootNode.Attributes.Append(attr);

                doc.AppendChild(RootNode);

                XmlText
                    xmlText;

                #if TEST_BR
                TestBr(RootNode);
                if ((xmlNodeList = doc.GetElementsByTagName("rootTable")) != null &&
                    xmlNodeList.Count > 0)
                {
                    node = xmlNodeList[0];
                    Console.WriteLine("ChildNodes.Count={0}", node.ChildNodes.Count);
                    xmlText = (XmlText)node.ChildNodes.Cast <XmlNode>().Where(n => n.NodeType == XmlNodeType.Text).Select(n => n).SingleOrDefault();
                }
                #endif

                node = doc.CreateElement("SmthElement");

                attr       = doc.CreateAttribute(AttrId);
                attr.Value = Id + Id;
                node.Attributes.Append(attr);

                attr       = doc.CreateAttribute(AttrIntId);
                attr.Value = "13";
                node.Attributes.Append(attr);

                attr       = doc.CreateAttribute(AttrDateTimeId);
                attr.Value = DateTime.Now.ToString("o");
                node.Attributes.Append(attr);

                xmlText = (XmlText)node.ChildNodes.Cast <XmlNode>().Where(n => n.NodeType == XmlNodeType.Text).Select(n => n).SingleOrDefault();
                node.AppendChild(doc.CreateTextNode("Test"));
                xmlText = (XmlText)node.ChildNodes.Cast <XmlNode>().Where(n => n.NodeType == XmlNodeType.Text).Select(n => n).SingleOrDefault();

                RootNode.AppendChild(node);

                Console.WriteLine(doc.InnerXml);

                XmlElement
                    e;

                if ((e = doc.GetElementById(Id)) != null)
                {
                    ;
                }
                if ((e = doc.GetElementById(Id + Id)) != null)
                {
                    ;
                }

                xmlNodeList = doc.GetElementsByTagName("SmthElement");
                if (xmlNodeList != null &&
                    xmlNodeList.Count > 0)
                {
                    node = xmlNodeList[0];
                }

                if ((node = doc.SelectSingleNode(string.Format("//*[@{0}=\"{1}\"]", AttrId, Id + Id))) != null)
                {
                    Console.WriteLine(node.Attributes.Count);

                    if ((attr = node.Attributes[AttrIntId]) != null)
                    {
                        int
                            tmpInt = Convert.ToInt32(attr.Value);

                        Console.WriteLine(tmpInt);
                    }

                    if ((attr = node.Attributes[AttrDateTimeId]) != null)
                    {
                        DateTime
                            tmpDateTime = Convert.ToDateTime(attr.Value);

                        Console.WriteLine(tmpDateTime);
                    }
                }

                if ((e = doc.DocumentElement) != null &&
                    e.HasChildNodes)
                {
                    foreach (XmlNode n in e.ChildNodes)
                    {
                        Console.WriteLine(n.Name);
                    }

                    node = e.FirstChild;
                    while (node != null)
                    {
                        Console.WriteLine(node.Name);
                        node = node.NextSibling;
                    }
                }
            }
            catch (Exception eException)
            {
                Console.WriteLine(eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace);
            }

            Console.ReadLine();
        }