await QueuedTask.Run(() =>
{
using (var kg = GetKnowledgeGraph())
{
if (kg == null)
return;
//Get all the domains in the KG
var domains = kg.GetDomains();
var sb = new SchemaBuilder(kg);
foreach (var domain in domains)
{
//skip the special provenance domain
var name = domain.GetName();
if (string.Compare(name, "esri__provenanceSourceType", true) == 0)
continue;//skip this one
//Delete all other domains
if (domain is RangeDomain rd)
sb.Delete(new RangeDomainDescription(rd));
else if (domain is CodedValueDomain cvd)
sb.Delete(new CodedValueDomainDescription(cvd));
}
try
{
//note: will throw an InvalidOperationException if there are no operations
//to run. Will also delete associated fields dependent on deleted domain(s)
if (!kg.ApplySchemaEdits(sb))
{
var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
System.Diagnostics.Debug.WriteLine($"Delete domains error: {err_msg}");
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
});