Esempio n. 1
0
        public void TitleOnly()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC01-TitleOnly.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC01-TitleOnly"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
        }
Esempio n. 2
0
        public void ItemizedList1()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC42-ItemizedList1.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC42-ItemizedList1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/itemizedlist/listitem/para").InnerXml, Is.EqualTo("ItemizedList1"));
        }
Esempio n. 3
0
        public void MixedFormattingItalic1()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC29-MixedFormatting.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC29-MixedFormatting"));
            Assert.That(xml.SelectSingleNode("/chapter/section[3]/para[2]/emphasis").InnerXml, Is.EqualTo("Example"));
            Assert.That(xml.SelectSingleNode("/chapter/section[3]/para[2]/text()[last()]").InnerText, Is.EqualTo(": Italic"));
        }
Esempio n. 4
0
        public void TitleWithBody()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC02-TitleWithBody.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC02-TitleWithBody"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("This is some text body."));
        }
Esempio n. 5
0
        public void QuotesInTitle()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC27-QuotesInTitle.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC27-QuotesInTitle"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo(@"Requirement1 ""X"""));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("This is a requirement."));
        }
Esempio n. 6
0
        public void FormattingSubscript()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC25-FormattingSubscript.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC25-FormattingSubscript"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo(@"This contains a subscript v<subscript>t</subscript>."));
        }
Esempio n. 7
0
        public void FormattingUnderline()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC23-FormattingUnderline.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC23-FormattingUnderline"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo(@"This contains some <emphasis role=""underline"">underline </emphasis>text."));
        }
Esempio n. 8
0
        public void FormattingItalics()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC22-FormattingItalics.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC22-FormattingItalics"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo(@"This contains some <emphasis>italic </emphasis>text."));
        }
Esempio n. 9
0
        public void FormattingBold2()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC21-FormattingBold2.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC21-FormattingBold2"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo(@"This <emphasis role=""bold"">text </emphasis>contains two <emphasis role=""bold"">bold </emphasis>elements."));
        }
Esempio n. 10
0
        public void FormattingBold1()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC20-FormattingBold1.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC20-FormattingBold1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo(@"This is some sample <emphasis role=""bold"">bold </emphasis>text."));
        }
Esempio n. 11
0
        public void SpecialQuotes()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC07-SpecialQuotes.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC07-SpecialQuotes"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("Special Quotes “HIGH”"));
        }
Esempio n. 12
0
        public void OrderedList2()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC41-OrderedList2.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC41-OrderedList2"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/orderedlist/listitem[1]/para").InnerXml, Is.EqualTo("Ordered List 1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/orderedlist/listitem[2]/para").InnerXml, Is.EqualTo("Ordered List 2"));
        }
Esempio n. 13
0
        public void TitleWithBodyParagraphs()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC03-TitleWithBodyParagraphs.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC03-TitleWithBodyParagraphs"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("This text has two paragraphs"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[3]").InnerXml, Is.EqualTo("This is paragraph 2."));
        }
Esempio n. 14
0
        public void BothLists1()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC44-BothLists1.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC44-BothLists1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/orderedlist[1]/listitem/para").InnerXml, Is.EqualTo("Ordered List"));
            Assert.That(xml.SelectSingleNode("/chapter/section/orderedlist[1]/listitem/orderedlist/listitem/para").InnerXml, Is.EqualTo("Itemized List"));
            Assert.That(xml.SelectSingleNode("/chapter/section/orderedlist[2]/listitem/para").InnerXml, Is.EqualTo("Ordered List "));
        }
Esempio n. 15
0
        public void NestedRequirements1()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC05-NestedRequirements1.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC05-NestedRequirements1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("This is requirement 1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/section/title").InnerXml, Is.EqualTo("Subrequirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/section/para[2]").InnerXml, Is.EqualTo("This is requirement 1.1"));
        }
Esempio n. 16
0
        public void MultipleRequirements()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC04-MultipleRequirements.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC04-MultipleRequirements"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/para[2]").InnerXml, Is.EqualTo("This is requirement 1"));
            Assert.That(xml.SelectSingleNode("/chapter/section[2]/title").InnerXml, Is.EqualTo("Requirement2"));
            Assert.That(xml.SelectSingleNode("/chapter/section[2]/para[2]").InnerXml, Is.EqualTo("This is requirement 2"));
        }
Esempio n. 17
0
        private static void BackupMetaClass(XmlNode root, MetaClass mc)
        {
            XmlDocumentFragment xmlMetaClass = root.OwnerDocument.CreateDocumentFragment();

            xmlMetaClass.InnerXml = "<MetaClass><Namespace></Namespace><Name></Name><FriendlyName></FriendlyName><MetaClassType></MetaClassType><ParentClass></ParentClass><TableName></TableName><Description></Description><FieldListChangedSqlScript></FieldListChangedSqlScript><Tag></Tag></MetaClass>";

            xmlMetaClass.SelectSingleNode("MetaClass/Namespace").InnerXml     = mc.Namespace;
            xmlMetaClass.SelectSingleNode("MetaClass/Name").InnerXml          = mc.Name;
            xmlMetaClass.SelectSingleNode("MetaClass/FriendlyName").InnerXml  = mc.FriendlyName;
            xmlMetaClass.SelectSingleNode("MetaClass/MetaClassType").InnerXml = mc.MetaClassType.ToString();

            if (mc.Parent != null)
            {
                xmlMetaClass.SelectSingleNode("MetaClass/ParentClass").InnerXml = mc.Parent.Name;
            }

            xmlMetaClass.SelectSingleNode("MetaClass/TableName").InnerXml   = mc.TableName;
            xmlMetaClass.SelectSingleNode("MetaClass/Description").InnerXml = mc.Description;

            if (mc.FieldListChangedSqlScript != null)
            {
                xmlMetaClass.SelectSingleNode("MetaClass/FieldListChangedSqlScript").InnerXml = mc.FieldListChangedSqlScript;
            }

            if (mc.Tag != null)
            {
                xmlMetaClass.SelectSingleNode("MetaClass/Tag").InnerXml = Convert.ToBase64String((byte[])mc.Tag);
            }

            root.AppendChild((XmlNode)xmlMetaClass);
        }
Esempio n. 18
0
        public void FormattingMultiple()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC26-FormattingMultiple.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC26-FormattingMultiple"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));

            // This <b>contains </b><i>multiple </i><u>elements</u>. <i>E</i><i><sub>t</sub></i><i> = mc</i><i><sup>2</sup></i>.
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml,
                        Is.EqualTo(@"This <emphasis role=""bold"">contains </emphasis><emphasis>multiple </emphasis><emphasis role=""underline"">elements</emphasis>. " +
                                   @"<emphasis>E</emphasis><emphasis><subscript>t</subscript></emphasis><emphasis> = mc</emphasis><emphasis><superscript>2</superscript></emphasis>."));
        }
Esempio n. 19
0
        /// <summary>
        /// 指定の DefaultLocators.xml ファイルからコメントアウトされた
        /// 'locator_ref' と 'portal_locators' の要素を カスタムListViewItem のコレクションに抽出
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        private System.Collections.Generic.List <LocatorItem> getCommentedLocatorsList(XmlDocument doc)
        {
            List <LocatorItem> locators = new List <LocatorItem>();

            try
            {
                XmlNodeList locatorNodes = doc.SelectNodes("//comment()[contains(.,'<locator_ref>')]");
                foreach (XmlNode locatorNode in locatorNodes)
                {
                    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
                    docFrag.InnerXml = locatorNode.InnerText;

                    string name     = docFrag.SelectSingleNode("//locator_ref/name").InnerText;
                    string dispname = docFrag.SelectSingleNode("//locator_ref/display_name").InnerText;
                    docFrag = null;

                    LocatorItem locator = createLocatorItem(name, dispname, false, LocatorItem.LocatorTypes.SERVER, false);
                    locators.Add(locator);
                }

                XmlNodeList portalNodes = doc.SelectNodes("//comment()[contains(.,'<portal_locators>')]");
                foreach (XmlNode portalNode in portalNodes)
                {
                    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
                    docFrag.InnerXml = portalNode.InnerText;

                    string name     = docFrag.SelectSingleNode("//portal_locators/display_name/@locator_name").Value;
                    string dispname = docFrag.SelectSingleNode("//portal_locators/display_name/@display_name").Value;
                    docFrag = null;

                    LocatorItem locator = createLocatorItem(name, dispname, false, LocatorItem.LocatorTypes.PORTAL, false);
                    locators.Add(locator);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return(locators);
        }
Esempio n. 20
0
        public void NestedRequirements2()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC06-NestedRequirements2.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC06-NestedRequirements2"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/para[2]").InnerXml, Is.EqualTo("Requirement 1"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/section/title").InnerXml, Is.EqualTo("Requirement3"));
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/section/para[2]").InnerXml, Is.EqualTo("Requirement 1.1"));
            Assert.That(xml.SelectSingleNode("/chapter/section[2]/title").InnerXml, Is.EqualTo("Requirement2"));
            Assert.That(xml.SelectSingleNode("/chapter/section[2]/para[2]").InnerXml, Is.EqualTo("Requirement 2"));
        }
        public HttpResponseMessage AddPersonDetails(string personType, [FromUri] string format = "xml")
        {
            HttpResponseMessage res = null;
            string role             = GetPersonRole(personType);

            string              strNewPerson  = Request.Content.ReadAsStringAsync().Result; //The Person Node is in the body of the request
            XmlDocument         xmlPeople     = GetPeopleDocument();                        //Common Routine to load up the People.xml document
            XmlElement          xe            = xmlPeople.CreateElement("PeopleToInsert");  //Need a root node
            XmlDocumentFragment frgPersonNode = xmlPeople.CreateDocumentFragment();         //One technique to INSERT a node into an XML Document

            frgPersonNode.InnerXml = strNewPerson;

            //Assign the ID of this new person by getting the maximum one in the people file and adding 1
            XmlNodeList xnlIDs = xmlPeople.SelectNodes(@"//@id");
            Int32       maxID  = Int32.MinValue;

            foreach (XmlNode xnID in xnlIDs)
            {
                if (Convert.ToInt32(xnID.InnerXml) > maxID)
                {
                    maxID = Convert.ToInt32(xnID.InnerXml);
                }
            }
            Int32      nextID   = maxID + 1;
            XmlElement xePerson = (XmlElement)frgPersonNode.SelectSingleNode(".");

            xePerson.SetAttribute("id", nextID.ToString());

            xmlPeople.DocumentElement.AppendChild(frgPersonNode);
            string         statusMessage = string.Empty;
            HttpStatusCode statusCode;
            bool           bValidationStatus = MakeSureXMLIsStillValid(xmlPeople, ref statusMessage); //Common Routine to run the XSD against the new XML to make sure it is valid, and make sure there are unique IDs

            //Save the XML to the file
            if (bValidationStatus == true)
            {
                SavePeopleDocument(xmlPeople); //Common Routine to save the People.xml document
                statusMessage = "Creation Successful";
                statusCode    = HttpStatusCode.Created;
            }
            else
            {
                statusCode = HttpStatusCode.BadRequest;
            }

            res            = CreateResponse(format, statusMessage); //Common Routine to create an HttpResponseMessage
            res.StatusCode = statusCode;

            return(res);
        }
Esempio n. 22
0
        public void ScreenFormatting()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC28-Screen.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC28-Screen"));

            // REQUIREMENT 1
            Assert.That(xml.SelectSingleNode("/chapter/section[1]/para[2]").InnerXml, Is.EqualTo("Example of a screen element"));

            // Check that the tag immediately after this paragraph is a screen with code
            XmlNode node1 = xml.SelectSingleNode("/chapter/section[1]/para[2]");

            node1 = node1.NextSibling;
            while (node1.NodeType != XmlNodeType.Element)
            {
                node1 = node1.NextSibling;
            }

            Assert.That(node1.InnerXml, Is.EqualTo("public void Dispose() { }"));
            Assert.That(node1.Name, Is.EqualTo("screen"));

            // REQUIREMENT 2
            Assert.That(xml.SelectSingleNode("/chapter/section[2]/para[2]").InnerXml, Is.EqualTo("Further examples"));

            // Check that the tag immediately after this paragraph is a screen with code
            XmlNode node2 = xml.SelectSingleNode("/chapter/section[2]/para[2]");

            node2 = node2.NextSibling;
            while (node2.NodeType != XmlNodeType.Element)
            {
                node2 = node2.NextSibling;
            }

            Assert.That(node2.InnerXml, Is.EqualTo(
                            "protected virtual void Dispose(bool disposing) {\n  if (disposing) {\n    // ..\n  }\n}"));
            Assert.That(node2.Name, Is.EqualTo("screen"));
        }
Esempio n. 23
0
        /// <summary>
        /// コメントアウトされた locator_ref ロケーター要素の name と display_name の値を返す
        /// xpath = //comment()[contains(.,'<locator_ref>')]
        /// コメントアウトされた portal_locators ポータルロケータ name と display_name の値を返す
        /// xpath = //comment()[contains(.,'<portal_locators>')]
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        private System.Collections.Generic.Dictionary <string, string> getCommentedLocators(XmlDocument doc)
        {
            Dictionary <string, string> commentedList = new Dictionary <string, string>();

            try {
                XmlNodeList locatorNodes = doc.SelectNodes("//comment()[contains(.,'<locator_ref>')]");
                foreach (XmlNode locatorNode in locatorNodes)
                {
                    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
                    docFrag.InnerXml = locatorNode.InnerText;

                    string name     = docFrag.SelectSingleNode("//name").InnerText;
                    string dispname = docFrag.SelectSingleNode("//display_name").InnerText;
                    commentedList.Add(name, dispname);
                    docFrag = null;
                }

                XmlNodeList portalNodes = doc.SelectNodes("//comment()[contains(.,'<portal_locators>')]");
                foreach (XmlNode portalNode in portalNodes)
                {
                    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
                    docFrag.InnerXml = portalNode.InnerText;

                    string name     = docFrag.SelectSingleNode("//display_name/@locator_name").Value;
                    string dispname = docFrag.SelectSingleNode("//display_name/@display_name").Value;
                    commentedList.Add(name, dispname);
                    docFrag = null;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            return(commentedList);
        }
Esempio n. 24
0
        public void BothLists2()
        {
            XmlDocumentFragment xml = LoadXmi(@"XMI\TC45-BothLists2.xml");

            Assert.That(xml.SelectSingleNode("/chapter/title").InnerXml, Is.EqualTo("TC45-BothLists2"));
            Assert.That(xml.SelectSingleNode("/chapter/section/title").InnerXml, Is.EqualTo("Requirement1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/itemizedlist/listitem/para").InnerXml, Is.EqualTo("Itemized List 1"));
            Assert.That(xml.SelectSingleNode("/chapter/section/itemizedlist/listitem/itemizedlist/listitem/itemizedlist/listitem/itemizedlist/listitem[1]/para").InnerXml, Is.EqualTo("Itemized List 2"));
            Assert.That(xml.SelectSingleNode("/chapter/section/itemizedlist/listitem/itemizedlist/listitem/itemizedlist/listitem/itemizedlist/listitem[2]/para").InnerXml, Is.EqualTo("Itemized List 3"));
            Assert.That(xml.SelectSingleNode("/chapter/section/para[2]").InnerXml, Is.EqualTo("(Note we really wanted nested lists, but EA doesn't seem to let this happen)"));
        }
Esempio n. 25
0
        private static IEnumerable ExtractNodes(XmlNode element, string includeFileName)
        {
            XmlDocument ownerDocument = element is XmlDocument ? element as XmlDocument : element.OwnerDocument;

            XmlDocumentFragment fragment = ownerDocument.CreateDocumentFragment();

            try
            {
                //XmlDocument includeDoc = ChoXmlDocument.Load(includeFileName);
                XmlDocument includeDoc = new XmlDocument(_nameTable);
                includeDoc.Load(includeFileName);

                foreach (XmlAttribute attr in element.Attributes)
                {
                    if (attr.Name != PathToken &&
                        attr.Name != CinchoNSToken)
                    {
                        includeDoc.DocumentElement.SetAttribute(attr.Name, attr.Value);
                    }
                }

                fragment.InnerXml = includeDoc.InnerXml;

                return(new XmlNode[] { fragment.SelectSingleNode("/*") });
            }
            catch (XmlException)
            {
                try
                {
                    using (StreamReader sr = File.OpenText(includeFileName))
                        fragment.InnerXml = sr.ReadToEnd();

                    return(fragment.SelectNodes("child::node()" /*"/*|/comment()"*/));
                }
                catch (Exception innerEx)
                {
                    throw new ChoXmlDocumentException(String.Format("{0}: Error loading xml file.", includeFileName), innerEx);
                }
            }
            catch (Exception ex)
            {
                throw new ChoXmlDocumentException(String.Format("{0}: Error loading xml file.", includeFileName), ex);
            }
        }
Esempio n. 26
0
        private static void BackupMetaField(XmlNode root, MetaField mf)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }
            if (mf == null)
            {
                throw new ArgumentNullException("mf");
            }

            XmlDocumentFragment xmlMetaField = root.OwnerDocument.CreateDocumentFragment();

            xmlMetaField.InnerXml = "<MetaField><Namespace></Namespace><Name></Name><FriendlyName></FriendlyName><Description></Description><DataType></DataType><Length></Length><AllowNulls></AllowNulls><SaveHistory></SaveHistory><AllowSearch></AllowSearch><MultiLanguageValue></MultiLanguageValue><Tag></Tag></MetaField>";

            xmlMetaField.SelectSingleNode("MetaField/Namespace").InnerXml          = mf.Namespace;
            xmlMetaField.SelectSingleNode("MetaField/Name").InnerXml               = mf.Name;
            xmlMetaField.SelectSingleNode("MetaField/FriendlyName").InnerXml       = mf.FriendlyName;
            xmlMetaField.SelectSingleNode("MetaField/Description").InnerXml        = mf.Description;
            xmlMetaField.SelectSingleNode("MetaField/DataType").InnerXml           = mf.DataType.ToString();
            xmlMetaField.SelectSingleNode("MetaField/Length").InnerXml             = mf.Length.ToString(_culture);
            xmlMetaField.SelectSingleNode("MetaField/AllowNulls").InnerXml         = mf.AllowNulls.ToString();
            xmlMetaField.SelectSingleNode("MetaField/SaveHistory").InnerXml        = mf.SaveHistory.ToString();
            xmlMetaField.SelectSingleNode("MetaField/AllowSearch").InnerXml        = mf.AllowSearch.ToString();
            xmlMetaField.SelectSingleNode("MetaField/MultiLanguageValue").InnerXml = mf.MultilanguageValue.ToString();

            if (mf.Tag != null)
            {
                xmlMetaField.SelectSingleNode("MetaField/Tag").InnerXml = Convert.ToBase64String((byte[])mf.Tag);
            }

            if (mf.OwnerMetaClassIdList.Count > 0)
            {
                foreach (int MetaClassId in mf.OwnerMetaClassIdList)
                {
                    MetaClass mc = MetaClass.Load(MetaClassId);

                    XmlNode xmlOwnerMetaClass = (XmlNode)root.OwnerDocument.CreateElement("OwnerMetaClass");
                    xmlOwnerMetaClass.InnerXml = mc.Name;

                    xmlMetaField.SelectSingleNode("MetaField").AppendChild(xmlOwnerMetaClass);
                }
            }

            // Dictionary
            if (mf.Dictionary != null)
            {
                foreach (MetaDictionaryItem dicItem in mf.Dictionary)
                {
                    XmlNode xmlDictionaryItem = (XmlNode)root.OwnerDocument.CreateElement("Dictionary");
                    xmlDictionaryItem.InnerXml = dicItem.Value;
                    xmlMetaField.SelectSingleNode("MetaField").AppendChild(xmlDictionaryItem);
                }
            }

            root.AppendChild((XmlNode)xmlMetaField);
        }
Esempio n. 27
0
        public HttpResponseMessage UpdatePeopleDetails(string Id, [FromUri] string format = "xml")
        {
            HttpResponseMessage res = null;

            string              strUpdatePerson = Request.Content.ReadAsStringAsync().Result; //The Person Node is in the body of the request
            XmlDocument         xmlPeople       = GetPeopleDocument();                        //Common Routine to load up the People.xml document
            XmlElement          xe           = xmlPeople.CreateElement("PeopleToUpdate");     //Need a root node
            XmlDocumentFragment xReplacement = xmlPeople.CreateDocumentFragment();            //One technique to INSERT a node into an XML Document

            xReplacement.InnerXml = strUpdatePerson;
            string         statusMessage = string.Empty;
            HttpStatusCode statusCode;

            //Make sure the ID in the replacement person matches the ID in the URL
            string  xPathToGetReplacementID = @"//Person/@id";
            XmlNode xnReplacementID         = xReplacement.SelectSingleNode(xPathToGetReplacementID);

            if (xnReplacementID != null)
            {
                string strReplacementID = xnReplacementID.InnerText;
                if (strReplacementID == Id) // So far so good
                {
                    //Make sure there is a Person to replace
                    string  xPathToFindPersonWithThisId = @"//Person[@id=" + Id + "]";
                    XmlNode xnPersonToBeReplaced        = xmlPeople.SelectSingleNode(xPathToFindPersonWithThisId);
                    if (xnPersonToBeReplaced != null)
                    {
                        xnPersonToBeReplaced.ParentNode.ReplaceChild(xReplacement, xnPersonToBeReplaced);
                        bool bValidationStatus = MakeSureXMLIsStillValid(xmlPeople, ref statusMessage); //Common Routine to run the XSD against the new XML to make sure it is valid, and make sure there are unique IDs
                        if (bValidationStatus == true)
                        {
                            SavePeopleDocument(xmlPeople); //Common Routine to save the People.xml document
                            statusMessage = "Update Successful";
                            statusCode    = HttpStatusCode.OK;
                        }
                        else
                        {
                            statusCode = HttpStatusCode.BadRequest;
                        }
                    }
                    else
                    {
                        statusMessage = "Update Unsuccessul -- Nothing to Update";
                        statusCode    = HttpStatusCode.BadRequest;
                    }
                }
                else
                {
                    statusMessage = "Update Unsuccessul -- IDs do not match";
                    statusCode    = HttpStatusCode.BadRequest;
                }
            }
            else
            {
                statusMessage = "Update Unsuccessul -- ID missing";
                statusCode    = HttpStatusCode.BadRequest;
            }

            res            = CreateResponse(format, statusMessage); //Common Routine to create an HttpResponseMessage
            res.StatusCode = statusCode;
            return(res);
        }
Esempio n. 28
0
        private void ProcessIncomingSensorData(string topic, string message)
        {
            if (!((cbNO2.Checked && "NO2".Equals(topic.Trim())) || (cbCO.Checked && "CO".Equals(topic.Trim())) || (cbO3.Checked && "O3".Equals(topic.Trim()))))
            {
                return;
            }


            XmlDocument doc = new XmlDocument();

            doc.LoadXml(message);

            ValidateXml(doc, topic);

            this.BeginInvoke(new MethodInvoker(delegate {
                if (!isValid)
                {
                    textBox1.Text = validationMessage + " ---- " + message;
                }
                else
                {
                    textBox1.Text = message;
                }
            }));
            if (!isValid)
            {
                return;
            }

            //Get XML from String
            XmlDocumentFragment fragment = doc.CreateDocumentFragment();

            fragment.InnerXml = message;
            //Get SensorValue
            Console.WriteLine(fragment.OuterXml);
            XmlNode sensorValueNo = fragment.SelectSingleNode("/airMonit/value");
            float   sensorValue   = float.Parse(sensorValueNo.InnerText, CultureInfo.InvariantCulture);

            String  dataProcessed = null;
            Boolean alarm         = false;

            HashSet <string> alarmMessagesList = new HashSet <string>();

            XmlNodeList listConditions = null;

            // inicio das verificaçoes
            if ("NO2".Equals(topic))
            {
                listConditions = trigger_rulesDoc.
                                 SelectNodes("/rules/parameter[@name='NO2' and @status = 'active']/condition");
            }
            else if ("CO".Equals(topic))
            {
                listConditions = trigger_rulesDoc.
                                 SelectNodes("/rules/parameter[@name='CO' and @status = 'active']/condition");
            }
            else if ("O3".Equals(topic))
            {
                listConditions = trigger_rulesDoc.SelectNodes("/rules/parameter[@name='O3' and @status = 'active']/condition");
            }

            foreach (XmlNode condition in listConditions)
            {
                float ruleValue = float.Parse(condition["value"].InnerText, CultureInfo.InvariantCulture);

                string operatorValue = condition["operator"].InnerText;

                string status = condition["status"].InnerText;

                switch (operatorValue)
                {
                case "equals":
                    if ("active".Equals(status.Trim()) && sensorValue == ruleValue)
                    {
                        alarm = true;     //alarm ativado
                        alarmMessagesList.Add(condition["message"].InnerText);
                    }
                    break;

                case "less":
                    if ("active".Equals(status) && sensorValue < ruleValue)
                    {
                        alarm = true;     //alarm ativado
                        alarmMessagesList.Add(condition["message"].InnerText);
                    }
                    break;

                case "greater":
                    if ("active".Equals(status) && sensorValue > ruleValue)
                    {
                        alarm = true;     //alarm ativado
                        alarmMessagesList.Add(condition["message"].InnerText);
                    }
                    break;

                case "between":
                    //ir buscar segundo valor
                    float ruleValue2 = float.Parse(condition["value2"].InnerText, CultureInfo.InvariantCulture);

                    if ("active".Equals(status) && sensorValue >= ruleValue && sensorValue <= ruleValue2)
                    {
                        alarm = true;     //alarm ativado
                        alarmMessagesList.Add(condition["message"].InnerText);
                    }
                    break;
                }
            }

            // Fim das verificaçoes

            if (alarm == true)
            {
                foreach (string s in alarmMessagesList)
                {
                    XmlElement alarmMessageXML = doc.CreateElement("alarmMessage");
                    alarmMessageXML.InnerText = s;
                    fragment.FirstChild.AppendChild(alarmMessageXML);
                }

                dataProcessed = fragment.OuterXml;

                XmlDocument doc2 = new XmlDocument();
                doc2.LoadXml(dataProcessed);
                doc2.Save(@"app_data\alarms.xml");
                ValidateXml(doc2, "Alarm");

                if (isValid)
                {
                    SendProcessedDataToBroker(dataProcessed, "ALARM");
                }
            }
        }
Esempio n. 29
0
        private static string[] ExpandIncludes(XmlNode section, string baseDirectory, List <string> parentFileList)
        {
            if (!String.IsNullOrEmpty(baseDirectory) && !parentFileList.Contains(baseDirectory) && !String.IsNullOrEmpty(Path.GetFileName(baseDirectory)))
            {
                parentFileList.Add(baseDirectory);
            }

            if (!String.IsNullOrEmpty(baseDirectory))
            {
                baseDirectory = Path.GetDirectoryName(baseDirectory);
            }

            List <string> includeFileList = new List <string>();

            XmlNodeList includeNodeList = section.SelectNodes(String.Format("//include[@{0}]", PathToken));

            foreach (XmlElement element in includeNodeList)
            {
                string includeFileName = element.GetAttribute(PathToken);
                //if (String.IsNullOrEmpty(includeFileName)) continue;
                if (!String.IsNullOrEmpty(baseDirectory) && !Path.IsPathRooted(includeFileName))
                {
                    includeFileName = Path.Combine(baseDirectory, includeFileName);
                }

                if (!String.IsNullOrEmpty(baseDirectory) && IsCircularFileExists(parentFileList, includeFileName))
                {
                    throw new ChoXmlDocumentException(String.Format("Circular reference encountered on the {0} file.", baseDirectory));
                }

                if (!includeFileList.Contains(includeFileName))
                {
                    includeFileList.Add(includeFileName);
                }

                XmlDocument         ownerDocment = section is XmlDocument ? section as XmlDocument : section.OwnerDocument;
                XmlDocumentFragment fragment     = ownerDocment.CreateDocumentFragment();

                try
                {
                    XmlDocument includeDoc = ChoXmlDocument.Load(includeFileName);

                    foreach (XmlAttribute attr in element.Attributes)
                    {
                        if (attr.Name != PathToken)
                        {
                            includeDoc.DocumentElement.SetAttribute(attr.Name, attr.Value);
                        }
                    }

                    fragment.InnerXml = includeDoc.InnerXml;

                    XmlElement xmlSubElement = (XmlElement)fragment.SelectSingleNode("/*");

                    string[] innerIncludeFileList = ExpandIncludes(xmlSubElement, baseDirectory, parentFileList);
                    foreach (string innerIncludeFile in innerIncludeFileList)
                    {
                        if (!includeFileList.Contains(includeFileName))
                        {
                            includeFileList.Add(innerIncludeFile);
                        }
                    }

                    element.ParentNode.ReplaceChild(xmlSubElement, element);
                    xmlSubElement.ParentNode.InsertBefore(xmlSubElement.OwnerDocument.CreateComment(String.Format(String.Format("DO NOT REMOVE - BEGIN INCLUDE {0}", includeFileName))),
                                                          xmlSubElement);
                    xmlSubElement.ParentNode.AppendChild(xmlSubElement.OwnerDocument.CreateComment(String.Format(String.Format("DO NOT REMOVE - END INCLUDE {0}", includeFileName))));
                }
                catch (XmlException)
                {
                    try
                    {
                        using (StreamReader sr = File.OpenText(includeFileName))
                            fragment.InnerXml = sr.ReadToEnd();

                        XmlNode parentNode = element.ParentNode;

                        parentNode.RemoveChild(element);

                        bool    isFirstChild = true;
                        XmlNode lastChild    = null;
                        foreach (XmlNode xmlNode in fragment.SelectNodes("/*|//comment()"))
                        {
                            if (xmlNode == null)
                            {
                                continue;
                            }

                            if (xmlNode is XmlElement && xmlNode.Name == "include")
                            {
                                string[] innerIncludeFileList = ExpandIncludes(xmlNode, includeFileName, parentFileList); //, false);
                                foreach (string innerIncludeFile in innerIncludeFileList)
                                {
                                    if (!includeFileList.Contains(includeFileName))
                                    {
                                        includeFileList.Add(innerIncludeFile);
                                    }
                                }
                            }

                            parentNode.AppendChild(xmlNode);
                            if (isFirstChild)
                            {
                                parentNode.InsertBefore(parentNode.OwnerDocument.CreateComment(String.Format(String.Format("DO NOT REMOVE - BEGIN INCLUDE {0}", includeFileName))),
                                                        xmlNode);
                                isFirstChild = false;
                            }
                            lastChild = xmlNode;
                        }
                        parentNode.InsertAfter(parentNode.OwnerDocument.CreateComment(String.Format(String.Format("DO NOT REMOVE - END INCLUDE {0}", includeFileName))),
                                               lastChild);
                    }
                    catch (Exception innerEx)
                    {
                        throw new ChoXmlDocumentException(String.Format("{0}: Error loading xml file.", includeFileName), innerEx);
                    }
                }
                catch (Exception ex)
                {
                    throw new ChoXmlDocumentException(String.Format("{0}: Error loading xml file.", includeFileName), ex);
                }
            }

            return(includeFileList.ToArray());
        }