Beispiel #1
0
        public virtual void TestTitle()
        {
            this.ReportDetail("**** TestTitle");
            IThingGraph graph = new ThingGraph();
            IThing      thing = Factory.CreateItem();

            graph.Add(thing);

            IThing title   = Factory.CreateItem("Title1");
            var    digidoc = new DigidocSchema(graph, thing);

            // test the new description:
            digidoc.Title = title;
            ValidateTitle(digidoc, graph, thing, title);
            ValidateTitle(digidoc, graph, thing, title);

            // add same description again:
            digidoc.Title = title;
            ValidateTitle(digidoc, graph, thing, title);

            // the first description will be an orphan:
            IThing orphan = title;

            // make a new description:
            title         = Factory.CreateItem("Title2");
            digidoc.Title = title;
            ValidateTitle(digidoc, graph, thing, title);

            // test if orphan is deleted:
            Assert.IsFalse(graph.Contains(orphan), "Orphan not deleted");

            // take a new schema:
            digidoc = new DigidocSchema(graph, thing);
            ValidateTitle(digidoc, graph, thing, title);
        }
Beispiel #2
0
        /// <summary>
        /// enumerates all things of scene's selected elements
        /// if a Digidoc is the only selected, then the Pages of the Digidoc are enumerated
        /// </summary>
        /// <param name="scene"></param>
        /// <returns></returns>
        public IEnumerable <IThing> SelectedThings(IGraphScene <IVisual, IVisualEdge> scene)
        {
            var visuals = scene.Selected.Elements;

            if (visuals.Count() == 0)
            {
                visuals = scene.Graph.Where(v => !(v is IVisualEdge));
            }
            if (visuals.Count() == 0)
            {
                return(null);
            }

            IEnumerable <IThing> things = null;

            if (visuals.Count() == 1)
            {
                var thing   = scene.Graph.ThingOf(visuals.First());
                var digidoc = new DigidocSchema(scene.Graph.ThingGraph(), thing);
                if (digidoc.HasPages())
                {
                    things = digidoc.OrderedPages();
                }
            }
            if (things == null)
            {
                things = visuals
                         .OrderBy(v => v.Location, new PointComparer {
                    Delta = 20
                })
                         .Select(v => scene.Graph.ThingOf(v));
            }
            return(things);
        }
Beispiel #3
0
        public bool IsPage(IGraph <IVisual, IVisualEdge> source, IVisual page)
        {
            var digidoc   = new DigidocSchema(source.ThingGraph(), source.ThingOf(page));
            var pageThing = source.ThingOf(page) as IStreamThing;
            var info      = new ImageContentSpot();

            return(pageThing != null && info.Supports(pageThing.StreamType));
        }
        public void CreateDocuments(IThingGraph graph, IThing root, int count)
        {
            var digidoc = new DigidocSchema();

            for (int i = 0; i < count; i++)
            {
                var document = digidoc.CreateDocument(graph, null);
                digidoc.CreatePage(graph, document, null, 1);
                graph.Add(Factory.CreateEdge(root, document, DigidocSchema.Document));
            }
        }
        public void ReadPagesFromDir(IThingGraph graph, IThing document, string path)
        {
            var digidoc             = new DigidocSchema();
            var imageStreamProvider = new ImageStreamContentIo();
            var nr = 1;

            foreach (var file in Directory.GetFiles(path).OrderBy(f => f))
            {
                if (imageStreamProvider.Detector.Supports(Path.GetExtension(file)))
                {
                    var stream = imageStreamProvider.ReadContent(IoUtils.UriFromFileName(file));
                    if (stream != null && stream.Data != null)
                    {
                        digidoc.CreatePage(graph, document, stream, nr);
                        nr++;
                    }
                }
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public void ValidateTitle(DigidocSchema schema, IThingGraph graph, IThing thing, IThing title)
        {
            Assert.AreSame(schema.Title, title);

            this.ReportDetail(GraphTestUtils.ReportGraph <IThing, ILink>(graph, "* Title added"));
            bool found       = false;
            bool firstMarker = false;

            foreach (ILink link in graph.Edges(thing))
            {
                if (link.Marker == DigidocSchema.DocumentTitle)
                {
                    Assert.IsFalse(firstMarker, "second title found");
                    firstMarker = true;
                }
                if (link.Leaf == schema.Title && link.Marker == DigidocSchema.DocumentTitle &&
                    link.Leaf == title)
                {
                    Assert.IsFalse(found);
                    found = true;
                }
            }
            Assert.IsTrue(found, "Title not found");
        }
Beispiel #8
0
        public IEnumerable <Content <Stream> > PageStreams(IGraph <IVisual, IVisualEdge> source, IVisual document)
        {
            var digidoc = new DigidocSchema(source.ThingGraph(), source.ThingOf(document));

            return(digidoc.PageStreams());
        }
Beispiel #9
0
        public IEnumerable <IVisual> Pages(IGraph <IVisual, IVisualEdge> source, IVisual document)
        {
            var digidoc = new DigidocSchema(source.ThingGraph(), source.ThingOf(document));

            return(digidoc.Pages().Select(t => source.VisualOf(t)));
        }
Beispiel #10
0
        public ActionResult Index(string id)
        {
            Trace.WriteLine("HomeController.Index({0})", id);
            ActionResult result = base.HttpNotFound("not found");

            ViewBag.Message = id ?? "<null>";
            ViewBag.Id      = id;

            var things = Backend.ResolveRequest(id);

            if (things == null)
            {
                return(View("About", new HtmlContent {
                    Description = "not found",
                    Data = string.Format("{0}<br/>{1}", id, "not found")
                }));
            }

            Action <Content> setViewBag = content => {
                ViewBag.Title = content.Description;
                ViewBag.Id    = content.Source;
            };

            Func <IEnumerable <IThing>, ActionResult> linksOfThings =
                ts => View(Views.Hrefs, new Hrefs {
                Refs = Backend.HrefsOfThings(ts)
            });

            Func <IThing, Content, ActionResult> contentAndLinks = (thing, c) => {
                var leafs = Backend.HrefsOfThings(Backend.Leafs(thing)
                                                  .OrderBy(t => Backend.ThingDataToDisplay(t)))
                            .ToArray();
                var roots = Backend.HrefsOfThings(Backend.Roots(thing)
                                                  .OrderBy(t => Backend.ThingDataToDisplay(t)))
                            .ToArray();
                return(View(Views.ContentAndLinks, new ContentAndLinks {
                    Content = c, Leafs = leafs, Roots = roots
                }));
            };

            Func <IThing, Content, ActionResult> digidoc = (thing, c) => {
                var doc   = new DigidocSchema(Backend.ThingGraph, thing);
                var leafs = Backend.HrefsOfThings(doc.OrderedPages());
                var roots = Backend.HrefsOfThings(Backend.Roots(thing).OrderBy(t => Backend.ThingDataToDisplay(t)));
                // TODO: what if pages are no images, but text or something else?
                return(View(Views.DigiDoc, new ContentAndLinks {
                    Content = c, Leafs = leafs, Roots = roots
                }));
            };

            Func <IThing, Content, ActionResult> sheet = (thing, c) => {
                var hrefsOf = Backend.VisualHrefsOf(thing as IStreamThing);
                var leafs   = Backend.HrefsOfThings(Backend.Leafs(thing)
                                                    .OrderBy(t => Backend.ThingDataToDisplay(t)))
                              .ToArray();
                var roots = Backend.HrefsOfThings(Backend.Roots(thing)
                                                  .OrderBy(t => Backend.ThingDataToDisplay(t)))
                            .ToArray();
                return(View(Views.SheetContent, new VisualHrefContent {
                    Hrefs = hrefsOf, Roots = roots, Description = c.Description, Leafs = leafs
                }));
            };

            if (things.Count() == 1)
            {
                var thing = things.First();
                if (thing is IStreamThing)
                {
                    if (Backend.IsConvertibleToHtml(thing))
                    {
                        var content = Backend.HtmlContent(thing as IStreamThing);
                        setViewBag(content);
                        result = contentAndLinks(thing, content);
                    }
                    else if (((StreamThing)thing).StreamType == ContentTypes.LimadaSheet)
                    {
                        var content = Backend.StreamContent(thing as StreamThing);
                        setViewBag(content);
                        result = sheet(thing, content);
                    }
                    else
                    {
                        var content = Backend.StreamContent(thing as StreamThing);
                        setViewBag(content);
                        result = File(content.Data, content.MimeType);
                    }
                }
                else if (thing != null)
                {
                    var content = new Content {
                        Description = Backend.ThingToDisplay(thing).ToString(),
                        Source      = thing.Id.ToString("X16"),
                    };
                    setViewBag(content);
                    var doc = new DigidocSchema(Backend.ThingGraph, thing);
                    if (doc.HasPages())
                    {
                        result = digidoc(thing, content);
                    }
                    else
                    {
                        result = contentAndLinks(thing, content);
                    }
                }
            }
            else if (things.Count() > 1)
            {
                var content = new Content {
                    Description = id + " ...",
                    Source      = "",
                };
                setViewBag(content);
                result = View(Views.ContentAndLinks,
                              new ContentAndLinks {
                    Content = content,
                    Leafs   = Backend.HrefsOfThings(things).OrderBy(l => l.Text),
                    Roots   = new Href[0]
                });
            }
            return(result);
        }