Пример #1
0
 /// <summary>
 /// Initializes a new instance of GenerateReportDialog
 /// </summary>
 public GenerateReportDialog(ORMModel model)
 {
     InitializeComponent();
     myModel             = model;
     chkLbOptions.Sorted = true;
     chkLbOptions.Value  = VerbalizationReportContent.All;
 }
Пример #2
0
        public void PopulationSampleTest(Store store)
        {
            myTestServices.LogValidationErrors("Expect V2=100 Population Mandatory");

            myTestServices.LogMessage("Testing IsIndependent and PopulationMandatoryError associated with implied mandatory constraint");
            ORMModel   model = store.ElementDirectory.FindElements <ORMModel>()[0];
            ObjectType v2    = (ObjectType)model.ObjectTypesDictionary.GetElement("V2").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Set IsIndependent"))
            {
                v2.IsIndependent = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Set IsIndependent, No error expected after explicit transaction");
            store.UndoManager.Undo();
            DomainTypeDescriptor.CreatePropertyDescriptor(v2, ObjectType.IsIndependentDomainPropertyId).SetValue(v2, true);
            myTestServices.LogValidationErrors("Set IsIndependent, No error expected after implicit transaction");
            store.UndoManager.Undo();

            myTestServices.LogMessage("Testing PopulationMandatoryError by turning on a SimpleMandatory constraint.");
            RoleBase   rightRole  = v2.PlayedRoleCollection[0];
            RoleBase   leftRole   = rightRole.OppositeRole;
            FactType   factType   = rightRole.FactType;
            ObjectType populateMe = leftRole.Role.RolePlayer;
            LinkedElementCollection <ObjectTypeInstance> populateMeInstances = populateMe.ObjectTypeInstanceCollection;
            LinkedElementCollection <ObjectTypeInstance> v2Instances         = v2.ObjectTypeInstanceCollection;

            using (Transaction t = store.TransactionManager.BeginTransaction("Set IsMandatory"))
            {
                leftRole.Role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Set IsMandatory, expect new errors for instances 'Tom' and 'Dick'");
            FactTypeInstance factTypeInstance;

            using (Transaction t = store.TransactionManager.BeginTransaction("Populate first row"))
            {
                factTypeInstance          = new FactTypeInstance(store);
                factTypeInstance.FactType = factType;
                new FactTypeRoleInstance(leftRole.Role, populateMeInstances[0]).FactTypeInstance = factTypeInstance;
                new FactTypeRoleInstance(rightRole.Role, v2Instances[0]).FactTypeInstance        = factTypeInstance;
                t.Commit();
            }

            myTestServices.LogMessage("Adding second population row one role at a time");
            myTestServices.LogValidationErrors("Add a complete FactTypeInstance for Tom, 1 error remaining for 'Dick'");
            using (Transaction t = store.TransactionManager.BeginTransaction("Populate second row"))
            {
                factTypeInstance          = new FactTypeInstance(store);
                factTypeInstance.FactType = factType;
                new FactTypeRoleInstance(leftRole.Role, populateMeInstances[1]).FactTypeInstance = factTypeInstance;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Add a partial FactTypeInstance for Dick, 1 error remaining for partial FactTypeInstance");
            using (Transaction t = store.TransactionManager.BeginTransaction("Finish second row populations"))
            {
                new FactTypeRoleInstance(rightRole.Role, v2Instances[0]).FactTypeInstance = factTypeInstance;
                t.Commit();
            }
        }
        public void SubsetMandatory_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initially");
            ORMModel model  = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role     role_2 = (Role)store.ElementDirectory.GetElement(new Guid("82DF5594-2020-4CA3-8154-FD92EE83F726"));

            myTestServices.LogValidationErrors("Intoduce Error: Make a role of supertype mandatory");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Found. Calling Undo to remove error...");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error removed with undo.");


            myTestServices.LogValidationErrors("Intoduce Error: Make a role of subtype mandatory");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Found. Calling Undo to remove error...");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add simple mandatory constraint"))
            {
                role_2.IsMandatory = false;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed with changing property value...");
        }
Пример #4
0
        public void ExactlyOneTest_1b(Store store)
        {
            myTestServices.LogValidationErrors("No errors expected");
            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("FrequencyConstraint1").SingleElement;

            // DomainTypeDescriptor.CreatePropertyDescriptor(constraint, FrequencyConstraint.MaxFrequencyDomainPropertyId).SetValue(constraint, 1);
            myTestServices.LogValidationErrors("Introduce Error[FrequencyConstraintExactlyOneError]");
            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                constraint.MinFrequency = 1;
                constraint.MaxFrequency = 1;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Fixing error with error activation service");
            ((IORMToolServices)store).ModelErrorActivationService.ActivateError(constraint, constraint.FrequencyConstraintExactlyOneError);
            myTestServices.LogValidationErrors("[FrequencyConstraintExactlyOneError] removed, different error introduced. Removing new error");

            // Deleting one of the two uniqnuess constraints...
            UniquenessConstraint uniqueC = (UniquenessConstraint)model.ConstraintsDictionary.GetElement("InternalUniquenessConstraint5").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                uniqueC.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("All errors resolved");
        }
Пример #5
0
        public void Test2(Store store)
        {
            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "WithIndependent");
            ORMModel   model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            ObjectType objectType = (ObjectType)model.ObjectTypesDictionary.GetElement("SomeLength").FirstElement;

            DomainTypeDescriptor.CreatePropertyDescriptor(objectType, ObjectType.IsIndependentDomainPropertyId).SetValue(objectType, false);
        }
Пример #6
0
        public void Test2(Store store)
        {
            myTestServices.LogValidationErrors("Before constraint duplication/implication repair");

            // Find the fact that that needs fixing and repair it
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FactType fact  = (FactType)store.ElementDirectory.GetElement(new Guid("009787C8-37C8-43EB-933A-7C5B469D1310"));

            fact.RemoveImpliedInternalUniquenessConstraints();
            myTestServices.LogValidationErrors("After constraint duplication/implication repair");
        }
Пример #7
0
 /// <summary>
 /// ChangeRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ORMModel)
 /// Synchronize the <see cref="P:AbstractionModel.Name">name</see> of the <see cref="AbstractionModel"/>
 /// with the <see cref="P:ORMModel.Name">name</see> of the <see cref="ORMModel"/>
 /// </summary>
 private static void ORMModelChangedRule(ElementPropertyChangedEventArgs e)
 {
     if (e.DomainProperty.Id == ORMModel.NameDomainPropertyId)
     {
         ORMModel         model            = (ORMModel)e.ModelElement;
         AbstractionModel abstractionModel = AbstractionModelIsForORMModel.GetAbstractionModel(model);
         if (abstractionModel != null)
         {
             abstractionModel.Name = model.Name;
         }
     }
 }
Пример #8
0
        public void UniqueUniqueImplied_1a(Store store)
        {
            myTestServices.LogValidationErrors("Start with one Implication Error");
            ORMModel             model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            UniquenessConstraint constraint = (UniquenessConstraint)model.ConstraintsDictionary.GetElement("ExternalUniquenessConstraint_A").SingleElement;

            myTestServices.LogMessage("Removing the Implied Uniqueness Costraint...");
            using (Transaction t = store.TransactionManager.BeginTransaction("Remove Implied Uniqueness Costraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed with removal of Implied Constraint");
        }
Пример #9
0
        public void EqualityMandatoryImplied_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role     role  = (Role)store.ElementDirectory.GetElement(new Guid("1C424E34-8369-41EC-850F-FD24E7B30C7A"));

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error is removed with Undo");
        }
Пример #10
0
        public void DTBlankTest2b(Store store)
        {
            myTestServices.LogValidationErrors("Before removing error");
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FloatingPointNumericDataType numeric = model.Store.ElementDirectory.FindElements <FloatingPointNumericDataType>()[0];
            ObjectType o = (ObjectType)model.ObjectTypesDictionary.GetElement("WifeId").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Remove invalid data type error"))
            {
                //remove
                o.DataType = numeric;
                t.Commit();
            }

            myTestServices.LogValidationErrors("After removing error");
        }
Пример #11
0
        public void ConstContradictTests_1b(Store store)
        {
            myTestServices.LogValidationErrors("ExclusionContradictsEqualityError exists");

            ORMModel           model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            EqualityConstraint constraint = (EqualityConstraint)model.ConstraintsDictionary.GetElement("EqConstraint").FirstElement;

            myTestServices.LogValidationErrors("Removing Equality Constraint");

            using (Transaction t = store.TransactionManager.BeginTransaction("Remove Eq Constraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Removed");
        }
Пример #12
0
        /// <summary>
        /// Creates a new form to filter errors for the given ORM model.
        /// </summary>
        /// <param name="model">The orm model for which to filter errors.</param>
        public ModelErrorDisplayFilterForm(ORMModel model)
        {
            this.myModel = model;
            InitializeComponent();
            LoadCategories();

            ITree   tree       = new VirtualTree();
            IBranch rootBranch = new InitialCategoriesBranch(myCategories, myErrors);

            tree.Root = rootBranch;

#if VISUALSTUDIO_9_0 // MSBUG: Hack workaround crashing bug in VirtualTreeControl.OnToggleExpansion
            this.virtualTreeControl.ColumnPermutation = new ColumnPermutation(1, new int[] { 0 }, false);
#endif
            this.virtualTreeControl.Tree = tree;
        }
Пример #13
0
        public void Test5(Store store)
        {
            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "FullyAbsorbed");

            myTestServices.LogMessage("Separate a one-to-main objectification");
            ORMModel   model              = store.ElementDirectory.FindElements <ORMModel>()[0];
            ObjectType birthObjectType    = (ObjectType)model.ObjectTypesDictionary.GetElement("Birth").FirstElement;
            FactType   factTypeToSeparate = birthObjectType.PreferredIdentifier.RoleCollection[0].Proxy.FactType;
            MappingCustomizationModel customizationModel;

            using (Transaction t = store.TransactionManager.BeginTransaction("Separate assimilated objectification"))
            {
                customizationModel = new MappingCustomizationModel(store);
                AssimilationMapping mapping = new AssimilationMapping(store, new PropertyAssignment(AssimilationMapping.AbsorptionChoiceDomainPropertyId, AssimilationAbsorptionChoice.Separate));
                new AssimilationMappingCustomizesFactType(mapping, factTypeToSeparate);
                mapping.Model = customizationModel;
                t.Commit();
            }
            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "SeparateObjectification");

            myTestServices.LogMessage("Add a longer assimilation chain with a separate end point");
            ObjectType          partyObjectType = (ObjectType)model.ObjectTypesDictionary.GetElement("Party").FirstElement;
            AssimilationMapping partyIsThingAssimilationMapping;

            using (Transaction t = store.TransactionManager.BeginTransaction("Longer assimilation chain"))
            {
                partyObjectType.ReferenceModeDisplay = "";                 // Using ReferenceModeDisplay instead of ReferenceModeString to automatically kill Party_id
                ObjectType thingObjectType = new ObjectType(store, new PropertyAssignment(ObjectType.NameDomainPropertyId, "Thing"), new PropertyAssignment(ObjectType.IsIndependentDomainPropertyId, true));
                thingObjectType.Model = model;
                thingObjectType.ReferenceModeString = "id";
                SubtypeFact partyIsThingSubtypeFact = SubtypeFact.Create(partyObjectType, thingObjectType);
                partyIsThingAssimilationMapping = new AssimilationMapping(store, new PropertyAssignment(AssimilationMapping.AbsorptionChoiceDomainPropertyId, AssimilationAbsorptionChoice.Separate));
                new AssimilationMappingCustomizesFactType(partyIsThingAssimilationMapping, partyIsThingSubtypeFact);
                partyIsThingAssimilationMapping.Model = customizationModel;
                t.Commit();
            }

            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "SeparateRemoteSupertype");

            myTestServices.LogMessage("Remove the remote separation");
            using (Transaction t = store.TransactionManager.BeginTransaction(""))
            {
                partyIsThingAssimilationMapping.AbsorptionChoice = AssimilationAbsorptionChoice.Absorb;
                t.Commit();
            }
        }
 /// <summary>
 /// Shows a modal dialog to edit the property.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="provider"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public sealed override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null)
     {
         ORMModel element = EditorUtility.ResolveContextInstance(context.Instance, false) as ORMModel;
         if (element != null)
         {
             IUIService uiService;
             if (null != (provider = (element.Store as IORMToolServices).ServiceProvider) &&
                 null != (uiService = (IUIService)provider.GetService(typeof(IUIService))))
             {
                 uiService.ShowDialog(new ModelErrorDisplayFilterForm(element));
             }
         }
     }
     return(value);
 }
Пример #15
0
        public void FCMinMaxTest2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("FrequencyConstraint1").SingleElement;
            int min = constraint.MinFrequency;
            int max = constraint.MaxFrequency;

            using (Transaction t = store.TransactionManager.BeginTransaction("Fix Constraint"))
            {
                //Make the error
                constraint.MinFrequency = max;
                constraint.MaxFrequency = min;
                t.Commit();
            }

            myTestServices.LogValidationErrors("After adding error");
        }
Пример #16
0
        public void ExclusionMandatoryContra_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];

            // Input file(ExclusionMandatoryContra_1a.Load.orm) specific code.
            // Recommend finding a better method of retrieving the role in context.
            FactType factType = model.FactTypeCollection[2];
            Role     role     = (Role)factType.RoleCollection[0];

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error is removed with Undo");
        }
Пример #17
0
					/// <summary>
					/// Sets the reference modes for the control
					/// </summary>
					/// <param name="model"></param>
					public void SetModel(ORMModel model)
					{
						if (model != myModel)
						{
							Store newStore = (model == null) ? null : model.Store;
							if (myStore != null && myStore != newStore && !myStore.Disposed)
							{
								ManageStoreEvents(myStore, EventHandlerAction.Remove);
							}
							if (newStore != null && newStore != myStore)
							{
								ManageStoreEvents(newStore, EventHandlerAction.Add);

							}
							this.myModel = model;
							this.myStore = newStore;
							int count = myIntrinsicReferenceModesList.Count;
							this.myIntrinsicReferenceModesList.Clear();
							if (myModify != null && count != 0)
							{
								myModify(this, BranchModificationEventArgs.DeleteItems(this, 0, count));
							}
							if (model != null)
							{
								foreach (ReferenceMode mode in model.ReferenceModeCollection)
								{
									IntrinsicReferenceMode intMode = mode as IntrinsicReferenceMode;
									if (intMode != null)
									{
										this.myIntrinsicReferenceModesList.Add(intMode);
									}
								}
								myIntrinsicReferenceModesList.Sort();
							}
							count = myIntrinsicReferenceModesList.Count;
							if (myModify != null && count != 0)
							{
								myModify(this, BranchModificationEventArgs.InsertItems(this, -1, count));
							}
						}
					}
Пример #18
0
        public void ExactlyOneTest1a(Store store)
        {
            myTestServices.LogValidationErrors("No errors expected");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("TestFrequency").SingleElement;

            DomainTypeDescriptor.CreatePropertyDescriptor(constraint, FrequencyConstraint.MaxFrequencyDomainPropertyId).SetValue(constraint, 1);
            myTestServices.LogValidationErrors("Error introduced");

            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                constraint.MinFrequency = 3;
                constraint.MaxFrequency = 4;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error cleared with code");
            store.UndoManager.Undo();
            ((IORMToolServices)store).ModelErrorActivationService.ActivateError(constraint, constraint.FrequencyConstraintExactlyOneError);
            myTestServices.LogValidationErrors("Fixing error with error activation service");
        }
Пример #19
0
        public void DTBlankTest2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];

            model.Store.ElementDirectory.FindElement(UnspecifiedDataType.DomainClassId);
            UnspecifiedDataType unspecified = model.Store.ElementDirectory.FindElements <UnspecifiedDataType>()[0];

            ObjectType o = (ObjectType)model.ObjectTypesDictionary.GetElement("WifeId").SingleElement;


            using (Transaction t = store.TransactionManager.BeginTransaction("Add invalid data type error"))
            {
                //Make the error
                o.DataType = unspecified;
                t.Commit();
            }

            myTestServices.LogValidationErrors("After adding error");
        }
Пример #20
0
        public void MandatoryMandatory_1a(Store store)
        {
            myTestServices.LogValidationErrors("Start with no Error");
            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role                role_A     = (Role)store.ElementDirectory.GetElement(new Guid("FA2156EE-8612-47F3-8DB8-861814BAD997"));
            Role                role_B     = (Role)store.ElementDirectory.GetElement(new Guid("7DD25522-062E-4134-8B7A-F453FD979281"));
            MandatoryConstraint constraint = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint1").SingleElement;

            myTestServices.LogMessage("Introducing error via creating additional implied mandatory constraint");
            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Costraint"))
            {
                role_A.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error Received. Proceed to removal via removing the other Mandatory Constraint");
            using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed.");
        }
Пример #21
0
        public void Test3(Store store)
        {
            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "OriginalOrder");
            ORMModel   model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            ObjectType objectType = (ObjectType)model.ObjectTypesDictionary.GetElement("A").FirstElement;

            myTestServices.LogMessage("Reorder columns on composite pid with no referenced composite elements");
            using (Transaction t = store.TransactionManager.BeginTransaction("Reorder columns on pid with no referenced composite elements"))
            {
                objectType.PreferredIdentifier.RoleCollection.Move(0, 1);
                t.Commit();
            }
            objectType = (ObjectType)model.ObjectTypesDictionary.GetElement("E").FirstElement;
            myTestServices.Compare(store, (MethodInfo)MethodInfo.GetCurrentMethod(), "AfterReorder");

            myTestServices.LogMessage("Reorder columns on composite pid with referenced composite elements");
            using (Transaction t = store.TransactionManager.BeginTransaction("Reorder columns on pid with no referenced composite elements"))
            {
                objectType.PreferredIdentifier.RoleCollection.Move(0, 1);
                t.Commit();
            }
        }
Пример #22
0
        public void ExclusionMandatoryContra_1b(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            Role                role       = (Role)store.ElementDirectory.GetElement(new Guid("1C424E34-8369-41EC-850F-FD24E7B30C7A"));
            ExclusionConstraint constraint = (ExclusionConstraint)model.ConstraintsDictionary.GetElement("ExclusionConstraint1").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed upon Removal of Exclusion Constraint");
        }
Пример #23
0
        public void NMinus1Test2a(Store store)
        {
            myTestServices.LogValidationErrors("Before adding error");
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FactType fact  = (FactType)store.ElementDirectory.GetElement(new Guid("655E4D9B-9835-4BE2-A7BC-FEBE51A32E84"));
            LinkedElementCollection <RoleBase> roles = fact.RoleCollection;


            using (Transaction t = store.TransactionManager.BeginTransaction("Fix Constraint"))
            {
                foreach (UniquenessConstraint constraint in fact.GetInternalConstraints <UniquenessConstraint>())
                {
                    //Make the error
                    constraint.RoleCollection.Clear();
                    constraint.RoleCollection.Add(roles[0].Role);
                    break;
                }

                t.Commit();
            }
            myTestServices.LogValidationErrors("After adding error");
        }
Пример #24
0
        public void Test1(Store store)
        {
            // The store has been preloaded at this point with the .orm file specified in the
            // Tests.Test1.Compare.orm resource embedded into this project. If an embedded resource
            // is not found with this name, then a new orm file is created by loading the default
            // 'ORM Model File' template. This creates a model called 'NewModel' with a single diagram
            // attached to it.

            // Dump a report of the current model validation errors. The loaded file is missing an
            // internal constraint on a fact type, so we expect errors
            myTestServices.LogValidationErrors("Before constraint repair");

            // Find the fact that that needs fixing and repair it
            //ORMModel model = (ORMModel)store.ElementDirectory.GetElement(ORMModel.DomainClassId);
            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];
            FactType fact  = (FactType)store.ElementDirectory.GetElement(new Guid("CB33E377-9ADC-46BA-8E1B-24AE46BC0854"));
            Role     role  = fact.RoleCollection[1].Role;

            // At this point, we either need to open a transaction on the store with
            // using (Transaction t = store.TransactionManager.BeginTransaction("Transaction name"))
            // or we grab the property descriptor, which emulates setting the property through the
            // property grid and pushes a transaction for us.

            DomainTypeDescriptor.CreatePropertyDescriptor(role, Role.MultiplicityDomainPropertyId).SetValue(role, RoleMultiplicity.ExactlyOne);

            // Turn the following code back on to demonstrate a comparison failure

            // ~~ outdated code, do not turn on ~~//
            //fact = (FactType)model.FactTypesDictionary.GetElement("FactType2").SingleElement;
            //fact.CreatePropertyDescriptor(store.MetaDataDirectory.FindMetaAttribute(NamedElement.NameMetaAttributeGuid), fact).SetValue(fact, "changeFactType2");
            // ~~ /outdated code, do not turn on ~~//


            // After the method exits, the Compare and LogValidationErrors methods will be run automatically against
            // the test service. The expected results for the Compare are in Tests.Test1.Compare.orm. You can also
            // compare at intermediate stages by explicitly running the IORMToolTestServices.Compare function, generally
            // with a reference name to distinguish the intermediate stages from the automatic comparison.
        }
Пример #25
0
        public void MandatoryMandatory_1b(Store store)
        {
            myTestServices.LogValidationErrors("Start with one Implication Error");
            ORMModel            model        = store.ElementDirectory.FindElements <ORMModel>()[0];
            MandatoryConstraint constraint_1 = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint1").SingleElement;
            MandatoryConstraint constraint_2 = (MandatoryConstraint)model.ConstraintsDictionary.GetElement("InclusiveOrConstraint2").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint"))
            {
                constraint_1.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed with removal of a Constraint");
            myTestServices.LogValidationErrors("Undo to bring to initial condition");
            store.UndoManager.Undo();

            myTestServices.LogValidationErrors("Proceed to remove the other Mandatory Constraint");
            using (Transaction t = store.TransactionManager.BeginTransaction("Remove a Mandatory Costraint"))
            {
                constraint_2.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("All Errors Removed");
        }
Пример #26
0
        private void SaveChanges()
        {
            ORMModel model = myModel;
            ModelErrorDisplayFilter filter = model.ModelErrorDisplayFilter;
            Store store = model.Store;

            using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.ModelErrorDisplayFilterChangeTransactionName))
            {
                bool       deleteFilter = true, anyChanges = false;
                Error[]    errors     = myErrors;
                Category[] categories = myCategories;
                foreach (Category category in categories)
                {
                    bool allExcluded = true, allIncluded = true;

                    if (category.FirstError == -1)
                    {
                        allExcluded = false;
                        allIncluded = true;
                    }
                    else
                    {
                        for (int i = category.FirstError; i <= category.LastError; ++i)
                        {
                            Error error = errors[i];
                            if (error.IsExcluded != error.WasExcluded)
                            {
                                anyChanges = true;
                            }
                            if (error.IsExcluded)
                            {
                                deleteFilter = false;

                                allIncluded = false;
                            }
                            else
                            {
                                allExcluded = false;
                            }

                            if (anyChanges && !deleteFilter && !allExcluded && !allIncluded)
                            {
                                break;
                            }
                        }
                    }

                    if (allIncluded)
                    {
                        category.IsExcluded = false;
                    }
                    else if (allExcluded)
                    {
                        category.IsExcluded = true;
                    }
                }

                if (deleteFilter)
                {
                    //if all errors are included, we can delete the filter
                    anyChanges = true;
                    if (filter != null)
                    {
                        filter.Delete();
                    }
                }
                else if (anyChanges)
                {
                    if (filter == null)
                    {
                        filter       = new ModelErrorDisplayFilter(store);
                        filter.Model = model;
                    }

                    foreach (Category category in categories)
                    {
                        if (category.Type != null)
                        {
                            filter.ToggleCategory(category.Type, category.IsExcluded);
                        }
                    }

                    foreach (Error error in errors)
                    {
                        filter.ToggleError(error.Type, error.IsExcluded);
                    }

                    filter.CommitChanges();
                }
                if (anyChanges && t.HasPendingChanges)
                {
                    t.Commit();
                }
            }
        }
 /// <summary>
 /// Sets the Reference modes
 /// </summary>
 /// <param name="model"></param>
 public void SetModel(ORMModel model)
 {
     myHeaders.SetModel(model);
 }
Пример #28
0
        private void DrawDiagram(bool refresh, ModelElement element, IHierarchyContextEnabled hierarchyElement)
        {
            bool storeChange = false;
            if (hierarchyElement == null && (myDiagram == null || (element != null && (storeChange = (element.Store != myDiagram.Store)))))
            {
                ModelElement selectedElement = element;
                element = myCurrentlySelectedObject as ModelElement;
                if (element != null && ((element.IsDeleted || element.Store == null) || storeChange))
                {
                    myCurrentlySelectedObject = null;
                    mySelectedPartitionId = null;
                    RemoveDiagram();
                }
                hierarchyElement = myCurrentlySelectedObject;
                if (hierarchyElement == null && selectedElement != null && !selectedElement.IsDeleted && selectedElement.Store != null)
                {
                    ORMModel attachToModel = selectedElement as ORMModel;
                    if (attachToModel != null)
                    {
                        EnsureDiagram(attachToModel);
                    }
                }
            }
            else if (hierarchyElement == myCurrentlySelectedObject && hierarchyElement != null && !refresh && (myDiagram != null && myDiagram.HasChildren))
            {
                return;
            }
            if (hierarchyElement == null)
            {
                return;
            }
            myCurrentlySelectedObject = hierarchyElement;
            mySelectedPartitionId = ((ModelElement)hierarchyElement).Partition.AlternateId;
            ORMModel model = hierarchyElement.Model;
            if (model == null)
            {
                return;
            }
            this.EnsureDiagram(model);
            if (myDiagram == null)
            {
                return;
            }
            Store store = element.Store;
            IORMToolServices toolServices = (IORMToolServices)store;
            if (!toolServices.CanAddTransaction)
            {
                return;
            }
            using (Transaction t = store.TransactionManager.BeginTransaction("Draw Context Diagram"))
            {
                myDiagram.NestedChildShapes.Clear();
                myDiagram.AutoPopulateShapes = true;

                PlaceObject(hierarchyElement);
                LinkedElementCollection<ShapeElement> collection = myDiagram.NestedChildShapes;
                LayoutManager bl = new LayoutManager(myDiagram, toolServices.GetLayoutEngine(typeof(ORMRadialLayoutEngine)));
                foreach (ShapeElement shape in collection)
                {
                    bl.AddShape(shape, false);
                }
                bl.Layout(true);

                myDiagram.AutoPopulateShapes = false;
                if (t.HasPendingChanges)
                {
                    t.Commit();
                }
            }
            return;
        }
 /// <summary>
 /// Sets the reference modes for the class
 /// </summary>
 /// <param name="model"></param>
 public void SetModel(ORMModel model)
 {
     myCustomBranch.SetModel(model);
     myIntrinsicBranch.SetModel(model);
     myReferenceModeKindsBranch.SetModel(model);
 }
Пример #30
0
        /// <summary>
        /// Implements <see cref="IModelErrorActivation.ActivateModelError"/> for
        /// the <see cref="ValueComparisonConstraintOperatorNotSpecifiedError"/>
        /// </summary>
        protected new bool ActivateModelError(ModelError error)
        {
            ValueComparisonConstraintOperatorNotSpecifiedError operatorError;
            ValueComparisonRolesNotComparableError             comparabilityError;
            ValueComparisonConstraint constraint;
            Store store;
            bool  retVal = true;

            if (null != (operatorError = error as ValueComparisonConstraintOperatorNotSpecifiedError))
            {
                store      = Store;
                constraint = operatorError.ValueComparisonConstraint;
                EditorUtility.ActivatePropertyEditor(
                    (store as IORMToolServices).ServiceProvider,
                    DomainTypeDescriptor.CreatePropertyDescriptor(constraint, ValueComparisonConstraint.OperatorDomainPropertyId),
                    true);
            }
            else if (null != (comparabilityError = error as ValueComparisonRolesNotComparableError))
            {
                constraint = comparabilityError.ValueComparisonConstraint;
                LinkedElementCollection <Role> constraintRoles = constraint.RoleCollection;
                Role role1;
                Role role2;
                ObjectTypePlaysRole rolePlayerLink1;
                ObjectTypePlaysRole rolePlayerLink2;
                ObjectType          rolePlayer1 = null;
                ObjectType          rolePlayer2 = null;
                Role[] valueRoles1 = null;
                Role[] valueRoles2 = null;
                // The default behavior is to activate the role sequence
                // for editing. However, if the problem is with a single
                // resolved value type, and the units are correct, then
                // we need to select the first directly detached object.
                if (constraintRoles.Count == 2 &&
                    null != (rolePlayerLink1 = ObjectTypePlaysRole.GetLinkToRolePlayer(role1 = constraintRoles[0])) &&
                    null != (rolePlayerLink2 = ObjectTypePlaysRole.GetLinkToRolePlayer(role2 = constraintRoles[1])) &&
                    (rolePlayerLink1.RolePlayer == rolePlayerLink2.RolePlayer ||
                     (null != (valueRoles1 = role1.GetValueRoles()) &&
                      null != (valueRoles2 = role2.GetValueRoles()) &&
                      DataType.IsComparableValueType(rolePlayer1 = valueRoles1[0].RolePlayer, rolePlayer2 = valueRoles2[0].RolePlayer, !constraint.IsDirectional))))
                {
                    bool verifiedReferenceMode = true;
                    if (valueRoles1 != null)
                    {
                        ORMModel      model          = null;
                        ReferenceMode referenceMode1 = (valueRoles1.Length > 1) ?
                                                       ReferenceMode.FindReferenceModeFromEntityNameAndValueName(rolePlayer1.Name, valueRoles1[1].RolePlayer.Name, model = constraint.ResolvedModel) :
                                                       null;
                        ReferenceMode referenceMode2 = (valueRoles2.Length > 1) ?
                                                       ReferenceMode.FindReferenceModeFromEntityNameAndValueName(rolePlayer2.Name, valueRoles2[1].RolePlayer.Name, model ?? constraint.ResolvedModel) :
                                                       null;
                        bool referenceMode1IsUnit = referenceMode1 != null && referenceMode1.Kind.ReferenceModeType == ReferenceModeType.UnitBased;
                        bool referenceMode2IsUnit = referenceMode2 != null && referenceMode2.Kind.ReferenceModeType == ReferenceModeType.UnitBased;
                        verifiedReferenceMode = referenceMode1IsUnit ? (referenceMode2IsUnit && referenceMode1 == referenceMode2) : !referenceMode2IsUnit;
                    }
                    if (verifiedReferenceMode)
                    {
                        // Find a connected role player
                        foreach (ExternalConstraintLink constraintLink in MultiShapeUtility.GetEffectiveAttachedLinkShapes <ExternalConstraintLink>(this))
                        {
                            FactTypeShape factTypeShape;
                            if (constraintLink.AssociatedConstraintRole.Role == role1 &&
                                null != (factTypeShape = constraintLink.FromShape as FactTypeShape))
                            {
                                foreach (RolePlayerLink rolePlayerLinkShape in MultiShapeUtility.GetEffectiveAttachedLinkShapes <RolePlayerLink>(factTypeShape))
                                {
                                    if (rolePlayerLinkShape.AssociatedRolePlayerLink == rolePlayerLink1)
                                    {
                                        Diagram.ActiveDiagramView.Selection.Set(new DiagramItem(rolePlayerLinkShape.ToShape));
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
                ActivateNewRoleSequenceConnectAction(null);
            }
            else
            {
                retVal = base.ActivateModelError(error);
            }
            return(retVal);
        }