public bool ApplyDiff(IDiffResult diffResult)
        {
            // TODO: Make async
            Log.LogTrace("ApplyDiff: {0}", diffResult.ToString());
            var store = GetStore();

            if (!diffResult.Success)
            {
                Log.LogTrace("ApplyDiff: Aborting attempt to apply a failed diff command result");
                return(false);
            }
            var updateGraph = new NonIndexedGraph {
                BaseUri = new Uri("http://example.org/")
            };
            var parser = new NQuadsParser();

            Log.LogTrace("ApplyDiff: Applying deletes");
            parser.Parse(diffResult.FileDiffs.SelectMany(diff => diff.Deleted),
                         triple => store.Retract(triple.Subject, triple.Predicate, triple.Object, triple.GraphUri),
                         updateGraph);
            updateGraph.Clear();
            Log.LogTrace("ApplyDiff: Applying inserts");
            parser.Parse(diffResult.FileDiffs.SelectMany(diff => diff.Inserted),
                         triple => store.Assert(triple.Subject, triple.Predicate, triple.Object, triple.GraphUri),
                         updateGraph);
            Log.LogTrace("ApplyDiff: Flushing changes");
            store.Flush();
            Log.LogTrace("ApplyDiff: Completed");
            return(true);
        }
        public void Import(string testDataFile)
        {
            var defaultGraph = new Graph();
            var parser       = new NQuadsParser();

            using (var reader = File.OpenText(testDataFile))
            {
                parser.Parse(reader, t => Store.Assert(t.Subject, t.Predicate, t.Object, t.GraphUri), defaultGraph);
            }
            Store.Flush();
        }
        public void ParseDiff(IDiffResult diffResult, QuinceDiff quinceDiff)
        {
            // TODO: Make async
            Log.LogTrace("ParseDiff: {0}", diffResult.ToString());
            if (!diffResult.Success)
            {
                Log.LogTrace("ParseDiff: Aborting attempt to apply a failed diff command result");
                return;
            }
            var diffGraph = new NonIndexedGraph {
                BaseUri = new Uri("http://example.org/")
            };
            var parser = new NQuadsParser();

            Log.LogTrace("ParseDiff: Parsing deletes");
            parser.Parse(diffResult.FileDiffs.Where(fd => fd.FilePath.StartsWith("_s")).SelectMany(diff => diff.Deleted),
                         quinceDiff.Deleted,
                         diffGraph);
            diffGraph.Clear();
            Log.LogTrace("ParseDiff: Parsing inserts");
            parser.Parse(diffResult.FileDiffs.Where(fd => fd.FilePath.StartsWith("_s")).SelectMany(diff => diff.Inserted),
                         quinceDiff.Inserted,
                         diffGraph);
        }
Beispiel #4
0
        public void CanGenerateRdfFromRepository()
        {
            var repoDir = Path.Combine(_tmpDir, "quince");

            Directory.CreateDirectory(repoDir);
            var repo         = new DynamicFileStore(repoDir, 100);
            var defaultGraph = new Graph();
            var parser       = new NQuadsParser();

            using (var reader = File.OpenText(Path.Join("data", "test1.nq")))
            {
                parser.Parse(reader, t => repo.Assert(t.Subject, t.Predicate, t.Object, t.GraphUri), defaultGraph);
            }

            repo.Flush();
            var mockQuinceFactory = new Mock <IQuinceStoreFactory>();

            mockQuinceFactory.Setup(x => x.MakeQuinceStore(It.IsAny <string>())).Returns(repo);
            var rdfGeneratorMock = new Mock <ITripleCollectionHandler>();

            rdfGeneratorMock.Setup(x => x.HandleTripleCollection(It.Is <IList <Triple> >(c =>
                                                                                         c.All(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/s/s0"))))).Verifiable();
            var fileGeneratorFactoryMock = new Mock <IFileGeneratorFactory>();

            fileGeneratorFactoryMock.Setup(x => x.MakeRdfFileGenerator(It.IsAny <IResourceFileMapper>(),
                                                                       It.IsAny <IEnumerable <Uri> >(), It.IsAny <IProgressLog>(), It.IsAny <int>())).Returns(rdfGeneratorMock.Object);

            var rdfResourceFileMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri("http://example.org/id/"), "data"));
            var htmlResourceFileMapper = new ResourceFileMapper(
                new ResourceMapEntry(new Uri("http://example.org/id/"), "doc"));
            var ddRepository = new DataDockRepository(
                _tmpDir, new Uri("http://example.org/"), new MockProgressLog(),
                mockQuinceFactory.Object, fileGeneratorFactoryMock.Object,
                rdfResourceFileMapper, htmlResourceFileMapper, _uriService);

            ddRepository.GenerateRdf(new[] { new Uri("http://example.org/g/g1") });

            // Should be invoked to generate files for subject IRIs
            rdfGeneratorMock.Verify(x => x.HandleTripleCollection(It.Is <IList <Triple> >(c =>
                                                                                          c.All(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/s/s0")))),
                                    Times.Once);
            // Should not be invoked to generate files for object IRIs
            rdfGeneratorMock.Verify(x => x.HandleTripleCollection(It.Is <IList <Triple> >(
                                                                      c => c.Any(t => (t.Subject as IUriNode).Uri.ToString().Equals("http://example.org/id/resource/o/o0")))), Times.Never);
        }