Beispiel #1
0
        public void ReadXml(XmlReader r, PointF scale, TimestampMapper timestampMapper, Metadata metadata)
        {
            Clear();

            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                switch (r.Name)
                {
                case "DrawingStyle":
                    style = new DrawingStyle(r);
                    BindStyle();
                    break;

                case "AutoNumber":
                    AbstractMultiDrawingItem item = MultiDrawingItemSerializer.Deserialize(r, scale, timestampMapper, metadata);
                    AutoNumber number             = item as AutoNumber;
                    if (number != null)
                    {
                        metadata.AddMultidrawingItem(this, number);
                    }
                    break;

                default:
                    string unparsed = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed);
                    break;
                }
            }

            r.ReadEndElement();
        }
        public static AbstractMultiDrawingItem DeserializeMemento(string data, Metadata metadata)
        {
            AbstractMultiDrawingItem item = null;

            PointF identityScale = new PointF(1, 1);

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;
            settings.CloseInput = true;

            using (XmlReader r = XmlReader.Create(new StringReader(data), settings))
            {
                r.MoveToContent();

                if (!(r.Name == "DrawingMemento"))
                {
                    return(null);
                }

                r.ReadStartElement();

                item = Deserialize(r, identityScale, TimeHelper.IdentityTimestampMapper, metadata);

                if (item is ITrackable)
                {
                    metadata.TrackabilityManager.ReadTracker(r, identityScale, TimeHelper.IdentityTimestampMapper);
                    metadata.TrackabilityManager.Assign(item as ITrackable);
                }
            }

            return(item);
        }
        public void ReadXml(XmlReader r, PointF scale, TimestampMapper timestampMapper, Metadata metadata)
        {
            Clear();

            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                if (r.Name == "Spotlight")
                {
                    AbstractMultiDrawingItem item = MultiDrawingItemSerializer.Deserialize(r, scale, timestampMapper, metadata);
                    Spotlight spotlight           = item as Spotlight;
                    if (spotlight != null)
                    {
                        metadata.AddMultidrawingItem(this, spotlight);
                    }
                }
                else
                {
                    string unparsed = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed);
                }
            }

            r.ReadEndElement();
            initializing = false;
        }
Beispiel #4
0
        /// <summary>
        /// Adds a new item to a multi drawing.
        /// </summary>
        public void AddMultidrawingItem(AbstractMultiDrawing multidrawing, AbstractMultiDrawingItem item)
        {
            multidrawing.Add(item);
            SelectDrawing(multidrawing);

            if (MultiDrawingItemAdded != null)
            {
                MultiDrawingItemAdded(this, new MultiDrawingItemEventArgs(item, multidrawing));
            }
        }
Beispiel #5
0
        public override void Add(AbstractMultiDrawingItem item)
        {
            AutoNumber number = item as AutoNumber;

            if (number == null)
            {
                return;
            }

            selected = InsertSorted(number);
        }
        public override HistoryMemento PerformUndo()
        {
            HistoryMemento redoMemento = new HistoryMementoAddMultiDrawingItem(metadata, manager, itemId);

            redoMemento.CommandName = commandName;

            AbstractMultiDrawingItem item = MultiDrawingItemSerializer.DeserializeMemento(data, metadata);

            metadata.AddMultidrawingItem(manager, item);

            // TODO: re instate the associated trackable drawing.

            return(redoMemento);
        }
        public override void Add(AbstractMultiDrawingItem item)
        {
            Spotlight spotlight = item as Spotlight;

            if (spotlight == null)
            {
                return;
            }

            spotlights.Add(spotlight);
            selected = spotlights.Count - 1;

            if (TrackableDrawingAdded != null)
            {
                TrackableDrawingAdded(this, new TrackableDrawingEventArgs(spotlight));
            }
        }
        public static AbstractMultiDrawingItem Deserialize(XmlReader r, PointF scaling, TimestampMapper timestampMapper, Metadata metadata)
        {
            AbstractMultiDrawingItem item = null;

            // Find the right class to instanciate.
            // The class must derive from AbstractMultiDrawingItem and have the corresponding [XmlType] C# attribute.
            bool     itemRead = false;
            Assembly a        = Assembly.GetExecutingAssembly();

            foreach (Type t in a.GetTypes())
            {
                if (t.BaseType != typeof(AbstractMultiDrawingItem))
                {
                    continue;
                }

                object[] attributes = t.GetCustomAttributes(typeof(XmlTypeAttribute), false);
                if (attributes.Length <= 0 || ((XmlTypeAttribute)attributes[0]).TypeName != r.Name)
                {
                    continue;
                }

                ConstructorInfo ci = t.GetConstructor(new[] { typeof(XmlReader), typeof(PointF), typeof(TimestampMapper), typeof(Metadata) });
                if (ci == null)
                {
                    break;
                }

                object[] parameters = new object[] { r, scaling, timestampMapper, metadata };
                item     = (AbstractMultiDrawingItem)Activator.CreateInstance(t, parameters);
                itemRead = item != null;

                break;
            }

            if (!itemRead)
            {
                string unparsed = r.ReadOuterXml();
                log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed);
            }

            return(item);
        }
 public MultiDrawingItemEventArgs(AbstractMultiDrawingItem item, AbstractMultiDrawing manager)
 {
     this.item    = item;
     this.manager = manager;
 }
        public static string SerializeMemento(Metadata metadata, AbstractMultiDrawing manager, AbstractMultiDrawingItem item, SerializationFilter filter)
        {
            IKvaSerializable kvaDrawing = item as IKvaSerializable;

            if (kvaDrawing == null)
            {
                return("");
            }

            string result = "";

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = false;
            settings.CloseOutput = true;

            StringBuilder builder = new StringBuilder();

            using (XmlWriter w = XmlWriter.Create(builder, settings))
            {
                w.WriteStartElement("DrawingMemento");

                DrawingSerializer.Serialize(w, kvaDrawing, filter);

                if (item is ITrackable)
                {
                    metadata.TrackabilityManager.WriteTracker(w, item.Id);
                }

                w.WriteEndElement();

                w.Flush();
                result = builder.ToString();
            }

            return(result);
        }
Beispiel #11
0
 public abstract void Add(AbstractMultiDrawingItem item);