public void SiblingRelationshipAutogenerates() { oms.BeginTransaction(); InstanceHandle ihClass = oms.GetInstance(KnownInstanceGuids.Classes.Class); InstanceHandle ihZzz = oms.CreateClass(GUID_ZZZ); oms.CommitTransaction(); oms.BeginTransaction(); InstanceHandle ihZzzInst1 = oms.CreateInstance(ihZzz); InstanceHandle ihClass_has_ZZZ = oms.CreateRelationshipInstance(ihClass, "has", ihZzz, GUID_CLASS_HAS_ZZZ); InstanceHandle ihZZZ_for_Class = oms.CreateRelationshipInstance(ihZzz, "for", ihClass, GUID_ZZZ_FOR_CLASS); oms.CommitTransaction(); oms.BeginTransaction(); oms.CreateRelationship(ihClass_has_ZZZ, oms.GetInstance(KnownRelationshipGuids.Relationship__has_sibling__Relationship), ihZZZ_for_Class); oms.CommitTransaction(); oms.BeginTransaction(); oms.CreateRelationship(ihClass, ihClass_has_ZZZ, ihZzzInst1); oms.CommitTransaction(); InstanceHandle ihZzzClass = oms.GetRelatedInstance(ihZzzInst1, ihZZZ_for_Class); Assert.AreEqual(ihClass, ihZzzClass); }
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(); }
private static void LoadObjectModel(this Oms oms, MochaClassLibraryObjectModel mcl) { foreach (MochaTenant tenant in mcl.Tenants) { oms.DefaultTenant = oms.GetTenant(tenant.Name); if (oms.DefaultTenant.IsEmpty) { throw new InvalidOperationException("attempted to load snapshot for nonexistent tenant"); } oms.BeginTransaction(); for (int j = 0; j < tenant.Instances.Count; j++) { oms.CreateInstance(tenant.Instances[j].ID, Guid.Empty); } oms.CommitTransaction(); } }
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); } }