Пример #1
0
        /// <summary>
        /// Checks desktop
        /// </summary>
        /// <param name="desktop">The desktop</param>
        /// <param name="binders">The serialization binders</param>
        /// <returns>List of exceptions or null if right</returns>
        public static List <Exception> Check(IDesktop desktop, SerializationBinder[] binders)
        {
            exceptions = new List <Exception>();
            bool b = false;

            try
            {
                IEnumerable <IObjectLabel> objects = desktop.Objects;
                IEnumerable <IArrowLabel>  arrows  = desktop.Arrows;
                PureDesktopPeer            d       = new PureDesktopPeer();
                d.Copy(objects, arrows, true);
                d.SetParents();
                Stream stream = new MemoryStream();
                d.Save(stream);
                PureDesktopPeer dnew = new PureDesktopPeer();
                b = dnew.Load(stream);
                dnew.Dispose();
            }
            catch (Exception e)
            {
                e.ShowError(10);
                if (exceptions != null)
                {
                    exceptions.Add(e);
                }
            }
            List <Exception> res = b ? null : exceptions;

            exceptions = null;
            desktop.SetParents();
            return(res);
        }
Пример #2
0
        /// <summary>
        /// Desktop from stream
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <returns>Desktop</returns>
        public static IDesktop DesktopFromStream(this System.IO.Stream stream)
        {
            PureDesktopPeer desktop = new PureDesktopPeer();
            bool            success = desktop.Load(stream);

            return(success ? desktop : null);
        }
Пример #3
0
 /// <summary>
 /// Refreshes a desktop
 /// </summary>
 /// <param name="desktop">The desktop</param>
 public static void Refresh(this IDesktop desktop)
 {
     if (desktop is PureDesktopPeer)
     {
         PureDesktopPeer p = desktop as PureDesktopPeer;
         p.Refresh();
     }
 }
Пример #4
0
        /// <summary>
        /// Creates desktop from Xml documet
        /// </summary>
        /// <param name="document">The document</param>
        /// <param name="create">The create function</param>
        /// <returns>The desktop</returns>
        public static PureDesktopPeer LoadFromXml(this XmlDocument document, Func <XmlElement, object> create)
        {
            PureDesktopPeer desktop = new PureDesktopPeer();
            Dictionary <string, IObjectLabel> dictionary = new Dictionary <string, IObjectLabel>();
            XmlElement objs = document.GetElementsByTagName("Objects")[0] as XmlElement;

            foreach (XmlElement e in objs.ChildNodes)
            {
                string name = e.GetAttribute("Name");
                object o    = create(e);
                if (o == null)
                {
                    continue;
                }
                string t = o.GetType() + "";
                string k = "";
                if (t.Equals("DataPerformer.DataLink") | t.Equals("DataPerformer.VectorFormulaConsumer"))
                {
                    k = "Mv";
                }
                PureObjectLabelPeer l = new PureObjectLabelPeer(name, k, t, 0, 0);
                dictionary[name] = l;
                desktop.AddObjectLabel(l, o as ICategoryObject, true);
                l.Desktop = desktop;
            }
            XmlElement arrs = document.GetElementsByTagName("Arrows")[0] as XmlElement;

            foreach (XmlElement e in arrs.ChildNodes)
            {
                string         name = e.GetAttribute("Name");
                ICategoryArrow a    = create(e) as ICategoryArrow;
                if (a == null)
                {
                    continue;
                }
                string s = e.GetAttribute("Source");
                string t = e.GetAttribute("Target");
                if (!dictionary.ContainsKey(s) | !dictionary.ContainsKey(t))
                {
                    continue;
                }
                try
                {
                    desktop.AddArrowWithExistingLabels(a, dictionary[s], dictionary[t], name, "");
                }
                catch (Exception)
                {
                }
            }
            return(desktop);
        }
Пример #5
0
        /// <summary>
        /// Create desktop from bytes
        /// </summary>
        /// <param name="buffer">Buffer</param>
        /// <returns>The desktop</returns>
        public static IDesktop DesktopFromBytes(this byte[] buffer)
        {
            if (buffer == null)
            {
                return(null);
            }
            if (buffer.Length == 0)
            {
                return(null);
            }
            PureDesktopPeer desktop = new PureDesktopPeer();
            bool            success = desktop.Load(buffer);

            return(success ? desktop : null);
        }
Пример #6
0
        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            string t = Arrow.GetType().FullName;

            if (!t.Equals(type))
            {
                type = t;
            }
            info.AddValue("Kind", type);
            info.AddValue("Type", kind);
            info.AddValue("Name", name);
            info.AddValue("Arrow", arrow);
            info.AddValue("SourceNumber", sourceNumber);
            info.AddValue("TargetNumber", targetNumber);
            PureDesktopPeer.SaveLabel(label, bytes, info);
        }
Пример #7
0
        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            string t = Object.GetType().FullName;

            if (!t.Equals(type))
            {
                type = t;
            }
            info.AddValue("Kind", type);
            info.AddValue("Type", kind);
            info.AddValue("Name", name);
            info.AddValue("X", x);
            info.AddValue("Y", y);
            info.AddValue("Object", obj);
            PureDesktopPeer.SaveLabel(label, bytes, info);
        }
Пример #8
0
        /// <summary>
        /// Checks loading from stream
        /// </summary>
        /// <param name="stream">The stream</param>
        /// <returns>List of exceptions</returns>
        public static List <Exception> Check(Stream stream)
        {
            bool b = false;
            SerializationBinder binder = SerializationInterface.StaticExtensionSerializationInterface.Binder;

            exceptions = new List <Exception>();
            try
            {
                PureDesktopPeer d = new PureDesktopPeer();
                d.Load(stream, binder, true);
                d.SetParents();
                Stream s = new MemoryStream();
                d.Save(s);
                d.Dispose();
                PureDesktopPeer dnew = new PureDesktopPeer();
                b = dnew.Load(s, binder, true);
                dnew.Dispose();
            }
            catch (Exception e)
            {
                e.ShowError(10);
                if (exceptions != null)
                {
                    exceptions.Add(e);
                }
            }
            List <Exception> res = b ? null : exceptions;

            if (res != null)
            {
                if (res.Count == 0)
                {
                    res = null;
                }
            }
            exceptions = null;
            return(res);
        }
Пример #9
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected PureObjectLabelPeer(SerializationInfo info, StreamingContext context)
        {
            type = info.GetValue("Kind", typeof(string)) as string;
            kind = (string)info.GetValue("Type", typeof(string));
            name = (string)info.GetValue("Name", typeof(string));
            x    = (int)info.GetValue("X", typeof(int));
            y    = (int)info.GetValue("Y", typeof(int));
            obj  = info.GetValue("Object", typeof(object)) as ICategoryObject;
            string t = obj.GetType() + "";

            if (!t.Equals(type))
            {
                type = t;
            }
            try
            {
                bytes = PureDesktopPeer.LoadLabel(info);
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
            }
        }
Пример #10
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public PureArrowLabelPeer(SerializationInfo info, StreamingContext context)
        {
            type         = info.GetValue("Kind", typeof(string)) as string;
            kind         = (string)info.GetValue("Type", typeof(string));
            name         = (string)info.GetValue("Name", typeof(string));
            arrow        = info.GetValue("Arrow", typeof(object)) as ICategoryArrow;
            sourceNumber = info.GetValue("SourceNumber", typeof(object));
            targetNumber = info.GetValue("TargetNumber", typeof(object));
            string t = arrow.GetType() + "";

            if (!t.Equals(type))
            {
                type = t;
            }

            try
            {
                bytes = PureDesktopPeer.LoadLabel(info);
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
            }
        }
Пример #11
0
 /// <summary>
 /// Main constructor
 /// </summary>
 /// <param name="desktop">The parent desktop</param>
 public ObjectContainer(PureDesktopPeer desktop)
     : base(desktop)
 {
 }