Beispiel #1
0
        private void AddFavorites()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            var g    = rdf.GetFullGraph(_myProfile);
            var file = new NTripleFile(_data);

            file.Read(g).Wait();

            //some favorites.
            g.Update
            .ForBlank("favs", out var favs)
            .With(RDF.A, out _).Add(RDFS.List, out _)
            .Then()
            .List(g.Uri("https://duckduckgo.com/"),
                  g.Uri("https://inrupt.com/"),
                  g.Uri("https://github.com/"),
                  g.Uri("https://portal.azure.com/"))
            .Then()
            .For(g.Uri(_myProfile))
            .With(g.Uri("app:favorites")).Add(favs)
            //and I want to update the last modified.
            .Then()
            .With(Terms.DateModified, out _)
            .Set(DateTime.UtcNow);

            file.Write(g).Wait();
        }
Beispiel #2
0
        private void AddBasicProfile()
        {
            var rdf = RdfDataFactory.CreateNoLock();

            if (!_data.Exists())
            {
                throw new Exception("Call start first");
            }

            var g    = rdf.GetFullGraph("app:/profile#me");
            var file = new NTripleFile(_data);

            file.Read(g).Wait();

            g.Update.For(g.Uri(_myProfile))
            .With(RDFS.Label, out _).Add("My Name")
            .Then()
            .With(Terms.DateModified, out _).Add(DateTime.UtcNow)
            .Then()
            .With(Terms.Description, out _).Add("My basic profile data")
            .Then()
            .With(Terms.AlternativeTitle, out _).Add("ME");

            file.Write(g).Wait();
        }
        public async Task WriteRead()
        {
            var file = new FileInfo(
                Path.Combine(Files.AppData.NqFileTests.FullName,
                             nameof(WriteRead) + ".nt"));

            var rdf = new RdfData(new NodeFactory());

            var g = rdf.GetFullGraph("graph:1")
                    .Assert(rdf.Uri("sub1:/"), rdf.Uri("pred1:/"), rdf.New("basic text"));

            file.Directory.EnsureDelete();
            var t = new NTripleFile(file);
            await t.Write(g);

            file.Refresh();
            Assert.IsTrue(file.Exists);
            Assert.IsTrue(file.Length > 0, "wrote some data");

            //copy current so it doesn't delete.
            var gCopy = g.Query.ToList();

            g.Clear();
            await t.Read(g);

            IEqualityComparer <Quad> eq = new SameQuad();

            var gDiffs = g.Query.Except(gCopy, eq).ToList();

            Assert.IsFalse(gDiffs.Any(), "No difference");
        }
Beispiel #4
0
        public void BuildFileSystemInfo()
        {
            //data store
            var rdf = new RdfData(new NodeFactory());

            //read info
            var g = rdf.GetBlankGraph(nameof(BuildFileSystemInfo));

            g.Update.For(g.Uri(_rootFolder.AsUri()))
            .With("app:root", out _)
            .Add(true)
            .Add(g.Uri(_rootFolder.AsUri()));

            var q = new Queue <DirectoryInfo>();

            q.Enqueue(_rootFolder);

            //limit depth so not too long.
            BreadthFirstReadInfo(q, g.Update, rdf, 2);

            //save data
            _dataFile.EnsureDelete();
            var rdfFile = new NTripleFile(_dataFile);

            rdfFile.Write(g).Wait();

            Assert.IsTrue(_dataFile.Exists());
        }
        public void WriteTripleData()
        {
            var rdf = new RdfData(new NodeFactory());

            var target = new NTripleFile(Files.AppDataDir.GetFile(
                                             nameof(NTripleFileTests), nameof(WriteTripleData) + ".nt"));

            var g = rdf.BlankSelf("g1");

            rdf.Assert(g,
                       rdf.Uri("x:sub1"),
                       rdf.Uri("x:age"),
                       rdf.New(23));

            target.Write(rdf.GetGraph(g)).Wait();
        }
Beispiel #6
0
        public async Task WriteWithCrossGraphBlank()
        {
            var rdf = new RdfData(new NodeFactory());

            var g1 = rdf.GetBlankGraph();

            g1.Assert(rdf.Uri("bad:link"), rdf.Uri("app:test"), rdf.BlankSelf("other"));

            var file = Files.AppDataDir.GetFile(nameof(NodeWriterTests),
                                                nameof(WriteWithCrossGraphBlank) + ".nt")
                       .EnsureDelete();

            var target = new NTripleFile(file);

            try
            {
                await target.Write(g1);

                Assert.Fail("Cannot write if blank is scoped to other graph");
            }catch (BlankNodeScopedToInvalidGraph) {}
        }