Exemple #1
0
        void IFlickrParsable.Load(System.Xml.XmlReader reader)
        {

            if (reader.LocalName != "count" && !reader.ReadToFollowing("count"))
            {
                UtilityMethods.CheckParsingException(reader);
                return;
            }

            Count = reader.ReadElementContentAsInt();

            if( reader.LocalName != "prevphotos" ) reader.ReadToFollowing("prevphotos");
            reader.ReadToDescendant("photo");
            while (reader.LocalName == "photo")
            {
                FavoriteContextPhoto photo = new FavoriteContextPhoto();
                ((IFlickrParsable)photo).Load(reader);
                PreviousPhotos.Add(photo);
            }

            if (reader.LocalName != "nextphotos") reader.ReadToFollowing("nextphotos");
            reader.ReadToDescendant("photo");
            while (reader.LocalName == "photo")
            {
                FavoriteContextPhoto photo = new FavoriteContextPhoto();
                ((IFlickrParsable)photo).Load(reader);
                NextPhotos.Add(photo);
            }
        }
 public static float[] readFloatArray(System.Xml.XmlReader reader)
 {
     List<float> result = new List<float>();
     reader.ReadToDescendant("value");
     while (reader.Name.Equals("value"))
         result.Add(reader.ReadElementContentAsFloat());
     reader.ReadEndElement();
     return result.ToArray();
 }
        /// <summary>
        /// Generates a collection from its XML representation.
        /// </summary>
        /// <param name="reader">System.Xml.XmlReader</param>
        public void ReadXml(System.Xml.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"));
            }
              }
        }
Exemple #4
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.LocalName != "action" && !reader.ReadToDescendant("action"))
                throw new InvalidDataException();

            XmlHelper.ParseXml(reader, new XmlParseSet
            {
                {"name", () => this.Name = reader.ReadString()},
                {"argumentList", this.Arguments, "argument", () => new UpnpArgument()}
            });
        }
 public static Color readColor(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("IsKnownColor");
     bool isKnownColor = reader.ReadElementContentAsBoolean();
     string colorName = reader.ReadElementContentAsString();
     reader.ReadEndElement();
     if (isKnownColor)
         return Color.FromName(colorName);
     else
         return Color.FromArgb(int.Parse(colorName, System.Globalization.NumberStyles.HexNumber));
 }
 public static Font readFont(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("FontFamily");
     string fontFamily = reader.ReadElementContentAsString();
     float size = reader.ReadElementContentAsFloat();
     FontStyle style = FontStyle.Regular;
     // the style (italic, bold, etc...)
     if (Map.DataVersionOfTheFileLoaded >= 6)
         style = (FontStyle)Enum.Parse(typeof(FontStyle), reader.ReadElementContentAsString());
     // end of Font
     reader.ReadEndElement();
     return new Font(fontFamily, size, style);
 }
        void IFlickrParsable.Load(System.Xml.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");
        }
Exemple #8
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.LocalName != "action" && !reader.ReadToDescendant("action"))
                throw new InvalidDataException();

            var dict = new Dictionary<string, Action>()
            {
                {"name", () => this.Name = reader.ReadString()},
                {"argumentList", () => XmlHelper.ParseXmlCollection(reader, this.Arguments, "argument", () => new UpnpArgument())}
            };

            XmlHelper.ParseXml(reader, dict);
        }
Exemple #9
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.LocalName != "stateVariable" && !reader.ReadToDescendant("stateVariable"))
                throw new InvalidDataException();

            if (reader.HasAttributes)
                this.SendEvents = ((reader.GetAttribute("sendEvents") ?? "no") == "yes");

            XmlHelper.ParseXml(reader, new XmlParseSet
            {
                {"name", () => this.Name = reader.ReadString()},
                {"dataType", () => this.DataType = reader.ReadString()}
            });
        }
Exemple #10
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            if (reader.LocalName != "argument" && !reader.ReadToDescendant("argument"))
                throw new InvalidDataException();

            var dict = new Dictionary<string, Action>()
            {
                {"name", () => this.Name = reader.ReadString()},
                {"direction", () => this.Direction = reader.ReadString()},
                {"relatedStateVariable", () => this.RelatedStateVariable = reader.ReadString()}
            };

            XmlHelper.ParseXml(reader, dict);
        }
        public override void ReadXML(System.Xml.XmlReader input)
        {
            input.ReadToDescendant("min");
            var s = input.ReadString().Split(new char[] { ',' });
            if (s.Length != 3) throw new FormatException("Bounding box vector value formatted incorrectly.");
            this.MinX = float.Parse(s[0].Trim());
            this.MinY = float.Parse(s[1].Trim());
            this.MinZ = float.Parse(s[2].Trim());

            input.ReadToNextSibling("max");
            s = input.ReadString().Split(new char[] { ',' });
            if (s.Length != 3) throw new FormatException("Bounding box vector value formatted incorrectly.");
            this.MaxX = float.Parse(s[0].Trim());
            this.MaxY = float.Parse(s[1].Trim());
            this.MaxZ = float.Parse(s[2].Trim());
        }
Exemple #12
0
        public void Read(out string id, out Domain domain, out string attribName, out Type attribType, out object defaultVal, System.Xml.XmlReader reader)
        {
            id = null;
            domain = Domain.all;
            attribName = null;
            attribType = null;
            defaultVal = null;

            reader.MoveToAttribute("id");
            id = reader["id"];

            reader.MoveToAttribute("for");
            domain = (Domain)Enum.Parse(typeof(Domain), reader["for"]);

            reader.MoveToAttribute("attr.name");
            attribName = reader["attr.name"];

            reader.MoveToAttribute("attr.type");
            attribType = GraphMLConvert.ToType(reader["attr.type"]);

            reader.MoveToElement();

            // if there is a default value element, read it and convet
            if (reader.ReadToDescendant("default"))
            {
                string defaultValStr = null;
                ReadDefault(out defaultValStr, reader);
                defaultVal = ConvertDefaultValStr(defaultValStr, attribType);
                if (!reader.IsStartElement() && reader.Name=="default")
                        reader.Read();  // read the end tag element of default
            }
            else
            {
                // default value is system default
                defaultVal = GetDefault( attribType);
            }
        }
Exemple #13
0
        internal void UnpersistPipes(IPipes pipes, System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "Pipes"

            if (reader.ReadToDescendant("Pipe"))
            {
                UnpersistPipe(pipes, reader);
                while (reader.ReadToNextSibling("Pipe"))
                {
                    UnpersistPipe(pipes, reader);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }
        }
Exemple #14
0
        public void ReadXml(System.Xml.XmlReader reader)
        {
            // reset the counter of modifications because we just load the map (no modification done)
            mNumberOfModificationSinceLastSave = 0;
            // version
            readVersionNumber(reader);
            // check if the BlueBrick program is not too old, that
            // means the user try to load a file generated with
            /// a earlier version of BlueBrick
            if (mDataVersionOfTheFileLoaded > CURRENT_DATA_VERSION)
            {
                MessageBox.Show(null, Properties.Resources.ErrorMsgProgramObsolete,
                    Properties.Resources.ErrorMsgTitleError, MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }
            // get the number of layer for the progressbar
            if (mDataVersionOfTheFileLoaded >= 3)
            {
                int nbItems = reader.ReadElementContentAsInt();
                // init the progress bar with the real number of layer items (+1 for the header +1 for the link rebuilding)
                MainForm.Instance.resetProgressBar(nbItems + 2);
            }
            // check is there is a background color
            if (reader.Name.Equals("BackgroundColor"))
                mBackgroundColor = XmlReadWrite.readColor(reader);
            // data of the map
            mAuthor = reader.ReadElementContentAsString();
            mLUG = reader.ReadElementContentAsString();
            mShow = reader.ReadElementContentAsString();
            reader.ReadToDescendant("Day");
            int day = reader.ReadElementContentAsInt();
            int month = reader.ReadElementContentAsInt();
            int year = reader.ReadElementContentAsInt();
            mDate = new DateTime(year, month, day);
            // read the comment if the version is greater than 0
            if (mDataVersionOfTheFileLoaded > 0)
            {
                reader.ReadToFollowing("Comment");
                mComment = reader.ReadElementContentAsString().Replace("\n", Environment.NewLine);
            }
            else
            {
                reader.ReadToFollowing("CurrentSnapGridSize");
            }
            if (mDataVersionOfTheFileLoaded < 2)
            {
                // skip the static data of layers that before we were saving
                // but now I think it is stupid, since we don't have action to change that
                // and we don't have way to update the enabled of the buttons
                reader.ReadElementContentAsFloat(); // CurrentSnapGridSize
                reader.ReadElementContentAsBoolean(); // SnapGridEnabled
                reader.ReadElementContentAsFloat(); // CurrentRotationStep
            }

            // read the export data if the version is 5 or higher
            if (mDataVersionOfTheFileLoaded > 4)
            {
                reader.ReadToDescendant("ExportPath");
                // read the relative export path and store it temporarly in the absolute path variable
                // the absolute path will be computed after the xml serialization is finished
                mExportAbsoluteFileName = reader.ReadElementContentAsString();
                // read the other export info
                mExportFileTypeIndex = reader.ReadElementContentAsInt();
                mExportArea = XmlReadWrite.readRectangleF(reader);
                mExportScale = reader.ReadElementContentAsFloat();
                // read even more info from version 8
                if (mDataVersionOfTheFileLoaded > 7)
                {
                    mExportWatermark = XmlReadWrite.readBoolean(reader);
                    mExportBrickHull = XmlReadWrite.readBoolean(reader);
                    mExportElectricCircuit = XmlReadWrite.readBoolean(reader);
                    mExportConnectionPoints = XmlReadWrite.readBoolean(reader);
                }
                reader.ReadEndElement();
            }

            // selected layer
            int selectedLayerIndex = reader.ReadElementContentAsInt();
            // step the progress bar after the read of the header
            MainForm.Instance.stepProgressBar();

            // layers
            // first clear the hashtable that contains all the bricks
            Map.sHashtableForRulerAttachementRebuilding.Clear();
            // then load all the layers
            bool layerFound = reader.ReadToDescendant("Layer");
            while (layerFound)
            {
                // get the 'type' attribute of the layer
                reader.ReadAttributeValue();
                string layerType = reader.GetAttribute(0);

                // instantiate the right layer according to the type
                Layer layer = null;
                if (layerType.Equals("grid"))
                    layer = new LayerGrid();
                else if (layerType.Equals("brick"))
                    layer = new LayerBrick();
                else if (layerType.Equals("text"))
                    layer = new LayerText();
                else if (layerType.Equals("area"))
                    layer = new LayerArea();
                else if (layerType.Equals("ruler"))
                    layer = new LayerRuler();

                // read and add the new layer
                if (layer != null)
                {
                    layer.ReadXml(reader);
                    mLayers.Add(layer);
                }

                // read the next layer
                layerFound = reader.ReadToNextSibling("Layer");
            }
            reader.ReadEndElement(); // end of Layers

            // once we have finished to read all the layers thus all the items, we need to recreate all the links they have between them
            foreach (Layer layer in mLayers)
                layer.recreateLinksAfterLoading();
            // then clear again the hash table to free the memory
            Map.sHashtableForRulerAttachementRebuilding.Clear();

            // step the progress bar after the rebuilding of links
            MainForm.Instance.stepProgressBar();

            // if the selected index is valid, reset the selected layer
            // use the setter in order to enable the toolbar buttons
            if ((selectedLayerIndex >= 0) && (selectedLayerIndex < mLayers.Count))
                SelectedLayer = mLayers[selectedLayerIndex];
            else
                SelectedLayer = null;

            // DO NOT READ YET THE BRICK URL LIST, BECAUSE THE BRICK DOWNLOAD FEATURE IS NOT READY
            if (false)
            {
                // read the url of all the parts for version 5 or later
                if ((mDataVersionOfTheFileLoaded > 5) && !reader.IsEmptyElement)
                {
                    bool urlFound = reader.ReadToDescendant("BrickUrl");
                    while (urlFound)
                    {
                        // read the next url
                        urlFound = reader.ReadToNextSibling("BrickUrl");
                    }
                    reader.ReadEndElement();
                }
            }

            // construct the watermark
            computeGeneralInfoWatermark();
            // for old version, make disapear the progress bar, since it was just an estimation
            MainForm.Instance.finishProgressBar();
        }
Exemple #15
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();
                }
            }
        }
Exemple #16
0
        internal void UnpersistCore(IWorkSpace workSpace, System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "WorkSpace"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];

            reader.MoveToAttribute("mode");
            string modeStr = reader["mode"];

            reader.MoveToElement();

            workSpace.Id = new Guid(idStr);
            workSpace.ExecMode = (ExecutionModes)Enum.Parse(typeof(ExecutionModes), modeStr);

            // -------------------------

            int startDepth = reader.Depth;

            // in expected order
            if (reader.ReadToDescendant("Settings"))
            {
                UnpersistSettingsMgr(workSpace.SettingsMgr, reader);

                if (reader.ReadToNextSibling("Options"))
                {
                    UnpersistOptionsMgr(workSpace.OptionsMgr, reader);
                }
                if (reader.ReadToNextSibling("Variables"))
                {
                    UnpersistVarMgr(workSpace.VarMgr, reader);
                }
                if (reader.ReadToNextSibling("Elements"))
                {
                    UnpersistElements(workSpace.ElementsMgr, reader);
                }
                if (reader.ReadToNextSibling("Pipes"))
                {
                    UnpersistPipes(workSpace.PipesMgr, reader);
                }
                if (reader.ReadToNextSibling("WorkSpaceProperties"))
                {
                    UnpersistProperties(workSpace.WSProperties, reader);
                }
                // read up to the end "WorkSpace" tag
                if (reader.Depth > startDepth)
                {
                    reader.Read();
                }
            }
        }
Exemple #17
0
        public virtual void ReadXml(System.Xml.XmlReader reader)
        {
            // The budget is already cleared cause a new instance of Budget is created for serialization

            // set the existing flag to false before reading. If the reading goes well (no exception thrown) we will set it to true
            mIsExisting = false;

            // version
            reader.ReadToDescendant("Version");
            mDataVersionOfTheFileLoaded = reader.ReadElementContentAsInt();

            // read the parts
            bool partFound = reader.ReadToDescendant("Part");
            while (partFound)
            {
                // read the part name and value (get the new value if it was renamed)
                string partId = BrickLibrary.Instance.getActualPartNumber(reader.GetAttribute("id"));
                int budget = reader.ReadElementContentAsInt();
                // and set the budget
                mBudget.Add(partId, budget);
                // read the next part
                partFound = reader.Name.Equals("Part");
            }
            // read the PartList tag, to finish the list of parts
            reader.Read();

            // after that the reading went well (no exception thrown)
            // set the flag to tell that the budget now exists
            mIsExisting = true;
            // reset the was modified flag cause we just load a new budget
            this.WasModified = false;
        }
 public static RectangleF readRectangleF(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("X");
     float x = reader.ReadElementContentAsFloat();
     float y = reader.ReadElementContentAsFloat();
     float width = reader.ReadElementContentAsFloat();
     float height = reader.ReadElementContentAsFloat();
     reader.ReadEndElement();
     return (new RectangleF(x, y, width, height));
 }
Exemple #19
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();
     }
 }
        internal void UnpersistOutPortMgr(System.Xml.XmlReader reader)
        {
            // Assumes reader has started the read of element "OutputPortMgr"

            if (reader.ReadToDescendant("OutputPort"))
            {
                Guid portId;
                int portIndex = -1;
                UnpersistOutPort(reader, out portId, out portIndex);
                while (reader.ReadToNextSibling("OutputPort"))
                {
                    UnpersistOutPort(reader, out portId, out portIndex);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }

            // no InputPortMgr id to add to the TicketBuilder
        }
        internal void UnpersistOutPort(System.Xml.XmlReader reader, out Guid portId, out int portIndex)
        {
            // Assumes reader has started the read of element "OutputPort"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];
            reader.MoveToAttribute("index");
            string indexStr = reader["index"];
            reader.MoveToElement();

            portId = new Guid(idStr);
            portIndex = XmlConvert.ToInt32(indexStr);

            if (reader.ReadToDescendant("OutboundPipe"))
            {
                Guid pipeId;
                UnpersistOutboundPipe(reader, out pipeId);
                while (reader.ReadToNextSibling("OutboundPipe"))
                {
                    UnpersistOutboundPipe(reader, out pipeId);
                }
            }
            if (reader.IsStartElement() && !reader.IsEmptyElement)
            {
                reader.Read();
            }

            TicketBuilder.AddOutputPortId(portId, portIndex);
        }
        internal void UnpersistCore(System.Xml.XmlReader reader, out IElement element)
        {
            element = null;

            // Assumes reader has started the read of element "Element"
            reader.MoveToAttribute("id");
            string idStr = reader["id"];

            reader.MoveToAttribute("typeId");
            string typeIdStr = reader["typeId"];

            reader.MoveToAttribute("typeName");
            string typeName = reader["typeName"];

            reader.MoveToElement();

            TicketBuilder.ElementId = new Guid(idStr);
            TicketBuilder.TypeId = new Guid(typeIdStr);

            // -------------------------

            int startDepth = reader.Depth;

            // in expected order
            if (reader.ReadToDescendant("Fx"))  // Fx node must be there, it has an id to read in
            {
                UnpersistFx(reader);

                if (reader.ReadToNextSibling("InputPortMgr"))
                {
                    UnpersistInPortMgr(reader);
                }
                if (reader.ReadToNextSibling("OutputPortMgr"))
                {
                    UnpersistOutPortMgr(reader);
                }

                IElementTicket ticket = TicketBuilder.Ticket;
                element = ReConstitute(ticket);

                if (reader.ReadToNextSibling("Settings"))
                {
                    UnpersistSettingsMgr(element, reader);
                }
                // Options are not currently being used or persisted
                //if (reader.ReadToNextSibling("Options"))
                //{
                //    UnpersistOptionsMgr(reader);
                //}
                if (reader.ReadToNextSibling("ParamMgr"))
                {
                    UnpersistParamMgr(element, reader);
                }

                // read up to the end "Element" tag
                if (reader.Depth > startDepth)
                {
                    reader.Read();
                }
            }
        }
            public override void ReadXml(System.Xml.XmlReader reader)
            {
                // read the id of the brick, then add this brick in the hashtable
                if (Map.DataVersionOfTheFileLoaded >= 7)
                {
                    int brickId = int.Parse(reader.GetAttribute(0));
                    Id = brickId.ToString();
                    Map.sHashtableForRulerAttachementRebuilding.Add(brickId, this);
                }
                // read the base class
                base.ReadXml(reader);
                // avoid using the accessor to reduce the number of call of updateBitmap
                mPartNumber = BrickLibrary.Instance.getActualPartNumber(reader.ReadElementContentAsString().ToUpperInvariant());
                // but then update its electric list
                mElectricCircuitIndexList = BrickLibrary.Instance.getElectricCircuitList(mPartNumber);
                mOrientation = reader.ReadElementContentAsFloat();
                mActiveConnectionPointIndex = reader.ReadElementContentAsInt();
                // the altitude
                if (Map.DataVersionOfTheFileLoaded >= 3)
                    mAltitude = reader.ReadElementContentAsFloat();
                // update the bitmap
                updateImage();
                updateSnapMargin();
                // read the connexion points if any
                reader.ReadAttributeValue();
                int count = int.Parse(reader.GetAttribute(0));

                // check the number of connection is the same in the Brick library and in the loading file.
                // They can be different if the file was saved with an old part library and then one part
                // was updated to add or remove connection. So there is 3 different cases:
                // - if they are the same: no problems.
                // - if there is more connections in the part lib than in the file: we reserve enough space in the list,
                // based on the library value, and then we will add empty connections instances to fullfill the list
                // after finishing reading the connection tag.
                // - if there is more parts in the file than in the list, we need to discard some connection,
                // so we add a check in the parsing to create the last connections as default one (of type brick).
                // This will ensure that the link will be broken (because all connections or type BRICK are
                // broken after the loading of the file is finished) and then the GC will destroy these connections.
                // And of course the list is reserved based on the library value.

                // So first, we ask the number of connection to the part lib then allocate
                // the list of connection based on the number set in the library and not the number
                // read in the file, because finally the number of connection must be like the part lib says
                int connectionCountInBrickLibrary = BrickLibrary.Instance.getConnectionCount(mPartNumber);
                if (connectionCountInBrickLibrary > 0)
                    mConnectionPoints = new List<ConnectionPoint>(connectionCountInBrickLibrary);

                // now check if we need to parse some connection in the file
                if (count > 0)
                {
                    // declare a counter for the connections
                    int connexionIndex = 0;
                    bool connexionFound = reader.ReadToDescendant("Connexion");
                    while (connexionFound)
                    {
                        // a boolean saying if the current connection is valid or will be destroyed later
                        // because it is over the number indicated by the part library
                        // be careful mConnectionPoints can be null, so use the int var instead
                        bool isConnectionValid = (connexionIndex < connectionCountInBrickLibrary);

                        // read the id (hashcode key) of the connexion
                        reader.ReadAttributeValue();
                        String id = reader.GetAttribute(0);
                        int hashCode = int.Parse(id.Substring(1));

                        // look in the hastable if this connexion alread exists, else create it
                        ConnectionPoint connexion = ConnectionPoint.sHashtableForLinkRebuilding[hashCode] as ConnectionPoint;
                        if (connexion == null)
                        {
                            // instanciate a ConnectionPoint, and add it in the hash table
                            if (isConnectionValid)
                                connexion = new ConnectionPoint(this, connexionIndex);
                            else
                                connexion = new ConnectionPoint();
                            ConnectionPoint.sHashtableForLinkRebuilding.Add(hashCode, connexion);
                        }
                        else
                        {
                            // set the connexion type, if not set during the above creation
                            if (isConnectionValid)
                                connexion.Type = BrickLibrary.Instance.getConnexionType(this.PartNumber, connexionIndex);
                        }

                        //read the connexion data and add it in the Connection list
                        connexion.mMyBrick = this;
                        connexion.ReadXml(reader);

                        // during the reading of the connection list in the file, we check if
                        // we didn't reached the limit of the part library. If there is more connection
                        // in the file than in the part lib, we continue to read the connections,
                        // but we don't add them in the connection list.
                        if (isConnectionValid)
                            mConnectionPoints.Add(connexion);

                        // increment the connexion index
                        connexionIndex++;

                        // read the next brick
                        connexionFound = reader.ReadToNextSibling("Connexion");
                    }
                    reader.ReadEndElement();

                    // check if we read all the connections in the file, if not we have to instanciate
                    // empty connection to fullfill the list
                    if (mConnectionPoints != null)
                        for (int i = mConnectionPoints.Count; i < mConnectionPoints.Capacity; ++i)
                        {
                            ConnectionPoint connexion = new ConnectionPoint(this, i);
                            mConnectionPoints.Add(connexion);
                            // we don't need to add this connection in the hastable since we know this
                            // connection doesn't exist in the file, so there is no link attached to it
                        }

                    // update the connexion position which is not stored in the bbm file
                    // in file version before 3 it was stored, but I removed it because the connexion
                    // point can move in different part libraries
                    updateConnectionPosition();
                }
                else
                {
                    reader.Read();
                }
                // read the end element of the brick
                reader.ReadEndElement();
            }
 public static Point readPoint(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("X");
     int x = reader.ReadElementContentAsInt();
     int y = reader.ReadElementContentAsInt();
     reader.ReadEndElement();
     return new Point(x, y);
 }
	/// <summary>
	/// Loads the inventory from XML.
	/// </summary>
	/// <param name="reader">Reader.</param>
	public void LoadInventory(System.Xml.XmlReader reader) {
		int itemCount = 0;
		reader.ReadToFollowing ("Inventory");
		reader.ReadToDescendant ("Item");
		do {
			string id = reader.GetAttribute ("ID");
			inventory [itemCount] = database [int.Parse (id)].Clone ();
			reader.ReadToDescendant ("Quantity");
			inventory [itemCount].stackSize = reader.ReadElementContentAsInt();
			Debug.Log ("Just parsed " + inventory [itemCount]);
			itemCount++;
			reader.ReadEndElement();
		} while(reader.ReadToNextSibling("Item"));
		reader.ReadEndElement ();
	}
 public static PointF readPointF(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("X");
     float x = reader.ReadElementContentAsFloat();
     float y = reader.ReadElementContentAsFloat();
     reader.ReadEndElement();
     return new PointF(x, y);
 }
Exemple #27
0
 /// <summary>
 /// Generate object from its XML representation</summary>
 /// <param name="reader">XmlReader stream from which object is deserialized</param>
 public void ReadXml(System.Xml.XmlReader reader)
 {
     if (reader.ReadToFollowing(this.GetType().Name))
     {
         if (reader.ReadToDescendant("Content"))
         {
             do
             {
                 String ucid = reader.GetAttribute("UCID");
                 DockContent content = Root.GetContent(ucid);
                 if (content != null)
                 {
                     AddContent(content);
                 }
             } while (reader.ReadToNextSibling("Content"));
         }
         reader.Read();
     }
 }
            public void ReadXml(System.Xml.XmlReader reader)
            {
                reader.MoveToContent();

                int row = 0;
                if (reader.IsStartElement("KeyButtonCollection") || reader.ReadToDescendant("KeyButtonCollection"))
                {
                    int rows = Convert.ToInt32(reader.GetAttribute("rows"));
                    _keys = new KeyButton[rows][];

                    if (reader.ReadToDescendant("KeyButtonRow"))
                    {
                        do
                        {
                            int col = 0;
                            int cols = Convert.ToInt32(reader.GetAttribute("cols"));
                            _keys[row] = new KeyButton[cols];

                            if (reader.ReadToDescendant("KeyButton"))
                            {
                                do
                                {
                                    _keys[row][col] = new KeyButton();
                                    _keys[row][col].ReadXml(reader);
                                    col++;
                                } while (reader.ReadToNextSibling("KeyButton"));
                            }
                            row++;
                        } while (reader.ReadToNextSibling("KeyButtonRow"));
                    }
                }
            }
 public void ReadXml(System.Xml.XmlReader reader)
 {
     // read the position of the connexion (for file version under 4)
     if (Map.DataVersionOfTheFileLoaded <= 3)
         mPositionInStudWorldCoord = XmlReadWrite.readPointF(reader);
     else
         reader.ReadToDescendant("LinkedTo");
     // check if we have a link
     if (reader.IsEmptyElement)
     {
         mConnectionLink = null;
         reader.Read();
     }
     else
     {
         var linkString = reader.ReadElementContentAsString();
         // remove character 'c' preceding the link id
         int hashCodeOfTheLink = int.Parse(linkString.Substring(1));
         // look in the hastable if this connexion alread exists, else create it
         mConnectionLink = ConnectionPoint.sHashtableForLinkRebuilding[hashCodeOfTheLink] as ConnectionPoint;
         if (mConnectionLink == null)
         {
             // instanciate a ConnectionPoint, and add it in the hash table
             mConnectionLink = new ConnectionPoint();
             ConnectionPoint.sHashtableForLinkRebuilding.Add(hashCodeOfTheLink, mConnectionLink);
         }
     }
 }
Exemple #30
0
 public void readVersionNumber(System.Xml.XmlReader reader)
 {
     reader.ReadToDescendant("Version");
     mDataVersionOfTheFileLoaded = reader.ReadElementContentAsInt();
 }