ReadContentAsDouble() 공개 메소드

public ReadContentAsDouble ( ) : double
리턴 double
예제 #1
0
        public void Restore(XmlReader reader)
        {
            int count = reader.AttributeCount;
            for (int i = 0; i < count; ++i)
            {
                reader.MoveToAttribute(i);
                switch (reader.Name)
                {
                    case "top":
                        Top = reader.ReadContentAsDouble();
                        break;

                    case "left":
                        Left = reader.ReadContentAsDouble();
                        break;

                    case "width":
                        Width = reader.ReadContentAsDouble();
                        break;

                    case "height":
                        Height = reader.ReadContentAsDouble();
                        break;

                    case "state":
                        State = (WindowState) Enum.Parse(typeof (WindowState), reader.Value);
                        break;
                }
            }
        }
예제 #2
0
 public override void ReadXml(XmlReader reader)
 {
     reader.ReadStartElement();
     reader.ReadStartElement("X");
     var x = reader.ReadContentAsDouble();
     reader.ReadEndElement();
     reader.ReadStartElement("Y");
     var y = reader.ReadContentAsDouble();
     reader.ReadEndElement();
     Value = new Point(x, y);
     reader.ReadEndElement();
 }
예제 #3
0
        public static double ReadElementAsDouble(this XmlReader xw, string localName)
        {
            xw.ReadStartElement(localName);
            var result = xw.ReadContentAsDouble();

            xw.ReadEndElement();
            return(result);
        }
예제 #4
0
파일: Rope.cs 프로젝트: samgoat/NC
 public void ReadXml(XmlReader reader)
 {
     reader.MoveToAttribute("span");
       if (reader.NodeType == XmlNodeType.Attribute)
     Span = (int)reader.ReadContentAsDouble();
       reader.MoveToElement();
       Text = reader.ReadElementContentAsString();
       double length;
       if (double.TryParse(Text, out length))
     Length = length;
 }
예제 #5
0
파일: Place.cs 프로젝트: rmck/FlickrNet
 void IFlickrParsable.Load(XmlReader reader)
 {
     while (reader.MoveToNextAttribute())
       {
     switch (reader.LocalName)
     {
       case "name":
     this.Description = reader.Value;
     continue;
       case "place_id":
     this.PlaceId = reader.Value;
     continue;
       case "place_url":
     this.PlaceUrl = reader.Value;
     continue;
       case "place_type_id":
     this.PlaceType = (PlaceType) reader.ReadContentAsInt();
     continue;
       case "place_type":
     this.PlaceType = (PlaceType) Enum.Parse(typeof (PlaceType), reader.Value, true);
     continue;
       case "woeid":
     this.WoeId = reader.Value;
     continue;
       case "woe_name":
     this.WoeName = reader.Value;
     continue;
       case "latitude":
     this.Latitude = reader.ReadContentAsDouble();
     continue;
       case "longitude":
     this.Longitude = reader.ReadContentAsDouble();
     continue;
       case "timezone":
     this.TimeZone = reader.Value;
     continue;
       case "photo_count":
     this.PhotoCount = new int?(reader.ReadContentAsInt());
     continue;
       default:
     continue;
     }
       }
       reader.Read();
       while (reader.NodeType != XmlNodeType.EndElement)
       {
     if (reader.NodeType == XmlNodeType.Text)
     {
       this.Description = reader.ReadContentAsString();
     }
     else
     {
       string localName = reader.LocalName;
     }
       }
       reader.Read();
 }
예제 #6
0
        /// <summary>
        /// Restores the specified part of the state of a serialised object from an XML stream.
        /// </summary>
        /// Members that don't have a serialised value are left untouched.
        /// Unknown XML elements are reported to <see cref="AW2.Helpers.Log"/>.
        /// If the deserialised object is of a type that implements <see cref="IConsistencyCheckable"/>,
        /// the object is made consistent after deserialisation.
        /// <param name="reader">Where to read the serialised data.</param>
        /// <param name="elementName">Name of the XML element where the object is stored.</param>
        /// <param name="objType">Type of the value to deserialise.</param>
        /// <param name="limitationAttribute">Limit the deserialisation to members with this attribute.</param>
        /// <param name="tolerant">If true, errors are not raised for missing or extra XML elements.</param>
        /// <returns>The deserialised object.</returns>
        public static object DeserializeXml(XmlReader reader, string elementName, Type objType, Type limitationAttribute, bool tolerant)
        {
            try
            {
                // Sanity checks
                if (limitationAttribute != null &&
                    !typeof(Attribute).IsAssignableFrom(limitationAttribute))
                    throw new ArgumentException("Expected an attribute, got " + limitationAttribute.Name);

                // XML consistency checks
                if (!reader.IsStartElement())
                    throw new XmlException("Deserialisation expected start element");
                if (!reader.IsStartElement(elementName))
                    throw new XmlException("Deserialisation expected start element " + elementName + " but got " + reader.Name);

                var writtenType = GetWrittenType(reader, elementName, objType);

                // Deserialise
                object returnValue;
                bool emptyXmlElement = reader.IsEmptyElement;
                reader.Read();
                if (emptyXmlElement)
                    returnValue = Serialization.CreateInstance(writtenType);
                else if (writtenType.IsPrimitive || writtenType == typeof(string))
                    returnValue = reader.ReadContentAs(writtenType, null);
                else if (writtenType.IsEnum)
                    returnValue = DeserializeXmlEnum(reader, writtenType);
                else if (writtenType == typeof(Color))
                    returnValue = DeserializeXmlColor(reader, limitationAttribute, tolerant);
                else if (writtenType == typeof(TimeSpan))
                    returnValue = TimeSpan.FromSeconds(reader.ReadContentAsDouble());
                else if (writtenType == typeof(Curve))
                    returnValue = DeserializeXmlCurve(reader, limitationAttribute, tolerant);
                else if (IsIEnumerable(writtenType))
                    returnValue = DeserializeXmlIEnumerable(reader, objType, limitationAttribute, writtenType, tolerant);
                else
                    returnValue = DeserializeXmlOther(reader, limitationAttribute, writtenType, tolerant);

                if (!emptyXmlElement)
                    reader.ReadEndElement();
                if (writtenType != objType)
                    returnValue = Cast(returnValue, objType);
                if (typeof(IConsistencyCheckable).IsAssignableFrom(writtenType))
                    ((IConsistencyCheckable)returnValue).MakeConsistent(limitationAttribute);
                return returnValue;
            }
            catch (MemberSerializationException e)
            {
                e.MemberName = elementName + "." + e.MemberName;
                throw;
            }
        }
예제 #7
0
        /// <summary>
        /// Write a number.
        /// </summary>
        private static void WriteNumber(AmfStreamWriter writer, XmlReader input)
        {
            WriteTypeMarker(writer, Amf0TypeMarker.Number);

            var value = input.ReadContentAsDouble();
            writer.Write(value);
        }
예제 #8
0
        private void LoadAttributes(System.Xml.XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "name":
                    Description = reader.Value;
                    break;

                case "place_id":
                    PlaceId = reader.Value;
                    break;

                case "place_url":
                    PlaceUrl = reader.Value;
                    break;

                case "place_type_id":
                    PlaceType = (PlaceType)reader.ReadContentAsInt();
                    break;

                case "place_type":
                    PlaceType = (PlaceType)Enum.Parse(typeof(PlaceType), reader.Value, true);
                    break;

                case "woeid":
                    WoeId = reader.Value;
                    break;

                case "woe_name":
                    WoeName = reader.Value;
                    break;

                case "latitude":
                    Latitude = reader.ReadContentAsDouble();
                    break;

                case "longitude":
                    Longitude = reader.ReadContentAsDouble();
                    break;

                case "accuracy":
                    Accuracy = (GeoAccuracy)reader.ReadContentAsInt();
                    break;

                case "context":
                    Context = (GeoContext)reader.ReadContentAsInt();
                    break;

                case "timezone":
                    TimeZone = reader.Value;
                    break;

                case "has_shapedata":
                    HasShapeData = reader.Value == "1";
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    break;
                }
            }

            reader.Read();
        }
예제 #9
0
        /// <summary>
        /// Reads the DataValues section
        /// </summary>
        protected override IList<Series> ReadDataValues(XmlReader r)
        {
            int valueCount;
            var lst = new List<DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4);

            var qualifiers = new Dictionary<string, Qualifier>();
            var methods = new Dictionary<string, Method>();
            var sources = new Dictionary<string, Source>();
            var qualityControlLevels = new Dictionary<string, QualityControlLevel>();
            var samples = new Dictionary<string,Sample>();
            var labMethods = new Dictionary<string, LabMethod>();
            var offsets = new Dictionary<string, OffsetType>();
            var seriesDictionary = new Dictionary<string, Series>();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (r.Name == "value")
                    {
                        //create a new empty data value and add it to the list
                        var wrapper = new DataValueWrapper();
                        var val = new DataValue();
                        wrapper.DataValue = val;
                        lst.Add(wrapper);

                        if (r.HasAttributes)
                        {
                            var censorCode = r.GetAttribute("censorCode");
                            if (!string.IsNullOrEmpty(censorCode))
                            {
                                val.CensorCode = censorCode;
                            }
                            val.LocalDateTime = Convert.ToDateTime(r.GetAttribute("dateTime"), CultureInfo.InvariantCulture);

                            //utcOffset
                            var utcOffset = r.GetAttribute("timeOffset");
                            val.UTCOffset = !String.IsNullOrEmpty(utcOffset) ? ConvertUtcOffset(utcOffset) : 0.0;

                            //dateTimeUtc
                            var dateTimeUTC = r.GetAttribute("dateTimeUTC");
                            val.DateTimeUTC = !String.IsNullOrEmpty(dateTimeUTC) ? Convert.ToDateTime(dateTimeUTC, CultureInfo.InvariantCulture) : val.LocalDateTime;

                            //method
                            var methodID = r.GetAttribute("methodCode");
                            if (String.IsNullOrEmpty(methodID))
                            {
                                //try methodID instead of methodCode
                                methodID = r.GetAttribute("methodID");
                                if (String.IsNullOrEmpty(methodID))
                                {
                                    methodID = "unknown"; //when a method is unspecified
                                }
                            }
                            if (!methods.ContainsKey(methodID))
                            {
                                var newMethod = Method.Unknown;
                                methods.Add(methodID, newMethod);
                            }
                            wrapper.MethodID = methodID;

                            //quality control level
                            var qualityCode = r.GetAttribute("qualityControlLevelCode");
                            if (String.IsNullOrEmpty(qualityCode))
                            {
                                qualityCode = r.GetAttribute("qualityControlLevelID");
                                if (string.IsNullOrEmpty(qualityCode))
                                {
                                    qualityCode = "unknown"; //when the quality control level is unspecified
                                }
                            }
                            if (!qualityControlLevels.ContainsKey(qualityCode))
                            {
                                var qualControl = QualityControlLevel.Unknown;
                                qualControl.Code = qualityCode;
                                qualControl.Definition = qualityCode;
                                qualControl.Explanation = qualityCode;
                                qualityControlLevels.Add(qualityCode, qualControl);
                            }
                            wrapper.QualityID = qualityCode;

                            //source
                            string sourceID = r.GetAttribute("sourceCode");
                            if (string.IsNullOrEmpty(sourceID))
                            {
                                sourceID = r.GetAttribute("sourceID");
                                if (String.IsNullOrEmpty(sourceID))
                                {
                                    sourceID = "unknown"; //when a source is unspecified
                                }
                            }
                            if (!sources.ContainsKey(sourceID))
                            {
                                sources.Add(sourceID, Source.Unknown);
                            }
                            wrapper.SourceID = sourceID;
                            wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination----

                            //sample
                            string sampleCode = r.GetAttribute("labSampleCode");
                            if (!String.IsNullOrEmpty(sampleCode))
                            {
                                if (!samples.ContainsKey(sampleCode))
                                {
                                    samples.Add(sampleCode, Sample.Unknown);
                                }
                            }
                            wrapper.SampleID = sampleCode;

                            //qualifiers
                            string qualifierCodes = r.GetAttribute("qualifiers");
                            if (!String.IsNullOrEmpty(qualifierCodes))
                            {
                                if (!qualifiers.ContainsKey(qualifierCodes))
                                {
                                    var newQualifier = new Qualifier {Code = qualifierCodes};
                                    qualifiers.Add(qualifierCodes, newQualifier);
                                    val.Qualifier = newQualifier;
                                }
                                else
                                {
                                    val.Qualifier = qualifiers[qualifierCodes];
                                }
                            }

                            //vertical offset
                            string offsetCode = r.GetAttribute("offsetTypeCode");
                            if (string.IsNullOrEmpty(offsetCode))
                            {
                                offsetCode = r.GetAttribute("offsetTypeID");
                            }
                            if (!String.IsNullOrEmpty(offsetCode))
                            {
                                if (!offsets.ContainsKey(offsetCode))
                                {
                                    offsets.Add(offsetCode, new OffsetType());
                                }
                                string offsetValue = r.GetAttribute("offsetValue");
                                if (!String.IsNullOrEmpty(offsetValue))
                                {
                                    val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture);
                                }
                            }
                            wrapper.OffsetID = offsetCode;
                        }

                        //data value
                        r.Read();
                        val.Value = r.ReadContentAsDouble();

                    }
                    else if (r.Name == "method")
                    {
                        var method = ReadMethod(r);
                        var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture);
                        if (methods.ContainsKey(methodCodeKey))
                        {
                            methods[methodCodeKey] = method;
                        }
                    }
                    else if (r.Name == "source")
                    {
                        var source = ReadSource(r);
                        var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture);
                        if (sources.ContainsKey(sourceCodeKey))
                        {
                            sources[sourceCodeKey] = source;
                        }
                    }
                    else if (r.Name == "qualityControlLevel")
                    {
                        var qcLevel = ReadQualityControlLevel(r);
                        var qcCodeKey = qcLevel.Code;
                        if (qualityControlLevels.ContainsKey(qcCodeKey))
                        {
                            qualityControlLevels[qcCodeKey] = qcLevel;
                        }
                    }
                    else if (r.Name == "qualifier")
                    {
                        ReadQualifier(r, qualifiers);
                    }
                    else if (r.Name == "sample")
                    {
                        ReadSample(r, samples, labMethods);
                    }
                    else if (r.Name == "offset")
                    {
                        ReadOffset(r, offsets);
                    }
                }
            }

            //to assign special properties of each data value
            foreach (var wrapper in lst)
            {
                var val = wrapper.DataValue;

                //which series does the data value belong to?
                var seriesCode = wrapper.SeriesCode;
                if (!seriesDictionary.ContainsKey(seriesCode))
                {
                    Series newSeries = new Series();
                    seriesDictionary.Add(seriesCode, newSeries);
                    //assign method, source and qual.control level
                    try
                    {
                        newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)];
                        newSeries.Source = sources[SeriesCodeHelper.GetSourceCode(seriesCode)];
                        newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)];
                    }
                    catch { }
                }

                //add the data value to the correct series
                var series = seriesDictionary[seriesCode];
                series.DataValueList.Add(val);
                val.Series = series;

                Sample sample;
                if (!string.IsNullOrEmpty(wrapper.SampleID) &&
                    samples.TryGetValue(wrapper.SampleID, out sample))
                {
                    val.Sample = sample;
                }
                OffsetType offset;
                if (!string.IsNullOrEmpty(wrapper.OffsetID) &&
                    offsets.TryGetValue(wrapper.OffsetID, out offset))
                {
                    val.OffsetType = offset;
                }
                if (series.Method == null)
                {
                    series.Method = methods[wrapper.MethodID];
                }
                if (series.Source == null)
                {
                    series.Source = sources[wrapper.SourceID];
                }
                if (series.QualityControlLevel == null)
                {
                    series.QualityControlLevel = qualityControlLevels[wrapper.QualityID];
                }
            }
            //to check the qualifiers
            CheckQualifiers(qualifiers);

            return seriesDictionary.Values.ToList();
        }
예제 #10
0
        protected virtual void ReadSpatialReference(XmlReader r, Site site)
        {
            while (r.Read())
            {
                //lat long datum (srs)
                if (r.NodeType == XmlNodeType.Element && r.Name == "geogLocation")
                {
                    if (r.HasAttributes)
                    {
                        site.SpatialReference = new SpatialReference();
                        string srsName = r.GetAttribute("srs");
                        if (String.IsNullOrEmpty(srsName))
                        {
                            srsName = "unknown";
                        }
                        site.SpatialReference.SRSName = srsName;
                    }
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (XmlContext.AdvanceReaderPastEmptyElement(r))
                {
                    //Empty element - advance and continue...
                    continue;
                }

                //latitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "latitude")
                {
                    r.Read();
                    site.Latitude = r.ReadContentAsDouble();
                }

                //longitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "longitude")
                {
                    r.Read();
                    site.Longitude = r.ReadContentAsDouble();
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "X")
                {
                    r.Read();
                    site.LocalX = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "Y")
                {
                    r.Read();
                    site.LocalY = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.EndElement && r.Name == "geoLocation")
                {
                    return;
                }
            }
        }
예제 #11
0
파일: PlaceInfo.cs 프로젝트: rmck/FlickrNet
 private void LoadAttributes(XmlReader reader)
 {
     while (reader.MoveToNextAttribute())
       {
     switch (reader.LocalName)
     {
       case "name":
     this.Description = reader.Value;
     continue;
       case "place_id":
     this.PlaceId = reader.Value;
     continue;
       case "place_url":
     this.PlaceUrl = reader.Value;
     continue;
       case "place_type_id":
     this.PlaceType = (PlaceType) reader.ReadContentAsInt();
     continue;
       case "place_type":
     this.PlaceType = (PlaceType) Enum.Parse(typeof (PlaceType), reader.Value, true);
     continue;
       case "woeid":
     this.WoeId = reader.Value;
     continue;
       case "woe_name":
     this.WoeName = reader.Value;
     continue;
       case "latitude":
     this.Latitude = reader.ReadContentAsDouble();
     continue;
       case "longitude":
     this.Longitude = reader.ReadContentAsDouble();
     continue;
       case "accuracy":
     this.Accuracy = new GeoAccuracy?((GeoAccuracy) reader.ReadContentAsInt());
     continue;
       case "context":
     this.Context = new GeoContext?((GeoContext) reader.ReadContentAsInt());
     continue;
       case "timezone":
     this.TimeZone = reader.Value;
     continue;
       case "has_shapedata":
     this.HasShapeData = reader.Value == "1";
     continue;
       default:
     continue;
     }
       }
       reader.Read();
 }
예제 #12
0
        /// <summary>
        /// Reads the DataValues section
        /// </summary>
        protected override IList<Series> ReadDataValues(XmlReader r)
        {
            int valueCount;
            var lst = new List<DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4);

            var qualifiers = new Dictionary<string, Qualifier>();
            var methods = new Dictionary<string, Method>();
            var sources = new Dictionary<string, Source>();
            var qualityControlLevels = new Dictionary<string, QualityControlLevel>();
            var samples = new Dictionary<string, Sample>();
            var labMethods = new Dictionary<string, LabMethod>();
            var offsets = new Dictionary<string, OffsetType>();
            var seriesDictionary = new Dictionary<string, Series>();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (r.Name == "value")
                    {
                        //create a new empty data value and add it to the list
                        var wrapper = new DataValueWrapper();
                        var val = new DataValue();
                        wrapper.DataValue = val;
                        lst.Add(wrapper);

                        if (r.HasAttributes)
                        {
                            var censorCode = r.GetAttribute("censorCode");
                            if (!string.IsNullOrEmpty(censorCode))
                            {
                                val.CensorCode = censorCode;
                            }
                            val.LocalDateTime = Convert.ToDateTime(r.GetAttribute("dateTime"), CultureInfo.InvariantCulture);

                            //utcOffset
                            var utcOffset = r.GetAttribute("timeOffset");
                            val.UTCOffset = !String.IsNullOrEmpty(utcOffset) ? ConvertUtcOffset(utcOffset) : 0.0;

                            //dateTimeUtc
                            var dateTimeUTC = r.GetAttribute("dateTimeUTC");
                            val.DateTimeUTC = !String.IsNullOrEmpty(dateTimeUTC) ? Convert.ToDateTime(dateTimeUTC, CultureInfo.InvariantCulture) : val.LocalDateTime;

                            //method
                            var methodID = r.GetAttribute("methodCode");
                            if (String.IsNullOrEmpty(methodID))
                            {
                                //try methodID instead of methodCode
                                methodID = r.GetAttribute("methodID");
                                if (String.IsNullOrEmpty(methodID))
                                {
                                    methodID = "unknown"; //when a method is unspecified
                                }
                            }
                            if (!methods.ContainsKey(methodID))
                            {
                                var newMethod = Method.Unknown;
                                methods.Add(methodID, newMethod);
                            }
                            wrapper.MethodID = methodID;

                            //quality control level
                            var qualityCode = r.GetAttribute("qualityControlLevelCode");
                            if (String.IsNullOrEmpty(qualityCode))
                            {
                                qualityCode = r.GetAttribute("qualityControlLevelID");
                                if (string.IsNullOrEmpty(qualityCode))
                                {
                                    qualityCode = "unknown"; //when the quality control level is unspecified
                                }
                            }

                            //BCC - 24-Aug-2016 - Check for a quality code of space-delimited terms...
                            string[] terms = qualityCode.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                            foreach (var term in terms)
                            {
                                if (!qualityControlLevels.ContainsKey(term))
                            {
                                var qualControl = QualityControlLevel.Unknown;
                                    qualControl.Code = term;
                                    qualControl.Definition = term;
                                    qualControl.Explanation = term;
                                    qualityControlLevels.Add(term, qualControl);
                            }
                            }

                            wrapper.QualityID = qualityCode;

                            //source
                            string sourceID = r.GetAttribute("sourceCode");
                            if (string.IsNullOrEmpty(sourceID))
                            {
                                sourceID = r.GetAttribute("sourceID");
                                if (String.IsNullOrEmpty(sourceID))
                                {
                                    sourceID = "unknown"; //when a source is unspecified
                                }
                            }
                            if (!sources.ContainsKey(sourceID))
                            {
                                sources.Add(sourceID, Source.Unknown);
                            }
                            wrapper.SourceID = sourceID;
                            wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination----

                            //sample
                            string sampleCode = r.GetAttribute("labSampleCode");
                            if (!String.IsNullOrEmpty(sampleCode))
                            {
                                if (!samples.ContainsKey(sampleCode))
                                {
                                    samples.Add(sampleCode, Sample.Unknown);
                                }
                            }
                            wrapper.SampleID = sampleCode;

                            //qualifiers
                            string qualifierCodes = r.GetAttribute("qualifiers");
                            if (!String.IsNullOrEmpty(qualifierCodes))
                            {
                                if (!qualifiers.ContainsKey(qualifierCodes))
                                {
                                    var newQualifier = new Qualifier { Code = qualifierCodes };
                                    qualifiers.Add(qualifierCodes, newQualifier);
                                    val.Qualifier = newQualifier;
                                }
                                else
                                {
                                    val.Qualifier = qualifiers[qualifierCodes];
                                }
                            }

                            //vertical offset
                            string offsetCode = r.GetAttribute("offsetTypeCode");
                            if (string.IsNullOrEmpty(offsetCode))
                            {
                                offsetCode = r.GetAttribute("offsetTypeID");
                            }
                            if (!String.IsNullOrEmpty(offsetCode))
                            {
                                if (!offsets.ContainsKey(offsetCode))
                                {
                                    offsets.Add(offsetCode, new OffsetType());
                                }
                                string offsetValue = r.GetAttribute("offsetValue");
                                if (!String.IsNullOrEmpty(offsetValue))
                                {
                                    val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture);
                                }
                            }
                            wrapper.OffsetID = offsetCode;
                        }

                        //data value
                        r.Read();
                        val.Value = r.ReadContentAsDouble();

                    }
                    else if (r.Name == "method")
                    {
                        var method = ReadMethod(r);
                        var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture);
                        if (methods.ContainsKey(methodCodeKey))
                        {
                            methods[methodCodeKey] = method;
                        }
                    }
                    else if (r.Name == "source")
                    {
                        var source = ReadSource(r);
                        var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture);
                        if (sources.ContainsKey(sourceCodeKey))
                        {
                            sources[sourceCodeKey] = source;
                        }
                    }
                    else if (r.Name == "qualityControlLevel")
                    {
                        var qcLevel = ReadQualityControlLevel(r);
                        var qcCodeKey = qcLevel.Code;
                        if (qualityControlLevels.ContainsKey(qcCodeKey))
                        {
                            qualityControlLevels[qcCodeKey] = qcLevel;
                        }
                    }
                    else if (r.Name == "qualifier")
                    {
                        ReadQualifier(r, qualifiers);
                    }
                    else if (r.Name == "sample")
                    {
                        ReadSample(r, samples, labMethods);
                    }
                    else if (r.Name == "offset")
                    {
                        ReadOffset(r, offsets);
                    }
                }
            }

            //to assign special properties of each data value
            foreach (var wrapper in lst)
            {
                var val = wrapper.DataValue;

                //which series does the data value belong to?
                var seriesCode = wrapper.SeriesCode;
                if (!seriesDictionary.ContainsKey(seriesCode))
                {
                    Series newSeries = new Series();
                    seriesDictionary.Add(seriesCode, newSeries);
                    //assign method, source and qual.control level
                    try
                    {
                        newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)];
                        newSeries.Source = sources[SeriesCodeHelper.GetSourceCode(seriesCode)];

                        //BCC - 24-Aug-2016 - Add logic to handle space-delimited quality codes...
                        var qcCode = SeriesCodeHelper.GetQualityCode(seriesCode);
                        string[] terms = qcCode.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                        if (1 == terms.Length)
                        {
                            //One quality code found...
                        newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)];
                    }
                        else
                        {
                            //Multiple quality codes found...
                            var qcl = new QualityControlLevel();
                            string separator = " | ";

                            qcl.Code = qcCode;
                            qcl.Definition = String.Empty;
                            qcl.Explanation = String.Empty;
                            foreach (var term in terms)
                            {
                                var qclTemp = qualityControlLevels[term];

                                qcl.Definition += qclTemp.Definition + separator;
                                qcl.Explanation += qclTemp.Explanation + separator;
                            }

                            qcl.Definition = qcl.Definition.Substring(0, qcl.Definition.Length - separator.Length);
                            qcl.Explanation = qcl.Explanation.Substring(0, qcl.Explanation.Length - separator.Length);

                            //Set the OriginId to a minimum value to indicate a 'pseudo' instance...
                            int min = qualityControlLevels.Values.Min(value => value.OriginId);
                            qcl.OriginId = min - 1;

                            newSeries.QualityControlLevel = qcl;

                            //Add compound key to dictionary, if indicated...
                            if ( ! qualityControlLevels.ContainsKey(qcl.Code))
                            {
                                qualityControlLevels.Add(qcl.Code, qcl);
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        //Any exception happening here?
                        string msg = ex.Message;

                        int n = 5;

                        ++n;
                    }
                }

                //add the data value to the correct series
                var series = seriesDictionary[seriesCode];
                series.DataValueList.Add(val);
                val.Series = series;

                Sample sample;
                if (!string.IsNullOrEmpty(wrapper.SampleID) &&
                    samples.TryGetValue(wrapper.SampleID, out sample))
                {
                    val.Sample = sample;
                }
                OffsetType offset;
                if (!string.IsNullOrEmpty(wrapper.OffsetID) &&
                    offsets.TryGetValue(wrapper.OffsetID, out offset))
                {
                    val.OffsetType = offset;
                }
                if (series.Method == null)
                {
                    series.Method = methods[wrapper.MethodID];
                }
                if (series.Source == null)
                {
                    series.Source = sources[wrapper.SourceID];
                }
                if (series.QualityControlLevel == null)
                {
                    series.QualityControlLevel = qualityControlLevels[wrapper.QualityID];
                }
            }
            //to check the qualifiers
            CheckQualifiers(qualifiers);

            return seriesDictionary.Values.ToList();
        }
        private void LoadAttributes(XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "name":
                        Description = reader.Value;
                        break;
                    case "place_id":
                        PlaceId = reader.Value;
                        break;
                    case "place_url":
                        PlaceUrl = reader.Value;
                        break;
                    case "place_type_id":
                        PlaceType = (PlaceType)reader.ReadContentAsInt();
                        break;
                    case "place_type":
                        PlaceType = (PlaceType)Enum.Parse(typeof(PlaceType), reader.Value, true);
                        break;
                    case "woeid":
                        WoeId = reader.Value;
                        break;
                    case "woe_name":
                        WoeName = reader.Value;
                        break;
                    case "latitude":
                        Latitude = reader.ReadContentAsDouble();
                        break;
                    case "longitude":
                        Longitude = reader.ReadContentAsDouble();
                        break;
                    case "accuracy":
                        Accuracy = (GeoAccuracy)reader.ReadContentAsInt();
                        break;
                    case "context":
                        Context = (GeoContext)reader.ReadContentAsInt();
                        break;
                    case "timezone":
                        TimeZone = reader.Value;
                        break;
                    case "has_shapedata":
                        HasShapeData = reader.Value == "1";
                        break;
                    case "id":
                        // Ignore the Photo ID
                        break;
                    default:
                        UtilityMethods.CheckParsingException(reader);
                        break;
                }
            }

            reader.Read();
        }
예제 #14
0
 private static double ReadDouble(XmlReader reader)
 {
     reader.Read();
     var result = reader.ReadContentAsDouble();
     return result;
 }
예제 #15
0
        private static DateTime ReadDate(XmlReader reader, SerializationContext context)
        {
            reader.Read();
            var milliseconds = reader.ReadContentAsDouble();
            var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            var offset = TimeSpan.FromMilliseconds(milliseconds);
            var result = origin + offset;

            context.References.Add(new AmfReference { Reference = result, AmfxType = AmfxContent.Date });

            return result;
        }
예제 #16
0
파일: Photo.cs 프로젝트: rmck/FlickrNet
 protected void Load(XmlReader reader, bool allowExtraAtrributes)
 {
     if (!(reader.LocalName != "photo"))
     ;
       while (reader.MoveToNextAttribute())
       {
     switch (reader.LocalName)
     {
       case "id":
     this.PhotoId = reader.Value;
     if (string.IsNullOrEmpty(reader.Value))
     {
       reader.Skip();
       return;
     }
     else
       continue;
       case "owner":
     this.UserId = reader.Value;
     continue;
       case "secret":
     this.Secret = reader.Value;
     continue;
       case "server":
     this.Server = reader.Value;
     continue;
       case "farm":
     this.Farm = reader.Value;
     continue;
       case "title":
     this.Title = reader.Value;
     continue;
       case "ispublic":
     this.IsPublic = reader.Value == "1";
     continue;
       case "isfamily":
     this.IsFamily = reader.Value == "1";
     continue;
       case "isfriend":
     this.IsFriend = reader.Value == "1";
     continue;
       case "tags":
     string str1 = reader.Value;
     char[] chArray = new char[1]
     {
       ' '
     };
     foreach (string str2 in str1.Split(chArray))
       this.Tags.Add(str2);
     continue;
       case "datetaken":
     this.DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value);
     continue;
       case "datetakengranularity":
       case "isprimary":
       case "is_primary":
       case "has_comment":
     continue;
       case "dateupload":
     this.DateUploaded = UtilityMethods.UnixTimestampToDate(reader.Value);
     continue;
       case "license":
     this.License = (LicenseType) int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture);
     continue;
       case "ownername":
     this.OwnerName = reader.Value;
     continue;
       case "lastupdate":
     this.LastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value);
     continue;
       case "originalformat":
     this.OriginalFormat = reader.Value;
     continue;
       case "originalsecret":
     this.OriginalSecret = reader.Value;
     continue;
       case "place_id":
     this.PlaceId = reader.Value;
     continue;
       case "woeid":
     this.WoeId = reader.Value;
     continue;
       case "accuracy":
     this.Accuracy = (GeoAccuracy) reader.ReadContentAsInt();
     continue;
       case "latitude":
     this.Latitude = reader.ReadContentAsDouble();
     continue;
       case "longitude":
     this.Longitude = reader.ReadContentAsDouble();
     continue;
       case "machine_tags":
     this.MachineTags = reader.Value;
     continue;
       case "o_width":
     this.OriginalWidth = int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture);
     continue;
       case "o_height":
     this.OriginalHeight = int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture);
     continue;
       case "views":
     this.Views = new int?(int.Parse(reader.Value, (IFormatProvider) CultureInfo.InvariantCulture));
     continue;
       case "media":
     this.Media = reader.Value;
     continue;
       case "media_status":
     this.MediaStatus = reader.Value;
     continue;
       case "iconserver":
     this.IconServer = reader.Value;
     continue;
       case "iconfarm":
     this.IconFarm = reader.Value;
     continue;
       case "username":
     this.OwnerName = reader.Value;
     continue;
       case "pathalias":
       case "path_alias":
     this.PathAlias = reader.Value;
     continue;
       case "url_sq":
     this.urlSquare = reader.Value;
     continue;
       case "width_sq":
     this.SquareThumbnailWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_sq":
     this.SquareThumbnailHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_t":
     this.urlThumbnail = reader.Value;
     continue;
       case "width_t":
     this.ThumbnailWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_t":
     this.ThumbnailHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_q":
     this.urlLargeSquare = reader.Value;
     continue;
       case "width_q":
     this.LargeSquareThumbnailWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_q":
     this.LargeSquareThumbnailHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_n":
     this.urlSmall320 = reader.Value;
     continue;
       case "width_n":
     this.Small320Width = new int?(reader.ReadContentAsInt());
     continue;
       case "height_n":
     this.Small320Height = new int?(reader.ReadContentAsInt());
     continue;
       case "url_s":
     this.urlSmall = reader.Value;
     continue;
       case "width_s":
     this.SmallWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_s":
     this.SmallHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_m":
     this.urlMedium = reader.Value;
     continue;
       case "width_m":
     this.MediumWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_m":
     this.MediumHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_c":
     this.urlMedium800 = reader.Value;
     continue;
       case "width_c":
     this.Medium800Width = new int?(reader.ReadContentAsInt());
     continue;
       case "height_c":
     this.Medium800Height = new int?(reader.ReadContentAsInt());
     continue;
       case "url_l":
     this.urlLarge = reader.Value;
     continue;
       case "width_l":
     this.LargeWidth = new int?(reader.ReadContentAsInt());
     continue;
       case "height_l":
     this.LargeHeight = new int?(reader.ReadContentAsInt());
     continue;
       case "url_z":
     this.urlMedium640 = reader.Value;
     continue;
       case "width_z":
     this.Medium640Width = new int?(reader.ReadContentAsInt());
     continue;
       case "height_z":
     this.Medium640Height = new int?(reader.ReadContentAsInt());
     continue;
       case "url_o":
     this.urlOriginal = reader.Value;
     continue;
       case "width_o":
     this.OriginalWidth = reader.ReadContentAsInt();
     continue;
       case "height_o":
     this.OriginalHeight = reader.ReadContentAsInt();
     continue;
       case "url_h":
     this.Large1600Url = reader.Value;
     continue;
       case "width_h":
     this.Large1600Width = new int?(reader.ReadContentAsInt());
     continue;
       case "height_h":
     this.Large1600Height = new int?(reader.ReadContentAsInt());
     continue;
       case "url_k":
     this.Large2048Url = reader.Value;
     continue;
       case "width_k":
     this.Large2048Width = new int?(reader.ReadContentAsInt());
     continue;
       case "height_k":
     this.Large2048Height = new int?(reader.ReadContentAsInt());
     continue;
       case "dateadded":
     this.DateAddedToGroup = new DateTime?(UtilityMethods.UnixTimestampToDate(reader.Value));
     continue;
       case "date_faved":
     this.DateFavorited = new DateTime?(UtilityMethods.UnixTimestampToDate(reader.Value));
     continue;
       case "can_comment":
     this.CanComment = new bool?(reader.Value == "1");
     continue;
       case "can_addmeta":
     this.CanAddMeta = new bool?(reader.Value == "1");
     continue;
       case "can_blog":
     this.CanBlog = new bool?(reader.Value == "1");
     continue;
       case "can_print":
     this.CanPrint = new bool?(reader.Value == "1");
     continue;
       case "can_download":
     this.CanDownload = new bool?(reader.Value == "1");
     continue;
       case "can_share":
     this.CanShare = new bool?(reader.Value == "1");
     continue;
       case "geo_is_family":
     if (this.GeoPermissions == null)
     {
       this.GeoPermissions = new GeoPermissions();
       this.GeoPermissions.PhotoId = this.PhotoId;
     }
     this.GeoPermissions.IsFamily = reader.Value == "1";
     continue;
       case "geo_is_friend":
     if (this.GeoPermissions == null)
     {
       this.GeoPermissions = new GeoPermissions();
       this.GeoPermissions.PhotoId = this.PhotoId;
     }
     this.GeoPermissions.IsFriend = reader.Value == "1";
     continue;
       case "geo_is_public":
     if (this.GeoPermissions == null)
     {
       this.GeoPermissions = new GeoPermissions();
       this.GeoPermissions.PhotoId = this.PhotoId;
     }
     this.GeoPermissions.IsPublic = reader.Value == "1";
     continue;
       case "geo_is_contact":
     if (this.GeoPermissions == null)
     {
       this.GeoPermissions = new GeoPermissions();
       this.GeoPermissions.PhotoId = this.PhotoId;
     }
     this.GeoPermissions.IsContact = reader.Value == "1";
     continue;
       case "context":
     this.GeoContext = new GeoContext?((GeoContext) reader.ReadContentAsInt());
     continue;
       case "rotation":
     this.Rotation = new int?(reader.ReadContentAsInt());
     continue;
       default:
     int num = allowExtraAtrributes ? 1 : 0;
     continue;
     }
       }
       reader.Read();
       if (!(reader.LocalName == "description"))
     return;
       this.Description = reader.ReadElementContentAsString();
 }
예제 #17
0
        /// <summary>
        /// Serializes the XML to an instance.
        /// </summary>
        /// <param name="reader"></param>
        void IFlickrParsable.Load(XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "name":
                        Description = reader.Value;
                        break;
                    case "place_id":
                        PlaceId = reader.Value;
                        break;
                    case "place_url":
                        PlaceUrl = reader.Value;
                        break;
                    case "place_type_id":
                        PlaceType = (PlaceType) reader.ReadContentAsInt();
                        break;
                    case "place_type":
                        PlaceType = (PlaceType) Enum.Parse(typeof (PlaceType), reader.Value, true);
                        break;
                    case "woeid":
                        WoeId = reader.Value;
                        break;
                    case "latitude":
                        Latitude = reader.ReadContentAsDouble();
                        break;
                    case "longitude":
                        Longitude = reader.ReadContentAsDouble();
                        break;
                    case "timezone":
                        TimeZone = reader.Value;
                        break;
                    case "photo_count":
                        PhotoCount = reader.ReadContentAsInt();
                        break;
                    case "woe_name":
                        WoeName = reader.Value;
                        break;
                    default:
                        UtilityMethods.CheckParsingException(reader);
                        break;
                }
            }

            reader.Read();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Text)
                {
                    Description = reader.ReadContentAsString();
                }
                else
                {
                    switch (reader.LocalName)
                    {
                        default:
                            UtilityMethods.CheckParsingException(reader);
                            break;
                    }
                }
            }

            reader.Read();
        }
예제 #18
0
파일: Photo.cs 프로젝트: dimspace/crackhead
        /// <summary>
        /// Protected method that does the actual initialization of the Photo instance. Should be called by subclasses of the Photo class.
        /// </summary>
        /// <param name="reader">The reader containing the XML to be parsed.</param>
        /// <param name="allowExtraAtrributes">Wheither to allow unknown extra attributes. In debug builds will throw an exception if this parameter is false and an unknown attribute is found.</param>
        protected void Load(XmlReader reader, bool allowExtraAtrributes)
        {
            if (reader.LocalName != "photo")
                UtilityMethods.CheckParsingException(reader);

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "id":
                        PhotoId = reader.Value;
                        if (String.IsNullOrEmpty(reader.Value))
                        {
                            reader.Skip();
                            return;
                        }
                        break;
                    case "owner":
                        UserId = reader.Value;
                        break;
                    case "secret":
                        Secret = reader.Value;
                        break;
                    case "server":
                        Server = reader.Value;
                        break;
                    case "farm":
                        Farm = reader.Value;
                        break;
                    case "title":
                        Title = reader.Value;
                        break;
                    case "ispublic":
                        IsPublic = reader.Value == "1";
                        break;
                    case "isfamily":
                        IsFamily = reader.Value == "1";
                        break;
                    case "isfriend":
                        IsFriend = reader.Value == "1";
                        break;
                    case "tags":
                        foreach (string tag in reader.Value.Split(' '))
                        {
                            Tags.Add(tag);
                        }
                        break;
                    case "datetaken":
                        // For example : 2007-11-04 08:55:18
                        DateTaken = UtilityMethods.ParseDateWithGranularity(reader.Value);
                        break;
                    case "datetakengranularity":
                        break;
                    case "dateupload":
                        DateUploaded = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "license":
                        License = (LicenseType)int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;
                    case "ownername":
                        OwnerName = reader.Value;
                        break;
                    case "lastupdate":
                        LastUpdated = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "originalformat":
                        OriginalFormat = reader.Value;
                        break;
                    case "originalsecret":
                        OriginalSecret = reader.Value;
                        break;
                    case "place_id":
                        PlaceId = reader.Value;
                        break;
                    case "woeid":
                        WoeId = reader.Value;
                        break;
                    case "accuracy":
                        Accuracy = (GeoAccuracy)reader.ReadContentAsInt();
                        break;
                    case "latitude":
                        Latitude = reader.ReadContentAsDouble();
                        break;
                    case "longitude":
                        Longitude = reader.ReadContentAsDouble();
                        break;
                    case "machine_tags":
                        MachineTags = reader.Value;
                        break;
                    case "o_width":
                        OriginalWidth = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;
                    case "o_height":
                        OriginalHeight = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;
                    case "views":
                        Views = int.Parse(reader.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;
                    case "media":
                        Media = reader.Value;
                        break;
                    case "media_status":
                        MediaStatus = reader.Value;
                        break;
                    case "iconserver":
                        IconServer = reader.Value;
                        break;
                    case "iconfarm":
                        IconFarm = reader.Value;
                        break;
                    case "username":
                        OwnerName = reader.Value;
                        break;
                    case "isprimary":
                    case "is_primary":
                        break;
                    case "pathalias":
                        PathAlias = reader.Value;
                        break;
                    case "url_sq":
                        urlSquare = reader.Value;
                        break;
                    case "width_sq":
                        SquareThumbnailWidth = reader.ReadContentAsInt();
                        break;
                    case "height_sq":
                        SquareThumbnailHeight = reader.ReadContentAsInt();
                        break;
                    case "url_t":
                        urlThumbnail = reader.Value;
                        break;
                    case "width_t":
                        ThumbnailWidth = reader.ReadContentAsInt();
                        break;
                    case "height_t":
                        ThumbnailHeight = reader.ReadContentAsInt();
                        break;
                    case "url_q":
                        urlLargeSquare = reader.Value;
                        break;
                    case "width_q":
                        LargeSquareThumbnailWidth = reader.ReadContentAsInt();
                        break;
                    case "height_q":
                        LargeSquareThumbnailHeight = reader.ReadContentAsInt();
                        break;
                    case "url_n":
                        urlSmall320 = reader.Value;
                        break;
                    case "width_n":
                        Small320Width = reader.ReadContentAsInt();
                        break;
                    case "height_n":
                        Small320Height = reader.ReadContentAsInt();
                        break;
                    case "url_s":
                        urlSmall = reader.Value;
                        break;
                    case "width_s":
                        SmallWidth = reader.ReadContentAsInt();
                        break;
                    case "height_s":
                        SmallHeight = reader.ReadContentAsInt();
                        break;
                    case "url_m":
                        urlMedium = reader.Value;
                        break;
                    case "width_m":
                        MediumWidth = reader.ReadContentAsInt();
                        break;
                    case "height_m":
                        MediumHeight = reader.ReadContentAsInt();
                        break;
                    case "url_l":
                        urlLarge = reader.Value;
                        break;
                    case "width_l":
                        LargeWidth = reader.ReadContentAsInt();
                        break;
                    case "height_l":
                        LargeHeight = reader.ReadContentAsInt();
                        break;
                    case "url_z":
                        urlMedium640 = reader.Value;
                        break;
                    case "width_z":
                        Medium640Width = reader.ReadContentAsInt();
                        break;
                    case "height_z":
                        Medium640Height = reader.ReadContentAsInt();
                        break;
                    case "url_o":
                        urlOriginal = reader.Value;
                        break;
                    case "width_o":
                        OriginalWidth = reader.ReadContentAsInt();
                        break;
                    case "height_o":
                        OriginalHeight = reader.ReadContentAsInt();
                        break;
                    case "dateadded":
                        DateAddedToGroup = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "date_faved":
                        DateFavorited = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "has_comment": // Gallery photos return this, but we ignore it and set GalleryPhoto.Comment instead.
                        break;
                    case "can_comment":
                        CanComment = reader.Value == "1";
                        break;
                    case "can_addmeta":
                        CanAddMeta = reader.Value == "1";
                        break;
                    case "can_blog":
                        CanBlog = reader.Value == "1";
                        break;
                    case "can_print":
                        CanPrint = reader.Value == "1";
                        break;
                    case "can_download":
                        CanDownload = reader.Value == "1";
                        break;
                    case "can_share":
                        CanShare = reader.Value == "1";
                        break;
                    case "geo_is_family":
                        if (GeoPermissions == null)
                        {
                            GeoPermissions = new GeoPermissions();
                            GeoPermissions.PhotoId = PhotoId;
                        }
                        GeoPermissions.IsFamily = reader.Value == "1";
                        break;
                    case "geo_is_friend":
                        if (GeoPermissions == null)
                        {
                            GeoPermissions = new GeoPermissions();
                            GeoPermissions.PhotoId = PhotoId;
                        }
                        GeoPermissions.IsFriend = reader.Value == "1";
                        break;
                    case "geo_is_public":
                        if (GeoPermissions == null)
                        {
                            GeoPermissions = new GeoPermissions();
                            GeoPermissions.PhotoId = PhotoId;
                        }
                        GeoPermissions.IsPublic = reader.Value == "1";
                        break;
                    case "geo_is_contact":
                        if (GeoPermissions == null)
                        {
                            GeoPermissions = new GeoPermissions();
                            GeoPermissions.PhotoId = PhotoId;
                        }
                        GeoPermissions.IsContact = reader.Value == "1";
                        break;
                    case "context":
                        GeoContext = (GeoContext)reader.ReadContentAsInt();
                        break;
                    case "rotation":
                        Rotation = reader.ReadContentAsInt();
                        break;
                    default:
                        if (!allowExtraAtrributes) UtilityMethods.CheckParsingException(reader);
                        break;
                }
            }

            reader.Read();

            if (reader.LocalName == "description")
                Description = reader.ReadElementContentAsString();
        }
예제 #19
0
 public override double ReadContentAsDouble()
 {
     CheckAsync();
     return(_coreReader.ReadContentAsDouble());
 }
예제 #20
0
 override public void ParseOtherData(string readerName, XmlReader reader)
 {
     bool end = false;
     switch (readerName)
     {
         case "fat":
             this.fat = reader.Value;
             break;
         case "carbs":
             this.carbs = reader.Value;
             break;
         case "protein":
             this.protein = reader.Value;
             break;
         case "ingredients":
             this.ingredients = reader.Value;
             break;
         case "instructions":
             this.instructions = reader.Value;
             break;
         case "mealTime":
         case "exerciseTime":
             this.duration = reader.Value;
             break;
         case "type":
             this.exerciseType = reader.Value;
             break;
         case "percentLike":
             this.percentLike = reader.ReadContentAsDouble();
             break;
     }
 }
        private static TableStorageField ToObject(XmlReader reader, string edmType, bool isNull, string propertyName)
        {
            object value;
            Type dataType;
            string formatString;

            if(edmType == TableStorageConstants.Edm.TYPE_BINARY)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    using(Stream stream = new MemoryStream())
                    {
                        const int size = 256;
                        byte[] buffer = new byte[size];
                        int count;

                        while((count = reader.ReadContentAsBase64(buffer, 0, size)) > 0)
                        {
                            stream.Write(buffer, 0, count);
                        }

                        stream.Seek(0, SeekOrigin.Begin);

                        value = stream;
                    }
                }

                dataType = typeof(byte[]);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_BOOLEAN)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsBoolean();
                }

                dataType = typeof(bool);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_DATETIME)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsDateTime();
                }

                dataType = typeof(DateTime);
                formatString = TableStorageConstants.Edm.DATE_TIME_FORMAT;
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_DOUBLE)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsDouble();
                }

                dataType = typeof(double);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_GUID)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = Guid.Parse(reader.ReadContentAsString());
                }

                dataType = typeof(Guid);
                formatString = "{0:D}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_INT)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsInt();
                }

                dataType = typeof(int);
                formatString = "{0}";
            }
            else if(edmType == TableStorageConstants.Edm.TYPE_LONG)
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsLong();
                }

                dataType = typeof(long);
                formatString = "{0}";
            }
            else if(StringComparer.OrdinalIgnoreCase.Equals(TableStorageConstants.Edm.TYPE_STRING, edmType))
            {
                if(isNull)
                {
                    value = DBNull.Value;
                }
                else
                {
                    value = reader.ReadContentAsString();
                }

                dataType = typeof(string);
                formatString = "{0}";
            }
            else
            {
                throw new TableStorageException(string.Format("The type, '{0},' is not supported.", edmType));
            }

            return new TableStorageField(value, edmType, propertyName, isNull, dataType, formatString);
        }
예제 #22
0
파일: Place.cs 프로젝트: Rokkot/smallstuff
        /// <summary>
        /// Serializes the XML to an instance.
        /// </summary>
        /// <param name="reader"></param>
        void IFlickrParsable.Load(System.Xml.XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "name":
                    Description = reader.Value;
                    break;

                case "place_id":
                    PlaceId = reader.Value;
                    break;

                case "place_url":
                    PlaceUrl = reader.Value;
                    break;

                case "place_type_id":
                    PlaceType = (PlaceType)reader.ReadContentAsInt();
                    break;

                case "place_type":
                    PlaceType = (PlaceType)Enum.Parse(typeof(PlaceType), reader.Value, true);
                    break;

                case "woeid":
                    WoeId = reader.Value;
                    break;

                case "woe_name":
                    WoeName = reader.Value;
                    break;

                case "latitude":
                    Latitude = reader.ReadContentAsDouble();
                    break;

                case "longitude":
                    Longitude = reader.ReadContentAsDouble();
                    break;

                case "timezone":
                    TimeZone = reader.Value;
                    break;

                case "photo_count":
                    PhotoCount = reader.ReadContentAsInt();
                    break;

                default:
                    UtilityMethods.CheckParsingException(reader);
                    break;
                }
            }

            reader.Read();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Text)
                {
                    Description = reader.ReadContentAsString();
                }
                else
                {
                    switch (reader.LocalName)
                    {
                    default:
                        UtilityMethods.CheckParsingException(reader);
                        break;
                    }
                }
            }

            reader.Read();
        }
예제 #23
0
파일: ShapeData.cs 프로젝트: rmck/FlickrNet
 void IFlickrParsable.Load(XmlReader reader)
 {
     while (reader.MoveToNextAttribute())
       {
     switch (reader.LocalName)
     {
       case "created":
     this.DateCreated = UtilityMethods.UnixTimestampToDate(reader.Value);
     continue;
       case "alpha":
     this.Alpha = reader.ReadContentAsDouble();
     continue;
       case "count_points":
     this.PointCount = reader.ReadContentAsInt();
     continue;
       case "count_edges":
     this.EdgeCount = reader.ReadContentAsInt();
     continue;
       case "has_donuthole":
     this.HasDonutHole = reader.Value == "1";
     continue;
       case "is_donuthole":
     this.IsDonutHole = reader.Value == "1";
     continue;
       default:
     continue;
     }
       }
       reader.Read();
       while (reader.NodeType != XmlNodeType.EndElement)
       {
     switch (reader.LocalName)
     {
       case "polylines":
     reader.Read();
     while (reader.LocalName == "polyline")
     {
       Collection<PointD> collection = new Collection<PointD>();
       string str1 = reader.ReadElementContentAsString();
       string str2 = str1;
       char[] chArray1 = new char[1]
       {
         ' '
       };
       foreach (string str3 in str2.Split(chArray1))
       {
         char[] chArray2 = new char[1]
         {
           ','
         };
         string[] strArray = str3.Split(chArray2);
         if (strArray.Length != 2)
           throw new ParsingException("Invalid polypoint found in polyline : '" + str1 + "'");
         collection.Add(new PointD(double.Parse(strArray[0], (IFormatProvider) NumberFormatInfo.InvariantInfo), double.Parse(strArray[1], (IFormatProvider) NumberFormatInfo.InvariantInfo)));
       }
       this.PolyLines.Add(collection);
     }
     reader.Read();
     continue;
       case "urls":
     reader.Skip();
     continue;
       default:
     continue;
     }
       }
       reader.Read();
 }
        void IFlickrParsable.Load(XmlReader reader)
        {
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "created":
                        DateCreated = UtilityMethods.UnixTimestampToDate(reader.Value);
                        break;
                    case "alpha":
                        Alpha = reader.ReadContentAsDouble();
                        break;
                    case "count_points":
                        PointCount = reader.ReadContentAsInt();
                        break;
                    case "count_edges":
                        EdgeCount = reader.ReadContentAsInt();
                        break;
                    case "has_donuthole":
                        HasDonutHole = reader.Value == "1";
                        break;
                    case "is_donuthole":
                        IsDonutHole = reader.Value == "1";
                        break;
                    default:
                        UtilityMethods.CheckParsingException(reader);
                        break;
                }
            }

            reader.Read();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.LocalName)
                {
                    case "polylines":
                        reader.Read();
                        while (reader.LocalName == "polyline")
                        {
                            var polyline = new Collection<PointD>();
                            string polystring = reader.ReadElementContentAsString();
                            string[] points = polystring.Split(' ');
                            foreach (string point in points)
                            {
                                string[] xy = point.Split(',');
                                if (xy.Length != 2)
                                    throw new ParsingException("Invalid polypoint found in polyline : '" + polystring +
                                                               "'");
                                polyline.Add(new PointD(double.Parse(xy[0], NumberFormatInfo.InvariantInfo),
                                                        double.Parse(xy[1], NumberFormatInfo.InvariantInfo)));
                            }
                            PolyLines.Add(polyline);
                        }
                        reader.Read();
                        break;
                    case "urls":
                        reader.Skip();
                        break;
                }
            }

            reader.Read();
        }
예제 #25
0
        public void ReadXml(XmlReader reader)
        {
            reader.ReadStartElement();

            reader.ReadStartElement();
            Rolls = (short)reader.ReadContentAsInt();
            reader.ReadEndElement();

            reader.ReadStartElement();
            DiceFaces = (short)reader.ReadContentAsInt();
            reader.ReadEndElement();

            reader.ReadStartElement();
            Multiplier = (short)reader.ReadContentAsDouble();
            reader.ReadEndElement();

            reader.ReadStartElement();
            ToAdd = (short)reader.ReadContentAsInt();
            reader.ReadEndElement();

            reader.ReadEndElement();
        }
예제 #26
0
 void IFlickrParsable.Load(XmlReader reader)
 {
     if (reader == null)
     throw new ArgumentNullException("reader");
       if (reader.LocalName != "suggestion")
     return;
       while (reader.MoveToNextAttribute())
       {
     switch (reader.LocalName)
     {
       case "id":
     this.SuggestionId = reader.Value;
     continue;
       case "photo_id":
     this.PhotoId = reader.Value;
     continue;
       case "date_suggested":
     this.DateSuggested = UtilityMethods.UnixTimestampToDate(reader.Value);
     continue;
       default:
     continue;
     }
       }
       reader.Read();
       while (reader.LocalName != "suggestion" && reader.NodeType != XmlNodeType.EndElement)
       {
     switch (reader.LocalName)
     {
       case "suggested_by":
     this.SuggestedByUserId = reader.GetAttribute("nsid");
     this.SuggestedByUserName = reader.GetAttribute("username");
     reader.Skip();
     continue;
       case "note":
     this.Note = reader.ReadElementContentAsString();
     continue;
       case "location":
     while (reader.MoveToNextAttribute())
     {
       switch (reader.LocalName)
       {
         case "woeid":
           this.WoeId = reader.Value;
           continue;
         case "latitude":
           this.Latitude = reader.ReadContentAsDouble();
           continue;
         case "longitude":
           this.Longitude = reader.ReadContentAsDouble();
           continue;
         case "accuracy":
           this.Accuracy = (GeoAccuracy) reader.ReadContentAsInt();
           continue;
         default:
           continue;
       }
     }
     reader.Skip();
     continue;
       default:
     continue;
     }
       }
 }
예제 #27
0
 /// <summary>
 /// Write a date.
 /// </summary>
 private static void WriteDate(AmfStreamWriter writer, XmlReader input)
 {
     var value = input.ReadContentAsDouble();
     WriteDate(writer, value);
 }