protected override async Task ProcessStore(TripleStore store) { ResolverCollectorEventSource.Log.ProcessingBatch(BatchCount); try { SparqlResultSet distinctIds = SparqlHelpers.Select(store, Utils.GetResource("sparql.SelectDistinctPackage.rq")); IDictionary<Uri, IGraph> resolverResources = new Dictionary<Uri, IGraph>(); foreach (SparqlResult row in distinctIds) { string id = row["id"].ToString(); SparqlParameterizedString sparql = new SparqlParameterizedString(); sparql.CommandText = Utils.GetResource("sparql.ConstructResolverGraph.rq"); string baseAddress = _storage.BaseAddress.ToString(); sparql.SetLiteral("id", id); sparql.SetLiteral("base", baseAddress); sparql.SetLiteral("extension", ".json"); sparql.SetLiteral("galleryBase", GalleryBaseAddress); sparql.SetLiteral("contentBase", ContentBaseAddress); IGraph packageRegistration = SparqlHelpers.Construct(store, sparql.ToString()); if (packageRegistration.Triples.Count == 0) { throw new Exception("packageRegistration.Triples.Count == 0"); } Uri registrationUri = new Uri(baseAddress + id.ToLowerInvariant() + ".json"); resolverResources.Add(registrationUri, packageRegistration); } if (resolverResources.Count != distinctIds.Count) { throw new Exception("resolverResources.Count != distinctIds.Count"); } await MergeAll(resolverResources); } finally { ResolverCollectorEventSource.Log.ProcessedBatch(BatchCount); store.Dispose(); } }
async Task ProcessStore(TripleStore store) { try { SparqlResultSet distinctIds = SparqlHelpers.Select(store, Utils.GetResource("sparql.SelectDistinctPackage.rq")); IDictionary<Uri, IGraph> resolverResources = new Dictionary<Uri, IGraph>(); foreach (SparqlResult row in distinctIds) { string id = row["id"].ToString(); SparqlParameterizedString sparql = new SparqlParameterizedString(); sparql.CommandText = Utils.GetResource("sparql.ConstructResolverGraph.rq"); string baseAddress = _storage.BaseAddress + _storage.Container + "/resolver/"; sparql.SetLiteral("id", id); sparql.SetLiteral("base", baseAddress); sparql.SetLiteral("extension", ".json"); IGraph packageRegistration = SparqlHelpers.Construct(store, sparql.ToString()); Uri registrationUri = new Uri(baseAddress + id.ToLowerInvariant() + ".json"); resolverResources.Add(registrationUri, packageRegistration); } if (resolverResources.Count != distinctIds.Count) { throw new Exception("resolverResources.Count != distinctIds.Count"); } await MergeAll(resolverResources); } finally { store.Dispose(); } }
public void SparqlInjection() { String baseQuery = @"PREFIX ex: <http://example.org/Vehicles/> SELECT * WHERE { ?s a @type . }"; SparqlParameterizedString query = new SparqlParameterizedString(baseQuery); SparqlQueryParser parser = new SparqlQueryParser(); List<String> injections = new List<string>() { "ex:Car ; ex:Speed ?speed", "ex:Plane ; ?prop ?value", "ex:Car . EXISTS {?s ex:Speed ?speed}", "ex:Car \u0022; ex:Speed ?speed" }; foreach (String value in injections) { query.SetLiteral("type", value); query.SetLiteral("@type", value); Console.WriteLine(query.ToString()); Console.WriteLine(); SparqlQuery q = parser.ParseFromString(query.ToString()); Assert.AreEqual(1, q.Variables.Count(), "Should only be one variable in the query"); } }
async Task DeletePackage(Uri resourceUri, string version) { string existingJson = await _storage.Load(resourceUri); if (existingJson != null) { IGraph currentPackageRegistration = Utils.CreateGraph(existingJson); using (TripleStore store = new TripleStore()) { store.Add(currentPackageRegistration, true); SparqlParameterizedString sparql = new SparqlParameterizedString(); sparql.CommandText = Utils.GetResource("sparql.DeletePackage.rq"); sparql.SetLiteral("version", version); IGraph modifiedPackageRegistration = SparqlHelpers.Construct(store, sparql.ToString()); if (CountPackage(modifiedPackageRegistration) == 0) { await _storage.Delete(resourceUri); } else { string content = Utils.CreateJson(modifiedPackageRegistration, _resolverFrame); await _storage.Save("application/json", resourceUri, content); } } } }