예제 #1
0
 /// <summary>
 /// an expandwalk with roots of thing
 /// attention! use it only once, or make tolist or toarray
 /// </summary>
 /// <param name="thing"></param>
 /// <returns></returns>
 public IEnumerable <IThing> Roots(IThing thing)
 {
     return(ThingGraph.Walk()
            .ExpandWalk(thing, 0, Walk.Roots <IThing, ILink> ())
            .Where(item => !(item.Node is ILink || item.Node == thing))
            .Select(item => item.Node));
 }
예제 #2
0
        public void ThingIdSerializerTest()
        {
            IThingGraph graph = new ThingGraph();
            IThing      thing = factory.CreateItem();

            graph.Add(thing);
            graph.Add(factory.CreateItem());

            ThingXmlIdSerializer serializer = new ThingXmlIdSerializer();

            serializer.Graph  = graph;
            serializer.Things = graph;

            foreach (IThing t in graph)
            {
                Assert.IsTrue(serializer.Things.Contains(t));
            }

            Stream s = new MemoryStream();

            serializer.Write(s);
            s.Position = 0;

            serializer       = new ThingXmlIdSerializer();
            serializer.Graph = graph;
            serializer.Read(s);
            foreach (IThing t in graph)
            {
                Assert.IsTrue(serializer.Things.Contains(t));
            }
        }
예제 #3
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);
        }
예제 #4
0
        public void CompletedThingsDigidocTest()
        {
            var thingGraph = new ThingGraph();
            var factory    = new DigidocSampleFactory();

            factory.Graph = thingGraph;
            factory.Populate();

            var graph           = new SchemaThingGraph(thingGraph);
            var expectedDefault = new IThing[] {
                DigidocSchema.Document,
                DigidocSchema.DocumentTitle,
                DigidocSchema.DocumentDefaultLink,
                DigidocSchema.PageNumber,
                DigidocSchema.PageDefaultLink,
                DigidocSchema.DocumentPage,
                DigidocSchema.HidePagesLink,
                ViewMetaSchema.Hide,
                MetaSchema.DescriptionMarker,
            };

            var pageItems = new List <IThing> ();

            for (int i = 0; i < factory.PageCount; i++)
            {
                pageItems.Add(factory.Nodes[factory.PageNodeStart + i * 2]);
                pageItems.Add(factory.Edges[factory.PageEdgeStart + i * 2]);
            }
            Prove(
                new IThing[] { factory.Nodes[1] },
                expectedDefault.Union(
                    new IThing[] {
                factory.Nodes[1],
                factory.Nodes[2],
                factory.Edges[1],
            }).Union(
                    pageItems
                    )
                , graph);

            Prove(
                new IThing[] { factory.Nodes[1], factory.Nodes[3], factory.Edges[2] },
                expectedDefault.Union(
                    new IThing[] {
                factory.Nodes[1],
                factory.Nodes[2],
                factory.Nodes[3],
                factory.Nodes[4],
                factory.Edges[1],
                factory.Edges[2],
                factory.Edges[3],
            }).Union(
                    pageItems
                    )
                , graph);
        }
예제 #5
0
        public void ProveSample(ISampleGraphFactory <IGraphEntity, IGraphEdge> data)
        {
            data.Count = 10;
            data.Populate();
            this.ReportDetail(data.GetType().FullName + "\t" + data.Count);

            var thingGraph = new ThingGraph();
            var mapper     =
                new GraphMapper <IGraphEntity, IThing, IGraphEdge, ILink>(
                    data.Graph, thingGraph, new GraphEntity2ThingTransformer());

            ProveMapper <IGraphEntity, IThing, IGraphEdge, ILink>(data.Graph, thingGraph, mapper);
        }
예제 #6
0
        public void Initialize()
        {
            SchemaFacade.InitSchemata();
            descriptions.Clear();
            hiddens.Clear();
            describedMarkers.Clear();

            descriptions.Add(CommonSchema.DescriptionMarker.Id);
            hiddens.Add(CommonSchema.DescriptionMarker.Id);

            IThingGraph markerGraph = new ThingGraph();
            var         markers     = Markers();

            GraphExtensions.MergeInto(Schema.IdentityGraph, markerGraph);
            ThingGraph.DeepCopy(markers, markerGraph);
            markerGraph.DeepCopy(markers, ThingGraph);

            foreach (var marker in markerGraph)
            {
                var markerId = marker.Id;
                foreach (var link in markerGraph.Edges(marker))
                {
                    if (link.Marker == null)
                    {
                        continue;
                    }

                    var idLink = (ILink <Id>)link;

                    if (ViewMetaSchemaHideEnabled &&
                        idLink.Marker == ViewMetaSchema.Hide.Id &&
                        idLink.Leaf == markerId)
                    {
                        hiddens.Add(markerId);
                    }

                    if (idLink.Marker == MetaSchema.DescriptionMarker.Id)
                    {
                        if (idLink.Leaf == markerId)
                        {
                            hiddens.Add(markerId);
                            descriptions.Add(markerId);
                        }
                        else
                        {
                            describedMarkers[markerId] = idLink.Leaf;
                        }
                    }
                }
            }
        }
예제 #7
0
        public void CompletedThingsSimpleTest()
        {
            var thingGraph = new ThingGraph();
            var factory    = new DescriptionSampleFactory();

            factory.Graph = thingGraph;
            factory.Populate();

            var graph = new SchemaThingGraph(thingGraph);

            Prove(
                new IThing[] { factory.Nodes[1] },
                new IThing[] { factory.Nodes[1], factory.Nodes[2], factory.Edges[1], CommonSchema.DescriptionMarker },
                graph);
        }
예제 #8
0
        public void TestGraphPairFactory()
        {
            IThingGraph thingGraph = new ThingGraph();

            var factory =
                new SampleGraphPairFactory <IThing, IGraphEntity, ILink, IGraphEdge> (
                    new ProgrammingLanguageFactory <IGraphEntity, IGraphEdge> (),
                    new GraphEntity2ThingTransformer().Reverted()
                    );

            factory.Mapper.Sink = thingGraph;
            factory.Populate(thingGraph);

            Trace.Write(
                GraphTestUtils.ReportGraph <IThing, ILink> (thingGraph, factory.Name));
        }
예제 #9
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);
        }
예제 #10
0
 public virtual IEnumerable <IThing> ResolveRequest(string request)
 {
     if (string.IsNullOrEmpty(request))
     {
         return(new IThing[] { this.Topic() });
     }
     else
     {
         Int64 id = 0;
         if (Int64.TryParse(request, NumberStyles.HexNumber, null, out id))
         {
             var thing = ThingGraph.GetById(id);
             return(new IThing[] { thing });
         }
         else
         {
             var things = ThingGraph.Search(request, false);
             return(things);
         }
     }
     return(null);
 }
예제 #11
0
        public virtual IThingGraph Open(Stream stream)
        {
            var sink = new ThingGraph();

            if (stream != null && stream.Length > 0)
            {
                try {
                    var serializer = new ThingXmlSerializer {
                        Graph = sink
                    };

                    serializer.Read(stream);
                    sink.AddRange(serializer.Things);
                } catch (Exception ex) {
                    Registry.Pooled <IExceptionHandler>()
                    .Catch(new Exception("File load failed: " + ex.Message, ex), MessageType.OK);
                } finally {
                    stream.Close();
                }
            }
            return(sink);
        }
예제 #12
0
        public IGraphPair <IGraphEntity, IThing, IGraphEdge, ILink> MakeGraphPair(
            ISampleGraphFactory <IGraphEntity, IGraphEdge> source, ThingGraph target)
        {
            source.Count = 10;
            source.Populate();

            var mapper =
                new GraphMapper <IGraphEntity, IThing, IGraphEdge, ILink>(
                    source.Graph,
                    target,
                    new GraphEntity2ThingTransformer());

            mapper.ConvertSinkSource();

            var graphPair =
                new GraphPair <IGraphEntity, IThing, IGraphEdge, ILink>(
                    new Graph <IGraphEntity, IGraphEdge>(),
                    target,
                    new GraphEntity2ThingTransformer());

            return(graphPair);
        }
예제 #13
0
        public virtual void TestDescription()
        {
            string testName = "TestDescription";

            this.ReportDetail(testName);
            IThingGraph graph = new ThingGraph();
            IThing      thing = Factory.CreateItem();

            graph.Add(thing);

            IThing       description = Factory.CreateItem("Description1");
            CommonSchema schema      = new CommonSchema(graph, thing);

            // test the new description:
            schema.Description = description;
            ValidateDescription(schema, graph, thing, description);
            ValidateDescription(schema, graph, thing, description);

            // add same description again:
            schema.Description = description;
            ValidateDescription(schema, graph, thing, description);

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

            // make a new description:
            description        = Factory.CreateItem("Description2");
            schema.Description = description;
            ValidateDescription(schema, graph, thing, description);

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

            // take a new schema:
            schema = new CommonSchema(graph, thing);
            ValidateDescription(schema, graph, thing, description);

            ReportSummary();
        }
예제 #14
0
 protected override ThingGraphContent OpenInternal(Iori source)
 {
     try {
         IThingGraph thingGraph = null;
         var         fileName   = source.ToFileName();
         if (File.Exists(fileName))
         {
             using (var file = new FileStream(fileName, FileMode.Open))
                 thingGraph = Open(file);
         }
         else
         {
             thingGraph = new ThingGraph();
         }
         return(new ThingGraphContent {
             Data = thingGraph, Source = source, ContentType = XmlThingGraphSpot.ContentType
         });
     } catch (Exception ex) {
         Registry.Pooled <IExceptionHandler>()
         .Catch(new Exception("File load failed: " + ex.Message, ex), MessageType.OK);
     }
     return(null);
 }
예제 #15
0
        public void TestGraphPair(ISampleGraphFactory <IGraphEntity, IGraphEdge> source, ThingGraph target)
        {
            source.Count = 10;
            source.Populate();
            this.ReportDetail(source.GetType().FullName + "\t" + source.Count);

            var graphPair =
                new HollowGraphPair <IGraphEntity, IThing, IGraphEdge, ILink> (
                    source.Graph,
                    target,
                    new GraphEntity2ThingTransformer());

            var mapper = graphPair.Mapper;

            mapper.ConvertSinkSource();

            var convertionTesterOne = new MapperTester <IGraphEntity, IThing, IGraphEdge, ILink> ();

            mapper.ConvertSinkSource();
            convertionTesterOne.ProveConversion(graphPair.Sink, graphPair.Source, mapper.Get);

            var newEntity = new GraphEntity <string> ("new");

            graphPair.Add(newEntity);
            convertionTesterOne.ProveConversion(graphPair.Sink, graphPair.Source, mapper.Get);
        }
예제 #16
0
 public virtual IThing UniqueThing(IThing thing)
 {
     return(ThingGraph.UniqueThing(thing));
 }
예제 #17
0
 public virtual void AddMarker(IThing thing)
 {
     ThingGraph.AddMarker(thing);
 }