Ejemplo n.º 1
0
        /// <summary>
        /// Provide description information for the passthrough DataType properties
        /// </summary>
        protected override string GetDescription(ElementPropertyDescriptor propertyDescriptor)
        {
            Guid propertyId = propertyDescriptor.DomainPropertyInfo.Id;
            Guid passthroughPropertyId;

            if (propertyId == Column.DataTypeScaleDomainPropertyId)
            {
                passthroughPropertyId = ObjectType.DataTypeScaleDomainPropertyId;
            }
            else if (propertyId == Column.DataTypeLengthDomainPropertyId)
            {
                passthroughPropertyId = ObjectType.DataTypeLengthDomainPropertyId;
            }
            else
            {
                return(base.GetDescription(propertyDescriptor));
            }
            Column     column;
            ObjectType valueType;

            if (null != (column = propertyDescriptor.ModelElement as Column) &&
                null != (valueType = column.AssociatedValueType))
            {
                return(DomainTypeDescriptor.CreatePropertyDescriptor(valueType, valueType.Store.DomainDataDirectory.GetDomainProperty(passthroughPropertyId)).Description);
            }
            return(base.GetDescription(propertyDescriptor));
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Activate the Name property in the Properties Window
        /// for the specified element
        /// </summary>
        /// <param name="targetElement">The underlying model element with a name property</param>
        protected void ActivateNameProperty(ModelElement targetElement)
        {
            Store store = Store;

            EditorUtility.ActivatePropertyEditor(
                (store as IORMToolServices).ServiceProvider,
                DomainTypeDescriptor.CreateNamePropertyDescriptor(targetElement),
                false);
        }
                        public GroupingTypeData(ElementGroupingType groupingTypeInstance, DomainClassInfo groupingTypeClassInfo)
                        {
                            GroupingTypeInstance  = groupingTypeInstance;
                            GroupingTypeClassInfo = groupingTypeClassInfo;
                            Type groupingTypeClass = groupingTypeClassInfo.ImplementationClass;

                            DisplayName    = DomainTypeDescriptor.GetDisplayName(groupingTypeClass);
                            Description    = DomainTypeDescriptor.GetDescription(groupingTypeClass);
                            SelectionState = (groupingTypeInstance != null) ? (GroupingTypeSelectionState.InitiallySelected | GroupingTypeSelectionState.CurrentlySelected) : 0;
                        }
Ejemplo n.º 6
0
            public static PropertyDescriptor CreateDescriptor(ModelElement contextElement)
            {
                Store store = contextElement.Store;
                IList <DiagramDisplay> containers = store.ElementDirectory.FindElements <DiagramDisplay>();

                if (containers.Count != 0)
                {
                    DiagramDisplay     container  = containers[0];
                    PropertyDescriptor descriptor = DomainTypeDescriptor.CreatePropertyDescriptor(container, store.DomainDataDirectory.GetDomainProperty(DiagramDisplay.SaveDiagramPositionDomainPropertyId));
                    return(new DiagramContextDescriptor(container, descriptor));
                }
                return(null);
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a property descriptor for the given property on
        /// the element to emulate the behavior of modifying this
        /// property in the properties window. This will succeed if the property
        /// passed in has a corresponding meta attribute.
        /// </summary>
        /// <param name="element">The element to create a descriptor for</param>
        /// <param name="propertyName">The name of the property on the native object.
        /// Note that the name of this property may be displayed differently in the
        /// properties window. For example, Role.RolePlayerDisplay is shown as RolePlayer
        /// in the properties window.</param>
        /// <returns>PropertyDescriptor, or null if not available</returns>
        public PropertyDescriptor CreatePropertyDescriptor(ModelElement element, string propertyName)
        {
            Type         elementType = element.GetType();
            PropertyInfo propInfo    = elementType.GetProperty(propertyName);

            if (propInfo != null)
            {
                DomainPropertyInfo attrInfo = element.Store.DomainDataDirectory.FindDomainClass(propInfo.DeclaringType).FindDomainProperty(propertyName, true);
                if (attrInfo != null)
                {
                    return(DomainTypeDescriptor.CreatePropertyDescriptor(element, attrInfo));
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This method adds the passed in ExtensionModelBinding to the ListView on the ExtensionManager dialogue.
        /// </summary>
        /// <param name="extensionBinding">The extension you want to add.</param>
        private void AddItemToListView(ExtensionModelBinding extensionBinding)
        {
            Type         type = extensionBinding.Type;
            ListViewItem lvi  = new ListViewItem();

            lvi.Tag = extensionBinding.NamespaceUri;
            if (null != myStore.FindDomainModel(extensionBinding.DomainModelId))
            {
                lvi.Checked = true;
            }

            //Add the DisplayName
            lvi.SubItems.Add(DomainTypeDescriptor.GetDisplayName(type));

            //Add the Description
            lvi.SubItems.Add(DomainTypeDescriptor.GetDescription(type));

            lvExtensions.Items.Add(lvi);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Implements IModelErrorActivation.ActivateModelError
        /// </summary>
        protected new bool ActivateModelError(ModelError error)
        {
            RingConstraintTypeNotSpecifiedError ringTypeError;
            bool retVal = true;

            if (null != (ringTypeError = error as RingConstraintTypeNotSpecifiedError))
            {
                Store          store      = Store;
                RingConstraint constraint = ringTypeError.RingConstraint;
                EditorUtility.ActivatePropertyEditor(
                    (store as IORMToolServices).ServiceProvider,
                    DomainTypeDescriptor.CreatePropertyDescriptor(constraint, RingConstraint.RingTypeDomainPropertyId),
                    true);
            }
            else
            {
                retVal = base.ActivateModelError(error);
            }
            return(retVal);
        }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
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.
        }
                public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                {
                    ElementGrouping grouping;
                    LinkedElementCollection <ElementGroupingType> groupingTypes;
                    int groupingTypeCount;

                    if (destinationType == typeof(string) &&
                        null != context &&
                        null != (grouping = context.Instance as ElementGrouping) &&
                        0 != (groupingTypeCount = (groupingTypes = grouping.GroupingTypeCollection).Count))
                    {
                        if (groupingTypeCount == 1)
                        {
                            return(DomainTypeDescriptor.GetDisplayName(groupingTypes[0].GetType()));
                        }
                        else
                        {
                            StringBuilder builder   = new StringBuilder();
                            TextInfo      textInfo  = culture.TextInfo;
                            string        separator = textInfo.ListSeparator;
                            if (!char.IsWhiteSpace(separator, separator.Length - 1))
                            {
                                separator += " ";
                            }
                            for (int i = 0; i < groupingTypeCount; ++i)
                            {
                                if (i != 0)
                                {
                                    builder.Append(separator);
                                }
                                builder.Append(DomainTypeDescriptor.GetDisplayName(groupingTypes[i].GetType()));
                            }
                            return(builder.ToString());
                        }
                    }
                    return(base.ConvertTo(context, culture, value, destinationType));
                }
Ejemplo n.º 13
0
            public static ExpandableExtensionPropertyDescriptor CreateExtensionDescriptor(IORMPropertyExtension extensionElement)
            {
                ModelElement       element = extensionElement as ModelElement;
                DomainPropertyInfo extensionExpandableTopLevelPropertyInfo = element.Store.DomainDataDirectory.FindDomainProperty(extensionElement.ExtensionExpandableTopLevelPropertyId);

                // If ExtensionExpandableTopLevelPropertyGuid is invalid or Guid.Empty, FindDomainProperty returns null.
                bool readOnly = (extensionExpandableTopLevelPropertyInfo == null);

                PropertyDescriptor        descriptor;
                ExpandableObjectConverter expandableConverter;

                if (!readOnly)
                {
                    descriptor          = DomainTypeDescriptor.CreatePropertyDescriptor(element, extensionExpandableTopLevelPropertyInfo);
                    expandableConverter = new ExpandableExtensionConverter(extensionElement, descriptor);
                }
                else
                {
                    descriptor          = null;
                    expandableConverter = new ExpandableObjectConverter();
                }

                return(new ExpandableExtensionPropertyDescriptor(extensionElement, expandableConverter, readOnly, descriptor));
            }
Ejemplo n.º 14
0
        /// <summary>
        /// Add shared model error activation handlers. Activation handlers are
        /// static, this is called once during intitial load.
        /// </summary>
        /// <param name="store">The <see cref="Store"/></param>
        public static void RegisterModelErrorActivators(Store store)
        {
            IORMToolServices toolServices;
            IORMModelErrorActivationService activationService;

            if (null != (toolServices = store as IORMToolServices) &&
                null != (activationService = toolServices.ModelErrorActivationService))
            {
                #region Role error activation
                activationService.RegisterErrorActivator(
                    typeof(Role),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is RolePlayerRequiredError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            RoleTypeDescriptor.GetRolePlayerDisplayPropertyDescriptor((Role)selectedElement),
                            true);
                    }
                    else if (error is ValueConstraintError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, Role.ValueRangeTextDomainPropertyId),
                            false);
                    }
                    else if (error is CardinalityRangeOverlapError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            RoleTypeDescriptor.CardinalityDisplayPropertyDescriptor,
                            false);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // Role error activation
                #region ValueConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(ValueConstraint),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is ValueConstraintError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, ValueConstraint.TextDomainPropertyId),
                            false);
                    }
                    else if (error is ConstraintDuplicateNameError)
                    {
                        ActivateNameProperty(selectedElement);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // ValueConstraint error activation
                #region CardinalityConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(CardinalityConstraint),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is CardinalityRangeOverlapError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, CardinalityConstraint.TextDomainPropertyId),
                            false);
                    }
                    else if (error is ConstraintDuplicateNameError)
                    {
                        ActivateNameProperty(selectedElement);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // CardinalityConstraint error activation
                #region SetConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(SetConstraint),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is ConstraintDuplicateNameError)
                    {
                        ActivateNameProperty(selectedElement);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // SetConstraint error activation
                #region FrequencyConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(FrequencyConstraint),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is FrequencyConstraintExactlyOneError)
                    {
                        ((FrequencyConstraint)selectedElement).ConvertToUniquenessConstraint();
                    }
                    else if (error is FrequencyConstraintNonRestrictiveRangeError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, FrequencyConstraint.MinFrequencyDomainPropertyId),
                            false);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // FrequencyConstraint error activation
                #region RingConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(RingConstraint),
                    false,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is RingConstraintTypeNotSpecifiedError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, RingConstraint.RingTypeDomainPropertyId),
                            true);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // RingConstraint error activation
                #region ValueComparisonConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(ValueComparisonConstraint),
                    false,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    if (error is ValueComparisonConstraintOperatorNotSpecifiedError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, ValueComparisonConstraint.OperatorDomainPropertyId),
                            true);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // ValueComparisonConstraint error activation
                #region SetComparisonConstraint error activation
                activationService.RegisterErrorActivator(
                    typeof(SetComparisonConstraint),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    ConstraintDuplicateNameError duplicateName;
                    if (null != (duplicateName = error as ConstraintDuplicateNameError))
                    {
                        ActivateNameProperty(selectedElement);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // SetComparisonConstraint error activation
                #region ObjectType error activation
                activationService.RegisterErrorActivator(
                    typeof(ObjectType),
                    false,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    bool retVal = true;
                    PopulationMandatoryError populationMandatory;
                    if (error is DataTypeNotSpecifiedError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            ObjectTypeTypeDescriptor.DataTypeDisplayPropertyDescriptor,
                            true);
                    }
                    else if (error is EntityTypeRequiresReferenceSchemeError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, ObjectType.ReferenceModeDisplayDomainPropertyId),
                            true);
                    }
                    else if (error is ValueConstraintError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, ObjectType.ValueRangeTextDomainPropertyId),
                            false);
                    }
                    else if (error is CardinalityRangeOverlapError)
                    {
                        EditorUtility.ActivatePropertyEditor(
                            services.ServiceProvider,
                            ObjectTypeTypeDescriptor.CardinalityDisplayPropertyDescriptor,
                            false);
                    }
                    else if (error is ObjectTypeDuplicateNameError)
                    {
                        ActivateNameProperty(selectedElement);
                    }
                    else if (error is ObjectifiedInstanceRequiredError || error is TooFewEntityTypeRoleInstancesError)
                    {
                        ORMDesignerPackage.SamplePopulationEditorWindow.ActivateModelError(error);
                    }
                    else if (null != (populationMandatory = error as PopulationMandatoryError))
                    {
                        retVal = ORMDesignerPackage.SamplePopulationEditorWindow.AutoCorrectMandatoryError(populationMandatory, (ObjectType)selectedElement);
                    }
                    else
                    {
                        retVal = false;
                    }
                    return(retVal);
                });
                #endregion                 // ObjectType error activation
                #region FactType error activation
                activationService.RegisterErrorActivator(
                    typeof(FactType),
                    true,
                    delegate(IORMToolServices services, ModelElement selectedElement, ModelError error)
                {
                    PopulationMandatoryError populationMandatory;
                    TooFewReadingRolesError tooFew;
                    TooManyReadingRolesError tooMany;
                    ReadingRequiresUserModificationError userModification;
                    DuplicateReadingSignatureError duplicateSignature;
                    FactTypeRequiresReadingError noReading;
                    ValueConstraintError valueError;
                    CardinalityRangeOverlapError cardinalityRangeError;
                    FactType factType;
                    ImpliedInternalUniquenessConstraintError implConstraint;
                    Reading reading = null;
                    bool retVal     = true;
                    if (null != (populationMandatory = error as PopulationMandatoryError))
                    {
                        retVal = ORMDesignerPackage.SamplePopulationEditorWindow.AutoCorrectMandatoryError(populationMandatory, null, (FactType)selectedElement);
                    }
                    else if (null != (tooFew = error as TooFewReadingRolesError))
                    {
                        reading = tooFew.Reading;
                    }
                    else if (null != (tooMany = error as TooManyReadingRolesError))
                    {
                        reading = tooMany.Reading;
                    }
                    else if (null != (noReading = error as FactTypeRequiresReadingError))
                    {
                        factType = noReading.FactType;
                        Debug.Assert(factType != null);
                        ORMReadingEditorToolWindow newWindow = ORMDesignerPackage.ReadingEditorWindow;
                        newWindow.Show();
                        newWindow.ActivateReading(factType);
                    }
                    else if (null != (userModification = error as ReadingRequiresUserModificationError))
                    {
                        reading = userModification.Reading;
                    }
                    else if (null != (duplicateSignature = error as DuplicateReadingSignatureError))
                    {
                        factType = (FactType)selectedElement;
                        LinkedElementCollection <Reading> readings = duplicateSignature.ReadingCollection;
                        foreach (Reading testReading in readings)
                        {
                            if (testReading.ReadingOrder.FactType == factType)
                            {
                                reading = testReading;
                                break;
                            }
                        }
                        if (reading == null)
                        {
                            Objectification objectification;
                            if (null != (objectification = factType.Objectification))
                            {
                                foreach (Reading testReading in readings)
                                {
                                    if (testReading.ReadingOrder.FactType.ImpliedByObjectification == objectification)
                                    {
                                        reading = testReading;
                                        break;
                                    }
                                }
                            }
                            if (reading == null)
                            {
                                // Defensive, shouldn't happen.
                                reading = readings[0];
                            }
                        }
                    }
                    else if (null != (implConstraint = error as ImpliedInternalUniquenessConstraintError))
                    {
                        IServiceProvider provider;
                        IVsUIShell shell;
                        if (null != (provider = services.ServiceProvider) &&
                            null != (shell = (IVsUIShell)provider.GetService(typeof(IVsUIShell))))
                        {
                            Guid g = new Guid();
                            int pnResult;
                            shell.ShowMessageBox(0, ref g, ResourceStrings.PackageOfficialName,
                                                 ResourceStrings.ImpliedInternalConstraintFixMessage,
                                                 "", 0, OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                                                 OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_QUERY, 0, out pnResult);
                            if (pnResult == (int)DialogResult.Yes)
                            {
                                implConstraint.FactType.RemoveImpliedInternalUniquenessConstraints();
                            }
                        }
                    }
                    else if (null != (valueError = error as ValueConstraintError))
                    {
                        if (valueError.ContextValueConstraint is RoleValueConstraint)
                        {
                            EditorUtility.ActivatePropertyEditor(
                                services.ServiceProvider,
                                DomainTypeDescriptor.CreatePropertyDescriptor(selectedElement, ObjectType.ValueRangeTextDomainPropertyId),
                                false);
                        }
                        else
                        {
                            retVal = false;
                        }
                    }
                    else if (null != (cardinalityRangeError = error as CardinalityRangeOverlapError))
                    {
                        if (cardinalityRangeError.CardinalityConstraint is ObjectTypeCardinalityConstraint)
                        {
                            EditorUtility.ActivatePropertyEditor(
                                services.ServiceProvider,
                                ObjectTypeTypeDescriptor.CardinalityDisplayPropertyDescriptor,
                                false);
                        }
                        else
                        {
                            retVal = false;
                        }
                    }
                    else if (error is TooFewFactTypeRoleInstancesError || error is ObjectifyingInstanceRequiredError)
                    {
                        ORMDesignerPackage.SamplePopulationEditorWindow.ActivateModelError(error);
                    }
                    else
                    {
                        retVal = false;
                    }

                    if (reading != null)
                    {
                        // Open the reading editor window and activate the reading
                        ORMReadingEditorToolWindow window = ORMDesignerPackage.ReadingEditorWindow;
                        window.Show();
                        window.ActivateReading(reading);
                    }
                    return(retVal);
                });
                #endregion                 // FactType error activation
            }
        }
Ejemplo n.º 15
0
        public void ResolvePreferredTest1(Store store)
        {
            IElementDirectory   directory       = store.ElementDirectory;
            SubtypeFact         FiveToTwo       = (SubtypeFact)directory.GetElement(new Guid("9B85CC3F-FAA1-485B-A6CA-DE65165C6AE5"));
            SubtypeFact         FiveToThree     = (SubtypeFact)directory.GetElement(new Guid("C48F356A-DC20-4CD8-AD6A-EE4518622FFB"));
            SubtypeFact         SixToFive       = (SubtypeFact)directory.GetElement(new Guid("321CD412-8DAA-4D35-8D4E-D8D5915F07E0"));
            SubtypeFact         SixToSeven      = (SubtypeFact)directory.GetElement(new Guid("D6A4C2F2-3F99-4E2F-AB2F-407E03AB6F42"));
            SubtypeFact         FiveToFour      = (SubtypeFact)directory.GetElement(new Guid("DE1FC770-19A5-4CA9-AEF7-CE1204D80270"));
            SubtypeFact         SevenToFour     = (SubtypeFact)directory.GetElement(new Guid("71D29425-481E-445B-8F8A-63E9F29F761A"));
            ORMModel            model           = FiveToTwo.Model;
            RoleValueConstraint valueConstraint = (RoleValueConstraint)model.ConstraintsDictionary.GetElement("RoleValueConstraint1").SingleElement;

            myTestServices.LogValidationErrors("Expected three initial errors");

            myTestServices.LogMessage("Scenario 1: Make 5->2 preferred path, sibling and downstream subtypes should all be preferred");
            DomainTypeDescriptor.CreatePropertyDescriptor(FiveToTwo, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(FiveToTwo, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("5->4, 6->5, 6->7 are on the preferred path: " + (FiveToFour.ProvidesPreferredIdentifier && SixToFive.ProvidesPreferredIdentifier && SixToSeven.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a string type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 2: Make 5->3 preferred path, downstream subtypes are no ambiguous");
            DomainTypeDescriptor.CreatePropertyDescriptor(FiveToThree, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(FiveToThree, true);
            myTestServices.LogValidationErrors("Two errors expected");
            myTestServices.LogMessage("5->2, 5->4, 6->5, 6->7 are not preferred: " + (!(FiveToTwo.ProvidesPreferredIdentifier || FiveToFour.ProvidesPreferredIdentifier || SixToFive.ProvidesPreferredIdentifier || SixToSeven.ProvidesPreferredIdentifier)).ToString());

            myTestServices.LogMessage("Scenario 3: Make 6->5 preferred path");
            DomainTypeDescriptor.CreatePropertyDescriptor(SixToFive, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(SixToFive, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("6->7 is not on the preferred path: " + (!SixToSeven.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a number type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 4: Make 6->7 preferred path");
            DomainTypeDescriptor.CreatePropertyDescriptor(SixToSeven, SubtypeFact.ProvidesPreferredIdentifierDomainPropertyId).SetValue(SixToSeven, true);
            myTestServices.LogValidationErrors("No errors expected");
            myTestServices.LogMessage("6->5 is not on the preferred path: " + (!SixToFive.ProvidesPreferredIdentifier).ToString());
            myTestServices.LogMessage("ValueConstraint should be a string type: " + valueConstraint.Text);

            myTestServices.LogMessage("Scenario 5: Delete 7->4 to break subtype structure");
            using (Transaction t = store.TransactionManager.BeginTransaction("Break graph"))
            {
                SevenToFour.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Expecting invalid graph, detached valuetype, and no reference scheme errors");

            myTestServices.LogMessage("Scenario 6: Delete 6->5 to make graph valid");
            using (Transaction t = store.TransactionManager.BeginTransaction("Graph OK"))
            {
                SixToFive.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Expecting detached valuetype and no reference scheme errors");

            myTestServices.LogMessage("Scenario 7: Set identifier on 7 to clear errors");
            using (Transaction t = store.TransactionManager.BeginTransaction("Clear errors"))
            {
                SixToSeven.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
            myTestServices.LogValidationErrors("No errors expected");

            myTestServices.LogValidationErrors("Scenario 8: (Undo scenarios 5-7) Make 5->4 preferred path and give 4 an explicit id in one transaction");
            store.UndoManager.Undo();
            store.UndoManager.Undo();
            store.UndoManager.Undo();
            using (Transaction t = store.TransactionManager.BeginTransaction("Change id and make preferred in one transaction"))
            {
                // Note that doing this in the opposite order in two transactions has the same result
                FiveToFour.ProvidesPreferredIdentifier   = true;
                FiveToFour.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
            myTestServices.LogValidationErrors("No errors expected");

            myTestServices.LogValidationErrors("Scenario 9: (Undo scenario 8) Make 5->4 preferred path then give 4 an explicit id to make 5 and 6 ambiguous");
            store.UndoManager.Undo();
            using (Transaction t = store.TransactionManager.BeginTransaction("Change preferred path"))
            {
                FiveToFour.ProvidesPreferredIdentifier = true;
                t.Commit();
            }
            using (Transaction t = store.TransactionManager.BeginTransaction("Introduce id that interferes with split identifier path"))
            {
                FiveToFour.Supertype.ReferenceModeString = "id";
                t.Commit();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a property descriptor for the the given meta attribute.
        /// Property descriptors emulate the behavior of modifying this
        /// property in the properties window.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="attributeId">The meta attribute id for the property. This
        /// is available as a static field in the public object model of the element
        /// you're trying to set. For example, to change the name property of a FactType
        /// element you would use FactType.NameMetaAttributeGuid as your attributeId</param>
        /// <returns>PropertyDescriptor, or null if not available</returns>
        public PropertyDescriptor CreatePropertyDescriptor(ModelElement element, Guid attributeId)
        {
            DomainPropertyInfo attrInfo = element.Store.DomainDataDirectory.FindDomainProperty(attributeId);

            return((attrInfo != null) ? DomainTypeDescriptor.CreatePropertyDescriptor(element, attrInfo) : null);
        }
Ejemplo n.º 17
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);
        }