public static void EnsurePublicTypeRegistration(string userUri, string registrationName, string registrationType, string registrationLocation) { // going too fast to publicTypeIndex. should follow this : https://github.com/solid/solid/blob/master/proposals/data-discovery.md var publicTypeIndexUri = $"{userUri}/settings/publicTypeIndex.ttl"; var g = new Graph(); UriLoader.Load(g, new Uri(publicTypeIndexUri)); var query = new SparqlParameterizedString(); query.Namespaces.AddNamespace("s", new Uri("http://www.w3.org/ns/solid/terms#")); query.Namespaces.AddNamespace("schem", new Uri("http://schema.org")); // ?reg < http://www.w3.org/ns/solid/terms#forClass> <http://schema.org/TextDigitalDocument>. // ?reg < http://www.w3.org/ns/solid/terms#instance> <file:///C:/public/visitedplaces.ttl>. query.CommandText = @"SELECT ?reg WHERE { ?reg s:forClass @type . ?reg s:instance @location . }"; // file:///C:/public/notes.ttl => the URI contains file:///C: because it is made relative to where the document is, and here we downloaded it to local file ... query.SetUri("location", new Uri($"file:///C:/public/{registrationLocation}")); query.SetUri("type", new Uri(registrationType)); var registrationExists = ((SparqlResultSet)g.ExecuteQuery(query)).Any(); var token = GetSolidToken(); if (!registrationExists) { // create the type registration string payload = $"INSERT DATA {{:{registrationName} a <http://www.w3.org/ns/solid/terms#TypeRegistration>; <http://www.w3.org/ns/solid/terms#forClass> <http://schema.org/TextDigitalDocument> ; <http://www.w3.org/ns/solid/terms#instance> </public/{registrationLocation}> . }}"; var statusPatch = DataProviderHelper.SendPatch(publicTypeIndexUri, payload, token); if (statusPatch != HttpStatusCode.OK) { throw new GOServerException("PATCH Failed"); } } var documentUri = $"{userUri}/public/{registrationLocation}"; // verify the document exists var status = DataProviderHelper.SendHead(documentUri, token); if (status != HttpStatusCode.OK) { // create the document file otherwise /* string payload = @"@prefix : <#>. * @prefix schem: <http://schema.org/>. * @prefix XML: <http://www.w3.org/2001/XMLSchema#>. * @prefix go: <http://generativeobjects.com/apps#>."; */ status = DataProviderHelper.SendPost($"{userUri}/public/", registrationLocation, null, token); if (status != HttpStatusCode.OK) { throw new GOServerException("POST Failed"); } } }