ReadToDescendant() public method

public ReadToDescendant ( string name ) : bool
name string
return bool
Exemplo n.º 1
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("ContainerElement") == false)
            {
                throw new MyException("could not find the start of element ContainerElement");
            }

            int depth = reader.Depth;

            reader.ReadToDescendant("xx1:containee");
            reader.ReadToNextSibling("xx2", "Containee2");
            reader.ReadToNextSibling("Containee3");

            // moved to closing ContainerElement
            while (reader.Depth > depth && reader.Read())
            {
            }
            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));
            }
        }
Exemplo n.º 2
0
		private void readItems(XmlReader reader) {
			reader.ReadToFollowing ("ItemDatabase");
			bool continueReading = reader.ReadToDescendant ("Item");

			while (continueReading) {
				//Read all information from the .xml-file
				reader.ReadToDescendant ("Id");
				int id = reader.ReadElementContentAsInt ();
				reader.ReadToNextSibling ("Name");
				string name = reader.ReadElementContentAsString ();
				reader.ReadToNextSibling ("Description");
				string desc = reader.ReadElementContentAsString ();
				reader.ReadToNextSibling ("Value");
				int value = reader.ReadElementContentAsInt ();
				reader.ReadToNextSibling ("Type");
				string type = reader.ReadElementContentAsString ();
				ItemType t = type.StringToType ();

				//And add the item to the database
				Item i = new Item (name, desc, value, t, id);

				//check for attributes and add them to the item
				checkForAttributes(reader, i);

				//Add the item to the databse and read end element
				items.Add(i);
				reader.ReadEndElement ();
				//Check if there is another item to read
				continueReading = reader.ReadToNextSibling ("Item");
			}
		}
Exemplo n.º 3
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("NestedWriteString") == false)
            {
                throw new Exception("could not find the start of element NestedWriteString");
            }
            int depth = reader.Depth;

            reader.ReadToDescendant("container2");
            string content = reader.ReadString();

            if (content == null || content.Equals("container2 content") == false)
            {
                string msg = String.Format("NextWriteString: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} content = {3}", reader.Name, reader.NamespaceURI, reader.Value, content);
                throw new Exception(msg);
            }
            // moved to closing NestedWriteString
            while (reader.Depth > depth && reader.Read())
            {
            }

            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));
            }
        }
Exemplo n.º 4
0
        //Attempt to read batch.xml to load previous settings
        //If anything goes wrong, just start without any preloaded settings
        public void ReadXml(XmlReader reader)
        {
            try
            {
                FileDescs = new Dictionary<string, FbxFileDesc>();

                reader.ReadToFollowing("BatchConversion");

                reader.ReadToDescendant("Output");
                OutputDir = reader.ReadElementContentAsString();

                while (reader.LocalName == "FbxFile")
                {
                    var newFile = new FbxFileDesc();

                    reader.ReadToDescendant("Filename");
                    var newFilename = reader.ReadElementContentAsString();

                    if (reader.LocalName != "CollisionGeneration")
                        reader.ReadToNextSibling("CollisionGeneration");

                    newFile.CollisionType = reader.ReadElementContentAsString();

                    while (reader.LocalName == "AnimClip")
                    {
                        var newClip = new AnimationClipDesc();

                        reader.ReadToDescendant("Name");
                        var newClipName = reader.ReadElementContentAsString();

                        if (reader.LocalName != "Keyframes")
                        reader.ReadToNextSibling("Keyframes");

                        newClip.BeginFrame = double.Parse(reader.GetAttribute("Begin"));
                        newClip.EndFrame = double.Parse(reader.GetAttribute("End"));
                        newClip.Fps = double.Parse(reader.GetAttribute("FPS"));

                        reader.Read();
                        reader.ReadEndElement();

                        newFile.AnimationClips.Add(newClipName, newClip);
                    }

                    reader.ReadEndElement();
                    FileDescs.Add(newFilename, newFile);
                }
            }
            catch (Exception)
            {
                MessageBox.Show(ParentWindow, "Unable to read batch.xml, starting with a clean slate...",
                                "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                FileDescs = new Dictionary<string, FbxFileDesc>();
                OutputDir = "";
            }
        }
Exemplo n.º 5
0
        private void ExtractDefinitions(XmlReader reader, ResultFile trx)
        {
            if (reader.ReadToFollowing("TestDefinitions"))
            {
                if (reader.ReadToDescendant("UnitTest"))
                {
                    do
                    {
                        var testId = Guid.Parse(reader.GetAttribute("id"));
                        var tempResult = trx.Results.First(result => result.TestId == testId);
                        tempResult.Storage = reader.GetAttribute("storage");

                        if (reader.ReadToFollowing("TestMethod"))
                        {
                            tempResult.CodeBase = reader.GetAttribute("codeBase");
                            tempResult.AdapterTypeName = reader.GetAttribute("adapterTypeName");
                            tempResult.ClassName = reader.GetAttribute("className");
                        }

                        reader.ReadToNextSibling("UnitTest");
                    }
                    while (reader.ReadToNextSibling("UnitTest"));
                }
            }
        }
		public void LoadFromXml (XmlReader reader)
		{
			reader.ReadToDescendant ("plist");
			while (reader.Read () && reader.NodeType != XmlNodeType.Element);
			if (!reader.EOF)
				root = LoadFromNode (reader);
		}
Exemplo n.º 7
0
 void createPlayer(XmlReader reader)
 {
     Vector2 pos = Vector2.Zero;
     TextureMap t = new TextureMap();
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             switch (reader.Name)
             {
                 case "position":
                     {
                         reader.ReadToDescendant("x");
                         float x = (float)float.Parse((reader.GetAttribute(0)));
                         reader.ReadToNextSibling("y");
                         float y = (float)float.Parse((reader.GetAttribute(0)));
                         pos = new Vector2(x, y);
                     }
                     break;
                 default:
                     int o = 0;//fer teh deboog
                     break;
             }
         }
     }
     Player p = new Player(pos, t);
 }
Exemplo n.º 8
0
        public bool FromXml(XmlReader reader)
        {
            if (reader == null || reader.Name != "Lib")
            {
                return false;
            }

            if (reader.Name == "Order" || reader.ReadToDescendant("Order"))
            {
                Order = reader.ReadElementContentAsInt();
            }
            if (reader.Name == "Id" || reader.ReadToNextSibling("Id"))
            {
                Id = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Name" || reader.ReadToNextSibling("Name"))
            {
                Name = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Text" || reader.ReadToNextSibling("Text"))
            {
                Text = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Memo" || reader.ReadToNextSibling("Memo"))
            {
                Memo = reader.ReadElementContentAsString();
            }
            return true;
        }
Exemplo n.º 9
0
Arquivo: MRen.cs Projeto: burstas/rmps
        public bool FromXml(XmlReader reader)
        {
            if (reader == null || reader.Name != "Ren" || !reader.IsStartElement())
            {
                return false;
            }

            if (reader.Name == "Order" || reader.ReadToDescendant("Order"))
            {
                Order = reader.ReadElementContentAsInt();
            }
            if (reader.Name == "Id" || reader.ReadToNextSibling("Id"))
            {
                Id = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Name" || reader.ReadToNextSibling("Name"))
            {
                Name = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Command" || reader.ReadToNextSibling("Command"))
            {
                Command = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Remark" || reader.ReadToNextSibling("Remark"))
            {
                Remark = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Ren" && reader.NodeType == XmlNodeType.EndElement)
            {
                reader.ReadEndElement();
            }
            return true;
        }
Exemplo n.º 10
0
        private World <bool> LoadWorld(System.Xml.XmlReader reader)
        {
            // Write Map Root
            reader.ReadToDescendant("map");

            if (reader.Name != "map")
            {
                throw new ApplicationException("no map found.");
            }

            // Load Dimensions
            var width  = int.Parse(reader.GetAttribute("width"));
            var height = int.Parse(reader.GetAttribute("height"));

            var world = new World <bool>(width, height, true);

            reader.Read();
            while (reader.Name == "cell")
            {
                var x = int.Parse(reader.GetAttribute("x"));
                var y = int.Parse(reader.GetAttribute("y"));
                var v = bool.Parse(reader.GetAttribute("v"));

                world[x, y] = v;

                reader.Read();
            }

            reader.Read();

            return(world);
        }
Exemplo n.º 11
0
        private void expandNamespace_function(TreeNodeCollection outNodes, TreeNode outInstanceMethods, string strSection, string strNamespace, XmlReader reader)
        {
            bool bContinue = reader.ReadToDescendant("function");
            while (bContinue)
            {

               // if (reader.GetAttribute("args") != null) MessageBox.Show("instance?");

                NodeDocLnzFunction node = new NodeDocLnzFunction(strSection, strNamespace, reader.GetAttribute("name"));

                bool bInstance = reader.GetAttribute("instance") == "true";
                node.bIsInstanceMethod = bInstance;
                string strArgs = reader.GetAttribute("args"); if (strArgs != null && strArgs != "") node.strArguments = strArgs;
                string strReturns = reader.GetAttribute("returns"); if (strReturns != null && strReturns != "") node.strReturns = strReturns;
                node.strDocumentationAndExample = getFunctionDocAndExample(reader.ReadSubtree()); //assumes doc before example

                if (bInstance)
                {
                    //MessageBox.Show("instance found");
                    outInstanceMethods.Nodes.Add(node);
                }
                else
                    outNodes.Add(node);

                bContinue = ReadToNextSibling(reader, "function");
            }
            reader.Close();
        }
        private void expandNamespace_function(TreeNodeCollection outNodes, string strSection, string strNamespace, XmlReader reader)
        {
            bool bContinue = reader.ReadToDescendant("function");
            while (bContinue)
            {
                NodeDocPythonFunction node = newnode(strSection, strNamespace, reader.GetAttribute("name"));
                outNodes.Add(node);

                bool bInstance = reader.GetAttribute("instance") == "true";
                node.bIsInstanceMethod = bInstance;
                string strSyntax = reader.GetAttribute("fullsyntax"); if (strSyntax != null && strSyntax != "") node.strFullSyntax = strSyntax;
                node.strDocumentation = getFunctionDocAndExample(reader.ReadSubtree()); //assumes doc before example

                if (this.emphasizeStaticness())
                {
                    if (!bInstance)
                    {
                        //change visible node text to emphasize static-ness
                        node.Text = node.strNamespacename + "." + node.strFunctionname;
                    }
                }
                bContinue = ReadToNextSibling(reader, "function");
            }

            reader.Close();
        }
Exemplo n.º 13
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteCData") == false)
            {
                throw new MyException("Could not find the start of WriteCData");
            }
            string cdata = reader.ReadString();

            if (cdata == null || cdata.Equals("<hello world/>") == false)
            {
                msg = String.Format("WriteCData: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} cdata = {3}", reader.Name, reader.NamespaceURI, reader.Value, cdata);
                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));
            }
        }
Exemplo n.º 14
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteBase64") == false)
            {
                throw new MyException("Could not find the end of WriteBase64");
            }
            reader.Read();
            string base64 = reader.ReadContentAsString();

            byte[] bytes = Convert.FromBase64String(base64);
            string text  = System.Text.Encoding.UTF8.GetString(bytes);

            if (text == null || text.Equals("hello world") == false)
            {
                msg = String.Format("WriteBase64: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} base64 = {3}", reader.Name, reader.NamespaceURI, reader.Value, base64);
                throw new MyException(msg);
            }

            reader.MoveToElement();  // move back to WriteBase64 end

            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));
            }
        }
Exemplo n.º 15
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteBinHex") == false)
            {
                throw new MyException("Could not find the end of WriteBinHex");
            }
            reader.Read();
            string binHexString = reader.ReadContentAsString(); // good enuff.

            if (binHexString == null || binHexString.Length == 0)
            {
                msg = String.Format("WriteBinHex: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} binHexString = {3}", reader.Name, reader.NamespaceURI, reader.Value, binHexString);
                throw new MyException(msg);
            }

            reader.MoveToElement();  // move back to WriteBinHex end
            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));
            }
        }
Exemplo n.º 16
0
		public override void ReadXml(XmlReader reader)
		{
			reader.MoveToContent();
			if (reader.AttributeCount == 0)
				throw new MissingXmlAttributeException(@"Missing XML attribute ""value"".");
			Name = reader["name"];

			if (reader.IsEmptyElement)
			{
				reader.ReadEndElement();
				return;
			}


			if (reader.ReadToDescendant(ChildXmlTag))
			{
				while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == ChildXmlTag)
				{
					reader.ReadStartElement();
					reader.MoveToContent();

					IilParameter p = IilParameter.fromString(reader.LocalName);
					p.ReadXml(reader);
					Parameters.Add(p);
					reader.ReadEndElement();
				}
			}
			
            
			reader.ReadEndElement();
			//reader.Read();
		}
Exemplo n.º 17
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteAttributes") == false)
            {
                throw new MyException("Could not find the end of WriteAttributes");
            }
            //Console.WriteLine("After one ReadToDescendant Name = {0}", reader.Name);

            if (reader.HasAttributes)
            {
                int attribCount = 0;
                while (reader.MoveToNextAttribute())
                {
                    attribCount++;
                }
                //Console.WriteLine("attribCount = {0}", attribCount);
                if (attribCount != 3)
                {
                    throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType));
                }
            }
            else
            {
                throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType));
            }
            reader.MoveToElement(); // back at WriteAttributes
        }
Exemplo n.º 18
0
 public static Exception CreateResponseException(XmlReader reader)
 {
     if (reader == null)
     throw new ArgumentNullException("reader");
       reader.MoveToElement();
       if (!reader.ReadToDescendant("err"))
     throw new XmlException("No error element found in XML");
       int code = 0;
       string message = (string) null;
       while (reader.MoveToNextAttribute())
       {
     if (reader.LocalName == "code")
     {
       try
       {
     code = int.Parse(reader.Value, NumberStyles.Any, (IFormatProvider) NumberFormatInfo.InvariantInfo);
       }
       catch (FormatException ex)
       {
     throw new FlickrException("Invalid value found in code attribute. Value '" + (object) code + "' is not an integer");
       }
     }
     else if (reader.LocalName == "msg")
       message = reader.Value;
       }
       return (Exception) ExceptionHandler.CreateException(code, message);
 }
Exemplo n.º 19
0
 void IFlickrParsable.Load(XmlReader reader)
 {
     if (reader.LocalName != "auth")
     return;
       reader.ReadToDescendant("access_token");
       this.Token = reader.GetAttribute("oauth_token");
       this.TokenSecret = reader.GetAttribute("oauth_token_secret");
 }
Exemplo n.º 20
0
        public void ReadXmlContent(System.Xml.XmlReader reader, Func <Type, WSTableSource> getTSource)
        {
            base.ReadXmlContent(reader);

            bool done = false;

            while (reader.MoveToContent() == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "params":
                {
                    if (reader.ReadToDescendant("param"))
                    {
                        while (reader.MoveToContent() == XmlNodeType.Element)
                        {
                            string  pName = reader.GetAttribute("name");
                            WSParam param = GetXParam(pName, null, getTSource);
                            if (param == null)
                            {
                                reader.Skip();
                                continue;
                            }
                            else
                            {
                                if (param is WSTableParam)
                                {
                                    ((WSTableParam)param).ReadXml(reader);
                                }
                                else
                                {
                                    param.ReadXml(reader);
                                }
                            }

                            reader.MoveToContent();
                            if (!reader.Read())
                            {
                                break;
                            }
                        }
                    }
                    break;
                }

                default:
                {
                    done = true;
                    break;
                }
                }
                reader.MoveToContent();
                if (done || !reader.Read())
                {
                    break;
                }
            }
        }
Exemplo n.º 21
0
		public string FromXmlReader (XmlReader reader)
		{
			if (!reader.ReadToDescendant ("head"))
				return null;
			if (!reader.ReadToNextSibling ("body"))
				return null;

			return reader.ReadInnerXml ();
		}
Exemplo n.º 22
0
 // Gets the creation date of the Project Gutenberg catalog. This method should be called
 // before parsing the books and volumes because the creation date is at the beginning;
 // calling it later would not find the XML element with the date any more and would
 // continue reading the content to the end, skipping all content. This method expects a
 // reader returned by the method Open.
 public Date GetCreated(XmlReader reader)
 {
     Log.Verbose("Getting creation date...");
     if (!reader.ReadToFollowing("Description", RDF))
         throw new ApplicationException("Missing creation time.");
     if (!reader.ReadToDescendant("value", RDF))
         throw new ApplicationException("Missing creation date value.");
     return reader.ReadElementContentAsDate();
 }
 public void ReadXml(XmlReader reader)
 {
     reader.MoveToContent();
     reader.ReadToDescendant("Value1");
     Value1 = reader.ReadString();
     reader.ReadEndElement();
     reader.ReadStartElement("Value2");
     Value2 = int.Parse(reader.ReadString());
     ReadXmlCalled = true;
 }
Exemplo n.º 24
0
    public static List<SAMAlignedItem> ReadFrom(XmlReader source)
    {
      var result = new List<SAMAlignedItem>();

      source.ReadToFollowing("queries");
      if (source.ReadToDescendant("query"))
      {
        do
        {
          var query = new SAMAlignedItem();
          result.Add(query);

          query.Qname = source.GetAttribute("name");
          query.Sequence = source.GetAttribute("sequence");
          query.QueryCount = int.Parse(source.GetAttribute("count"));
          query.Sample = source.GetAttribute("sample");
          if (source.ReadToDescendant("location"))
          {
            do
            {
              var loc = new SAMAlignedLocation(query);

              loc.Seqname = source.GetAttribute("seqname");
              loc.Start = long.Parse(source.GetAttribute("start"));
              loc.End = long.Parse(source.GetAttribute("end"));
              loc.Strand = source.GetAttribute("strand")[0];
              loc.Cigar = source.GetAttribute("cigar");
              loc.AlignmentScore = int.Parse(source.GetAttribute("score"));
              loc.MismatchPositions = source.GetAttribute("mdz");
              loc.NumberOfMismatch = int.Parse(source.GetAttribute("nmi"));
              var nnmpattr = source.GetAttribute("nnpm");
              if (nnmpattr != null)
              {
                loc.NumberOfNoPenaltyMutation = int.Parse(nnmpattr);
              }
            } while (source.ReadToNextSibling("location"));
          }
        } while (source.ReadToNextSibling("query"));
      }

      return result;
    }
Exemplo n.º 25
0
        /// <summary>
        /// Generates a collection from its XML representation.
        /// </summary>
        /// <param name="reader">System.Xml.XmlReader</param>
        public void ReadXml(XmlReader reader)
        {
            this.Clear();
              if (reader.ReadToDescendant("SerializableStringDictionary"))
              {
              if (reader.ReadToDescendant("DictionaryEntry"))
              {
                  do
                  {
                      reader.MoveToAttribute("Key");
                      string key = reader.ReadContentAsString();
                      reader.MoveToAttribute("Value");
                      string value = reader.ReadContentAsString();

                      this.Add(key, value);

                  } while (reader.ReadToNextSibling("DictionaryEntry"));
              }
              }
        }
Exemplo n.º 26
0
 public static object Parse(
     XmlReader rdr,
     Type valueType,
     MappingAction action,
     out Type parsedType,
     out Type parsedArrayType)
 {
     parsedType = parsedArrayType = null;
     rdr.ReadToDescendant("value");
     var mappingStack = new MappingStack("request");
     return new XmlRpcDeserializer().ParseValueElement(rdr, valueType, mappingStack, action);
 }
        protected string getFunctionDocAndExample(XmlReader reader)
        {
            //assumes doc is before example. Otherwise, could miss an example.
            string strRes = "";
            bool bFound = reader.ReadToDescendant("doc");
            if (bFound) strRes += (unencodeXml(reader.ReadString()));
            bFound = reader.ReadToNextSibling("example");
            if (bFound) strRes += ("\r\n\r\nExample:\r\n" + unencodeXml(reader.ReadString()));

            reader.Close();
            return strRes;
        }
        void IFlickrParsable.Load(XmlReader reader)
        {
            if (reader.LocalName != "auth")
            {
                UtilityMethods.CheckParsingException(reader);
                return;
            }

            reader.ReadToDescendant("access_token");

            Token = reader.GetAttribute("oauth_token");
            TokenSecret = reader.GetAttribute("oauth_token_secret");
        }
Exemplo n.º 29
0
        void ITwentyThreeParsable.Load(System.Xml.XmlReader reader)
        {
            reader.ReadToDescendant("tag");

            while (reader.LocalName == "tag")
            {
                var member = new RawTag();
                ((ITwentyThreeParsable)member).Load(reader);
                Add(member);
            }

            reader.Skip();
        }
        public void ReadXml(System.Xml.XmlReader reader)
        {
            Initialize();

            if (reader.MoveToContent() == XmlNodeType.Element)
            {
                Default = reader["Default"];

                if (reader.ReadToDescendant("Translations"))
                {
                    if (reader.ReadToDescendant("Translation"))
                    {
                        while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "Translation")
                        {
                            _Translations.Add(reader["LanguageCode"], reader.ReadElementContentAsString());
                        }
                    }
                    reader.Read();
                }
                reader.Read();
            }
        }
Exemplo n.º 31
0
        void IFlickrParsable.Load(System.Xml.XmlReader reader)
        {
            reader.ReadToDescendant("tag");

            while (reader.LocalName == "tag")
            {
                RawTag member = new RawTag();
                ((IFlickrParsable)member).Load(reader);
                Add(member);
            }

            reader.Skip();
        }
 public void LoadFromXml(XmlReader reader)
 {
     
     reader.ReadToDescendant("plist");
     while (reader.Read())
     {
         if (reader.NodeType != XmlNodeType.Element) continue;
         //Console.WriteLine(reader.LocalName);
         //Console.WriteLine(reader.ToString());
         if (!reader.EOF)
             root = LoadFromNode(reader);
     }
 }
Exemplo n.º 33
0
        public void ReadXml(XmlReader reader)
        {
            if (reader.MoveToContent() == XmlNodeType.Element &&
                reader.LocalName == "repeat")
            {
                index = int.Parse(reader["index"]);

                if (reader.ReadToDescendant("template"))
                    template = XElement.Load(reader.ReadSubtree())
                        .Elements()
                        .First();
            }
        }
Exemplo n.º 34
0
        public void ReadXmlContent(System.Xml.XmlReader reader)
        {
            reader.MoveToContent();
            reader.Read();

            bool done = false;

            while (reader.MoveToContent() == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "aliaces":
                    if (reader.ReadToDescendant("aliace"))
                    {
                        List <string> aList = new List <string>();
                        while (reader.MoveToContent() == XmlNodeType.Element)
                        {
                            if (!reader.IsEmptyElement)
                            {
                                string aliace = reader.ReadElementContentAsString();
                                if (!string.IsNullOrEmpty(aliace))
                                {
                                    if (!aList.Contains(aliace))
                                    {
                                        aList.Add(aliace);
                                    }
                                }
                            }
                            if (!reader.Read())
                            {
                                break;
                            }
                        }
                        //MergeAliaces(aList);
                        ALIACES = aList;
                    }
                    break;

                default:
                {
                    done = true;
                    break;
                }
                }
                reader.MoveToContent();
                if (done || !reader.Read())
                {
                    break;
                }
            }
        }
Exemplo n.º 35
0
 public static object Parse(
   XmlReader rdr,
   Type valueType,
   MappingAction action,
   XmlRpcDeserializer deserializer,
   out Type parsedType,
   out Type parsedArrayType)
 {
   parsedType = parsedArrayType = null;
   rdr.ReadToDescendant("value");
   MappingStack parseStack = new MappingStack("request");
   object obj = deserializer.ParseValueElement(rdr, valueType, parseStack, action);
   return obj;
 }
Exemplo n.º 36
0
        public void ReadXml(XmlReader reader)
        {
            if (reader.LocalName != "icon" && !reader.ReadToDescendant("icon"))
                throw new InvalidDataException();

            XmlHelper.ParseXml(reader, new XmlParseSet
            {
                {"url", () => this.RelativeUrl = reader.ReadString()},
                {"mimetype", () => this.MimeType = reader.ReadString()},
                {"width", () => this.Width = reader.ReadElementContentAsInt()},
                {"height", () => this.Height = reader.ReadElementContentAsInt()},
                {"depth", () => this.Depth = reader.ReadElementContentAsInt()}
            });
        }
 private void ReadKeyElement(XmlReader reader, ILocalizationDictionary dictionary) {
   var id = reader.GetAttribute("id");
   if(!reader.ReadToDescendant("val")) return;
   do {
     var locale = reader.GetAttribute("for");
     if(locale==null) {
       throw new XmlLocalizationReaderException("Missing required attribute 'for' on element 'val'");
     }
     if(reader.IsEmptyElement) continue;
     reader.MoveToContent();
     var val = reader.ReadString();
     dictionary[locale, Prefix+id] = val;
   } while(reader.ReadToNextSibling("val"));
 }
Exemplo n.º 38
0
 internal Event(XmlReader reader)
 {
     reader.Read ();
     date = reader ["date"];
     country = reader ["country"];
     catalog_number = reader ["catalog-number"];
     barcode = reader ["barcode"];
     format = Utils.StringToEnum<ReleaseFormat> (reader ["format"]);
     if (reader.ReadToDescendant ("label")) {
         label = new Label (reader.ReadSubtree ());
         reader.Read (); // FIXME this is a workaround for Mono bug 334752
     }
     reader.Close ();
 }
 private void expandNamespace_namespace(TreeNodeCollection outNodes,  string strSection, string strNamespace, XmlReader reader)
 {
     bool bContinue = reader.ReadToDescendant("namespace");
     while (bContinue)
     {
         if (reader.GetAttribute("name") == strNamespace)
         {
             expandNamespace_function(outNodes, strSection, strNamespace, reader.ReadSubtree());
             reader.Close();
             return;
         }
         bContinue = ReadToNextSibling(reader, "namespace");
     }
     reader.Close();
 }
Exemplo n.º 40
0
 //! Parse group tag.
 private void ParseTag(XmlReader Xml, Dictionary<CharacterGroup, CharacterPartItem[]> Definition)
 {
     // Move to first child
     if (!Xml.ReadToDescendant("group"))
         throw new XmlException("Cannot find element 'group' - " + Xml.Name);
     do
     {
         // Make new character part list
         var character_parts = new List<CharacterPartItem>();
         // Get group type
         CharacterGroup group = (CharacterGroup)Convert.ToUInt16(Xml.GetAttribute("id"));
         // Get items
         Xml.ReadToDescendant("item");
         ushort type = 0;
         do
         {
             character_parts.Add(
                 new CharacterPartItem((CharacterType)type++, Xml.GetAttribute("prefab"))
             );
         } while (Xml.ReadToNextSibling("item"));
         // Add new group
         Definition[group] = character_parts.ToArray();
     } while (Xml.ReadToNextSibling("group"));
 }
Exemplo n.º 41
0
 void IFlickrParsable.Load(XmlReader reader)
 {
     if (reader.LocalName != "count" && !reader.ReadToFollowing("count"))
     return;
       this.Count = reader.ReadElementContentAsInt();
       if (reader.LocalName != "prevphotos")
     reader.ReadToFollowing("prevphotos");
       reader.ReadToDescendant("photo");
       while (reader.LocalName == "photo")
       {
     FavoriteContextPhoto favoriteContextPhoto = new FavoriteContextPhoto();
     favoriteContextPhoto.Load(reader);
     this.PreviousPhotos.Add(favoriteContextPhoto);
       }
       if (reader.LocalName != "nextphotos")
     reader.ReadToFollowing("nextphotos");
       reader.ReadToDescendant("photo");
       while (reader.LocalName == "photo")
       {
     FavoriteContextPhoto favoriteContextPhoto = new FavoriteContextPhoto();
     favoriteContextPhoto.Load(reader);
     this.NextPhotos.Add(favoriteContextPhoto);
       }
 }
Exemplo n.º 42
0
 private void expandNamespace_section(TreeNodeCollection outNodes, TreeNode outInstanceMethods, string strSection, string strNamespace, XmlReader reader)
 {
     bool bContinue = reader.ReadToDescendant("section");
     while (bContinue)
     {
         if (mainReader.GetAttribute("name") == strSection)
         {
             expandNamespace_namespace(outNodes, outInstanceMethods, strSection, strNamespace, reader.ReadSubtree());
             mainReader.Close();
             return;
         }
         bContinue = ReadToNextSibling(mainReader, "section");
     }
     mainReader.Close();
 }
Exemplo n.º 43
0
    public void ReadXml(System.Xml.XmlReader reader)
    {
        this.name   = reader["Name"];
        this.Width  = Int32.Parse(reader["Width"]);
        this.Height = Int32.Parse(reader["Height"]);
        initMap(Width, Height);
        XmlSerializer tileSerializer = new XmlSerializer(typeof(SerializedTile[]));

        reader.ReadToDescendant("ArrayOfSerializedTile");
        SerializedTile[] tiles = (SerializedTile[])tileSerializer.Deserialize(reader);
        foreach (SerializedTile tileInfo in tiles)
        {
            Tile[,] layer;
            this.tiles.TryGetValue(tileInfo.l, out layer);
            layer[tileInfo.x, tileInfo.y] = tileInfo.t;
        }
    }
Exemplo n.º 44
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteName") == false)
            {
                throw new MyException("could not find the start of element WriteName");
            }

            int       counter      = 0;
            const int NODES_AT_END = 3;

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

            if (counter != NODES_AT_END)
            {
                throw new MyException(String.Format("expected {0} nodes, but found {1}", NODES_AT_END, counter));
            }
        }
Exemplo n.º 45
0
        /// <summary>
        /// Deserialize from XML
        /// </summary>
        /// <param name="reader">   XML reader</param>
        void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
        {
            ChessBoard.MovePosS movePos;
            bool bIsEmpty;

            m_listMovePos.Clear();
            if (reader.MoveToContent() != XmlNodeType.Element || reader.LocalName != "MoveList")
            {
                throw new SerializationException("Unknown format");
            }
            else
            {
                bIsEmpty     = reader.IsEmptyElement;
                m_iPosInList = Int32.Parse(reader.GetAttribute("PositionInList"));
                if (bIsEmpty)
                {
                    reader.Read();
                }
                else
                {
                    if (reader.ReadToDescendant("Move"))
                    {
                        while (reader.IsStartElement())
                        {
                            movePos = new ChessBoard.MovePosS();
                            movePos.OriginalPiece = (ChessBoard.PieceE)Enum.Parse(typeof(ChessBoard.SerPieceE), reader.GetAttribute("OriginalPiece"));
                            movePos.StartPos      = (byte)Int32.Parse(reader.GetAttribute("StartingPosition"));
                            movePos.EndPos        = (byte)Int32.Parse(reader.GetAttribute("EndingPosition"));
                            movePos.Type          = (ChessBoard.MoveTypeE)Enum.Parse(typeof(ChessBoard.MoveTypeE), reader.GetAttribute("MoveType"));
                            m_listMovePos.Add(movePos);
                            reader.ReadStartElement("Move");
                        }
                    }
                    reader.ReadEndElement();
                }
            }
        }
Exemplo n.º 46
0
 public virtual void ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.ReadToDescendant("WriteStartAttribute") == false)
     {
         throw new Exception("could not find the start of element WriteStartAttribute");
     }
     //Console.WriteLine("{0}\r\n{1}", reader.Name, reader.NodeType);
     if (reader.HasAttributes)
     {
         int attribCount = 0;
         while (reader.MoveToNextAttribute())
         {
             attribCount++;
         }
         if (attribCount != 2)
         {
             throw new MyException(String.Format("expected 2 attributes, but found {0}", attribCount));
         }
     }
     else
     {
         throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 1", reader.Name, reader.NodeType));
     }
 }
Exemplo n.º 47
0
 public bool TryExtractGameSaveDescriptorFromFile(string outputFilePath, out GameSaveDescriptor gameSaveDescriptor, bool makeCurrent)
 {
     gameSaveDescriptor = null;
     if (File.Exists(outputFilePath))
     {
         Archive archive = null;
         try
         {
             archive = Archive.Open(outputFilePath, ArchiveMode.Open);
             MemoryStream stream = null;
             if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
             {
                 XmlReaderSettings settings = new XmlReaderSettings
                 {
                     CloseInput     = true,
                     IgnoreComments = true,
                     IgnoreProcessingInstructions = true,
                     IgnoreWhitespace             = true
                 };
                 using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                 {
                     if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                     {
                         ISerializationService service = Services.GetService <ISerializationService>();
                         XmlSerializer         xmlSerializer;
                         if (service != null)
                         {
                             xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                         }
                         else
                         {
                             xmlSerializer = new XmlSerializer(typeof(GameSaveDescriptor));
                         }
                         gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                         gameSaveDescriptor.SourceFileName = outputFilePath;
                         if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                         {
                             Diagnostics.LogError("Invalid game save; application version does not match.");
                             gameSaveDescriptor = null;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Diagnostics.LogWarning("Exception caught: " + ex.ToString());
             gameSaveDescriptor = null;
         }
         finally
         {
             if (archive != null)
             {
                 archive.Close();
             }
         }
         if (gameSaveDescriptor != null)
         {
             if (makeCurrent)
             {
                 this.GameSaveDescriptor = gameSaveDescriptor;
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 48
0
        private void LoadSystemSettings()
        {
            string strAppDir = Path.GetDirectoryName(Application.ExecutablePath);

            string strDiscCode         = ConfigurationManager.GetUserSettingString("DiscCode").Trim();
            string strPrtPath          = ConfigurationManager.GetUserSettingString("PrtPath").Trim();
            string strCurCul           = ConfigurationManager.GetUserSettingString("CultureName").Trim();
            string strConnectionString = ConfigurationManager.GetUserSettingString("ConnectionString").Trim();

            // Decrypt Password
            strConnectionString = PasswordProcessing(strConnectionString, true);

            if ("1" == ConfigurationManager.GetUserSettingString("DCEnable").Trim() ||
                (strDiscCode != null && strDiscCode.Length > 0))
            {
                this.cmbDiscList.Enabled = true;
            }
            else
            {
                this.cmbDiscList.Enabled = false;
            }

            // Get the Language File
            string strLangFilePath = strAppDir + "\\Localization\\";
            string strDefCul       = System.Globalization.CultureInfo.CurrentCulture.Name;
            string strDefLangFile  = null;
            string strCurLangFile  = null;

            DataRow drDef = dtLanguageTable.NewRow();

            drDef["F_Description"] = "Default";
            drDef["F_CulName"]     = "Default";
            dtLanguageTable.Rows.Add(drDef);

            string[] files = Directory.GetFiles(strLangFilePath, "*.xml");
            foreach (string file in files)
            {
                System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(file);
                xmlReader.ReadToDescendant("Localization");

                DataRow dr = dtLanguageTable.NewRow();
                dr["F_Description"] = xmlReader["description"];
                dr["F_CulName"]     = xmlReader["cultureName"];
                dr["F_FileName"]    = Path.GetFileName(file);
                dtLanguageTable.Rows.Add(dr);

                if (xmlReader["cultureName"] == strDefCul)
                {
                    strDefLangFile = dr["F_FileName"].ToString();
                }

                if (xmlReader["cultureName"] == strCurCul)
                {
                    strCurLangFile = dr["F_FileName"].ToString();
                }
            }

            if (strDefLangFile == null)
            {
                if (dtLanguageTable.Rows.Count > 1)
                {
                    drDef["F_FileName"] = dtLanguageTable.Rows[1]["F_FileName"];
                }
                else
                {
                    drDef["F_FileName"] = "";
                }
            }

            if (strCurLangFile == null)
            {
                strCurCul      = "Default";
                strCurLangFile = drDef["F_FileName"].ToString();
            }

            cmbLanguage.DataSource    = dtLanguageTable;
            cmbLanguage.DisplayMember = "F_Description";
            cmbLanguage.ValueMember   = "F_CulName";
            cmbLanguage.SelectedValue = strCurCul;

            string strLangFile = strLangFilePath + strCurLangFile;

            if (!LocalizationRecourceManager.LoadLocalResource(strLangFile))
            {
                UIMessageDialog.ShowMessageDialog("Failed to Load Language Resource!", "OVR System Error", false, this.Style);
            }

            this.sqlConnection.ConnectionString = strConnectionString;
            this.lbServerName.Text = this.sqlConnection.DataSource;
            this.lbDbName.Text     = this.sqlConnection.Database;
            this.txRptPrtPath.Text = strPrtPath;

            UpdateDisciplineList(strDiscCode);

            Localization();
        }
Exemplo n.º 49
0
 public override bool ReadToDescendant(string name)
 {
     CheckAsync();
     return(coreReader.ReadToDescendant(name));
 }
Exemplo n.º 50
0
        public new void ReadXmlContent(System.Xml.XmlReader reader)
        {
            base.ReadXmlContent(reader);

            bool done = false;

            while (reader.MoveToContent() == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                case "readAccessMode":
                    READ_ACCESS_MODE.ReadXml(reader);
                    break;

                case "writeAccessMode":
                    WRITE_ACCESS_MODE.ReadXml(reader);
                    break;

                case "allowedValues":
                    if (reader.ReadToDescendant("allowedValue"))
                    {
                        List <WSValue> values = new List <WSValue>();
                        while (reader.MoveToContent() == XmlNodeType.Element)
                        {
                            if (!reader.IsEmptyElement)
                            {
                                string aName = reader.GetAttribute("name");
                                if (string.IsNullOrEmpty(aName))
                                {
                                    reader.Skip();
                                }
                                else
                                {
                                    WSValue value = new WSValue(aName);
                                    value.ReadXml(reader);
                                    values.Add(value);
                                }
                            }
                            reader.MoveToContent();
                            if (!reader.Read())
                            {
                                break;
                            }
                        }
                        ALLOWED_VALUES = values;
                    }
                    break;

                default:
                {
                    reader.Skip();
                    done = true;
                    break;
                }
                }
                reader.MoveToContent();
                if (done || !reader.Read())
                {
                    break;
                }
            }
        }
        /// <summary>
        /// Parses the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public override T Parse <T>(System.Xml.XmlReader reader)
        {
            IRssFeed ret = (IRssFeed) new RssFeed();

            reader.Read();

            // RDF versions of RSS don't have version tags.
            //double version = double.Parse(reader.GetAttribute("version"));

            reader.ReadToDescendant("channel");

            bool readContent = false;

            while (readContent || reader.Read())
            {
                readContent = false;
                if (reader.NodeType == XmlNodeType.Element)
                {
                    readContent = true;
                    switch (reader.Name)
                    {
                    case "title":
                        ret.Title = reader.ReadElementContentAsString();
                        break;

                    case "link":
                        ret.FeedUri = CachedPropertiesProvider.ConvertToUri(reader.ReadElementContentAsString());
                        break;

                    case "description":
                        ret.Description = reader.ReadElementContentAsString();
                        break;

                    case "language":
                        ret.Culture = CachedPropertiesProvider.ConvertToCultureInfo(reader.ReadElementContentAsString());
                        break;

                    case "copyright":
                        ret.Copyright = reader.ReadElementContentAsString();
                        break;

                    case "managingEditor":
                        ret.ManagingEditor = reader.ReadElementContentAsString();
                        break;

                    case "webMaster":
                        ret.WebMaster = reader.ReadElementContentAsString();
                        break;

                    case "pubDate":
                        ret.PublicationDate = CachedPropertiesProvider.ConvertToTzDateTime(reader.ReadElementContentAsString());
                        break;

                    case "lastBuildDate":
                        ret.LastChanged = CachedPropertiesProvider.ConvertToTzDateTime(reader.ReadElementContentAsString());
                        break;

                    case "category":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.Category = ConvertToIRssCategory(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    case "generator":
                        ret.Generator = reader.ReadElementContentAsString();
                        break;

                    case "docs":
                        ret.Doc = CachedPropertiesProvider.ConvertToUri(reader.ReadElementContentAsString());
                        break;

                    case "cloud":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.Cloud = ConvertToIRssCloud(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    case "ttl":
                        ret.TimeToLive = CachedPropertiesProvider.ConvertToInt(reader.ReadElementContentAsString());
                        break;

                    case "image":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.Image = ConvertToIRssImage(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    /*case "rating":
                     *  break;*/
                    case "textInput":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.TextInput = ConvertToIRssTextInput(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    case "skipHours":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.SkipHours = ConvertToSkipHourList(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    case "skipDays":
                        using (XmlReader subReader = reader.ReadSubtree())
                        {
                            ret.SkipDays = ConvertToDayOfWeekList(subReader);
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    case "item":
                        using (XmlReader itemReader = reader.ReadSubtree())
                        {
                            ret.Items.Add(ParseItem(itemReader));
                        }
                        if (reader.IsEmptyElement)
                        {
                            readContent = false;
                        }
                        break;

                    default:
                        UnhandledElement(ret, reader);
                        break;
                    }
                }
            }
            reader.Close();
            return((T)ret);
        }
Exemplo n.º 52
0
    public GameSaveDescriptor GetMostRecentGameSaveDescritor()
    {
        string gameSaveDirectory = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(gameSaveDirectory))
        {
            return(null);
        }
        if (!Directory.Exists(gameSaveDirectory))
        {
            return(null);
        }
        ISerializationService service = Services.GetService <ISerializationService>();

        if (service == null)
        {
            return(null);
        }
        List <string>   list     = null;
        IRuntimeService service2 = Services.GetService <IRuntimeService>();

        if (service2 != null)
        {
            Diagnostics.Assert(service2.Runtime != null);
            Diagnostics.Assert(service2.Runtime.RuntimeModules != null);
            list = (from runtimeModule in service2.Runtime.RuntimeModules
                    select runtimeModule.Name).ToList <string>();
        }
        DirectoryInfo   directoryInfo = new DirectoryInfo(gameSaveDirectory);
        List <FileInfo> list2         = new List <FileInfo>();

        list2.AddRange(directoryInfo.GetFiles("*.zip"));
        list2.AddRange(directoryInfo.GetFiles("*.sav"));
        FileInfo[] array = (from f in list2
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        GameSaveDescriptor gameSaveDescriptor = null;

        if (array != null)
        {
            foreach (FileInfo fileInfo in array)
            {
                Archive archive = null;
                try
                {
                    archive = Archive.Open(fileInfo.FullName, ArchiveMode.Open);
                    MemoryStream stream = null;
                    if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                    {
                        XmlReaderSettings settings = new XmlReaderSettings
                        {
                            CloseInput     = true,
                            IgnoreComments = true,
                            IgnoreProcessingInstructions = true,
                            IgnoreWhitespace             = true
                        };
                        using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                        {
                            if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                            {
                                XmlSerializer xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                                gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                                gameSaveDescriptor.SourceFileName = fileInfo.FullName;
                                if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                                {
                                    gameSaveDescriptor = null;
                                }
                                if (gameSaveDescriptor != null)
                                {
                                    if (gameSaveDescriptor.RuntimeModules == null)
                                    {
                                        if (service2 != null)
                                        {
                                            if (list.Count != 1 || !(list[0] == service2.VanillaModuleName))
                                            {
                                                gameSaveDescriptor = null;
                                            }
                                        }
                                        else
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                    else
                                    {
                                        List <string> list3 = list.Except(gameSaveDescriptor.RuntimeModules).ToList <string>();
                                        List <string> list4 = gameSaveDescriptor.RuntimeModules.Except(list).ToList <string>();
                                        if (list3.Count + list4.Count != 0)
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Diagnostics.LogWarning("Exception caught: " + ex.ToString());
                    gameSaveDescriptor = null;
                }
                finally
                {
                    if (archive != null)
                    {
                        archive.Close();
                    }
                }
                if (gameSaveDescriptor != null)
                {
                    break;
                }
            }
        }
        return(gameSaveDescriptor);
    }
Exemplo n.º 53
0
    public IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(bool withAutoSave)
    {
        string path = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer   serializer      = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        DirectoryInfo   directory       = new DirectoryInfo(path);
        List <FileInfo> compatibleFiles = new List <FileInfo>();

        compatibleFiles.AddRange(directory.GetFiles("*.zip"));
        compatibleFiles.AddRange(directory.GetFiles("*.sav"));
        FileInfo[] files = (from f in compatibleFiles
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;
        XmlReaderSettings  xmlReaderSettings  = new XmlReaderSettings
        {
            CloseInput     = true,
            IgnoreComments = true,
            IgnoreProcessingInstructions = true,
            IgnoreWhitespace             = true
        };

        for (int i = 0; i < files.Length; i++)
        {
            gameSaveDescriptor = null;
            string fileName = files[i].FullName;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Exception exception = ex;
                Diagnostics.LogWarning("Exception caught: " + exception.ToString());
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null && gameSaveDescriptor.Closed)
            {
                gameSaveDescriptor = null;
            }
            if (gameSaveDescriptor != null && (withAutoSave || !gameSaveDescriptor.Title.StartsWith(global::GameManager.AutoSaveFileName)))
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Exemplo n.º 54
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToFollowing(this.GetType().Name))
            {
                String s = reader.GetAttribute(Orientation.GetType().Name);
                m_orientation = (Orientation)(Enum.Parse(Orientation.GetType(), s));
                switch (m_orientation)
                {
                case Orientation.Horizontal:
                    if (reader.ReadToDescendant("Column"))
                    {
                        RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Height));
                        do
                        {
                            double      width  = double.Parse(reader.GetAttribute("Width"));
                            IDockLayout layout = null;
                            reader.ReadStartElement();
                            if (reader.LocalName == typeof(DockedWindow).Name)
                            {
                                DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree());
                                layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null;
                                reader.ReadEndElement();
                            }
                            else if (reader.LocalName == typeof(GridLayout).Name)
                            {
                                GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree());
                                layout = gridLayout.Layouts.Count > 0 ? gridLayout : null;
                                reader.ReadEndElement();
                            }
                            if (layout != null)
                            {
                                if (Children.Count > 0)
                                {
                                    ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0));
                                    Children.Add(NewGridSplitter(Orientation));
                                }
                                ColumnDefinitions.Add(NewColumnDefinition(new GridLength(width, GridUnitType.Star), m_minGridSize.Width));
                                m_children.Add(layout);
                                Children.Add((FrameworkElement)layout);
                            }
                        } while (reader.ReadToNextSibling("Column"));
                    }
                    break;

                case Orientation.Vertical:
                    if (reader.ReadToDescendant("Row"))
                    {
                        ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Width));
                        do
                        {
                            double      height = double.Parse(reader.GetAttribute("Height"));
                            IDockLayout layout = null;
                            reader.ReadStartElement();
                            if (reader.LocalName == typeof(DockedWindow).Name)
                            {
                                DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree());
                                layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null;
                                reader.ReadEndElement();
                            }
                            else if (reader.LocalName == typeof(GridLayout).Name)
                            {
                                GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree());
                                layout = gridLayout.Layouts.Count > 0 ? gridLayout : null;
                                reader.ReadEndElement();
                            }
                            if (layout != null)
                            {
                                if (Children.Count > 0)
                                {
                                    RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0));
                                    Children.Add(NewGridSplitter(Orientation));
                                }
                                RowDefinitions.Add(NewRowDefinition(new GridLength(height, GridUnitType.Star), m_minGridSize.Height));
                                m_children.Add(layout);
                                Children.Add((FrameworkElement)layout);
                            }
                        } while (reader.ReadToNextSibling("Row"));
                    }
                    break;
                }
                for (int i = 0; i < Children.Count; i++)
                {
                    Grid.SetColumn(Children[i], Orientation == Orientation.Horizontal ? i : 0);
                    Grid.SetRow(Children[i], Orientation == Orientation.Vertical ? i : 0);
                }
                reader.ReadEndElement();
            }
        }
Exemplo n.º 55
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));
            }
        }
Exemplo n.º 56
0
    public static IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer serializer = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        List <string> fileNames  = new List <string>();

        fileNames.AddRange(Directory.GetFiles(path, "*.zip"));
        fileNames.AddRange(Directory.GetFiles(path, "*.sav"));
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;

        foreach (string fileName in fileNames)
        {
            gameSaveDescriptor = null;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
                    {
                        IgnoreComments   = true,
                        IgnoreWhitespace = true,
                        CloseInput       = true
                    };
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch
            {
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null)
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Exemplo n.º 57
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.ReadToDescendant("WriteAttributeString") == false)
            {
                throw new MyException("Could not find the end of WriteAttributeString");
            }
            //Console.WriteLine("AFter 1 reader.NodeType, {0} name {1} depth {2}", reader.NodeType, reader.Name, reader.Depth);
            if (reader.HasAttributes)
            {
                int    attribCount = 0;
                string msg         = null;
                while (reader.MoveToNextAttribute())
                {
                    Trace.WriteLine(String.Format("attribute[{0}], localname=\"{1}\" value=\"{2}\" namespaceURI=\"{3}\"", attribCount, reader.LocalName, reader.Value, reader.NamespaceURI));
                    if (String.IsNullOrEmpty(reader.LocalName))
                    {
                        continue;
                    }
                    switch (reader.LocalName)
                    {
                    case "attributeName":
                        if (reader.Prefix == null || !reader.Prefix.Equals("abc"))
                        {
                            msg = String.Format("attributeName: reader.Name = {0}, reader.NamespaceURI = {1} reader.Value = {2} reader.Prefix = {3}", reader.Name, reader.NamespaceURI, reader.Value, reader.Prefix);
                            throw new MyException(msg);
                        }
                        break;

                    case "attributeName2":
                        break;

                    case "attributeName3":
                        if (reader.NamespaceURI == null || !reader.NamespaceURI.Equals("myNameSpace3"))
                        {
                            msg = String.Format("attributeName: reader.Name = {0}, reader.NamespaceURI = {1} reader.ReadAttributeValue() = {2} reader.Prefix = {3}", reader.Name, reader.NamespaceURI, reader.Value, reader.Prefix);
                            throw new MyException(msg);
                        }
                        break;

                    default:

                        if (reader.Value != null && reader.Value.Equals("myNameSpace3"))
                        {
                            // this is my namespace declaration, it is OK
                            break;
                        }
                        if (reader.LocalName != null && reader.LocalName.Equals("abc"))
                        {
                            // this is my namespace declaration, it is OK
                            break;
                        }
                        msg = String.Format("DEFAULT LocalName <{0}> \r\n reader.Name = <{1}>, \r\n reader.NamespaceURI = <{2}> \r\n reader.ReadAttributeValue() = {3}", reader.LocalName, reader.Name, reader.NamespaceURI, reader.Value);
                        throw new MyException(msg);
                    }
                    attribCount++;
                }
                //Console.WriteLine("attribCount = {0}", attribCount);
                if (attribCount != 5)
                {
                    throw new MyException(String.Format("XmlReader says this node {0} {1} has no elements  and I expect 4", reader.Name, reader.NodeType));
                }
            }
            else
            {
                throw new MyException(String.Format("XmlReader says this node has no elements {0} {1} and I expect 3", reader.Name, reader.NodeType));
            }
            reader.MoveToElement(); // back at WriteAttributes
        }