Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }