コード例 #1
0
        public void DeleteTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document)
        {
            //Generate the JSON String
            Graph g = new Graph();

            g.Assert(ts);
            String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer);

            Object[] toDelete = MongoDBHelper.JsonArrayToObjects(json);

            //Then load the existing Triples from the Document
            Document mongoDoc = document.BeginWrite(false);

            if (mongoDoc["graph"] != null)
            {
                //Only need to do something if the Graph is non-empty
                List <Object> existing = MongoDBHelper.DocumentListToObjectList(mongoDoc["graph"]);
                foreach (Object obj in toDelete)
                {
                    existing.Remove(obj);
                }
                mongoDoc["graph"] = existing.ToArray();
            }
            document.EndWrite();
        }
コード例 #2
0
        public void AppendTriples(IEnumerable <Triple> ts, IDocument <Document, Document> document)
        {
            //Generate our JSON String
            Graph g = new Graph();

            g.Assert(ts);
            String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer);

            //Then convert this to a Document
            Document mongoDoc = document.BeginWrite(false);

            Object[] temp = MongoDBHelper.JsonArrayToObjects(json);
            if (mongoDoc["graph"] != null)
            {
                List <Object> existing = MongoDBHelper.DocumentListToObjectList(mongoDoc["graph"]);
                existing.AddRange(temp);
                mongoDoc["graph"] = existing.ToArray();
            }
            else
            {
                //If it was null this was a new Document
                mongoDoc["graph"] = temp;
            }
            document.EndWrite();
        }