ReadElementContentAsDouble() public method

public ReadElementContentAsDouble ( ) : double
return double
Beispiel #1
0
 internal override void ProcessXmlCore (XmlReader reader)
 {
     switch (reader.Name) {
     case "duration":
         duration = TimeSpan.FromMilliseconds (reader.ReadElementContentAsDouble ());
         break;
     case "release-list":
         if (reader.ReadToDescendant ("release")) {
             List<Release> releases = new List<Release> ();
             do releases.Add (new Release (reader.ReadSubtree ()));
             while (reader.ReadToNextSibling ("release"));
             this.releases = releases.AsReadOnly ();
         }
         break;
     case "puid-list":
         if (reader.ReadToDescendant ("puid")) {
             List<string> puids = new List<string> ();
             do puids.Add (reader["id"]);
             while (reader.ReadToNextSibling ("puid"));
             this.puids = puids.AsReadOnly ();
         }
         break;
     default:
         base.ProcessXmlCore (reader);
         break;
     }
 }
        public override void ReadXml(XmlReader reader)
        {
            complexParameters.Clear();
            primitiveParameters.Clear();

            reader.MoveToContent();

            reader.ReadStartElement();

            primitiveParameters.Add("DesiredValueStepSize", reader.ReadElementContentAsDouble());
            primitiveParameters.Add("AllowedOscillationPercentage", reader.ReadElementContentAsDouble());
            primitiveParameters.Add("GenerateSineWaveTestCases", reader.ReadElementContentAsBoolean());
            primitiveParameters.Add("SineFrequency", reader.ReadElementContentAsDouble());

            reader.ReadEndElement();
        }
 public override void read(XmlReader xr, string nameSpace)
 {
     this.Name = xr["Name", nameSpace];
     xr.ReadStartElement(/* Electrode */);
     this.X = xr.ReadElementContentAsDouble("X", nameSpace);
     this.Y = xr.ReadElementContentAsDouble("Y", nameSpace);
     this.Z = xr.ReadElementContentAsDouble("Z", nameSpace);
     xr.ReadEndElement(/* Electrode */);
 }
Beispiel #4
0
        private void ReadXml(XmlReader r)
        {
            try
            {
                double bid, ask, high, low;
                DateTime date;
                RateDirection direction;

                if (r.MoveToAttribute("Symbol")) { symbol = r.Value; }
                r.Read();
                r.Read();
                bid = r.ReadElementContentAsDouble("Bid", ""); r.Read();
                ask = r.ReadElementContentAsDouble("Ask", ""); r.Read();
                high = r.ReadElementContentAsDouble("High", ""); r.Read();
                low = r.ReadElementContentAsDouble("Low", ""); r.Read();
                direction = (RateDirection)r.ReadElementContentAsInt("Direction", ""); r.Read();
                date = r.ReadElementContentAsDateTime("Last", ""); r.Read();
                r.Read();
                RateData tempData = new RateData(bid, ask, high, low, date, direction);
                data.Add(tempData);
            }
            catch (Exception e) { throw e; }
        }
		public override object ReadField(XmlReader xmlReader)
		{
			return xmlReader.ReadElementContentAsDouble();
		}
        public override void ReadXml(XmlReader reader)
        {
            complexParameters.Clear();
            primitiveParameters.Clear();

            reader.MoveToContent();

            reader.ReadStartElement();

            primitiveParameters.Add("Regions", reader.ReadElementContentAsDouble());
            primitiveParameters.Add("PointsPerRegion", reader.ReadElementContentAsDouble());

            reader.MoveToFirstAttribute();

            int cnt = Int32.Parse(reader.GetAttribute("Count"));
            reader.ReadToFollowing("Requirement");
            IList<string> requirements = new List<string>();

            for (int i = 0; i < cnt; i++)
            {
                requirements.Add(reader.ReadElementContentAsString());
            }

            complexParameters.Add("Requirements", requirements);

            reader.ReadEndElement();

            primitiveParameters.Add("UseAdaptiveRandomSearch", reader.ReadElementContentAsBoolean());
            primitiveParameters.Add("OptimizationAlgorithm", reader.ReadElementContentAsString());
            reader.ReadEndElement();
        }
Beispiel #7
0
 public void ReadXml(XmlReader reader)
 {
     //the first element will be the name of the field. We just have to consume it!!
       reader.ReadStartElement();
       mElements = new double[3];
       mElements[0] = reader.ReadElementContentAsDouble("X", reader.NamespaceURI);
       mElements[1] = reader.ReadElementContentAsDouble("Y", reader.NamespaceURI);
       mElements[2] = reader.ReadElementContentAsDouble("Z", reader.NamespaceURI);
       reader.ReadEndElement();
 }
Beispiel #8
0
        /// <summary>
        /// Write a date.
        /// </summary>
        private static void WriteDate(AmfContext context, AmfStreamWriter writer, XmlReader input)
        {
            context.References.Add(new AmfReference { AmfxType = AmfxContent.Date });
            WriteTypeMarker(writer, Amf3TypeMarker.Date);

            var milliseconds = input.ReadElementContentAsDouble();

            //The first bit is a flag with value 1.
            //The remaining bits are not used.
            WriteUInt29(writer, 0 | 0x1);

            writer.Write(milliseconds);
        }
        private static void HandleConversion(XmlReader reader)
        {
            string fromUnit = reader.GetAttribute("fromUnit", "http://www.cornellracing.com/Units.xsd");
            string toUnit = reader.GetAttribute("toUnit", "http://www.cornellracing.com/Units.xsd");

            double preAdj = 0;
            double postAdj = 0;
            double scale = 1;

            bool doRead = true;

            while (!doRead || reader.Read()) {
                if (reader.NodeType == XmlNodeType.EndElement) {
                    UnitConversion uc = new UnitConversion(GetUnit(fromUnit), GetUnit(toUnit), preAdj, scale, postAdj);
                    AddConversion(uc);
                    return;
                }
                else if (reader.NodeType == XmlNodeType.Element) {
                    if (reader.LocalName == "scale") {
                        doRead = false;
                        scale = reader.ReadElementContentAsDouble();
                    }
                    else if (reader.LocalName == "offset") {
                        string prePost = reader.GetAttribute("order", "http://www.cornellracing.com/Units.xsd");
                        if (prePost == "pre") {
                            doRead = false;
                            preAdj = reader.ReadElementContentAsDouble();
                        }
                        else if (prePost == "post") {
                            doRead = false;
                            postAdj = reader.ReadElementContentAsDouble();
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("LotsOfData") == false)
            {
                throw new Exception("could not find the start of element LotsOfData");
            }

            if (reader.ReadToDescendant("Boolean") == false)
            {
                throw new Exception("could not find the start of element Boolean");
            }

            reader.Read();
            if (reader.ReadContentAsBoolean() == false)
            {
                throw new Exception("did not find the correct value in Boolean");
            }

            //DateTime
            if (reader.ReadToNextSibling("DateTime") == false)
            {
                throw new Exception("could not find the start of element DateTime");
            }

            reader.Read();
            DateTime now = reader.ReadContentAsDateTime();

            if (now != Now)
            {
                TimeSpan diff = new TimeSpan((now.Ticks - Now.Ticks));
                if (diff.TotalMilliseconds > 1000)
                {
                    // seconds are lost in Xml
                    throw new Exception(String.Format("Dates differ {0} {1} Ticks {2}", now, Now, (now.Ticks - Now.Ticks)));
                }
            }

            //DecimalValue
            if (reader.ReadToNextSibling("DecimalValue") == false)
            {
                throw new Exception("could not find the start of element DecimalValue");
            }
            //			reader.Read();
            decimal decimalValue = (decimal)reader.ReadElementContentAs(typeof(decimal), null);

            if (decimalValue != CommonUtilities.DecimalValue)
            {
                string msg = String.Format("different decimal Values {0} {1}", decimalValue, CommonUtilities.DecimalValue);
                throw new Exception(msg);
            }

            //DoubleValue
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "DoubleValue")
            {
                if (reader.ReadToNextSibling("DoubleValue") == false)
                {
                    throw new Exception("could not find the start of element DoubleValue");
                }
            }

            //reader.Read();
            double doubleValue = (double)reader.ReadElementContentAsDouble();

            if (doubleValue != CommonUtilities.DoubleValue)
            {
                string msg = String.Format("different double Values {0} {1}", doubleValue, CommonUtilities.DoubleValue);
                throw new Exception(msg);
            }

            //FloatValue
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "FloatValue")
            {
                if (reader.ReadToNextSibling("FloatValue") == false)
                {
                    throw new Exception("could not find the start of element FloatValue");
                }
            }

            //reader.Read();
            float floatValue = (float)reader.ReadElementContentAs(typeof(float), null);

            if (floatValue != CommonUtilities.FloatValue)
            {
                string msg = String.Format("different floatValue Values {0} {1}", floatValue, CommonUtilities.FloatValue);
                throw new MyException(msg);
            }

            //IntValue
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "IntValue")
            {
                if (reader.ReadToNextSibling("IntValue") == false)
                {
                    throw new Exception("could not find the start of element IntValue");
                }
            }
            //			reader.Read();
            int intValue = reader.ReadElementContentAsInt();

            if (intValue != CommonUtilities.IntValue)
            {
                string msg = String.Format("different intValue Values {0} {1}", intValue, CommonUtilities.IntValue);
                throw new MyException(msg);
            }

            //LongValue
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "LongValue")
            {
                if (reader.ReadToNextSibling("LongValue") == false)
                {
                    throw new Exception("could not find the start of element LongValue");
                }
            }
            //reader.Read();
            long longValue = (long)reader.ReadElementContentAs(typeof(long), null);

            if (longValue != CommonUtilities.LongValue)
            {
                string msg = String.Format("different longValue Values {0} {1}", longValue, CommonUtilities.LongValue);
                throw new MyException(msg);
            }

            //Object
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "Object")
            {
                if (reader.ReadToNextSibling("Object") == false)
                {
                    throw new MyException("could not find the start of element Object");
                }
            }

            //reader.Read();
            TimeSpan objectValue = (TimeSpan)reader.ReadElementContentAs(typeof(TimeSpan), null);

            if (objectValue != CommonUtilities.TimeSpanValue)
            {
                string msg = String.Format("different objectValue Values {0} {1}", objectValue, CommonUtilities.TimeSpanValue);
                throw new MyException(msg);
            }

            //StringValue
            if (reader.NodeType != System.Xml.XmlNodeType.Element && reader.Name != "StringValue")
            {
                if (reader.ReadToNextSibling("StringValue") == false)
                {
                    throw new MyException("could not find the start of element StringValue");
                }
            }

            //reader.Read();
            string stringValue = reader.ReadElementContentAsString();

            if (stringValue == null || stringValue.Equals(CommonUtilities.XmlStringForAttributes) == false)
            {
                string msg = String.Format("different stringValue Values {0} {1}", stringValue, CommonUtilities.XmlStringForAttributes);
                throw new MyException(msg);
            }

            int       counter      = 0;
            const int NODES_AT_END = 1;

            while (reader.Read())
            {
                counter++;
            }

            if (counter != NODES_AT_END)
            {
                throw new MyException(String.Format("expected {0} nodes, but found {1}", NODES_AT_END, counter));
            }
        }
        internal static WindowsStoreServiceAppPackageNode ParseXml(XmlReader reader)
        {
            var node = new WindowsStoreServiceAppPackageNode();

            reader.ReadStartElement();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.Name)
                {
                    case "I":
                        node.Id = reader.ReadElementContentAsString();
                        break;

                    case "R":
                        node.ReleaseId = reader.ReadElementContentAsString();
                        break;

                    case "Pfn":
                        node.FamilyName = reader.ReadElementContentAsString();
                        break;

                    case "L":
                        node.Language = reader.ReadElementContentAsString();
                        break;

                    case "T":
                        node.Title = reader.ReadElementContentAsString();
                        break;

                    case "Ico":
                        node.Icon = reader.ReadElementContentAsString();
                        break;

                    case "Bg":
                        node.BackgroundColor = reader.ReadElementContentAsString();
                        break;

                    case "Fg":
                        node.ForegroundColor = reader.ReadElementContentAsString();
                        break;

                    case "Cs":
                        node.CurrencySymbol = reader.ReadElementContentAsString();
                        break;

                    case "Cc":
                        node.Currency = reader.ReadElementContentAsString();
                        break;

                    case "P":
                        node.Price = reader.ReadElementContentAsDouble();
                        break;

                    case "C":
                        node.Category = WindowsStoreServiceAppCategoryNode.ParseXml(reader);
                        break;

                    case "Sc":
                        node.SubCategory = WindowsStoreServiceAppCategoryNode.ParseXml(reader);
                        break;

                    case "Lud":
                        node.LastUpdate = reader.ReadElementContentAsNullable<DateTime>();
                        break;

                    default:
                        reader.Skip();
                        break;
                }
            }

            reader.ReadEndElement();

            return node;
        }
        private void HandleConversion(XmlReader reader, ref double scale, ref double preOffset, ref double postOffset)
        {
            bool noRead = false;
            while (noRead || reader.Read()) {
                noRead = false;
                if (reader.NodeType == XmlNodeType.EndElement) {
                    if (reader.LocalName == "conversion")
                        return;
                }
                else if (reader.NodeType == XmlNodeType.Element) {
                    if (reader.LocalName == "scale") {
                        scale = reader.ReadElementContentAsDouble();
                        noRead = true;
                    }
                    else if (reader.LocalName == "offset") {
                        string prePost = reader.GetAttribute("order");
                        if (prePost == "pre")
                            preOffset = reader.ReadElementContentAsDouble();
                        else if (prePost == "post")
                            postOffset = reader.ReadElementContentAsDouble();
                        else
                            throw new InvalidOperationException();

                        noRead = true;
                    }
                }
            }
        }
        /// <summary>
        /// Creates an instance of the main diagnostic config object from an XmlReader
        /// </summary>
        internal static AnalyticsConfig Load(XmlReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            var result = new AnalyticsConfig();
            result.LatencyAlertThreshold = null;

            reader.GoToElement();
            reader.ReadStartElement();
            if (!reader.IsEmptyElement)
            {
                while (reader.GoToSibling())
                {
                    switch (reader.LocalName)
                    {
                        case "AdditionalData":
                            result.AdditionalData = reader.ReadElementContentAsString().Split(',').Select(kvp => kvp.Split('=')).ToDictionary(kvp => kvp[0], kvp => kvp[1]);
                            break;
                        case "Logging":
                            if (!reader.IsEmptyElement)
                            {
                                result.LoggingConfig = LoggingConfig.Load(reader);
                            }
                            else reader.Skip();
                            break;
                        case "Diagnostics":
                            if (!reader.IsEmptyElement)
                            {
                                reader.ReadStartElement();
                                while (reader.GoToSibling())
                                {
                                    switch (reader.LocalName)
                                    {
                                        case "TrackQuality":
                                            result.TrackQuality = Convert.ToBoolean(reader.ReadElementContentAsInt());
                                            break;
                                        case "TrackDownloadErrors":
                                            result.TrackDownloadErrors = Convert.ToBoolean(reader.ReadElementContentAsInt());
                                            break;
                                        case "AggregationIntervalMilliseconds":
                                            result.AggregationInterval = TimeSpan.FromMilliseconds(reader.ReadElementContentAsInt());
                                            break;
                                        case "PollingMilliseconds":
                                            result.PollingInterval = TimeSpan.FromMilliseconds(reader.ReadElementContentAsInt());
                                            break;
                                        case "LatencyAlertThreshold":
                                            result.LatencyAlertThreshold = reader.ReadElementContentAsDouble();
                                            break;
                                        case "QualityTracking":
                                            result.QualityConfig = QualityConfig.Load(reader);
                                            break;
                                        default:
                                            reader.Skip();
                                            break;
                                    }
                                }
                                reader.ReadEndElement();
                            }
                            else
                                reader.Skip();
                            break;

                        default:
                            reader.Skip();
                            break;
                    }
                }
                reader.ReadEndElement();
            }
            else
                reader.Skip();

            return result;
        }
Beispiel #14
0
        public virtual void ReadXml(XmlReader reader)
        {
            Position = Position.ReadXml(reader);
            Name = reader.ReadElementContentAsString();
            CT = reader.ReadElementContentAsInt();
            m_uniqueID = reader.ReadElementContentAsInt();

            m_ctIncreaseModifier = reader.ReadElementContentAsDouble();
            m_ctCostModifierToMove = reader.ReadElementContentAsDouble();
            m_ctCostModifierToAct = reader.ReadElementContentAsDouble();
       
            ListSerialization.ReadListFromXML(
                reader, 
                innerReader =>
                {
                    string typeName = reader.ReadElementContentAsString();
                    bool longTerm = Boolean.Parse(reader.ReadElementContentAsString());
                    IStatusEffectCore effect = EffectFactory.CreateEffectBaseObject(typeName, longTerm);
                    effect.ReadXml(reader);
                    AddEffect(effect);
                });
        }
 protected override Object DoRead(XmlReader reader)
 {
     return reader.ReadElementContentAsDouble();
 }
 static double ReadDoubleElement(XmlReader r) {
     return r.ReadElementContentAsDouble();
 }
        /// <summary>
        /// Helper function to read an XML element (not a full document)
        /// representing a cloud execution report.
        /// </summary>
        /// <remarks>
        /// Note that the XmlReader is expected to be positioned in the XML
        /// document such that the current node is a report element.
        /// </remarks>
        /// <param name="xr">The XmlReader object to read from.</param>
        /// <returns>
        /// A new report corresponding to the XML representation read.
        /// </returns>
        public static CloudExecutionReport ReadXml(XmlReader xr)
        {
            Util.Assert(xr.Name.Equals(CloudExecutionReport.XmlTag));

            string versionText = xr.GetAttribute(CloudExecutionReport.XmlVersionAttribute);
            int version = int.Parse(versionText, CultureInfo.InvariantCulture);

            string identifier = string.Empty;
            StatusCode status = StatusCode.Completed;
            string processingNode = "Unknown Benevolence";
            int exitCode = 0;
            string standardOutput = string.Empty;
            string standardError = string.Empty;
            double cpuTime = 0;
            bool inOutputFileMappings = false;
            List<BuildObjectValuePointer> outputFileMappings = new List<BuildObjectValuePointer>();
            List<BuildObject> outputFiles = new List<BuildObject>();
            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element)
                {
                    switch (xr.Name)
                    {
                        case XmlIdentifierElement:
                            identifier = xr.ReadElementContentAsString();
                            break;

                        case XmlStatusElement:
                            status = (StatusCode)Enum.Parse(typeof(StatusCode), xr.ReadElementContentAsString());
                            break;

                        case XmlProcessingNodeElement:
                            processingNode = xr.ReadElementContentAsString();
                            break;

                        case XmlExitCodeElement:
                            exitCode = xr.ReadElementContentAsInt();
                            break;

                        case XmlStandardOutputElement:
                            standardOutput = xr.ReadElementContentAsString();
                            break;

                        case XmlStandardErrorElement:
                            standardError = xr.ReadElementContentAsString();
                            break;

                        case XmlCpuTimeElement:
                            cpuTime = xr.ReadElementContentAsDouble();
                            break;

                        case XmlOutputFileMappingsElement:
                            inOutputFileMappings = true;
                            break;

                        case BuildObjectValuePointer.XmlTag:
                            Util.Assert(inOutputFileMappings);
                            outputFileMappings.Add(BuildObjectValuePointer.ReadXml(xr));
                            break;
                    }
                }
                else if (xr.NodeType == XmlNodeType.EndElement)
                {
                    if (xr.Name.Equals(CloudExecutionReport.XmlTag))
                    {
                        break;  // All done.
                    }

                    switch (xr.Name)
                    {
                        case XmlOutputFileMappingsElement:
                            inOutputFileMappings = false;
                            break;
                    }
                }
            }

            // REVIEW: Require element presence?  Sanity check things here?
            return new CloudExecutionReport(
                version,
                identifier,
                status,
                processingNode,
                exitCode,
                standardOutput,
                standardError,
                cpuTime,
                outputFileMappings);
        }
Beispiel #18
0
 public void ReadXml(XmlReader reader)
 {
     //the first element will be the name of the field. We just have to consume it!!
       reader.ReadStartElement();
       mElements = new double[4, 4];
       for (int x = 0; x < 4; x++)
       {
     for (int y = 0; y < 4; y++)
     {
       mElements[x, y] = reader.ReadElementContentAsDouble("Element", reader.NamespaceURI);
     }
       }
       reader.ReadEndElement();
 }
Beispiel #19
0
 public override void ReadXml(XmlReader reader)
 {
     Value = reader.ReadElementContentAsDouble();
 }
Beispiel #20
0
        public static IExecute ReadExecute(XmlReader reader, Counter<string> badTags)
        {
            //How did we start? Used for determining when we're done.
            string tag = reader.Name;
            List<IExecute> expressions = new List<IExecute>();
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "trigger_event")
                {
                    expressions.Add(ReadTriggerEvent(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "allow_event_selection")
                {
                    expressions.Add(new AllowEventSelectionExecute());
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "continue_turn")
                {
                    expressions.Add(Execute.CONTINUE_TURN);
                }
                else if (reader.NodeType == XmlNodeType.Element && (reader.Name == "everyone_in_room" || reader.Name == "any_child"))
                {
                    expressions.Add(ReadScopingLoop(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "set_scope")
                {
                    string scopeName = reader.GetAttribute("name");
                    expressions.Add(new SetScopeExecute(scopeName, ReadExecute(reader, badTags)));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "choose_character")
                {
                    string scopeName = reader.GetAttribute("name");
                    expressions.Add(ReadChooseCharacter(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && (reader.Name == "observe_information"))
                {
                    expressions.Add(ReadGainInformation(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && (reader.Name == "tell_information"))
                {
                    int overhearChance = int.Parse(reader.GetAttribute("overhear"));
                    string about = reader.GetAttribute("about");
                    string typeName = reader.GetAttribute("type");
                    InformationType type = StringToInformationType(typeName);
                    expressions.Add(new TellInformationExecute(ReadExecute(reader, badTags), overhearChance, about, type));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "prestige_change")
                {
                    expressions.Add(new PrestigeChangeExecute(reader.ReadElementContentAsInt()));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "apply_opinion_mod")
                {
                    expressions.Add(ReadApplyOpinionMod(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "give_job")
                {
                    expressions.Add(new GiveJobExecute(reader.ReadElementContentAsString()));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "spend_gold")
                {
                    expressions.Add(new SpendGoldExecute(reader.ReadElementContentAsInt()));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "get_gold")
                {
                    expressions.Add(new GetGoldExecute(reader.ReadElementContentAsInt()));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "multiply_observe_chance")
                {
                    expressions.Add(new MultiplyObserveChanceExecute(reader.ReadElementContentAsDouble()));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "debug")
                {
                    expressions.Add(Execute.DEBUG);
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "if")
                {
                    expressions.Add(ReadIfExecute(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "set_variable")
                {
                    string varName = reader.GetAttribute("name");
                    expressions.Add(new SetVariableExecute(varName, ReadCalc(reader)));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "offset_variable")
                {
                    string varName = reader.GetAttribute("name");
                    expressions.Add(new OffsetVariableExecute(varName, ReadCalc(reader)));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "random")
                {
                    expressions.Add(ReadRandom(reader, badTags));
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "create_child")
                {
                    expressions.Add(new CreateChildExecute());
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name == "move_to")
                {
                    expressions.Add(new MoveToExecute(reader.ReadElementContentAsString()));
                }
                else if (reader.NodeType == XmlNodeType.Element)
                {
                    badTags.Increment(reader.Name);
                }
                else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == tag)
                {
                    break;
                }
            }

            //Now that we've got all our expressions, there are a few special cases.
            //If we've only got a single expression, there's no point in anding them, so
            //we can just return that expression.
            //If there are no expressions, we should always be true (no restrictions.)
            //Otherwise, we'll just return an and of the expressions we have.
            if (expressions.Count == 1)
                return expressions[0];
            else if (expressions.Count == 0)
                return Execute.NOOP;
            else
                return new SequenceExecute(expressions.ToArray());
        }
Beispiel #21
0
 public void ReadXml(XmlReader reader)
 {
     reader.MoveToContent();
     reader.ReadStartElement();
     _id = reader.ReadElementContentAsInt("Id", reader.NamespaceURI);
     _model = (BoatModel)reader.ReadElementContentAsInt("Model", reader.NamespaceURI);
     _length = reader.ReadElementContentAsDouble("Length", reader.NamespaceURI);
     reader.ReadEndElement();
 }
        private PlistObjectBase LoadFromNode(XmlReader reader)
        {
            //Debug.Assert(reader.NodeType == XmlNodeType.Element);
            bool isEmpty = reader.IsEmptyElement;
            switch (reader.LocalName)
            {
                case "dict":
                    var dict = new PlistDictionary(true);
                    if (!isEmpty)
                    {
                        if (reader.ReadToDescendant("key"))
                            dict = LoadDictionaryContents(reader, dict);
                        reader.ReadEndElement();
                    }
                    return dict;

                case "array":
                    if (isEmpty)
                        return new PlistArray();

                    //advance to first node
                    reader.ReadStartElement();
                    while (reader.Read() && reader.NodeType != XmlNodeType.Element) ;

                    // HACK: plist data in iPods is not even valid in some cases! Way to go Apple!
                    // This hack checks to see if they really meant for this array to be a dict.
                    if (reader.LocalName == "key")
                    {
                        var ret = LoadDictionaryContents(reader, new PlistDictionary(true));
                        reader.ReadEndElement();
                        return ret;
                    }

                    var arr = new PlistArray();
                    do
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            var val = LoadFromNode(reader);
                            if (val != null)
                                arr.Add(val);
                        }
                    } while (reader.Read() && reader.NodeType != XmlNodeType.EndElement);
                    reader.ReadEndElement();
                    return arr;

                case "key":
                    return new PlistString(reader.ReadElementContentAsString());
                case "string":
                    return new PlistString(reader.ReadElementContentAsString());
                case "integer":
                    return new PlistInteger(reader.ReadElementContentAsInt());
                case "real":
                    return new PlistReal(reader.ReadElementContentAsDouble());
                case "false":
                    reader.ReadStartElement();
                    if (!isEmpty)
                        reader.ReadEndElement();
                    return new PlistBoolean(false);
                case "true":
                    reader.ReadStartElement();
                    if (!isEmpty)
                        reader.ReadEndElement();
                    return new PlistBoolean(true);
                case "data":
                    return new PlistData(reader.ReadElementContentAsString());
                case "date":
                    return new PlistDate(reader.ReadElementContentAsDateTime());
                default:
                    throw new XmlException(String.Format("Plist Node `{0}' is not supported", reader.LocalName));
            }
        }
 private Geocache ParseGroundSpeakCache(XmlReader reader, ref Geocache cache)
 {
     if (reader.LocalName == "cache")
     {
         string avail = reader.GetAttribute("available");
         string arch = reader.GetAttribute("archived");
         if (!String.IsNullOrEmpty(avail))
             cache.Available = Boolean.Parse(avail);
         else
             cache.Available = true;
         if (!String.IsNullOrEmpty(arch))
             cache.Archived = Boolean.Parse(arch);
         else
             cache.Archived = false;
         cache.CacheID = reader.GetAttribute("id");
     }
     else if (reader.LocalName == "DNF" && !m_ignoreExtraFields)
     {
         cache.DNF = reader.ReadElementContentAsBoolean();
     }
     else if (reader.LocalName == "FirstToFind"  && !m_ignoreExtraFields)
     {
         cache.FTF = reader.ReadElementContentAsBoolean();
     }
     else if (reader.LocalName == "UserData" && !m_ignoreExtraFields)
     {
         cache.User1 = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "User2" && !m_ignoreExtraFields)
     {
         cache.User2 = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "User3" && !m_ignoreExtraFields)
     {
         cache.User3 = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "User4" && !m_ignoreExtraFields)
     {
         cache.User4 = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "LatBeforeCorrect" && !m_ignoreExtraFields)
     {
         double corLat = cache.OrigLat;
         cache.Lat = reader.ReadElementContentAsDouble();
         cache.CorrectedLat = corLat;
     }
     else if (reader.LocalName == "LonBeforeCorrect" && !m_ignoreExtraFields)
     {
         double corLon = cache.OrigLon;
         cache.Lon = reader.ReadElementContentAsDouble();
         cache.CorrectedLon = corLon;
     }
     else if (reader.LocalName == "name")
     {
         cache.CacheName = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "placed_by")
     {
         cache.PlacedBy = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "owner")
     {
         cache.OwnerID = reader.GetAttribute("id");
         cache.CacheOwner = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "type")
     {
         ParseCacheType(reader.ReadElementContentAsString(), ref cache);
     }
     else if (reader.LocalName == "difficulty")
     {
         string diff = reader.ReadElementContentAsString();
         cache.Difficulty = float.Parse(diff, CultureInfo.InvariantCulture);
     }
     else if (reader.LocalName == "terrain")
     {
         string terr = reader.ReadElementContentAsString();
         cache.Terrain = float.Parse(terr, CultureInfo.InvariantCulture);
     }
     else if (reader.LocalName == "short_description")
     {
         string html = reader.GetAttribute("html");
         string val = reader.ReadElementContentAsString();
         if (html.Equals("False", StringComparison.InvariantCultureIgnoreCase))
             val = val.Replace("\n", "<br/>");
         cache.ShortDesc = val;
     }
     else if (reader.LocalName == "long_description")
     {
         string html = reader.GetAttribute("html");
         string val = reader.ReadElementContentAsString();
         if (html.Equals("False", StringComparison.InvariantCultureIgnoreCase))
             val = val.Replace("\n", "<br/>");
         cache.LongDesc = val;
     }
     else if (reader.LocalName == "encoded_hints")
     {
         cache.Hint = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "container")
     {
         cache.Container = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "logs" && !reader.IsEmptyElement)
     {
         ParseCacheLogs(ref cache, reader);
     }
     else if (reader.LocalName == "travelbugs" && !reader.IsEmptyElement)
     {
         ParseTravelBugs(ref cache, reader);
     }
     else if (reader.LocalName == "country")
     {
         cache.Country = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "state")
     {
         cache.State = reader.ReadElementContentAsString();
     }
     else if (reader.LocalName == "attributes")
     {
         parseCacheAttrs(ref cache, reader);
     }
     return cache;
 }
Beispiel #24
0
 public void ReadXml(XmlReader reader)
 {
     bool isEmpty = reader.IsEmptyElement;
       reader.ReadStartElement();
       if (isEmpty)
     return;
       while (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.Text)
       {
     if (reader.IsStartElement("title"))
       Title = reader.ReadElementString();
     else if (reader.IsStartElement("exploration"))
       Exploration = reader.ReadElementString();
     else if (reader.IsStartElement("alias"))
       Alias = reader.ReadElementString();
     else if (reader.IsStartElement("grade"))
       Grade = reader.ReadElementContentAsInt();
     else if (reader.IsStartElement("upper_grade"))
       UpperGrade = reader.ReadElementContentAsInt();
     else if (reader.IsStartElement("length"))
       Length = reader.ReadElementContentAsDouble();
     else if (reader.IsStartElement("warning"))
       Warning = reader.ReadElementString();
     else
       reader.ReadOuterXml();
       }
       reader.ReadEndElement();
 }
        internal static MarketplaceAppOfferNode ParseXml(XmlReader reader)
        {
            var node = new MarketplaceAppOfferNode();

            reader.ReadStartElement();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.LocalName)
                {
                    case "offerId":
                        node.OfferId = reader.ReadElementContentAsUrn();
                        break;

                    case "mediaInstanceId":
                        node.MediaInstanceId = reader.ReadElementContentAsUrn();
                        break;

                    case "clientTypes":
                        node.ClientTypes = reader.ReadElementContentAsArray(x => x.ReadElementContentAsString());
                        break;

                    case "paymentTypes":
                        node.PaymentTypes = reader.ReadElementContentAsArray(x => x.ReadElementContentAsString());
                        break;

                    case "store":
                        node.Store = reader.ReadElementContentAsString();
                        break;

                    case "price":
                        node.Price = reader.ReadElementContentAsDouble();
                        break;

                    case "displayPrice":
                        node.DisplayPrice = reader.ReadElementContentAsString();
                        break;

                    case "priceCurrencyCode":
                        node.PriceCurrencyCode = reader.ReadElementContentAsString();
                        break;

                    case "licenseRight":
                        node.LicenseRight = reader.ReadElementContentAsString();
                        break;

                    case "expiration":
                        node.Expiration = reader.ReadElementContentAsDateTime();
                        break;

                    default:
                        reader.Skip();
                        break;
                }
            }

            reader.ReadEndElement();

            return node;
        }
        internal static MarketplaceAppNode ParseXml(XmlReader reader)
        {
            var node = new MarketplaceAppNode();

            reader.ReadStartElement();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.Name)
                {
                    case "a:updated":
                        node.Updated = reader.ReadElementContentAsDateTime();
                        break;

                    case "a:title":
                        node.Title = reader.ReadElementContentAsString();
                        break;

                    case "a:id":
                        node.Id = reader.ReadElementContentAsUrn();
                        break;

                    case "a:content":
                        node.Content = MarketplaceAppContentNode.ParseXml(reader);
                        break;

                    case "iapCount":
                        node.IapCount = reader.ReadElementContentAsInt();
                        break;

                    case "sortTitle":
                        node.SortTitle = reader.ReadElementContentAsString();
                        break;

                    case "releaseDate":
                        node.ReleaseDate = reader.ReadElementContentAsDateTime();
                        break;

                    case "visibilityStatus":
                        node.VisibilityStatus = reader.ReadElementContentAsString();
                        break;

                    case "publisher":
                        node.Publisher = reader.ReadElementContentAsString();
                        break;

                    case "averageUserRating":
                        node.AverageUserRating = reader.ReadElementContentAsDouble();
                        break;

                    case "userRatingCount":
                        node.UserRatingCount = reader.ReadElementContentAsInt();
                        break;

                    case "image":
                        node.Image = MarketplaceAppImageNode.ParseXml(reader);
                        break;

                    case "screenshots":
                        node.Screenshots = reader.ReadElementContentAsArray(MarketplaceAppImageNode.ParseXml);
                        break;

                    case "categories":
                        node.Categories = reader.ReadElementContentAsArray(MarketplaceAppCategoryNode.ParseXml);
                        break;

                    case "tags":
                        node.Tags = reader.ReadElementContentAsArray(x => x.ReadElementContentAsString());
                        break;

                    case "taxString":
                        node.TaxString = reader.ReadElementContentAsString();
                        break;

                    case "backgroundImage":
                        node.BackgroundImage = MarketplaceAppImageNode.ParseXml(reader);
                        break;

                    case "offers":
                        node.Offers = reader.ReadElementContentAsArray(MarketplaceAppOfferNode.ParseXml);
                        break;

                    case "publisherId":
                        node.PublisherId = reader.ReadElementContentAsString();
                        break;

                    case "publisherGuid":
                        node.PublisherGuid = reader.ReadElementContentAsUrn();
                        break;

                    case "a:entry":
                        node.Entry = MarketplaceAppEntryNode.ParseXml(reader);
                        break;

                    default:
                        reader.Skip();
                        break;
                }
            }

            reader.ReadEndElement();

            return node;
        }
 public override double ReadElementContentAsDouble()
 {
     CheckAsync();
     return(_coreReader.ReadElementContentAsDouble());
 }
Beispiel #28
0
        /// <summary>
        /// deserialise this object
        /// </summary>
        /// <param name="reader">XmlReader to deserialize from</param>
        /// <returns>this</returns>
        internal ChapterItem Deserialize(XmlReader reader)
        {
            if (!reader.IsStartElement(xmlNode))
                throw new InvalidPlaylistException();

            reader.Read();
            while (!(reader.Name == xmlNode && reader.NodeType == XmlNodeType.EndElement)) {
                if (reader.IsStartElement("Position"))
                    Position = reader.ReadElementContentAsDouble();
                else if (reader.IsStartElement("ThumbSource"))
                    ThumbSource = new Uri(reader.ReadElementContentAsString(), UriKind.RelativeOrAbsolute);
                else if (reader.IsStartElement("Title"))
                    Title = reader.ReadElementContentAsString();
                else if (reader.IsStartElement())
                    throw new InvalidPlaylistException(xmlNode);
                else if (!reader.Read())
                    break;
            }
            return this;
        }
        // reader has read first node in object
        // when returns, must not have read past end of object
        object DeserializeMember( XmlReader xmlreader, Type membertype )
        {
            Console.WriteLine( "_DeserializeMember " + xmlreader.LocalName + " " + membertype.Name );

            if (membertype == typeof( int ) )
            {
                return xmlreader.ReadElementContentAsInt();
            }
            if (membertype == typeof( double ))
            {
                return xmlreader.ReadElementContentAsDouble();
            }
            if (membertype == typeof( bool ))
            {
                return Convert.ToBoolean( xmlreader.ReadElementContentAsString() );
            }
            if (membertype == typeof( string ))
            {
                return xmlreader.ReadElementContentAsString();
            }
            if (membertype.IsEnum)
            {
                string enumvalue = xmlreader.ReadElementContentAsString();
                return Enum.Parse( membertype, enumvalue );
            }
            if (membertype.IsArray)
            {
                ArrayList arraylist = new ArrayList();
                int thisdepth = xmlreader.Depth;
                string thisname = xmlreader.Name;
                Console.WriteLine( "thisdepth: " + thisdepth + " thisname: " + thisname );
                while (ReadNode(xmlreader))
                {
                    if (xmlreader.Depth <= thisdepth)
                    {
                        if (xmlreader.Name != thisname)
                        {
                            Console.WriteLine( " xmlreader.name: " + xmlreader.Name + " " + thisname );
                            putbacknode = true;
                        }
                        break;
                    }
                    object arrayitem = null;
                    if (membertype.GetElementType().IsPrimitive || membertype.GetElementType() == typeof( string ))
                    {
                        arrayitem = DeserializeMember( xmlreader, membertype.GetElementType() );
                    }
                    else
                    {
                        arrayitem = _Deserialize( xmlreader, membertype.GetElementType().Name );
                    }
                    arraylist.Add( arrayitem );
                    Console.WriteLine( "array item: " + arrayitem );
                    if (xmlreader.Depth <= thisdepth)
                    {
                        if (xmlreader.Name != thisname)
                        {
                            Console.WriteLine( " xmlreader.name: " + xmlreader.Name + " " + thisname );
                            putbacknode = true;
                        }
                        break;
                    }
                }
                Console.WriteLine( "done with this array" );
                object arrayresult = arraylist.ToArray( membertype.GetElementType() );
                //Console.WriteLine( arrayresult );
                return arrayresult;
            }
            if (membertype.IsClass)
            {
                object deserializedobject = _Deserialize( xmlreader, membertype.Name );
                Console.WriteLine( "deserialized object: " + deserializedobject );
                return deserializedobject;
            }
            throw new Exception("Unimplemented membertype: " + membertype );
        }
 /// <summary>
 /// Read a Phi-Theta electrode record; values are in degrees
 /// </summary>
 /// <param name="xr">Open Electrode File Stream</param>
 /// <param name="nameSpace">namesSpace or null</param>
 public override void read(XmlReader xr, string nameSpace)
 {
     this.Name = xr["Name", nameSpace];
     xr.ReadStartElement(/* Electrode */);
     this.Phi = xr.ReadElementContentAsDouble("Phi", nameSpace) * ToRad;
     this.Theta = xr.ReadElementContentAsDouble("Theta", nameSpace) * ToRad;
     xr.ReadEndElement(/* Electrode */);
 }