Esempio n. 1
0
        public IEnumerable <VisualHref> VisualHrefsOf(IStreamThing source)
        {
            source.DeCompress();

            IEnumerable <VisualHref> result = new VisualHref[0];
            var stream = source.Data;

            if (stream == null)
            {
                return(null);
            }
            try {
                stream.Position = 0;
                var graph = new VisualThingGraph()
                {
                    Source = ThingGraph
                };
                var serializer = new VisualThingXmlSerializer {
                    VisualThingGraph = graph, Layout = this.Layout
                };
                serializer.Read(stream);
                stream.Position = 0;

                result = serializer.VisualsCollection
                         .Where(v => !(v is IVisualEdge))
                         .Select(v => HrefOfVisual(graph, v))
                         .ToArray();
            } catch (Exception ex) {
                // TODO: stream-closed-error should never happen.Try to get reread the source
                Registry.Pooled <IExceptionHandler> ().Catch(ex, MessageType.OK);
            } finally {
                source.ClearRealSubject();
            }
            return(result);
        }
        public virtual GraphSceneDisplayMemento ReadDisplay(XElement node)
        {
            var memento = new GraphSceneDisplayMemento();

            var iori = ReadElement(node, NodeNames.Source);

            if (iori != null)
            {
                memento.Iori = Iori.FromFileName(Read <string> (iori, NodeNames.File));
            }

            memento.Info = new SceneInfoXmlSerializer().ReadSceneInfo(node);;

            var vp = ReadElement(node, NodeNames.Viewport);

            memento.Offset    = Read <Point> (vp, NodeNames.Offset);
            memento.ZoomState = Read <ZoomState> (vp, NodeNames.ZoomState);
            memento.Zoom      = Read <double> (vp, NodeNames.Zoom);

            var thingGraph = Mesh.BackGraph(memento.Iori);

            memento.Scene = Mesh.BackHandler <IThing, ILink>().CreateScene(thingGraph);

            var layout = ReadElement(node, NodeNames.Layout);

            memento.StyleSheetName = Read <string> (layout, NodeNames.StyleSheet);
            var styleSheet = Registry.Pooled <StyleSheets> ()[memento.StyleSheetName];

            // NEVER use the tempLayout in memento-Layout; this brings troubles if data changes
            // creating layout is done in memento.Restore
            Func <IGraphScene <IVisual, IVisualEdge> > scene = () => memento.Scene;
            var tempLayout = Registry.Create <IGraphSceneLayout <IVisual, IVisualEdge> > (scene, styleSheet);

            var serializer = new VisualThingXmlSerializer();

            serializer.VisualThingGraph = memento.Scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink> ();
            serializer.Layout           = tempLayout;

            serializer.XThings = ReadElement(node, VisualThingXmlSerializer.NodeNames.Things);

            serializer.ReadXThings();

            new GraphSceneFacade <IVisual, IVisualEdge> (() => memento.Scene, tempLayout)
            .Add(serializer.VisualsCollection, true, false);

            var sceneDetails = ReadElement(node, NodeNames.Scene);
            var foc          = Read <long> (sceneDetails, NodeNames.Focused);

            if (foc != 0)
            {
                var focThing = thingGraph.GetById(foc);
                if (focThing != null)
                {
                    memento.Scene.Focused = memento.Scene.Graph.VisualOf(focThing);
                }
            }
            memento.Scene.ClearSpatialIndex();

            return(memento);
        }
Esempio n. 3
0
        public virtual void Save(Stream s, IGraph <IVisual, IVisualEdge> source, IGraphSceneLayout <IVisual, IVisualEdge> layout)
        {
            var graph = source.Source <IVisual, IVisualEdge, IThing, ILink> ();

            if (graph != null)
            {
                var serializer = new VisualThingXmlSerializer {
                    VisualThingGraph = graph, Layout = layout, VisualsCollection = source
                };
                serializer.Write(s);
            }
        }
Esempio n. 4
0
        public virtual ICollection <IVisual> Read(Stream stream, IGraph <IVisual, IVisualEdge> source, IGraphSceneLayout <IVisual, IVisualEdge> layout)
        {
            var graph = source.Source <IVisual, IVisualEdge, IThing, ILink> ();

            if (graph == null)
            {
                return(null);
            }

            var serializer = new VisualThingXmlSerializer {
                VisualThingGraph = graph, Layout = layout
            };

            serializer.Read(stream);
            return(serializer.VisualsCollection);
        }
        public virtual XElement Write(GraphSceneDisplayMemento display)
        {
            var result = new XElement(NodeNames.Display);

            if (display.Iori != null)
            {
                result.Add(new XElement(NodeNames.Source, Write(NodeNames.File, display.Iori.ToString())));
            }
            else
            {
                // TODO: write MemoryThingGraph
            }

            var graph = display.Scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink> ();

            if (graph != null)
            {
                var serializer = new VisualThingXmlSerializer();
                serializer.VisualThingGraph = graph;
                serializer.Layout           = display.Layout;
                serializer.Write(display.Scene.Graph);
                result.Add(serializer.XThings);
            }

            var sceneInfoSerializer = new SceneInfoXmlSerializer();

            result.Add(sceneInfoSerializer.Write(display.Info));

            result.Add(new XElement(NodeNames.Viewport,
                                    Write(NodeNames.Offset, display.Offset),
                                    Write(NodeNames.ZoomState, display.ZoomState),
                                    Write(NodeNames.Zoom, display.Zoom)));

            // TODO: serialize Layout
            result.Add(new XElement(NodeNames.Layout,
                                    Write(NodeNames.StyleSheet, display.Layout.StyleSheet.Name)));

            var focused = display.Scene.Graph.ThingOf(display.Scene.Focused);

            if (focused != null)
            {
                result.Add(new XElement(NodeNames.Scene, Write(NodeNames.Focused, focused.Id.ToString("X"))));
            }
            return(result);
        }