Beispiel #1
0
        protected IGraphScene <IVisual, IVisualEdge> LoadFromStream(Stream source, IGraph <IVisual, IVisualEdge> sourceGraph, IGraphSceneLayout <IVisual, IVisualEdge> layout)
        {
            if (source == null || sourceGraph == null)
            {
                return(null);
            }

            try {
                sourceGraph.CheckLayout(layout);

                source.Position = 0;

                var scene = Mesh.CreateSinkScene(sourceGraph);
                layout = scene.CloneLayout(layout);

                var visuals = new SheetSerializer().Read(source, scene.Graph, layout);

                new GraphSceneFacade <IVisual, IVisualEdge> (() => scene, layout)
                .Add(visuals, true, false);

                source.Position = 0;

                return(scene);
            } catch (Exception ex) {
                // TODO: stream-closed-error should never happen.Try to get reread the source
                Registry.Pooled <IExceptionHandler> ().Catch(ex, MessageType.OK);
            }
            return(null);
        }
Beispiel #2
0
        protected SceneInfo SaveToThing(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout, IThing thing, string name)
        {
            var result = default(SceneInfo);

            if (thing is IStreamThing || thing == null)
            {
                var content = new Content <Stream> (
                    new MemoryStream(), CompressionType.bZip2, ContentTypes.LimadaSheet);

                var serializer = new SheetSerializer();
                serializer.Save(content.Data, scene.Graph, layout);
                content.Data.Position = 0;
                content.Description   = name;

                thing = new VisualThingsContentViz().AssignContent(scene.Graph, thing, content);

                result = SheetStore.RegisterSceneInfo(thing.Id, name);
                result.State.Hollow = false;
                result.State.Clean  = true;
                result.State.CopyTo(scene.State);
            }
            else
            {
                throw new ArgumentException("thing must be a StreamThing");
            }
            return(result);
        }
Beispiel #3
0
        Stream SaveSheet(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout)
        {
            var sheet = new SheetSerializer();
            var s     = new MemoryStream();

            sheet.Save(s, scene.Graph, scene.CloneLayout(layout));
            s.Position = 0;
            return(s);
        }
Beispiel #4
0
        public void TestSheet()
        {
            var sourceGraph =
                ModelHelper.GetSourceGraph <ProgrammingLanguageFactory <IGraphEntity, IGraphEdge> > ();

            var scene = new Scene();

            scene.Graph = sourceGraph;

            var thingGraph = sourceGraph.Source as IThingGraph;

            var layout = this.CreateLayout();

            layout.DataHandler = () => scene;

            new GraphSceneFacade <IVisual, IVisualEdge> (() => scene, layout)
            .Add(scene.Graph, true, false);

            var s = SaveSheet(scene, layout);

            var reader = new StreamReader(s);

            ReportDetail(reader.ReadToEnd());
            s.Position = 0;

            var newScene = new Scene();
            var sheet    = new SheetSerializer();

            var targetGraph = new VisualThingGraph(new VisualGraph(), thingGraph);

            newScene.Graph = targetGraph;
            s.Position     = 0;
            sheet.Read(s, newScene.Graph, newScene.CloneLayout(layout));

            foreach (var target in targetGraph)
            {
                var thing  = targetGraph.Get(target);
                var source = sourceGraph.Get(thing);

                Assert.AreEqual(target.Location, source.Location);
                Assert.AreEqual(target.Size, source.Size);
            }

            foreach (var source in sourceGraph)
            {
                var thing  = sourceGraph.Get(source);
                var target = targetGraph.Get(thing);

                Assert.AreEqual(target.Location, source.Location);
                Assert.AreEqual(target.Size, source.Size);
            }
        }
Beispiel #5
0
        void TestScene(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout, Stream s)
        {
            scene.CleanScene();

            var sheet = new SheetSerializer();

            s.Position = 0;
            sheet.Read(s, scene.Graph, scene.CloneLayout(layout));


            var visualThingGraph = scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink> ();

            foreach (var visual in scene.Elements)
            {
                var thing = visualThingGraph.Get(visual);
                Assert.IsNotNull(thing);
            }
        }