internal async void AddDocumentRecord2()
{
await QueuedTask.Run(() =>
{
using (var kg = GetKnowledgeGraph())
{
var propInfo = kg.GetPropertyNameInfo();
if (!propInfo.SupportsDocuments)
return false;
var edit_op = new EditOperation()
{
Name = "Create Document Example",
SelectNewFeatures = true
};
var doc_entity_name = propInfo.DocumentTypeName;
var hasdoc_rel_name = GetHasDocumentTypeName(kg.GetDataModel());
//Document can also be FeatureClass
var doc_tbl = kg.OpenDataset<Table>(doc_entity_name);
var doc_rel_tbl = kg.OpenDataset<Table>(hasdoc_rel_name);
//This is the document to be added...file, image, resource, etc.
var url = @"E:\Data\Temp\HelloWorld.txt";
// create the KnowledgeGraphDocumentDescription
var kgDocDesc = new KnowledgeGraphDocumentDescription(url);
// if there is a geometry use the following ctor
// var kgDocDesc = new KnowledgeGraphDocumentDescription(url, doc_location);
// if you have additional custom attributes
//var customDocAtts = new Dictionary<string, object>();
//customDocAtts.Add("custom_attrib", "Foo");
//customDocAtts.Add("custom_attrib2", "Bar");
//var kgDocDesc = new KnowledgeGraphDocumentDescription(url, null, customDocAtts);
// add additional properties if required
kgDocDesc.Keywords = @"text,file,example";
/// The Create method will auto-populate the Url, Name, FileExtension and contentType fields of the document row
/// from the path supplied.
var rowToken = edit_op.Create(doc_tbl, kgDocDesc);
//Get the entity whose document this is...
var org_fc = kg.OpenDataset<FeatureClass>("Organization");
var qf = new QueryFilter()
{
WhereClause = "name = 'Acme'",
SubFields = "*"
};
var origin_org_id = Guid.Empty;
using (var rc = org_fc.Search(qf))
{
if (!rc.MoveNext())
return false;
origin_org_id = rc.Current.GetGlobalID();//For the relate
}
// set up the row handles
var originHandle = new RowHandle(org_fc, origin_org_id); // entity
var destinationHandle = new RowHandle(rowToken); // document
// create the KnowledgeGraphRelationshipDescription
var rd = new KnowledgeGraphRelationshipDescription(originHandle, destinationHandle);
// if you have additional custom attributes for the "HasDocument" relationship
//var customHasDocAtts = new Dictionary<string, object>();
//customHasDocAtts.Add("custom_attrib", "Foo");
//customHasDocAtts.Add("custom_attrib2", "Bar");
//var rd = new KnowledgeGraphRelationshipDescription(originHandle, destinationHandle, customHasDocAtts);
// create the relate record using the same edit operation
edit_op.Create(doc_rel_tbl, rd);
//Call execute to create all the entities and relationship rows _together_
return edit_op.Execute();
}
return false;
});
}