Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public void CreateClassWithTranslation()
        {
            oms.BeginTransaction();

            InstanceHandle key = oms.CreateClass(TEST_CLASS_GUID, TEST_CLASS_NAME, TEST_CLASS_TITLE);

            oms.CommitTransaction();


            string name = oms.GetAttributeValue <string>(key, oms.GetInstance(KnownAttributeGuids.Text.Name));

            Assert.AreEqual(TEST_CLASS_NAME, name);

            string title = oms.GetTranslationValue(key, oms.GetInstance(KnownRelationshipGuids.Class__has_title__Translatable_Text_Constant), oms.GetInstance(KnownInstanceGuids.Languages.English));

            Assert.AreEqual(TEST_CLASS_TITLE, title);
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        private static void LoadMCX(this Oms oms, MochaSnapshotObjectModel mcx)
        {
            foreach (MochaSnapshotTransaction t in mcx.Transactions)
            {
                oms.DefaultTenant = oms.GetTenant(t.TenantName);
                if (oms.DefaultTenant.IsEmpty)
                {
                    throw new InvalidOperationException("attempted to load snapshot for nonexistent tenant");
                }

                oms.BeginTransaction();
                for (int j = 0; j < t.Operations.Count; j++)
                {
                    oms.LoadMCXOperation(t.Operations[j]);
                }
                oms.CommitTransaction();
            }
        }
Ejemplo n.º 5
0
        public void SetAttributeValue()
        {
            InstanceHandle keyClass         = oms.GetInstance(KnownInstanceGuids.Classes.Class);
            InstanceHandle keyAttributeName = oms.GetInstance(KnownAttributeGuids.Text.Name);

            oms.BeginTransaction();

            oms.SetAttributeValue(keyClass, keyAttributeName, SAV_TEST_VALUE);

            oms.CommitTransaction();

            string value = oms.GetAttributeValue <string>(keyClass, keyAttributeName);

            Assert.AreEqual(SAV_TEST_VALUE, value);
        }