Ejemplo n.º 1
0
        internal void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                // End of credit_card element, get out of here
                if (reader.Name == "credit_card" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "year":
                            this.ExpirationYear = reader.ReadElementContentAsInt();
                            break;

                        case "month":
                            this.ExpirationMonth = reader.ReadElementContentAsInt();
                            break;

                        case "last_four":
                            this.LastFour = reader.ReadElementContentAsString();
                            break;

                        case "type":
                            this.CreditCardType = reader.ReadElementContentAsString();
                            break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Dictionary<string, string> parsePackageInfo(string input)
        {
            if (!File.Exists(input))
                return new Dictionary<string, string>();

            Dictionary<string, string> details = new Dictionary<string, string>();

            try
            {
                #region Boring XML parsing
                // Try to parse the package_info.xml.
                XmlTextReader xmldoc = new XmlTextReader(input);
                xmldoc.DtdProcessing = DtdProcessing.Ignore;
                while (xmldoc.Read())
                {
                    if (xmldoc.NodeType.Equals(XmlNodeType.Element))
                    {
                        switch (xmldoc.LocalName)
                        {
                            case "id":
                                string mid = xmldoc.ReadElementContentAsString();
                                details.Add("modID", mid);

                                // Determine the mod author.
                                string[] pieces = mid.Split(':');
                                details.Add("modUser", pieces[0]);
                                break;

                            case "name":
                                details.Add("modName", xmldoc.ReadElementContentAsString());
                                break;

                            case "version":
                                details.Add("modVersion", xmldoc.ReadElementContentAsString());
                                break;

                            case "type":
                                if (xmldoc.ReadElementContentAsString() == "modification")
                                    details.Add("modType", "Modification");
                                else
                                    details.Add("modType", "Avatar pack");
                                break;

                            case "install":
                                if (!details.ContainsKey("modCompat"))
                                    details.Add("modCompat", xmldoc.GetAttribute("for"));

                                break;
                        }
                    }
                }
                xmldoc.Close();
                #endregion
                return details;
            }
            catch
            {
                return new Dictionary<string, string>();
            }
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader reader = new XmlTextReader(context.ResponseStream);
            SendMessageResponse response = new SendMessageResponse();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                            case MNSConstants.XML_ELEMENT_MESSAGE_ID:
                                response.MessageId = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
                                response.MessageBodyMD5 = reader.ReadElementContentAsString();
                                break;
                        }
                        break;
                }
            }
            reader.Close();
            return response;
        }
        public static void loadXML()
        {
            if (pointers.Count <= 0)  {
                reader = new XmlTextReader("RocketLeague.CT");

                while (reader.ReadToFollowing("CheatEntry"))
                {
                    reader.ReadToFollowing("Description");
                    string name = reader.ReadElementContentAsString().Trim('"');

                    reader.ReadToFollowing("Address");
                    string adress = reader.ReadElementContentAsString();
                    string offsets = "";

                    reader.ReadToFollowing("Offsets");
                    reader.Read();
                    while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                    {
                        offsets = "+" + reader.ReadElementContentAsString() + offsets;
                    }

                    pointers.Add(name, adress + offsets);
                }
                reader.Close();
            }
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader reader = new XmlTextReader(context.ResponseStream);
            ListQueueResponse response = new ListQueueResponse();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                            case MNSConstants.XML_ELEMENT_QUEUE_URL:
                                response.QueueUrls.Add(reader.ReadElementContentAsString());
                                break;
                            case MNSConstants.XML_ELEMENT_NEXT_MARKER:
                                response.NextMarker = reader.ReadElementContentAsString();
                                break;
                        }
                        break;
                }
            }
            reader.Close();
            return response;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The get location.
        /// </summary>
        /// <param name="ip">
        /// The ip.
        /// </param>
        /// <returns>
        /// The <see cref="GeolocateResult"/>.
        /// </returns>
        public static GeolocateResult GetLocation(this IPAddress ip)
        {
            // FIXME: ServiceLocator - logger & privateconfig
            var config = ServiceLocator.Current.GetInstance<IPrivateConfiguration>();
            var logger = ServiceLocator.Current.GetInstance<ILogger>().CreateChildLogger("IPAddressExtensions");

            if (config.IpInfoDbApiKey == string.Empty)
            {
                logger.Error("API key is empty, please fix this in configuration.");
                return new GeolocateResult();
            }

            var requestData =
                HttpRequest.Get(
                    "http://api.ipinfodb.com/v3/ip-city/?key=" + config.IpInfoDbApiKey + "&ip=" + ip + "&format=xml");

            using (Stream s = requestData.ToStream())
            {
                var xtr = new XmlTextReader(s);

                var result = new GeolocateResult();

                while (!xtr.EOF)
                {
                    xtr.Read();
                    switch (xtr.Name)
                    {
                        case "statusCode":
                            result.Status = xtr.ReadElementContentAsString();
                            break;
                        case "countryCode":
                            result.CountryCode = xtr.ReadElementContentAsString();
                            break;
                        case "countryName":
                            result.Country = xtr.ReadElementContentAsString();
                            break;
                        case "regionName":
                            result.Region = xtr.ReadElementContentAsString();
                            break;
                        case "cityName":
                            result.City = xtr.ReadElementContentAsString();
                            break;
                        case "zipCode":
                            result.ZipPostalCode = xtr.ReadElementContentAsString();
                            break;
                        case "latitude":
                            result.Latitude = xtr.ReadElementContentAsFloat();
                            break;
                        case "longitude":
                            result.Longitude = xtr.ReadElementContentAsFloat();
                            break;
                    }
                }

                return result;
            }
        }
Ejemplo n.º 7
0
		public Request CreateRequest(string testXMLFilePath)
		{
			using (var outlookApp = new WsApplication(new Microsoft.Office.Interop.Outlook.Application(), false))
			{
				using (var mailItem = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem))
				{
					int positionCount = 0;
					XmlReader reader = new XmlTextReader(testXMLFilePath);

					while (reader.Read())
					{
						switch (reader.NodeType)
						{
						case XmlNodeType.Element:
							if (reader.Name.CompareTo("subject") == 0)
							{
								mailItem.Subject = reader.ReadElementContentAsString();
							}
							else if (reader.Name.CompareTo("recipient") == 0)
							{
								mailItem.Recipients.Add(reader.ReadElementContentAsString());
							}
							else if (reader.Name.CompareTo("attachment") == 0)
							{
								string fileName = reader.ReadElementContentAsString();

								// We want the parent directory because the scripts live in \succeed and \fail below the folder containg the test files
								string testFilePath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(testXMLFilePath)).FullName, fileName);

								if (!File.Exists(testFilePath))
								{
									throw new Exception("Unable to find test file: " + fileName);
								}

								mailItem.Attachments.Add(testFilePath, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, ++positionCount, fileName);
							}
							break;
						}
					}
					mailItem.Save();

					// Now convert to to a request
					Request request = null;
					// Yes we are assuming the security has been disabled OK...but we're testing the decryption here, NOT the proxy/security code path
					_proxy = new OutlookMailProxy(mailItem);
					_email2Uro = new Email2Request(_proxy);
					request = _email2Uro.Convert(RequestChannel.Outlook, false);

					// Tidyup
					mailItem.Delete();

					return request;
				}
			}
		}
Ejemplo n.º 8
0
        private Compiler Parse(string xmlFilePath)
        {
            var compiler = new Compiler();
            var xmlReader = new XmlTextReader(xmlFilePath);
            xmlReader.Read();

            while (xmlReader.Read())
            {
                switch (xmlReader.Name)
                {
                    case "name":
                        {
                            compiler.Name = xmlReader.ReadElementContentAsString();
                        }
                        break;

                    case "location":
                        {
                            compiler.Location = Path.Combine(
                                AppDomain.CurrentDomain.BaseDirectory, xmlReader.ReadElementContentAsString());
                        }
                        break;

                    case "extension":
                        {
                            compiler.Extension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "arguments":
                        {
                            compiler.Arguments = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "compiledExtension":
                        {
                            compiler.CompiledExtension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "needShortName":
                        {
                            compiler.IsNeedShortPath = xmlReader.ReadElementContentAsBoolean();
                        }
                        break;
                }
            }

            if (compiler.Extension == string.Empty || compiler.Name == string.Empty || compiler.Location == string.Empty || compiler.CompiledExtension == string.Empty || compiler.Arguments == string.Empty)
                throw new Exception("Bad xml information about compiler");

            return compiler;
        }
Ejemplo n.º 9
0
 private void parseXML(string filename)
 {
     using (XmlTextReader reader = new XmlTextReader(filename))
     {
         reader.ReadToFollowing("title");
         Title = reader.ReadElementContentAsString();
         reader.ReadToFollowing("path");
         Path = reader.ReadElementContentAsString();
         reader.ReadToFollowing("description");
         Description = reader.ReadElementContentAsString();
         reader.ReadToFollowing("img_path");
         ImagePath = reader.ReadElementContentAsString();
     }
 }
Ejemplo n.º 10
0
 public bool LoadFromFile(string filename)
 {
     m_FileName = filename;
     bool bRet = false;
     XmlTextReader reader = null;
     try
     {
         reader = new XmlTextReader(m_FileName);
         while (reader.Read())
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element: // The node is an element.
                     switch (reader.Name)
                     {
                         case "name": reader.MoveToContent(); m_name = reader.ReadElementContentAsString(); break;
                         case "pass1": reader.MoveToContent(); m_pass1 = reader.ReadElementContentAsString(); break;
                         case "pass2": reader.MoveToContent(); m_pass2 = reader.ReadElementContentAsString(); break;
                         case "icon": reader.MoveToContent(); m_icon = reader.ReadElementContentAsInt(); break;
                         case "account":
                             {
                                 AccountItem newAccount = new AccountItem();
                                 if (newAccount.AccountXMLLoad(reader))
                                 {
                                     m_Accounts.Add(newAccount);
                                 }
                                 break;
                             }
                     }
                     break;
                 case XmlNodeType.EndElement:
                     break;
             }
         }
     }
     catch (System.IO.FileNotFoundException exception)
     {
         return false;
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error reading " + m_FileName);
     }
     finally
     {
         reader.Close();
     }
     return bRet;
 }
        internal override void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                if (reader.Name == "subscription_add_on" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Element) continue;

                switch (reader.Name)
                {
                    case "add_on_code":
                        AddOnCode = reader.ReadElementContentAsString();
                        break;

                    case "quantity":
                        Quantity = reader.ReadElementContentAsInt();
                        break;

                    case "unit_amount_in_cents":
                        UnitAmountInCents = reader.ReadElementContentAsInt();
                        break;
                }
            }
        }
Ejemplo n.º 12
0
 private string getFormatName(string fileLocation)
 {
     XmlTextReader XMLreader;
     XMLreader = new XmlTextReader(fileLocation);
     XMLreader.ReadToFollowing("format");
     return XMLreader.ReadElementContentAsString();
 }
Ejemplo n.º 13
0
        public void LoadFromFile()
        {
            var path = CreateAndGetPath();
            var xmlReader = new XmlTextReader(System.IO.File.OpenText(path));
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType != XmlNodeType.Element) continue;

                if (xmlReader.Name == Utils.XmlPrefix) Prefix = xmlReader.ReadElementContentAsString();
                if (xmlReader.Name == Utils.XmlTemplateName) TemplateName = xmlReader.ReadElementContentAsString();
                if (xmlReader.Name == Utils.XmlCode) Code = xmlReader.ReadElementContentAsString();
                if (xmlReader.Name == Utils.XmlFolder) Folder = xmlReader.ReadElementContentAsString();
            }

            xmlReader.Close();
        }
        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            XmlTextReader reader = new XmlTextReader(context.ResponseStream);
            ChangeMessageVisibilityResponse response = new ChangeMessageVisibilityResponse();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                            case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
                                response.ReceiptHandle = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
                                response.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
                                break;
                        }
                        break;
                }
            }
            reader.Close();
            return response;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Reads an InkML file and creates a number list strokes from the traces.
        /// </summary>
        /// <param name="pathToInkMLFile">The path to ink ML file.</param>
        /// <returns></returns>
        public static List<Stroke> ReadInkMLFile(string pathToInkMLFile)
        {
            List<Stroke> r = new List<Stroke>(10);
            FileStream inputstream =
                new FileStream(
                    path + Path.DirectorySeparatorChar + pathToInkMLFile,
                    FileMode.Open);

            XmlTextReader xmlr = new XmlTextReader(inputstream);

            while ((!UPXReader.IsEndElementTypeWithName(xmlr, "ink")))
            {
                if (UPXReader.IsElementTypeWithName(xmlr, "trace"))
                {
                    Console.WriteLine(XmlTools.ReadIDAttribute(xmlr));
                    r.Add(new Stroke(
                        Stroke.PointListFromInkMLTrace(
                            xmlr.ReadElementContentAsString())));
                }
                else xmlr.Read(); //overread element
            }

            xmlr.Close();
            inputstream.Close();

            return r;
        }
Ejemplo n.º 16
0
 private void readFile(XmlTextReader reader)
 {
     int line;
     if (int.TryParse(reader.GetAttribute("line"), out line))
         _currentStackLine.Line = line;
     _currentStackLine.File = reader.ReadElementContentAsString();
 }
Ejemplo n.º 17
0
        public static LocalizationData ReadXml(XmlTextReader xr)
        {
            Dictionary<String, Field[]> res = new Dictionary<string, Field[]>();
            if (xr.ReadToDescendant("localization"))
                if (xr.ReadToDescendant("type"))
                    do
                    {
                        List<Field> fields = new List<Field>();
                        var name = xr.GetAttribute("name");
                        if (xr.ReadToDescendant("field"))
                            do
                            {
                                switch (xr.NodeType)
                                {
                                    case XmlNodeType.Element:
                                        if (xr.Name == "field")
                                            fields.Add(new Field { FieldName = xr.GetAttribute("name"), LocalizedText = xr.ReadElementContentAsString() });
                                        break;
                                }
                            } while (xr.ReadToNextSibling("field"));

                        if (fields.Count > 0)
                            res[name] = fields.ToArray();
                    }
                    while (xr.ReadToNextSibling("type"));
            return new LocalizationData(res);
        }
Ejemplo n.º 18
0
        public List<string> LoadFromXml(string xmlFileName, string nodeName, string attributeName = "")
        {
            var items = new List<string>();
             if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(nodeName))
            return items;

             var r = new XmlTextReader(xmlFileName);
             while (r.Read())
             {
            string item = string.Empty;
            if (r.NodeType != XmlNodeType.Element || r.Name != nodeName) continue;
            if (string.IsNullOrEmpty(attributeName))
            {
               item = r.ReadElementContentAsString();
            }
            else
            {
               item = r.GetAttribute(attributeName);
            }
            if (string.IsNullOrEmpty(item)) continue;
            items.Add(item);
             }
             r.Close();

             return items;
        }
Ejemplo n.º 19
0
        // logs the user in and accesses their userId and userName
        public static void loginUser(out string userId, out string userName)
        {
            OAuth oAuth = new OAuth();
            oAuth.getOAuthToken();
            string userXML = oAuth.getOAuthDataUrl("http://www.goodreads.com/api/auth_user");
            userId = "";
            userName = "";

            // grab the user name and user id
            XmlTextReader textReader = new XmlTextReader(userXML);

            while (textReader.Read()) {
                textReader.MoveToElement();

                if (textReader.LocalName.Equals("user")) {
                    textReader.MoveToAttribute("id");
                    userId = textReader.Value;
                }

                if (textReader.LocalName.Equals("name")) {
                    userName = textReader.ReadElementContentAsString();
                }

            }
        }
Ejemplo n.º 20
0
		/// <summary>
		/// Create a dictionary of file/passwords from a test XML file
		/// </summary>
		/// <param name="testXMLFile"></param>
		/// <returns></returns>
		public Dictionary<string, MockContentEncryptionUi.PasswordInfo> ParsePasswordInfo(string testXMLFile)
		{
			Dictionary<string, MockContentEncryptionUi.PasswordInfo> pwdInfo = new Dictionary<string, MockContentEncryptionUi.PasswordInfo>();
			string path = Path.Combine(TestFileDirectory, testXMLFile);

			XmlReader reader = new XmlTextReader(path);

			while (reader.Read())
			{
				switch (reader.NodeType)
				{
					case XmlNodeType.Element:
						if (reader.Name.CompareTo("password") == 0)
						{
							if (reader.HasAttributes)
							{
								string openPwd = reader.GetAttribute("openpwd");
								string modifyPwd = reader.GetAttribute("modifypwd");
								MockContentEncryptionUi.PasswordInfo tmpInfo = new MockContentEncryptionUi.PasswordInfo(openPwd, modifyPwd);

								string fileName = reader.ReadElementContentAsString();
								pwdInfo[fileName.ToLower()] = tmpInfo;
							}
						}
						break;
				}
			}

			return pwdInfo;
		}
Ejemplo n.º 21
0
 public string GetXMLValue(XmlTextReader reader, String nodeName)
 {
     if (reader.ReadToDescendant(nodeName))
         return reader.ReadElementContentAsString();
     else
         return "";
 }
Ejemplo n.º 22
0
		protected override void LoadRules (Category c)
		{			
			// load xml file from smokey resources
			using (Stream ruleInfo = SmokeyRunner.Smokey.GetManifestResourceStream (c.Id + ".xml")) {
				using (XmlTextReader reader = new XmlTextReader (ruleInfo)) {
					reader.WhitespaceHandling = WhitespaceHandling.None;
			
					// we need to know all rule ids, names and descriptions
					while (reader.Read ()) {
						reader.ReadToFollowing ("Violation");	
						string ruleId = reader.GetAttribute ("checkID"); // id
						do {
							if (reader.EOF)
								break;
					
							reader.ReadToFollowing ("Translation");
						} while (reader.GetAttribute ("lang") != "en");
				
						if (reader.EOF)
								break;
				
						string ruleName = reader.GetAttribute ("typeName"); // name
						reader.ReadToFollowing ("Description");
						string ruleDescription = reader.ReadElementContentAsString (); // description
				
						SmokeyRule rule = new SmokeyRule (ruleId, ruleName, ruleDescription);
						SmokeyRuleCache.Add (rule);
						base.AddRule (c, rule);
					}
				}
			}
		}
Ejemplo n.º 23
0
        internal override void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                if (reader.Name == "note" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Element) continue;

                string href;
                switch (reader.Name)
                {
                    case "account":
                        href = reader.GetAttribute("href");
                        if (null != href)
                            AccountCode = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1));
                        break;

                    case "message":
                        Message = reader.ReadElementContentAsString();
                        break;

                    case "created_at":
                        CreatedAt = reader.ReadElementContentAsDateTime();
                        break;
                }
            }
        }
Ejemplo n.º 24
0
        public bool AccountXMLLoad(XmlTextReader reader)
        {
            string priv = "", pub = "";

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        string name = reader.Name;

                        string value = "";
                        if (name == "transactions" || name=="tx")
                        {

                        }
                        else
                        {
                            reader.MoveToContent();
                            value = reader.ReadElementContentAsString();
                        }

                        //reader.read
                        switch (name)
                        {
                            case "name": m_name = value; break;
                            case "privkey": priv = value; break;
                            case "pubkey": pub = value; break;
                            case "icon": m_icon = Convert.ToInt32(value); break;
                            case "numtx": m_tx = Convert.ToInt32(value); break;
                            case "addressid": m_addressid = Convert.ToUInt32(value); break;
                            case "balance": m_balance = Convert.ToInt64(value); break;
                            case "enabled": m_bEnabled = Convert.ToBoolean(value); break;
                            case "tx":
                                {
                                    AddressHistory tx = new AddressHistory();

                                    tx.hash = reader.GetAttribute("hash");
                                    tx.amount = Convert.ToInt64(reader.GetAttribute("amnt"));
                                    tx.fromto = reader.GetAttribute("from");
                                    tx.info = reader.GetAttribute("info");
                                    tx.type = Convert.ToInt32(reader.GetAttribute("type"));
                                    tx.time = Convert.ToInt64(reader.GetAttribute("time"));
                                    m_txhistory.Add(tx);
                                }
                                break;
                        }
                        break;
                    case XmlNodeType.EndElement:
                        if (reader.Name == "account")
                        {
                            m_Key.SetKeyByString(priv, pub);
                            return true;
                        }
                        break;
                }
            }
            return false;
        }
Ejemplo n.º 25
0
 //This function is to pull a specific item from the settings.xml
 public string GetSetting(string setting, string xmlFile)
 {
     string foundString ="";
     XmlTextReader xml = new XmlTextReader(xmlFile);
     xml.ReadToFollowing(setting);
     foundString = xml.ReadElementContentAsString(setting, "");
     return foundString;
 }
Ejemplo n.º 26
0
        public static TableOfContents Scan(Stream s)
        {
            var result = new TableOfContents();
            var levelPath = new Stack<int>();
            int ent = -1;

            using (XmlTextReader r = new XmlTextReader(s))
            {
            r.XmlResolver = null;

            while (r.Read())
            if (r.NodeType == XmlNodeType.Element)
            {
            if ((r.Name.Length == 2) &&
                (char.ToLower(r.Name[0]) == 'h') &&
                char.IsDigit(r.Name[1]))
            {
                int level = r.Name[1] - '0';
                string id = r.GetAttribute("id");
                string text = r.ReadElementContentAsString();

                if ((id != null) && (text != null))
                {
                while ((levelPath.Count > 0) &&
                       (levelPath.Peek() >= level))
                {
                    levelPath.Pop();
                    ent = result.Parent(ent);
                }

                levelPath.Push(level);
                ent = result.AddEntry(ent);

                result.SetName(ent, text);
                result.SetLinkref(ent, id);
                }
            }
            else if (r.Name.ToLower() == "title")
            {
                result.Title = r.ReadElementContentAsString();
            }
            }
            }

            return result;
        }
Ejemplo n.º 27
0
        public static VCase ReadFrom(string filePath, IProjectConfiguration config)
        {
            var vCase = new VCase();

            using (var stream = new StreamReader(filePath, Encoding.UTF8))
            using (var xml = new XmlTextReader(stream))
            {
                xml.ReadToFollowing("Case");

                if (xml.ReadToFollowing("Name"))
                {
                    vCase.Name = xml.ReadElementContentAsString();
                }

                if (xml.ReadToFollowing("CaseItems"))
                {
                    while (xml.ReadToFollowing("CaseItem"))
                    {
                        VCaseItem item = null;
                        xml.ReadToFollowing("Id");
                        var id = xml.ReadElementContentAsString();

                        xml.ReadToFollowing("DisplayName");
                        var displayName = xml.ReadElementContentAsString();

                        xml.ReadToFollowing("RelativePath");
                        var relativePath = xml.ReadElementContentAsString();

                        xml.ReadToFollowing("Type");
                        var type = xml.ReadElementContentAsString();
                        if (type == ProjectItem)
                        {
                            item = ProjectHandler.ReadFrom(xml, config);
                        }

                        Debug.Assert(item != null);
                        item.Id = new Guid(id);
                        item.DisplayName = displayName;
                        item.RelativePath = relativePath;
                        vCase.Items.Add(item);
                    }
                }
            }
            return vCase;
        }
Ejemplo n.º 28
0
        public override bool Execute()
        {
            XmlTextReader reader = new XmlTextReader(_filename);
            StreamWriter writer = new StreamWriter(_filename + ".log");
            string name;
            string success;
            string message;
            string stackTrace;

            writer.WriteLine("NUnit Failures for Build Performed on: " + DateTime.Now.ToString());
            writer.WriteLine();

            while (reader.Read())
            {
                if (reader.Name.EndsWith("test-case"))
                {

                    reader.MoveToNextAttribute();  //Name
                    name = reader.Value;
                    reader.MoveToNextAttribute(); //Executed
                    reader.MoveToNextAttribute(); //Success
                    success = reader.Value;

                    if (success == "False")
                    {
                        advanceToElement(ref reader, "message");
                        message = reader.ReadElementContentAsString();

                        advanceToElement(ref reader, "stack-trace");
                        stackTrace = reader.ReadElementContentAsString();

                        writer.Write(_failCount.ToString() + ") " + name);
                        _failCount++;
                        writer.WriteLine(" - " + message);
                        writer.WriteLine(stackTrace);
                        writer.WriteLine();
                    }
                }
            }

            writer.Close();
            reader.Close();
            return true;
        }
Ejemplo n.º 29
0
        internal Error(XmlTextReader reader, bool fromList)
        {
            if (fromList)
            {
                // list of errors returned
                // <errors>
                //    <error field="model_name.field_name" symbol="not_a_number" lang="en-US">is not a number</error>
                // </errors>
                if (reader.HasAttributes)
                {
                    Field = ReadAttr("field", reader);
                    Code = ReadAttr("code", reader);
                    Symbol = ReadAttr("symbol", reader);
                }

                Message = reader.ReadElementContentAsString();
                return;
            }

            // single error returned
            // <error>
            //    <symbol>asdf</symbol>
            //    <description>asdfasdf </symbol>
            // </error>
            while (reader.Read())
            {
                switch (reader.Name)
                {
                    case "symbol":
                        Symbol = reader.ReadElementContentAsString();
                        break;
                    case "description":
                        Message = reader.ReadElementContentAsString();
                        break;
                    case "details":
                        Details = reader.ReadElementContentAsString();
                        break;
                }

                if (reader.Name == "error" && reader.NodeType == XmlNodeType.EndElement)
                    break;
            }
        }
 private void readXmlContent()
 {
     XmlTextReader reader = new XmlTextReader(".\\configurationFiles\\FilePaths.xml");
     String osName = externalCode.OSVersionInfo.Name.Split(new char[]{' '})[0].ToLower();
     while (reader.ReadToFollowing("os"))
     {
         reader.MoveToFirstAttribute();
         if (reader.Value.Equals(osName))
         {
             reader.ReadToFollowing("fileName");
             this.fileName = reader.ReadElementContentAsString();
             reader.ReadToFollowing("environmentVariable");
             this.environmentVariable = reader.ReadElementContentAsString();
             reader.ReadToFollowing("path");
             this.path = reader.ReadElementContentAsString();
             break;
         }
     }
 }
Ejemplo n.º 31
0
        void ReadXMLFile(string filename)
        {
            //load the xml file into the XmlTextReader object.
            XmlTextReader XmlRdr = new System.Xml.XmlTextReader(filename);

            //while moving through the xml document.
            bool ListIsReady = false;

            LyricObject myLyric = new LyricObject();

            while (XmlRdr.Read())
            {
                ListIsReady = true; // guard to make sure we have font objects to fill with data..


                if (ListIsReady)
                {
                    //check the node type and look for the elements desired.
                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "Artist")
                    {
                        myLyric.Artist = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "Title")
                    {
                        myLyric.Title = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S1")
                    {
                        myLyric.S1 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S2")
                    {
                        myLyric.S2 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S3")
                    {
                        myLyric.S3 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S4")
                    {
                        myLyric.S4 = XmlRdr.ReadElementContentAsString();

                        m_LyricObject.Add(myLyric);
                        myLyric = new LyricObject();
                    }
                }
            } //endwhile
        }
Ejemplo n.º 32
0
        private int ReadXmlCommandFile(string filename)
        {
            string planFilePath = Path.GetDirectoryName(filename);

            this.MergeListFileArray = new List <MergeListFiles>();
            this.MergeListInfo      = new MergeListInfoDefn();

            MergeListFiles mergeElement = null;

            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(filename);

            int fileNotFoundCount = 0;

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name.ToLower())
                    {
                    case "file":
                        if (mergeElement != null)
                        {
                            this.MergeListFileArray.Add(mergeElement);
                        }

                        mergeElement = new MergeListFiles();
                        object exclude = reader.GetAttribute("exclude");
                        if (exclude != null)
                        {
                            if (exclude.ToString() == "1")
                            {
                                mergeElement.Include = false;
                            }
                        }

                        break;

                    case "path":
                        mergeElement.Path = reader.ReadElementContentAsString();

                        // resolve paths, if files were moved
                        if (File.Exists(mergeElement.Path) == false)
                        {
                            ++fileNotFoundCount;
                        }

                        break;

                    case "pages":
                        mergeElement.Pages = reader.ReadElementContentAsString();
                        break;

                    case "bookmark":
                        mergeElement.Bookmark = reader.ReadElementContentAsString();
                        break;

                    case "level":
                        mergeElement.Level = reader.ReadElementContentAsInt();
                        break;

                    case "info":
                        this.MergeListInfo.HasInfo = true;
                        break;

                    case "author":
                        this.MergeListInfo.HasInfo    = true;
                        this.MergeListInfo.InfoAuthor = reader.ReadElementContentAsString();
                        break;

                    case "title":
                        this.MergeListInfo.HasInfo   = true;
                        this.MergeListInfo.InfoTitle = reader.ReadElementContentAsString();
                        break;

                    case "subject":
                        this.MergeListInfo.HasInfo     = true;
                        this.MergeListInfo.InfoSubject = reader.ReadElementContentAsString();
                        break;

                    case "annotation":
                        this.MergeListInfo.Annotation = reader.ReadElementContentAsString();
                        break;

                    case "outfile":
                        this.MergeListInfo.OutFilename = reader.ReadElementContentAsString();
                        break;

                    case "startpage":
                        this.MergeListInfo.StartPage   = int.Parse(reader.ReadElementContentAsString());
                        this.MergeListInfo.NumberPages = true;
                        break;

                    case "paginationformat":
                        try
                        {
                            this.MergeListInfo.PaginationFormat = (PaginationFormatting.PaginationFormats) int.Parse(reader.ReadElementContentAsString());
                        }
                        catch
                        {
                            throw new Exception("Invalid value for pagination format in command file");
                        }

                        break;
                    }
                }
            }

            if (mergeElement != null)
            {
                this.MergeListFileArray.Add(mergeElement);
            }

            reader.Close();

            return(fileNotFoundCount);
        }