Пример #1
0
        public void ReadInnerXmlWrongInit()
        {
            document.LoadXml("<root>test of <b>mixed</b> string.</root>");
            XmlNodeReader nrdr = new XmlNodeReader(document);

            nrdr.ReadInnerXml();
            Assert.AreEqual(ReadState.Initial, nrdr.ReadState, "initial.ReadState");
            Assert.AreEqual(false, nrdr.EOF, "initial.EOF");
            Assert.AreEqual(XmlNodeType.None, nrdr.NodeType, "initial.NodeType");
        }
Пример #2
0
        private void GenerateFiles()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter           = "FL XML file (*.xml)|*.xml";
            fileDialog.FilterIndex      = 1;
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fileDialog.FileName);
                XmlNodeReader nodeReader = new XmlNodeReader(doc);
                TestPlan = new StreamWriter(plan);
                Criteria = new StreamWriter(criteria);
                TestPlan.WriteLine("GROUP(TESTBOX) BEGIN");
                //probably add here some more lines like testbox log enable
                Criteria.WriteLine("<MPG> TESTBOX_RCS, \"Auto generated Criteria code from RCS .xml file\"");
                Criteria.WriteLine("<DATA> TIMEOUT_I, 180000");
                while (nodeReader.Read())
                {
                    int nodes = nodeReader.AttributeCount;
                    if (nodeReader.IsStartElement() && nodeReader.Name.Equals("include"))
                    {
                        string            messageInclude = $"There's include file {nodeReader.ReadInnerXml()}\nDownload it and hit Yes to load it.\nTo skip - hit No.";
                        string            captionInclude = "Message!";
                        MessageBoxButtons buttonsInclude = MessageBoxButtons.YesNo;
                        DialogResult      resultInclude;
                        resultInclude = MessageBox.Show(messageInclude, captionInclude, buttonsInclude);
                        if (resultInclude == System.Windows.Forms.DialogResult.Yes)
                        {
                            GenerateExtra();
                        }
                    }
                    if (nodeReader.IsStartElement() && nodeReader.Name.Equals("testset"))
                    {
                        TestPlan.WriteLine($"  RUN({nodeReader.GetAttribute(0).ToUpper()}, \"{nodeReader.GetAttribute(1)} <{nodeReader.GetAttribute(0).ToUpper()}>\", mTestBox, DUT1:TESTBOX_RCS:{nodeReader.GetAttribute(0).ToUpper()},{new Func<string>(() => { if (String.IsNullOrEmpty(textBox1.Text)) return ""; else return $" CONNECTION_NAME_S:{textBox1.Text};".ToUpper(); }).Invoke()},)");
                        Criteria.WriteLine($"<MP:I> {nodeReader.GetAttribute(0).ToUpper()},\"{nodeReader.GetAttribute(1)} {new Func<string>(() => { if (nodes >= 4) return $"({ nodeReader.GetAttribute(3)})"; else return ""; }).Invoke()}\",,,EQU,1");
                        Criteria.WriteLine($"<DATA> TBCOMMAND_S,\"{nodeReader.GetAttribute(0)}\"{new Func<string>(() => { if (nodeReader.GetAttribute(0) == "cpm_0011") return $",,SEARCH_AS,cores:{textBox2.Text.ToString()}"; else if (nodeReader.GetAttribute(0) == "early_init") return $",,SEARCH_AS,{textBox3.Text.ToString()}"; else return ""; }).Invoke()}");
                    }
                }
                string            message = "No more includes\nAny other files to load?";
                string            caption = "Message!";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;
                result = MessageBox.Show(message, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    GenerateExtra();
                }
                TestPlan.WriteLine("END_GROUP");
                TestPlan.Close();
                Criteria.Close();
            }
        }
        public static string Read(XmlDocument xdoc)
        {
            var reader = new XmlNodeReader(xdoc);

            //Parse the file and display each of the nodes.
            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case "FlxTransactionResponse":
                        return reader.ReadInnerXml();
                }
            }

            return string.Empty;
        }
Пример #4
0
        List <string> ThesaurusParse(string xml)
        {
            List <string> synonyms = new List <string>();
            XmlDocument   doc      = new XmlDocument();

            doc.LoadXml(xml);
            XmlReader reader = new XmlNodeReader(doc);

            while (reader.ReadToFollowing("w") && synonyms.Count < synonymNumber)
            {
                reader.MoveToAttribute("r");
                string type = reader.Value;
                reader.MoveToContent();
                string result = reader.ReadInnerXml();
                if (type == "syn")
                {
                    synonyms.Add(result);
                }
            }

            return(synonyms);
        }
Пример #5
0
        protected bool SetValue(string name, XmlNodeReader reader, ref bool hasAlreadyMoveToNext)
        {
            hasAlreadyMoveToNext = false;
            if (name == null || name.Length < 1)
            {
                return(false);
            }

            try
            {
                PropertyInfo pi   = this.GetType().GetProperty(name);
                Type         type = pi.PropertyType;

                if (XObjectHelper.IsXObjectType(type))
                {
                    object theproperty = this.GetType().InvokeMember(name,
                                                                     /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                     BindingFlags.Instance | BindingFlags.GetProperty,
                                                                     null, this, new object[] { });

                    if (theproperty == null && reader.IsEmptyElement == false)
                    {
                        theproperty = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { theproperty });
                    }

                    if (theproperty != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, theproperty, new object[] { reader, name });

                        return(true);
                    }
                }

                if (XObjectHelper.IsXObjectCollectionType(type))
                {
                    object thecollection = this.GetType().InvokeMember(name,
                                                                       /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                       BindingFlags.Instance | BindingFlags.GetProperty,
                                                                       null, this, new object[] { });

                    if (thecollection == null && reader.IsEmptyElement == false)
                    {
                        thecollection = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { thecollection });
                    }

                    if (thecollection != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, thecollection, new object[] { reader, name });

                        return(true);
                    }
                }

                if (type == typeof(string))
                {
                    object[] olist = pi.GetCustomAttributes(XObjectHelper.XRawXmlStringAttributeType, false);
                    if (olist != null && olist.Length > 0)
                    {
                        XRawXmlStringAttribute a = olist[0] as XRawXmlStringAttribute;
                        if (a != null && a.EnableRawXmlString)
                        {
                            string rawXmlString = reader.ReadInnerXml();
                            hasAlreadyMoveToNext = true;

                            return(SetValueEx(name, rawXmlString));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("(" + name + ") " + e.ToString());
                XObjectManager.NotifyException(this, e);
                return(false);
            }

            return(SetValueEx(name, reader.ReadString()));
        }