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. 2
0
        public void ImportRawSource()
        {
            Save();
            Close(Data);
            bool tryIt = true;

            while (tryIt && MessageBoxShow("Open a new, non exisiting file", "RawImport", MessageBoxButtons.OkCancel) == DialogResult.Ok)
            {
                var fileDialog = new FileDialogMemento();
                DefaultDialogValues(fileDialog, WriteFilter);
                DefaultDialogValues(OpenFileDialog, ReadFilter);

                if (FileDialogShow(fileDialog, true) == DialogResult.Ok)
                {
                    var sinkFile = fileDialog.FileName;
                    fileDialog.ResetFileName();
                    if (File.Exists(sinkFile))
                    {
                        continue;
                    }
                    if (tryIt = MessageBoxShow("Open the file to import", "RawImport", MessageBoxButtons.OkCancel) == DialogResult.Ok)
                    {
                        if (FileDialogShow(OpenFileDialog, true) == DialogResult.Ok)
                        {
                            var sourceFile = OpenFileDialog.FileName;
                            if (!File.Exists(sourceFile))
                            {
                                MessageBoxShow("File does not exist", "RawImport", MessageBoxButtons.Ok);
                                break;
                            }

                            tryIt = false;
                            var sourceInfo         = Iori.FromFileName(sourceFile);
                            var sinkIo             = ThingGraphIoManager.GetSinkIO(Iori.FromFileName(sinkFile), IoMode.Write) as ThingGraphIo;
                            ThingGraphContent sink = null;

                            try {
                                sink = sinkIo.Open(Iori.FromFileName(sinkFile));
                                var repairer = Registry.Pooled <ThingGraphRepairPool>()
                                               .Find(sourceInfo.Extension, IoMode.Read) as IPipe <Iori, IThingGraph>;
                                this.AttachProgress(repairer as IProgress);
                                repairer.Use(Iori.FromFileName(sourceFile), sink.Data);
                            } catch (Exception ex) {
                                Registry.Pooled <IExceptionHandler>()
                                .Catch(new Exception("Raw import failed: " + ex.Message, ex), MessageType.OK);
                                sinkIo.Close(sink);
                                File.Delete(sinkFile);
                            }
                            sinkIo.Close(sink);
                            MessageBoxShow("Import successfull", "RawImport", MessageBoxButtons.Ok);
                            this.Open(Iori.FromFileName(sinkFile));
                            OpenFileDialog.ResetFileName();
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public void SaveAs()
 {
     DefaultDialogValues(SaveFileDialog, WriteFilter);
     SaveFileDialog.OverwritePrompt = false;
     if (FileDialogShow(SaveFileDialog, false) == DialogResult.Ok)
     {
         SaveAs(Iori.FromFileName(SaveFileDialog.FileName));
         SaveFileDialog.ResetFileName();
     }
 }
Esempio n. 4
0
 public void ExportSceneView(IGraphScene <IVisual, IVisualEdge> scene)
 {
     DefaultDialogValues(SaveFileDialog, WriteFilter);
     if (scene != null && scene.HasThingGraph())
     {
         SaveFileDialog.OverwritePrompt = false;
         if (FileDialogShow(SaveFileDialog, false) == DialogResult.Ok)
         {
             ExportSceneView(Iori.FromFileName(SaveFileDialog.FileName), scene);
             SaveFileDialog.ResetFileName();
         }
     }
 }
Esempio n. 5
0
        public void IntGraphTest()
        {
            Gateway.Open(Iori.FromFileName(FileName));
            var graphTest = new IntGraphTest();

            Limaki.Data.db4o.Graph <int, Edge <int> >
            graph = new Limaki.Data.db4o.Graph <int, Edge <int> > (Gateway);

            graphTest.Graph = graph;
            graphTest.Setup();
            graphTest.AllTests();
            graph.Clear();
            Gateway.Close();
        }
Esempio n. 6
0
        public void EdgeIsItemTest()
        {
            Gateway.Open(Iori.FromFileName(FileName));
            var graphTest = new EdgeIsItemGraphTest();

            Limaki.Data.db4o.Graph <Item <string>, EdgeItem <string> >
            graph = new Limaki.Data.db4o.Graph <Item <string>, EdgeItem <string> >(Gateway);

            graphTest.Graph = graph;
            graphTest.Setup();
            graphTest.AllTests();
            graph.Clear();
            Gateway.Close();
        }
Esempio n. 7
0
        public void StringGraphTest()
        {
            var graphTest = new StringGraphTest();

            Gateway.Open(Iori.FromFileName(FileName));
            Limaki.Data.db4o.Graph <string, Edge <string> > graph =
                new Limaki.Data.db4o.Graph <string, Edge <string> > (Gateway);

            graphTest.Graph = graph;
            graphTest.Setup();
            graphTest.AllTests();
            graph.Clear();

            Gateway.Close();
        }
Esempio n. 8
0
        public void BenchmarkOneTest()
        {
            var sceneFactory =
                new BenchmarkOneGraphFactory <IGraphEntity, IGraphEdge> ();

            Gateway.Open(Iori.FromFileName(FileName));

            var graph =
                new Limaki.Data.db4o.Graph <IGraphEntity, IGraphEdge>(Gateway);

            sceneFactory.Count = 10;

            sceneFactory.Populate(graph);
            //graph.Clear();
            Gateway.Close();
            ReportSummary();
        }
Esempio n. 9
0
        public void Open()
        {
            if (this.IsUnsaved(this.Data))
            {
                if (MessageBoxShow("You have an unsaved document. Do you want to save it?", "", MessageBoxButtons.YesNo) ==
                    DialogResult.Yes)
                {
                    SaveAs();
                }
            }

            DefaultDialogValues(OpenFileDialog, ReadFilter);
            if (FileDialogShow(OpenFileDialog, true) == DialogResult.Ok)
            {
                Open(Iori.FromFileName(OpenFileDialog.FileName));
                OpenFileDialog.ResetFileName();
            }
        }
Esempio n. 10
0
        public bool ImportFiles(IEnumerable <string> sourceFiles)
        {
            var result = true;

            if (sourceFiles.Count() > 0)
            {
                var progressSaved   = this.Progress;
                var progressHandler = Registry.Pooled <IProgressHandler> ();
                this.Progress = (m, i, max) => progressHandler.Write(m, i, max);
                try {
                    foreach (var sourceFile in sourceFiles)
                    {
                        if (File.Exists(sourceFile))
                        {
                            progressHandler.Show("Importing file " + sourceFile);
                            var sourceIori = Iori.FromFileName(sourceFile);
                            var sourceIo   = ThingGraphIoManager.GetSinkIO(sourceIori, IoMode.Read) as ThingGraphIo;
                            if (sourceIo != null)
                            {
                                ThingGraphContent source = null;
                                try {
                                    source = sourceIo.Open(sourceIori);
                                    new ThingGraphMerger {
                                        Progress = this.Progress
                                    }.Use(source.Data, Data.Data);
                                } catch (Exception ex) {
                                    Registry.Pooled <IExceptionHandler> ()
                                    .Catch(new Exception("Add file failed: " + ex.Message, ex), MessageType.OK);
                                    result = false;
                                } finally {
                                    sourceIo.Close(source);
                                }
                            }
                        }
                    }
                    Progress = null;
                    progressHandler.Close();
                } finally {
                    Progress = progressSaved;
                }
            }
            return(result);
        }
Esempio n. 11
0
        public bool OpenCommandLine()
        {
            var    result          = false;
            var    sourceFiles     = new List <string>();
            string fileToOpen      = null;
            string resumeFile      = null;
            var    exitAfterImport = false;

            var p = new OptionSet()
            {
                { "add=", a => sourceFiles.Add(a) },
                { "file=", a => fileToOpen = a },
                { "resume=", a => resumeFile = a },
                { "exit", a => exitAfterImport = a != null },
            };
            var options = p.Parse(Environment.GetCommandLineArgs());

            if (fileToOpen == null)
            {
                if (options.Count > 1)
                {
                    fileToOpen = options[1];
                }
            }

            if (fileToOpen != null && File.Exists(fileToOpen))
            {
                result = Open(Iori.FromFileName(fileToOpen));
            }

            if (result)
            {
                result = ImportFiles(sourceFiles);
            }

            if (exitAfterImport && ApplicationQuit != null)
            {
                ApplicationQuit();
            }
            return(result);
        }
Esempio n. 12
0
        public virtual void TestDocumentWithTestData()
        {
            IThingGraph thingGraph = new ThingGraph();
            var         prov       = new Limada.IO.Db4oThingGraphIo();
            var         d          = prov.Open(Iori.FromFileName(TestLocations.GraphtestDir + "DocumentTest.limo"));

            thingGraph = d.Data;

            this.ReportDetail("**** TestDocumentWithTestData");
            var factory = new DigidocSampleFactory();
            var digidoc = new DigidocSchema();
            var graph   = new SchemaThingGraph(thingGraph);

            Limada.Schemata.Schema.IdentityGraph.ForEach(s => graph.Add(s));

            var root = DigidocSchema.DocumentsRoot;
            var path = TestLocations.BlobSource;

            var document = digidoc.CreateDocument(graph, path);

            graph.Add(Factory.CreateEdge(root, document, DigidocSchema.Document));

            factory.ReadPagesFromDir(graph, document, path);

            var docs = graph.Edges(root).Where(l => l.Marker == DigidocSchema.Document).Select(l => l.Leaf);

            foreach (var doc in docs)
            {
                var title = graph.ThingToDisplay(doc);
                this.ReportDetail(title.ToString());
                var pages = graph.Edges(doc).Where(l => l.Marker == DigidocSchema.DocumentPage).Select(l => l.Leaf);
                foreach (var page in pages)
                {
                    var number = graph.ThingToDisplay(page);
                    Assert.IsNotNull(number);
                    this.ReportDetail(number.ToString());
                }
            }
            prov.Flush(d);
        }
Esempio n. 13
0
        public virtual void Read(XElement node, IConceptUsecase usecase)
        {
            var ms = new MeshXmlSerializer();

            ms.Read(node, Mesh);

            FileNames = ms.FileNames;

            var backHandler = Mesh.BackHandler <IThing, ILink> ();
            var filesOpen   = backHandler
                              .BackGraphs
                              .Select(g => new {
                Iori  = ThingMeshHelper.GetIori(g),
                Graph = g
            })
                              .Where(i => i.Iori != null)
                              .ToDictionary(k => k.Iori.ToString(), e => e.Graph);


            foreach (var file in ms.FileNames)
            {
                var io = Registry.Pooled <ThingGraphIoPool> ().Find(Path.GetExtension(file), Limaki.Contents.IO.IoMode.Read)
                         as ThingGraphIo;

                if (!filesOpen.ContainsKey(file))
                {
                    try {
                        var content = io.Open(Iori.FromFileName(file));
                        var g       = backHandler.WrapGraph(content.Data);
                        backHandler.RegisterBackGraph(g);
                    } catch (Exception e) {
                    }
                }
            }

            var displays = ReadElement(ReadElement(node, NodeNames.SplitView), NodeNames.Displays);

            foreach (var display in ReadElements(displays, GraphSceneDisplayXmlSerializer.NodeNames.Display))
            {
                var name = Read <string> (display, NodeNames.Name);
                var id   = Read <long> (display, SceneInfoXmlSerializer.NodeNames.Id);
                var d    = Mesh.Displays.Where(disp => disp.DataId == id).FirstOrDefault();
                if (d == null)
                {
                    var dm = ms.Displays.Where(disp => disp.Info.Id == id).FirstOrDefault();
                    if (name == NodeNames.SplitViewDisplay1 && dm != null)
                    {
                        dm.Restore(usecase.SplitView.Display1);
                        AfterRestore?.Invoke(d, name);
                    }
                    if (name == NodeNames.SplitViewDisplay2 && dm != null)
                    {
                        dm.Restore(usecase.SplitView.Display2);
                        AfterRestore?.Invoke(d, name);
                    }
                }
            }

            var homeId = Read <long> (ReadElement(node, NodeNames.Favorites), NodeNames.HomeId);

            usecase.FavoriteManager.HomeId = homeId;
        }