private static void Initialize(this Oms oms, MochaClassLibraryObjectModel mcl) { oms.BeginTransaction(); for (int i = 0; i < mcl.Libraries.Count; i++) { for (int j = 0; j < mcl.Libraries[i].Instances.Count; j++) { oms.CreateInstance(mcl.Libraries[i].Instances[j].ID, Guid.Empty); } } oms.CommitTransaction(); oms.BeginTransaction(); for (int i = 0; i < mcl.Libraries.Count; i++) { for (int j = 0; j < mcl.Libraries[i].Instances.Count; j++) { for (int k = 0; k < mcl.Libraries[i].Instances[j].AttributeValues.Count; k++) { oms.SetAttributeValue(oms.GetInstance(mcl.Libraries[i].Instances[j].ID), oms.GetInstance(mcl.Libraries[i].Instances[j].AttributeValues[k].AttributeInstanceID), mcl.Libraries[i].Instances[j].AttributeValues[k].Value); } } for (int j = 0; j < mcl.Libraries[i].Relationships.Count; j++) { Guid[] ids = new Guid[mcl.Libraries[i].Relationships[j].DestinationInstanceIDs.Count]; for (int k = 0; k < mcl.Libraries[i].Relationships[j].DestinationInstanceIDs.Count; k++) { ids[k] = mcl.Libraries[i].Relationships[j].DestinationInstanceIDs[k]; } oms.CreateRelationship(oms.GetInstance(mcl.Libraries[i].Relationships[j].SourceInstanceID), oms.GetInstance(mcl.Libraries[i].Relationships[j].RelationshipInstanceID), GuidsToInstances(oms, ids)); } } oms.CommitTransaction(); oms.BeginTransaction(); // create the Class::Instance.has parent Class relationship oms.CreateRelationship(oms.GetInstance(KnownInstanceGuids.Classes.Class), oms.GetInstance(KnownRelationshipGuids.Class__has__Instance), oms.GetInstance(KnownInstanceGuids.Classes.Class)); oms.CreateRelationship(oms.GetInstance(KnownInstanceGuids.Classes.Class), oms.GetInstance(KnownRelationshipGuids.Instance__for__Class), oms.GetInstance(KnownInstanceGuids.Classes.Class)); oms.CommitTransaction(); }
public void CreateRelationship() { InstanceHandle keyClass = oms.GetInstance(KnownInstanceGuids.Classes.Class); InstanceHandle keyAttribute = oms.GetInstance(KnownInstanceGuids.Classes.Attribute); oms.BeginTransaction(); InstanceHandle keyRelationship = oms.CreateRelationshipInstance(keyClass, "has test relationship", keyAttribute); // Class.has test relationship Attribute oms.CreateRelationship(keyClass, keyRelationship, keyAttribute); oms.CommitTransaction(); InstanceHandle[] keys = oms.GetRelatedInstances(keyClass, keyRelationship); Assert.NotNull(keys); Assert.AreEqual(1, keys.Length); Assert.AreEqual(keyAttribute, keys[0]); }
private static void LoadMCXOperation(this Oms oms, MochaSnapshotTransactionOperation op) { if (op is MochaSnapshotAssignAttributeTransactionOperation aa) { oms.SetAttributeValue(oms.GetInstance(aa.SourceInstanceID), oms.GetInstance(aa.AttributeInstanceID), aa.EffectiveDate, aa.Value); } else if (op is MochaSnapshotAssociateRelationshipTransactionOperation ar) { List <InstanceHandle> targetInstances = new List <InstanceHandle>(); foreach (Guid id in ar.TargetInstanceIDs) { targetInstances.Add(oms.GetInstance(id)); } oms.CreateRelationship(oms.GetInstance(ar.SourceInstanceID), oms.GetInstance(ar.RelationshipInstanceID), targetInstances.ToArray(), ar.EffectiveDate); } else if (op is MochaSnapshotCreateInstanceTransactionOperation ci) { oms.CreateInstance(ci.GlobalIdentifier, ci.ClassGlobalIdentifier); } }