Beispiel #1
0
        /// <summary>
        /// Modify the properties of this object.
        /// </summary>
        /// <param name="xmlOut">The XML writer.</param>
        /// <param name="targetName">The name of the object to change.</param>
        /// <param name="newName">The new name of this object.</param>
        /// <param name="newDesc">The new description of this object.</param>
        public void SaveModified(WriteXML xmlOut, String targetName,
                                 String newName, String newDesc)
        {
            AdvanceObjectsCollection();

            while (this.xmlIn.ReadToTag())
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;
                if (type == Tag.Type.BEGIN)
                {
                    String name = this.xmlIn.LastTag.GetAttributeValue(
                        PersistReader.ATTRIBUTE_NAME);
                    if (name.Equals(targetName))
                    {
                        IDictionary <String, String> replace =
                            new Dictionary <String, String>();
                        replace.Add("name", newName);
                        replace.Add("description", newDesc);
                        CopyXML(xmlOut, replace);
                    }
                    else
                    {
                        CopyXML(xmlOut, null);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Copy an XML object, no need to know what it contains, just
        /// copy it.  This way we will not damage unknown objects during
        /// a merge.
        /// </summary>
        /// <param name="xmlOut">The XML writer.</param>
        /// <param name="replace"></param>
        private void CopyXML(WriteXML xmlOut,
                             IDictionary <String, String> replace)
        {
            StringBuilder text  = new StringBuilder();
            int           depth = 0;
            int           ch;

            CopyAttributes(xmlOut, replace);
            String contain = this.xmlIn.LastTag.Name;

            xmlOut.BeginTag(contain);

            while ((ch = this.xmlIn.Read()) != -1)
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;

                if (ch == 0)
                {
                    if (type == Tag.Type.BEGIN)
                    {
                        if (text.Length > 0)
                        {
                            xmlOut.AddText(text.ToString());
                            text.Length = 0;
                        }

                        CopyAttributes(xmlOut, null);
                        xmlOut.BeginTag(this.xmlIn.LastTag.Name);
                        depth++;
                    }
                    else if (type == Tag.Type.END)
                    {
                        if (text.Length > 0)
                        {
                            xmlOut.AddText(text.ToString());
                            text.Length = 0;
                        }

                        if (depth == 0)
                        {
                            break;
                        }
                        else
                        {
                            xmlOut.EndTag(xmlIn.LastTag.Name);
                        }
                        depth--;
                    }
                }
                else
                {
                    text.Append((char)ch);
                }
            }

            xmlOut.EndTag(contain);
        }
Beispiel #3
0
 /// <summary>
 /// Read until the next tag of the specified name.
 /// </summary>
 /// <param name="name">The name searched for.</param>
 /// <returns>True if the tag was found.</returns>
 public bool ReadNextTag(String name)
 {
     while (this.xmlIn.ReadToTag())
     {
         Tag.Type type = this.xmlIn.LastTag.TagType;
         if (type == Tag.Type.BEGIN)
         {
             if (this.xmlIn.LastTag.Name.Equals(name))
             {
                 return(true);
             }
             else
             {
                 SkipObject();
             }
         }
     }
     return(false);
 }
Beispiel #4
0
 /// <summary>
 /// Advance to the specified tag.
 /// </summary>
 /// <param name="tag">The tag to advance to.</param>
 /// <returns>True if the tag was found.</returns>
 private bool AdvanceToTag(String tag)
 {
     while (this.xmlIn.ReadToTag())
     {
         Tag.Type type = this.xmlIn.LastTag.TagType;
         if (type == Tag.Type.BEGIN)
         {
             if (this.xmlIn.LastTag.Name.Equals(tag))
             {
                 return(true);
             }
             else
             {
                 SkipObject();
             }
         }
     }
     return(false);
 }
Beispiel #5
0
        /// <summary>
        /// Save all objects to the specified steam, skip the one specified by the
        /// skip parameter. Do not attempt to understand the structure, just copy.
        /// </summary>
        /// <param name="xmlOut">The XML writer to save the objects to.</param>
        /// <param name="skip">The object to skip.</param>
        public void SaveTo(WriteXML xmlOut, String skip)
        {
            AdvanceObjectsCollection();

            while (this.xmlIn.ReadToTag())
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;
                if (type == Tag.Type.BEGIN)
                {
                    String name = this.xmlIn.LastTag.GetAttributeValue(
                        PersistReader.ATTRIBUTE_NAME);
                    if (name.Equals(skip))
                    {
                        SkipObject();
                    }
                    else
                    {
                        CopyXML(xmlOut, null);
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Once you are in the objects collection, advance to a specific object.
        /// </summary>
        /// <param name="name"></param>
        /// <returns>The beginning tag of that object if its found, null otherwise.</returns>
        private bool AdvanceObjects(String name)
        {
            while (this.xmlIn.ReadToTag())
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;
                if (type == Tag.Type.BEGIN)
                {
                    String elementName = this.xmlIn.LastTag.GetAttributeValue(
                        "name");

                    if ((elementName != null) && elementName.Equals(name))
                    {
                        return(true);
                    }
                    else
                    {
                        SkipObject();
                    }
                }
            }
            return(false);
        }
Beispiel #7
0
 // データから作成
 public Element(Tag begin, string data, ref int point)
 {
     mName      = begin.get_name();
     mAttribute = begin.get_attribute();
     // 次のタグを用意
     for (; point < data.Length; ++point)
     {
         // 次のタグ
         if (data[point] == '<')
         {
             ++point;
             // コンストラクタでタグ読み込み
             Tag      tag = new Tag(data, ref point);
             Tag.Type t   = tag.get_type();
             // 開始タグ
             if (t == Tag.Type.BEGIN)
             {
                 // 子を1つ増やす
                 if (mChildren == null)
                 {
                     mChildren = new Element[1];
                 }
                 else
                 {
                     Array.Resize(ref mChildren, mChildren.Length + 1);
                 }
                 // 再帰構造
                 // 末尾に追加
                 mChildren[mChildren.Length - 1] = new Element(tag, data, ref point);
             }
             // 終了タグ
             else if (t == Tag.Type.END)
             {
                 break;  // タグが終わったらこのエレメントは読み込み完了
             }
         }
     }
 }
Beispiel #8
0
        /// <summary>
        /// Advance to the objects collection.
        /// </summary>
        public void AdvanceObjectsCollection()
        {
            while (this.xmlIn.ReadToTag())
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;
                if ((type == Tag.Type.BEGIN) &&
                    this.xmlIn.LastTag.Name.Equals(
                        PersistReader.TAG_OBJECTS))
                {
                    return;
                }
            }

            String str = "Can't find objects collection, invalid file.";

#if logging
            if (this.logger.IsErrorEnabled)
            {
                this.logger.Error(str);
            }
#endif
            throw new PersistError(str);
        }
Beispiel #9
0
        /// <summary>
        /// Skip the current object.
        /// </summary>
        private void SkipObject()
        {
            int depth = 0;

            while (this.xmlIn.ReadToTag())
            {
                Tag.Type type = this.xmlIn.LastTag.TagType;

                switch (type)
                {
                case Tag.Type.END:
                    if (depth == 0)
                    {
                        return;
                    }
                    depth--;
                    break;

                case Tag.Type.BEGIN:
                    depth++;
                    break;
                }
            }
        }
 public static Color Color(this Tag.Type tag)
 {
     return(colors[(int)tag]);
 }