public void ReadXml(XmlReader reader)
		{
			reader.MoveToContent();
			var empty = reader.IsEmptyElement;
			reader.ReadStartElement();
			if (!empty)
			{
				while (reader.MoveToContent() == XmlNodeType.Element)
				{
					if (reader.Name == @"ProductName" && !reader.IsEmptyElement)
					{
						ProductName = reader.ReadElementString();
					}
					else if (reader.Name == @"GlyphColor" && !reader.IsEmptyElement)
					{
						GlyphColor = ParseColor(reader.ReadElementString());
					}
					else
					{
						// consume the bad element and skip to next sibling or the parent end element tag
						reader.ReadOuterXml();
					}
				}
				reader.MoveToContent();
				reader.ReadEndElement();
			}
		}
Example #2
0
        // TwoWayRequest: Accept two integer values, return their sum
        public byte[] TwoWayRequest(WsWsaHeader header, XmlReader reader)
        {
            try
            {
                // Find beginning of request
                reader.ReadStartElement("TwoWayRequest", SimpleServiceNamespaceUri);

                // Find the values to be added
                int X = Convert.ToInt32(reader.ReadElementString("X", SimpleServiceNamespaceUri));
                int Y = Convert.ToInt32(reader.ReadElementString("Y", SimpleServiceNamespaceUri));

                Log.Comment("");
                Log.Comment("X = " + X.ToString() + " Y = " + Y.ToString());
                Log.Comment(X.ToString() + " + " + Y.ToString() + " = " + ((int)(X + Y)).ToString());
                Log.Comment("");

                // Return the response
                return TwoWayResponse(header, X + Y);
            }
            catch (Exception e)
            {
                // Something went wrong 
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }
        }
 public void ReadXml(XmlReader r)
 {
     r.Read(); // move past container
     r.ReadStartElement("dictionary");
     while (r.NodeType != XmlNodeType.EndElement) {
         r.ReadStartElement("item", NS);
         string key = r.ReadElementString("key", NS);
         string value = r.ReadElementString("value", NS);
         r.ReadEndElement();
         r.MoveToContent();
         dictionary.Add(key, value);
     }
 }
		 void IXmlSerializable.ReadXml(XmlReader r)
		{
			r.MoveToContent();
			r.ReadStartElement("Employee");
			
			 r.ReadStartElement("Name");
			 FirstName = r.ReadElementString("First", ns);
			 LastName = r.ReadElementString("Last", ns);
			r.ReadEndElement();
			r.MoveToContent();
			 ID = Int32.Parse(r.ReadElementString("ID", ns));
			 r.ReadEndElement();
			 
		}
		void IXmlSerializable.ReadXml(XmlReader reader)
		{
			reader.Read();
			reader.ReadStartElement("dictionary");
			while (reader.NodeType != XmlNodeType.EndElement)
			{
				reader.ReadStartElement("item");
				string key = reader.ReadElementString("key");
				string value = reader.ReadElementString("value");
				reader.ReadEndElement();
				reader.MoveToContent();
				dictionary.Add(key, value);
			}
			reader.ReadEndElement();
		}
        private void ReadElement(XmlReader reader, Bag parent) {
            var name = XmlConvert.DecodeName(reader.LocalName);
            var type = reader["type"];

            // is it a value node ? i.e. type=""
            if (type != null) {
                if (type == "Array") {
                    // go to first item
                    parent.SetMember(name, ReadArray(reader));
                    reader.Read();
                }
                else {
                    var typeCode = (TypeCode)Enum.Parse(typeof(TypeCode), type);
                    var value = SConvert.XmlDecode(typeCode, reader.ReadElementString());
                    parent.SetMember(name, value);
                }
            }
            else {
                var grappe = new Bag();
                reader.Read();
                parent.SetMember(name, grappe);
                while (reader.MoveToContent() == XmlNodeType.Element) {
                    ReadElement(reader, grappe);
                }

                reader.Read();
            }
        }
        void AddString(XmlReader reader, Hashtable strings)
        {
            string key = reader.Name;

            if (strings.ContainsKey(key))
                throw new InvalidDataException("Already contains key (" + key + ")");

            reader.Read();

            while (reader.IsStartElement())
            {
                string name = reader.Name;
                string value = reader.ReadElementString();

                if (string.IsNullOrEmpty(value))
                    continue;

                if (name == culture.Name)
                    strings.Add(key, value);

                if (name == "default" && culture.Equals(CultureInfo.InvariantCulture))
                    strings.Add(key, value);
            }

            reader.ReadEndElement();
        }
Example #8
0
 /// <summary>Reads the Elo from an xml writer.</summary>
 /// <remarks>
 /// Uses the string parse function of Elo.
 /// </remarks>
 /// <param name="reader">An xml reader.</param>
 void IXmlSerializable.ReadXml(XmlReader reader)
 {
     var s = reader.ReadElementString();
     BotInfo info;
     TryParse(s, out info);
     m_Name = info.m_Name;
     m_Version = info.m_Version;
     m_Inactive = info.m_Inactive;
 }
Example #9
0
        private void readBuilding(XmlReader inReader)
        {
            Building building = new Building();

            while (inReader.Read())
            {
                if (inReader.NodeType == XmlNodeType.Element)
                {
                    switch (inReader.Name.ToLower())
                    {
                        case "name":
                            building.Name = inReader.ReadElementString();
                            break;
                        case "identifier":
                            building.Identifier = inReader.ReadElementString();
                            break;
                        case "type":
                            switch (inReader.ReadElementString().ToLower())
                            {
                                case "pollutionreducer":
                                    building.Type = BuildingTypes.PollutionReducer;
                                    break;
                                case "powerplant":
                                    building.Type = BuildingTypes.Powerplant;
                                    break;
                                case "house":
                                    building.Type = BuildingTypes.House;
                                    break;
                                case "storage":
                                    building.Type = BuildingTypes.Storage;
                                    break;
                            }
                            break;
                        case "properties":
                            readProperties(inReader.ReadSubtree(), building.Values);
                            break;
                        case "active":
                            readActive(inReader.ReadSubtree(), building.Values);
                            break;
                        case "passive":
                            readPassive(inReader.ReadSubtree(), building.Values);
                            break;
                        case "construct":
                            readConstruct(inReader.ReadSubtree(), building.Values);
                            break;
                        case "upgrades":
                            readUpgrades(inReader.ReadSubtree(), building);
                            break;
                    }
                }
            }

            if (building.isValid()) Buildings.Add(building);
        }
Example #10
0
        internal Person(XmlReader rdr)
        {
            rdr.ReadStartElement("person");
            this.Id = int.Parse(rdr.ReadElementString("id"));
            this.FirstName = rdr.ReadElementString("first_name");
            this.LastName = rdr.ReadElementString("last_name");
            //Skipping Image Fields
            rdr.ReadToFollowing("title");
            this.Title = rdr.ReadElementString("title");
            this.Company = rdr.ReadElementString("company");

            int companyId;
            if (int.TryParse(rdr.ReadElementString("company_id"), out companyId))
                this.CompanyId = companyId;

            this.Tags = Tag.BuildList(rdr);
            this.Locations = Location.BuildList(rdr);
            this.MegaComments = MegaComment.BuildList(rdr);
            this.Notes = rdr.ReadElementString("notes");
            this.CreatedAt = rdr.ReadElementString("created_at").FromBatchBookFormat();
            this.UpdatedAt = rdr.ReadElementString("updated_at").FromBatchBookFormat();
            rdr.ReadEndElement();
        }
Example #11
0
        public byte[] OneWay(WsWsaHeader header, XmlReader reader)
        {
             try
            {
                // Find beginning of request
                reader.ReadStartElement("OneWay", SimpleServiceNamespaceUri);

                // Find the integer value
                int number = Convert.ToInt32(reader.ReadElementString("Param", SimpleServiceNamespaceUri));

                Log.Comment("");
                Log.Comment("Integer = " + number.ToString());
                Log.Comment("");

                return new byte[0];     // Empty response
            }
            catch (Exception e)
            {
                // Something went wrong
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }
        }
 private Page ParsePage(XmlReader PageElement)
 {
     Page page = new Page();
     int GotCount = 0;
     while (PageElement.Read())
     {
         switch (PageElement.Name)
         {
             case "title":
                 page.Title = PageElement.ReadElementString();
                 GotCount++;
                 break;
             case "redirect":
                 page.RedirectTo = PageElement.GetAttribute("title");
                 GotCount++;
                 break;
             case "text":
                 page.Text = PageElement.ReadElementString();
                 GotCount++;
                 break;
         }
         if (GotCount == 3) break;
     }
     return page;
 }
 private static String ReadMethodName(XmlReader reader)
 {
     RecursiveTypeSerializer.CheckTag(reader, XmlRpcSpec.METHOD_NAME_TAG);
     return reader.ReadElementString();
 }
 public virtual WebPart ImportWebPart(XmlReader reader, out string errorMessage)
 {
     WebPart part2;
     this.Personalization.EnsureEnabled(true);
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     bool flag = false;
     if (this.UsePermitOnly)
     {
         this.MinimalPermissionSet.PermitOnly();
         flag = true;
     }
     string str = string.Empty;
     try
     {
         try
         {
             Type type;
             IDictionary personalizablePropertyEntries;
             reader.MoveToContent();
             reader.ReadStartElement("webParts");
             ImportSkipTo(reader, "webPart");
             string attribute = reader.GetAttribute("xmlns");
             if (string.IsNullOrEmpty(attribute))
             {
                 errorMessage = System.Web.SR.GetString("WebPart_ImportErrorNoVersion");
                 return null;
             }
             if (!string.Equals(attribute, "http://schemas.microsoft.com/WebPart/v3", StringComparison.OrdinalIgnoreCase))
             {
                 errorMessage = System.Web.SR.GetString("WebPart_ImportErrorInvalidVersion");
                 return null;
             }
             ImportReadTo(reader, "metaData");
             reader.ReadStartElement("metaData");
             string str3 = null;
             string path = null;
             ImportSkipTo(reader, "type");
             str3 = reader.GetAttribute("name");
             path = reader.GetAttribute("src");
             ImportSkipTo(reader, "importErrorMessage");
             str = reader.ReadElementString();
             WebPart part = null;
             Control control = null;
             try
             {
                 bool isShared = this.Personalization.Scope == PersonalizationScope.Shared;
                 if (!string.IsNullOrEmpty(str3))
                 {
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MediumPermissionSet.PermitOnly();
                         flag = true;
                     }
                     type = WebPartUtil.DeserializeType(str3, true);
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MinimalPermissionSet.PermitOnly();
                         flag = true;
                     }
                     if (!this.IsAuthorized(type, null, null, isShared))
                     {
                         errorMessage = System.Web.SR.GetString("WebPartManager_ForbiddenType");
                         return null;
                     }
                     if (!type.IsSubclassOf(typeof(WebPart)))
                     {
                         if (!type.IsSubclassOf(typeof(Control)))
                         {
                             errorMessage = System.Web.SR.GetString("WebPartManager_TypeMustDeriveFromControl");
                             return null;
                         }
                         control = (Control) this.Internals.CreateObjectFromType(type);
                         control.ID = this.CreateDynamicWebPartID(type);
                         part = this.CreateWebPart(control);
                     }
                     else
                     {
                         part = (WebPart) this.Internals.CreateObjectFromType(type);
                     }
                 }
                 else
                 {
                     if (!this.IsAuthorized(typeof(UserControl), path, null, isShared))
                     {
                         errorMessage = System.Web.SR.GetString("WebPartManager_ForbiddenType");
                         return null;
                     }
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                     }
                     control = this.Page.LoadControl(path);
                     type = control.GetType();
                     if (this.UsePermitOnly)
                     {
                         this.MinimalPermissionSet.PermitOnly();
                         flag = true;
                     }
                     control.ID = this.CreateDynamicWebPartID(type);
                     part = this.CreateWebPart(control);
                 }
             }
             catch
             {
                 if (!string.IsNullOrEmpty(str))
                 {
                     errorMessage = str;
                 }
                 else
                 {
                     errorMessage = System.Web.SR.GetString("WebPartManager_ErrorLoadingWebPartType");
                 }
                 return null;
             }
             if (string.IsNullOrEmpty(str))
             {
                 str = System.Web.SR.GetString("WebPart_DefaultImportErrorMessage");
             }
             ImportSkipTo(reader, "data");
             reader.ReadStartElement("data");
             ImportSkipTo(reader, "properties");
             if (!reader.IsEmptyElement)
             {
                 reader.ReadStartElement("properties");
                 if (this.UsePermitOnly)
                 {
                     CodeAccessPermission.RevertPermitOnly();
                     flag = false;
                 }
                 this.ImportIPersonalizable(reader, (control != null) ? control : part);
                 if (this.UsePermitOnly)
                 {
                     this.MinimalPermissionSet.PermitOnly();
                     flag = true;
                 }
             }
             if (control != null)
             {
                 if (!reader.IsEmptyElement)
                 {
                     personalizablePropertyEntries = PersonalizableAttribute.GetPersonalizablePropertyEntries(type);
                     while (reader.Name != "property")
                     {
                         reader.Skip();
                         if (reader.EOF)
                         {
                             errorMessage = null;
                             return part;
                         }
                     }
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                     }
                     this.ImportFromReader(personalizablePropertyEntries, control, reader);
                     if (this.UsePermitOnly)
                     {
                         this.MinimalPermissionSet.PermitOnly();
                         flag = true;
                     }
                 }
                 ImportSkipTo(reader, "genericWebPartProperties");
                 reader.ReadStartElement("genericWebPartProperties");
                 if (this.UsePermitOnly)
                 {
                     CodeAccessPermission.RevertPermitOnly();
                     flag = false;
                 }
                 this.ImportIPersonalizable(reader, part);
                 if (this.UsePermitOnly)
                 {
                     this.MinimalPermissionSet.PermitOnly();
                     flag = true;
                 }
                 personalizablePropertyEntries = PersonalizableAttribute.GetPersonalizablePropertyEntries(part.GetType());
             }
             else
             {
                 personalizablePropertyEntries = PersonalizableAttribute.GetPersonalizablePropertyEntries(type);
             }
             while (reader.Name != "property")
             {
                 reader.Skip();
                 if (reader.EOF)
                 {
                     errorMessage = null;
                     return part;
                 }
             }
             if (this.UsePermitOnly)
             {
                 CodeAccessPermission.RevertPermitOnly();
                 flag = false;
             }
             this.ImportFromReader(personalizablePropertyEntries, part, reader);
             if (this.UsePermitOnly)
             {
                 this.MinimalPermissionSet.PermitOnly();
                 flag = true;
             }
             errorMessage = null;
             part2 = part;
         }
         catch (XmlException)
         {
             errorMessage = System.Web.SR.GetString("WebPartManager_ImportInvalidFormat");
             part2 = null;
         }
         catch (Exception exception)
         {
             if ((this.Context != null) && this.Context.IsCustomErrorEnabled)
             {
                 errorMessage = (str.Length != 0) ? str : System.Web.SR.GetString("WebPart_DefaultImportErrorMessage");
             }
             else
             {
                 errorMessage = exception.Message;
             }
             part2 = null;
         }
         finally
         {
             if (flag)
             {
                 CodeAccessPermission.RevertPermitOnly();
             }
         }
     }
     catch
     {
         throw;
     }
     return part2;
 }
Example #15
0
		public void ReadXml (XmlReader reader)
		{
			// Read the element enclosing the object
			reader.ReadStartElement();
			reader.MoveToContent ();

			// Reads the "data" element
			reader.ReadStartElement();
			reader.MoveToContent ();
			while (reader.NodeType != XmlNodeType.EndElement)
			{
				if (reader.NodeType == XmlNodeType.Element)
				{
					string key = reader.LocalName;
					data [key] = reader.ReadElementString ();
				}
				else
					reader.Skip ();
				reader.MoveToContent ();
			}

			reader.ReadEndElement ();
		}
Example #16
0
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();

            Rows = int.Parse(reader.GetAttribute("rows"));
            Cols = int.Parse(reader.GetAttribute("cols"));

            reader.ReadStartElement();

            if (Rows > 0 && Cols > 0)
            {
                _asTransposeRef = false;
                _matrix = new double[Rows][];
                for (int i = 0; i < Rows; i++)
                {
                    reader.ReadStartElement("r");
                    _matrix[i] = new double[Cols];
                    for (int j = 0; j < Cols; j++)
                        _matrix[i][j] = double.Parse(reader.ReadElementString("e"));
                    reader.ReadEndElement();
                }
            }
            else
                throw new InvalidOperationException("Invalid matrix size in XML!");

            reader.ReadEndElement();
        }
Example #17
0
 public void ReadXml(XmlReader reader)
 {
     reader.MoveToContent();
     name = reader.GetAttribute("name");
     reader.ReadStartElement();
     if (!reader.IsEmptyElement)
     {
         line1 = reader.ReadElementString("line1");
         line2 = reader.ReadElementString("line2");
         reader.ReadEndElement();
     }
 }
 protected void FromXmlInternal(XmlReader r, List<string> log)
 {
     while(r.Read())
     {
         if (r.NodeType == XmlNodeType.EndElement)
         {
             break;
         }
         if (r.NodeType == XmlNodeType.Whitespace)
         {
             continue;
         }
         switch(r.Name)
         {
             case "TargetFile":
                 targetFile = r.ReadElementString();
                 break;
             case "NewFileName":
                 newFileName = r.ReadElementString();
                 break;
             case "FileType":
                 fileTypeEnum = AssetFileEnumFromCompressedName(r.ReadElementString());
                 break;
             default:
                 log.Add(string.Format("In AssetFile.FromXmlInternal, unknown attribute '{0}'", r.Name));
                 break;
         }
     }
 }
        protected bool ReadXmlFileInternal(XmlReader r, List<string> log)
        {
            //Debug.Assert(root.LocalName == "AssetDefinition");
            while(r.Read()) {
                if (r.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }
                if (r.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                switch (r.Name)
                {
                    case "Name":
                        name = r.ReadElementString();
                        break;
                    case "Description":
                        description = r.ReadElementString();
                        break;
                    case "Category":
                        category = r.ReadElementString();
                        break;
                    case "Type":
                        typeEnum = AssetTypeDesc.AssetTypeEnumFromName(r.ReadElementString());
                        break;
                    case "Status":
                        status = AssetTypeDesc.AssetStatusEnumFromName(r.ReadElementString());
                        break;
                    case "Breakage":
                        breakage = r.ReadElementString();
                        break;
                    case "Files":

                        while (r.Read())
                        {
                            if (r.NodeType == XmlNodeType.Whitespace)
                            {
                                continue;
                            }
                            if (r.NodeType == XmlNodeType.EndElement)
                            {
                                break;
                            }
                            switch (r.Name)
                            {
                                case "AssetFile":
                                    files.Add(AssetFile.FromXml(r, log));

                                    break;
                            }
                        }
                        break;
                    case "Properties":
                        while (r.Read())
                        {
                            if (r.NodeType == XmlNodeType.Whitespace)
                            {
                                continue;
                            }
                            if (r.NodeType == XmlNodeType.EndElement)
                            {
                                break;
                            }
                            switch (r.Name)
                            {
                                case "Property":
                                    properties.Add(AssetProperty.FromXml(r));
                                    break;
                            }
                        }
                        break;

                    default:
                        log.Add(string.Format("In AssetDefinition.ReadXmlFileInternal, unknown attribute '{0}'",
                            r.Name));
                        break;
                }
            }
            return true;
        }
 private PlistDictionary LoadDictionaryContents(XmlReader reader, PlistDictionary dict)
 {
     Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.LocalName == "key");
     while (!reader.EOF && reader.NodeType == XmlNodeType.Element)
     {
         string key = reader.ReadElementString();
         while (reader.NodeType != XmlNodeType.Element && reader.Read())
             if (reader.NodeType == XmlNodeType.EndElement)
                 throw new Exception(String.Format("No value found for key {0}", key));
         PlistObjectBase result = LoadFromNode(reader);
         if (result != null)
             dict.Add(key, result);
         reader.ReadToNextSibling("key");
     }
     return dict;
 }
Example #21
0
		protected override bool ImportXml (XmlReader xr, IWarningLogger log) {
			bool gotdir = false;
			bool gotname = false;
			int depth = xr.Depth;

			while (xr.Depth >= depth) {
				if (xr.NodeType != XmlNodeType.Element) {
					//Console.WriteLine ("skipping {0}: {1} = \"{2}\"", xr.NodeType, xr.Name, xr.Value);
					xr.Read ();
					continue;
				}

				switch (xr.Name) {
				case "result":
					string ignore;

					Result r = Result.ImportXml (xr, out ignore, log);
					if (r == null)
						return true;
					if (!(r is MBDirectory)) {
						log.Warning (3019, "Result embedded in file result is not directory during XML import", null);
						return true;
					}
					dir = (MBDirectory) r;
					gotdir = true;
					break;
				case "name":
					name = xr.ReadElementString ();
					gotname = true;
					break;
				default:
					log.Warning (3019, "Unknown element in file result during XML import", xr.Name);
					xr.Skip ();
					break;
				}
			}

			if (!gotdir) {
				log.Warning (3019, "Did not find directory in file element during XML import", null);
				return true;
			}

			if (!gotname) {
				log.Warning (3019, "Did not find name in file element during XML import", null);
				return true;
			}
			
			return false;
		}
 SoapException ReadSoapException(XmlReader reader) {
     XmlQualifiedName faultCode = XmlQualifiedName.Empty;
     string faultString = null;
     string faultActor = null;
     string faultRole = null;
     XmlNode detail = null;
     SoapFaultSubCode subcode = null;
     string lang = null;
     bool soap12 = (reader.NamespaceURI == Soap12.Namespace);
     if (reader.IsEmptyElement) {
         reader.Skip();
     }
     else {
         reader.ReadStartElement();
         reader.MoveToContent();
         int depth = reader.Depth;
         while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None) {
             if (reader.NamespaceURI == Soap.Namespace || reader.NamespaceURI == Soap12.Namespace || reader.NamespaceURI == null || reader.NamespaceURI.Length == 0) {
                 if (reader.LocalName == Soap.Element.FaultCode || reader.LocalName == Soap12.Element.FaultCode) {
                     if (soap12)
                         faultCode = ReadSoap12FaultCode(reader, out subcode);
                     else
                         faultCode = ReadFaultCode(reader);
                 }
                 else if (reader.LocalName == Soap.Element.FaultString) {
                     lang = reader.GetAttribute(Soap.Attribute.Lang, Soap.XmlNamespace);
                     reader.MoveToElement();
                     faultString = reader.ReadElementString();
                 }
                 else if (reader.LocalName == Soap12.Element.FaultReason) {
                     if (reader.IsEmptyElement)
                         reader.Skip();
                     else {
                         reader.ReadStartElement(); // consume Reason element to get to Text child
                         reader.MoveToContent();
                         while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None) {
                             if (reader.LocalName == Soap12.Element.FaultReasonText && reader.NamespaceURI == Soap12.Namespace) {
                                 faultString = reader.ReadElementString();
                             }
                             else {
                                 reader.Skip();
                             }
                             reader.MoveToContent();
                         }
                         while (reader.NodeType == XmlNodeType.Whitespace) reader.Skip();
                         if (reader.NodeType == XmlNodeType.None) reader.Skip();
                         else reader.ReadEndElement();
                     }
                 }
                 else if (reader.LocalName == Soap.Element.FaultActor || reader.LocalName == Soap12.Element.FaultNode) {
                     faultActor = reader.ReadElementString();
                 }
                 else if (reader.LocalName == Soap.Element.FaultDetail || reader.LocalName == Soap12.Element.FaultDetail) {
                     detail = new XmlDocument().ReadNode(reader);
                 }
                 else if (reader.LocalName == Soap12.Element.FaultRole) {
                     faultRole = reader.ReadElementString();
                 }
                 else {
                     reader.Skip();
                 }
             }
             else {
                 reader.Skip();
             }
             reader.MoveToContent();
         }
         // Consume soap:Body and soap:Envelope closing tags
         while (reader.Read() && depth < reader.Depth) {
             // Nothing, just read on
         }
         // consume end tag
         if (reader.NodeType == XmlNodeType.EndElement) {
             reader.Read();
         }
     }
     if (detail != null || soap12) // with soap 1.2, can't tell if fault is for header
         return new SoapException(faultString, faultCode, faultActor, faultRole, lang, detail, subcode, null);
     else
         return new SoapHeaderException(faultString, faultCode, faultActor, faultRole, lang, subcode, null);
 }
 void IXmlSerializable.ReadXml(XmlReader r)
 {
     char[] buffer = null;
     string attribute = r.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
     if ((attribute != null) && XmlConvert.ToBoolean(attribute))
     {
         r.ReadElementString();
         this.SetNull();
     }
     else
     {
         buffer = r.ReadElementString().ToCharArray();
         this.SetBuffer(buffer);
     }
 }
		private static string GetIcuOptionFromNode(XmlReader reader)
		{
			Debug.Assert(reader.NodeType == XmlNodeType.Element);
			string result;
			switch (reader.Name)
			{
				case "suppress_contractions":
				case "optimize":
					result = String.Format(NewLine + "[{0} {1}]", reader.Name.Replace('_', ' '), reader.ReadElementString());
					break;
				default:
					throw new ApplicationException(String.Format("Invalid LDML collation option element: {0}", reader.Name));
			}
			return result;
		}
Example #25
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            reader.ReadStartElement();

            reader.ReadStartElement();
            Name = reader.ReadElementString();
            Exists = reader.ReadElementString().DeserializeObject<bool>();
            Size = reader.ReadElementString().DeserializeObject<ulong>();
            SubFilenames = reader.ReadElementString().DeserializeObject<List<string>>();
            InstallTime = reader.ReadElementString().DeserializeObject<DateTime>();
            Properties = reader.ReadElementString().DeserializeObject<SerializableDictionary<string, object>>();
            reader.ReadEndElement();

            reader.ReadEndElement();
        }
        /// <summary>
        /// Global eventing Subscribe stub.
        /// </summary>
        /// <param name="header">Header object.</param>
        /// <param name="reader">An XmlReader positioned at the begining of the Subscribe request body element.</param>
        /// <param name="serviceEndpoints">A Collection of serviceEndpoints used to determine what services contain the event source specified in the filter.</param>
        /// <returns>Byte array containing a Subscribe response.</returns>
        internal WsMessage Subscribe(WsWsaHeader header, XmlReader reader, WsServiceEndpoints serviceEndpoints)
        {
            WsMessage msg = null;

            // Parse Subscribe Request
            /////////////////////////////
            DpwsWseEventSink eventSink = new DpwsWseEventSink();
            try
            {
                reader.ReadStartElement("Subscribe", WsWellKnownUri.WseNamespaceUri);

                if (reader.IsStartElement("EndTo", WsWellKnownUri.WseNamespaceUri))
                {
                    eventSink.EndTo = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);
                }

                reader.ReadStartElement("Delivery", WsWellKnownUri.WseNamespaceUri);
                if (reader.IsStartElement("NotifyTo", WsWellKnownUri.WseNamespaceUri))
                {
                    eventSink.NotifyTo = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);
                }
                else
                {
                    throw new WsFaultException(header, WsFaultType.WseDeliverModeRequestedUnavailable);
                }

                reader.ReadEndElement();

                if (reader.IsStartElement("Expires", WsWellKnownUri.WseNamespaceUri))
                {
                    long expires = new WsDuration(reader.ReadElementString()).DurationInSeconds;

                    if (expires > 0)
                    {
                        eventSink.Expires = expires;
                    }
                    else
                    {
                        throw new WsFaultException(header, WsFaultType.WseInvalidExpirationTime);
                    }
                }
                else
                {
                    // Never Expires
                    eventSink.Expires = -1;
                }

                if (reader.IsStartElement("Filter", WsWellKnownUri.WseNamespaceUri))
                {
                    if (reader.MoveToAttribute("Dialect") == false || reader.Value != m_version.WsdpNamespaceUri + "/Action")
                    {
                        throw new WsFaultException(header, WsFaultType.WseFilteringRequestedUnavailable);
                    }

                    reader.MoveToElement();

                    String filters = reader.ReadElementString();

                    if (filters != String.Empty)
                    {
                        eventSink.Filters = filters.Split(' ');
                    }
                }

                XmlReaderHelper.SkipAllSiblings(reader);

                reader.ReadEndElement(); // Subscribe
            }
            catch (XmlException e)
            {
                throw new WsFaultException(header, WsFaultType.WseInvalidMessage, e.ToString());
            }

            // Parse urn:uuid from the To address
            string endpointAddress = FixToAddress(header.To);

            // Build a temporary collection of device services that match the specified endpoint address.
            WsServiceEndpoints matchingServices = new WsServiceEndpoints();
            for (int i = 0; i < serviceEndpoints.Count; ++i)
            {
                if (serviceEndpoints[i].EndpointAddress == endpointAddress)
                    matchingServices.Add(serviceEndpoints[i]);
            }

            // For each service with a matching endpoint and event sources add an event sink to the
            // event source collection
            for (int i = 0; i < matchingServices.Count; ++i)
            {
                DpwsWseEventSources eventSources = ((DpwsHostedService)matchingServices[i]).EventSources;

                // Set the EventSinkID
                eventSink.ID = "urn:uuid:" + Guid.NewGuid().ToString();

                // If subscribing to all event sources
                if (eventSink.Filters == null)
                {
                    int count = eventSources.Count;
                    for (int ii = 0; i < count; i++)
                    {
                        DpwsWseEventSource eventSource = eventSources[ii];
                        eventSink.StartTime = DateTime.Now.Ticks;
                        eventSource.EventSinks.Add(eventSink);
                    }
                }
                else
                {
                    // If subscribing to a specific event based on an event filter.
                    DpwsWseEventSource eventSource;
                    string[] filterList = eventSink.Filters;
                    int length = filterList.Length;
                    for (int ii = 0; i < length; i++)
                    {
                        if ((eventSource = eventSources[filterList[ii]]) != null)
                        {
                            eventSink.StartTime = DateTime.Now.Ticks;
                            eventSource.EventSinks.Add(eventSink);
                        }
                        else
                        {
                            throw new Exception("Event source " + filterList[ii] + " was not found.");
                        }
                    }
                }
            }

            // Generate Response
            //////////////////////////
            using(XmlMemoryWriter xmlWriter = XmlMemoryWriter.Create())
            {
                WsWsaHeader responseHeader = new WsWsaHeader(
                    WsWellKnownUri.WseNamespaceUri + "/SubscribeResponse",  // Action
                    header.MessageID,                                       // RelatesTo
                    header.ReplyTo.Address.AbsoluteUri,                     // To
                    null, null, null);                                      // ReplyTo, From, Any

                msg = new WsMessage(responseHeader, null, WsPrefix.Wse, null, 
                    new WsAppSequence(Device.AppSequence, Device.SequenceID, Device.MessageID));

                WsSoapMessageWriter smw = new WsSoapMessageWriter(m_version);
                smw.WriteSoapMessageStart(xmlWriter, msg);

                // write body
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "SubscribeResponse", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "SubscriptionManager", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "Address", null);
                // Create a uri. Use the path (by default will be a uuid) for the sub manager endpoint
                Uri subMgrUri = new Uri(((DpwsHostedService)matchingServices[0]).EndpointAddress);
                xmlWriter.WriteString("http://" + Device.IPV4Address + ":" + Device.Port + "/" + subMgrUri.AbsolutePath);
                xmlWriter.WriteEndElement(); // End Address
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wsa, "ReferenceParameters", null);
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "Identifier", null);
                xmlWriter.WriteString(eventSink.ID);
                xmlWriter.WriteEndElement(); // End Identifier
                xmlWriter.WriteEndElement(); // End ReferenceParameters
                xmlWriter.WriteEndElement(); // End SubscriptionManager
                xmlWriter.WriteStartElement(WsNamespacePrefix.Wse, "Expires", null);
                xmlWriter.WriteString(new WsDuration(eventSink.Expires).DurationString);
                xmlWriter.WriteEndElement(); // End Expires
                xmlWriter.WriteEndElement(); // End SubscribeResponse

                smw.WriteSoapMessageEnd(xmlWriter);

                // Return stream buffer
                msg.Body = xmlWriter.ToArray();
            }

            return msg;
        }
 private void ImportFromReader(IDictionary personalizableProperties, Control target, XmlReader reader)
 {
     ImportReadTo(reader, "property");
     bool flag = false;
     if (this.UsePermitOnly)
     {
         this.MinimalPermissionSet.PermitOnly();
         flag = true;
     }
     try
     {
         try
         {
             IDictionary dictionary;
             if (personalizableProperties != null)
             {
                 dictionary = new HybridDictionary();
             }
             else
             {
                 dictionary = new PersonalizationDictionary();
             }
             while (reader.Name == "property")
             {
                 string attribute = reader.GetAttribute("name");
                 string str2 = reader.GetAttribute("type");
                 string a = reader.GetAttribute("scope");
                 bool flag2 = string.Equals(reader.GetAttribute("null"), "true", StringComparison.OrdinalIgnoreCase);
                 if (((attribute == "AuthorizationFilter") || (attribute == "ZoneID")) || (attribute == "ZoneIndex"))
                 {
                     reader.ReadElementString();
                     if (!reader.Read())
                     {
                         throw new XmlException();
                     }
                     goto Label_03AA;
                 }
                 string s = reader.ReadElementString();
                 object obj2 = null;
                 bool flag3 = false;
                 PropertyInfo element = null;
                 if (personalizableProperties != null)
                 {
                     PersonalizablePropertyEntry entry = (PersonalizablePropertyEntry) personalizableProperties[attribute];
                     if (entry != null)
                     {
                         element = entry.PropertyInfo;
                         if ((Attribute.GetCustomAttribute(element, typeof(UrlPropertyAttribute), true) is UrlPropertyAttribute) && CrossSiteScriptingValidation.IsDangerousUrl(s))
                         {
                             throw new InvalidDataException(System.Web.SR.GetString("WebPart_BadUrl", new object[] { s }));
                         }
                     }
                 }
                 Type exportType = null;
                 if (!string.IsNullOrEmpty(str2))
                 {
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MediumPermissionSet.PermitOnly();
                         flag = true;
                     }
                     exportType = GetExportType(str2);
                     if (this.UsePermitOnly)
                     {
                         CodeAccessPermission.RevertPermitOnly();
                         flag = false;
                         this.MinimalPermissionSet.PermitOnly();
                         flag = true;
                     }
                 }
                 if ((element != null) && ((element.PropertyType == exportType) || (exportType == null)))
                 {
                     TypeConverterAttribute attribute2 = Attribute.GetCustomAttribute(element, typeof(TypeConverterAttribute), true) as TypeConverterAttribute;
                     if (attribute2 != null)
                     {
                         if (this.UsePermitOnly)
                         {
                             CodeAccessPermission.RevertPermitOnly();
                             flag = false;
                             this.MediumPermissionSet.PermitOnly();
                             flag = true;
                         }
                         Type type = WebPartUtil.DeserializeType(attribute2.ConverterTypeName, false);
                         if (this.UsePermitOnly)
                         {
                             CodeAccessPermission.RevertPermitOnly();
                             flag = false;
                             this.MinimalPermissionSet.PermitOnly();
                             flag = true;
                         }
                         if ((type != null) && type.IsSubclassOf(typeof(TypeConverter)))
                         {
                             TypeConverter converter = (TypeConverter) this.Internals.CreateObjectFromType(type);
                             if (Util.CanConvertToFrom(converter, typeof(string)))
                             {
                                 if (!flag2)
                                 {
                                     obj2 = converter.ConvertFromInvariantString(s);
                                 }
                                 flag3 = true;
                             }
                         }
                     }
                     if (!flag3)
                     {
                         TypeConverter converter2 = TypeDescriptor.GetConverter(element.PropertyType);
                         if (Util.CanConvertToFrom(converter2, typeof(string)))
                         {
                             if (!flag2)
                             {
                                 obj2 = converter2.ConvertFromInvariantString(s);
                             }
                             flag3 = true;
                         }
                     }
                 }
                 if (!flag3 && (exportType != null))
                 {
                     if (exportType == typeof(string))
                     {
                         if (!flag2)
                         {
                             obj2 = s;
                         }
                         flag3 = true;
                     }
                     else
                     {
                         TypeConverter converter3 = TypeDescriptor.GetConverter(exportType);
                         if (Util.CanConvertToFrom(converter3, typeof(string)))
                         {
                             if (!flag2)
                             {
                                 obj2 = converter3.ConvertFromInvariantString(s);
                             }
                             flag3 = true;
                         }
                     }
                 }
                 if (flag2 && (personalizableProperties == null))
                 {
                     flag3 = true;
                 }
                 if (flag3)
                 {
                     if (personalizableProperties != null)
                     {
                         dictionary.Add(attribute, obj2);
                     }
                     else
                     {
                         PersonalizationScope scope = string.Equals(a, PersonalizationScope.Shared.ToString(), StringComparison.OrdinalIgnoreCase) ? PersonalizationScope.Shared : PersonalizationScope.User;
                         dictionary.Add(attribute, new PersonalizationEntry(obj2, scope));
                     }
                     goto Label_03AA;
                 }
                 throw new HttpException(System.Web.SR.GetString("WebPartManager_ImportInvalidData", new object[] { attribute }));
             Label_035C:
                 if (((reader.EOF || (reader.Name == "genericWebPartProperties")) || (reader.Name == "properties")) || ((reader.Name == "ipersonalizable") && (reader.NodeType == XmlNodeType.EndElement)))
                 {
                     break;
                 }
                 reader.Skip();
             Label_03AA:
                 if (reader.Name != "property")
                 {
                     goto Label_035C;
                 }
             }
             if (personalizableProperties != null)
             {
                 IDictionary unknownProperties = BlobPersonalizationState.SetPersonalizedProperties(target, dictionary);
                 if ((unknownProperties != null) && (unknownProperties.Count > 0))
                 {
                     IVersioningPersonalizable personalizable = target as IVersioningPersonalizable;
                     if (personalizable != null)
                     {
                         personalizable.Load(unknownProperties);
                     }
                 }
             }
             else
             {
                 ((IPersonalizable) target).Load((PersonalizationDictionary) dictionary);
             }
         }
         finally
         {
             if (flag)
             {
                 CodeAccessPermission.RevertPermitOnly();
             }
         }
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// Event renew stub.
        /// </summary>
        /// <param name="header">Header object.</param>
        /// <param name="reader">An XmlReader positioned at the begining of the Renew request body element.</param>
        /// <param name="serviceEndpoints">A Collection of serviceEndpoints used to determine what services contain the specified event.</param>
        /// <returns>Byte array containing an Renew response.</returns>
        /// <remarks>This method is used by the stack framework. Do not use this method.</remarks>
        public WsMessage Renew(WsWsaHeader header, XmlReader reader, WsServiceEndpoints serviceEndpoints)
        {
            long newExpiration = 0;
            String eventSinkId = String.Empty;

            // Parse Renew request
            ////////////////////////////
            try
            {
                reader.ReadStartElement("Renew", WsWellKnownUri.WseNamespaceUri);

                if (reader.IsStartElement("Expires", WsWellKnownUri.WseNamespaceUri))
                {
                    newExpiration = new WsDuration(reader.ReadElementString()).DurationInSeconds;

                    if (newExpiration <= 0)
                    {
                        throw new WsFaultException(header, WsFaultType.WseInvalidExpirationTime);
                    }
                }
                else
                {
                    // Never Expires
                    newExpiration = -1;
                }

                eventSinkId = header.Any.GetNodeValue("Identifier", WsWellKnownUri.WseNamespaceUri);

                if (eventSinkId == null)
                {
                    throw new XmlException();
                }
            }
            catch (XmlException e)
            {
                throw new WsFaultException(header, WsFaultType.WseInvalidMessage, e.ToString());
            }

            // Parse urn:uuid from the To address
            string endpointAddress = FixToAddress(header.To);

            // Iterate the list of hosted services at the specified endpoint and renew each subscription
            // with and event source that matches the eventSinkID
            DpwsWseEventSink eventSink;
            bool eventSinkFound = false;

            DpwsHostedService endpoint = (DpwsHostedService)serviceEndpoints[endpointAddress];

            if(endpoint != null)
            {
                if ((eventSink = GetEventSink(endpoint.EventSources, eventSinkId)) != null)
                {
                    eventSinkFound = true;

                    // Update event sink expires time
                    eventSink.Expires = newExpiration;
                }
            }

            // Generate Response
            if (eventSinkFound)
                return GetStatusResponse(header, newExpiration); // It's just like the GetStatus Response
            throw new WsFaultException(header, WsFaultType.WseEventSourceUnableToProcess, "Subscription was not found. ID=" + eventSinkId);
        }
Example #29
0
		void IXmlSerializable.ReadXml(XmlReader r) {
			char[] value = null;
			
 			string isNull = r.GetAttribute("nil", XmlSchema.InstanceNamespace);
 			
			if (isNull != null && XmlConvert.ToBoolean(isNull)) {
                // VSTFDevDiv# 479603 - SqlTypes read null value infinitely and never read the next value. Fix - Read the next value.
                r.ReadElementString();
                SetNull();
			}
			else {
				value = r.ReadElementString().ToCharArray();
				SetBuffer(value);
			}
		}
Example #30
0
        void IXmlSerializable.ReadXml(XmlReader r)
        {
            byte[] value = null;

            string isNull = r.GetAttribute("nil", XmlSchema.InstanceNamespace);

            if (isNull != null && XmlConvert.ToBoolean(isNull))
            {
                // Read the next value.
                r.ReadElementString();
                SetNull();
            }
            else
            {
                string base64 = r.ReadElementString();
                if (base64 == null)
                {
                    value = Array.Empty<byte>();
                }
                else
                {
                    base64 = base64.Trim();
                    if (base64.Length == 0)
                        value = Array.Empty<byte>();
                    else
                        value = Convert.FromBase64String(base64);
                }
            }

            SetBuffer(value);
        }