Exemplo n.º 1
0
        /// <summary>
        /// search for all StringThings where link.Marker == Document && text = null or empty
        /// get the Title of things
        /// set text of target to title.text
        /// remove title
        /// set rootlinks.where(marker==Document) to  marker = CommonSchema.Commonmarker
        /// </summary>
        /// <param name="graph"></param>
        public virtual void CleanWrongDocuments(SchemaThingGraph graph, bool act)
        {
            graph.Add(CommonSchema.CommonMarker);
            var nullStringThings = graph.GetByData((string)null);

            foreach (var nullStringThing in nullStringThings)
            {
                var edges = graph.Edges(nullStringThing).ToArray();
                var disp  = graph.ThingToDisplay(nullStringThing);

                if (disp != nullStringThing)
                {
                    WriteLog("+\t{0}\t[{1}]", nullStringThing.Data ?? "<null>", nullStringThing.Id.ToString("X"));
                    var titleLink = edges.FirstOrDefault(l => l.Marker.Id == DigidocSchema.DocumentTitle.Id);
                    if (titleLink != null && titleLink.Leaf == disp)
                    {
                        WriteLog("\t-\t{0}\t[{1}]", disp.Data ?? "<null>", disp.Id.ToString("X"));
                        if (act)
                        {
                            nullStringThing.Data = disp.Data;
                            graph.Add(nullStringThing);
                            graph.Remove(titleLink);
                            var dispEdges = graph.Edges(disp).ToArray();
                            foreach (var link in dispEdges)
                            {
                                graph.ChangeEdge(link, nullStringThing, link.Root == disp);
                                graph.Add(link);
                            }
                            graph.Remove(disp);
                        }
                    }
                    var documentLink = edges.FirstOrDefault(l => l.Marker.Id == DigidocSchema.Document.Id);
                    if (documentLink != null)
                    {
                        WriteLog(string.Format("\t<>\t{0}\t{1}", DigidocSchema.Document.Data, CommonSchema.CommonMarker.Data));
                        if (act)
                        {
                            documentLink.Marker = CommonSchema.CommonMarker;
                            graph.Add(documentLink);
                        }
                    }
                }
                else
                {
                    //if (edges.Count() == 0)
                    //    WriteLog("--\t{0}\t[{1}]", disp.Data ?? "<null>", disp.Id.ToString("X"));
                    //else
                    //    WriteLog("-\t{0}\t[{1}]", disp.Data ?? "<null>", disp.Id.ToString("X"));
                }
            }
            Flush(graph);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public virtual void TestDocumentWithPages()
        {
            this.ReportDetail("**** TestDocumentWithPages");
            var factory = new DigidocSampleFactory();
            var graph   = new SchemaThingGraph(new ThingGraph());
            var root    = DigidocSchema.DocumentsRoot;

            factory.CreateDocuments(graph, root, 1);
            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());
                }
            }
        }