Ejemplo n.º 1
0
        /// <summary>
        /// Initial the role pattern and constraints for a standard
        /// subtype. This should be called after the subtype is parented
        /// by either the model or an alternate owner so that the created
        /// elements can also be properly parented.
        /// </summary>
        protected void InitializeIdentityFactType()
        {
            Store store;

            if (CopyMergeUtility.GetIntegrationPhase(store = this.Store) == CopyClosureIntegrationPhase.None)
            {
                IDictionary <object, object> contextInfo = store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
                try
                {
                    // Establish role collecton
                    contextInfo[InitializingIdentityFactTypeKey] = null;
                    LinkedElementCollection <RoleBase> roles = this.RoleCollection;
                    Partition         partition         = this.Partition;
                    SubtypeMetaRole   subTypeMetaRole   = new SubtypeMetaRole(partition);
                    SupertypeMetaRole superTypeMetaRole = new SupertypeMetaRole(partition);
                    roles.Add(subTypeMetaRole);
                    roles.Add(superTypeMetaRole);

                    // Add injection constraints
                    superTypeMetaRole.Multiplicity = RoleMultiplicity.ExactlyOne;
                    subTypeMetaRole.Multiplicity   = RoleMultiplicity.ZeroToOne;
                }
                finally
                {
                    contextInfo.Remove(InitializingIdentityFactTypeKey);
                }
            }
        }
        private static void FullyGenerateBarkerERModel(BarkerErModel barkerModel, AbstractionModel sourceModel, INotifyElementAdded notifyAdded)
        {
            LinkedElementCollection <EntityType>  barkerEntities = barkerModel.EntityTypeCollection;
            LinkedElementCollection <ConceptType> conceptTypes   = sourceModel.ConceptTypeCollection;
            Store store = barkerModel.Store;

            // Generate all Barker entities
            List <ConceptType> manyToMany = new List <ConceptType>();

            foreach (ConceptType conceptType in conceptTypes)
            {
                if (!IsSimpleManyToManyAssociation(conceptType))
                {
                    EntityType entity = new EntityType(
                        conceptType.Store,
                        new PropertyAssignment[] {
                        new PropertyAssignment(EntityType.NameDomainPropertyId, conceptType.Name)
                    });
                    new EntityTypeIsPrimarilyForConceptType(entity, conceptType);

                    barkerEntities.Add(entity);
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(entity, true);
                    }
                }
                else
                {
                    manyToMany.Add(conceptType);
                }
            }

            // For every concept type create all attributes that they represent, map uniquenesses that they participate in.
            int associationCounter = 0;

            foreach (ConceptType conceptType in conceptTypes)
            {
                if (!manyToMany.Contains(conceptType))
                {
                    CreateAttributesAndBinaryRelationships(conceptType, notifyAdded, ref associationCounter);
                }
                else
                {
                    CreateBinaryAssociation(conceptType, notifyAdded, ref associationCounter);
                }
            }

            // For each entity type in the Barker model generate relationships it plays and detemine which of its atrributes are mandatory and nullable.
            foreach (EntityType entity in barkerModel.EntityTypeCollection)
            {
                GenerateMandatoryConstraints(entity);
            }
        }
            /// <summary>
            /// Create a connection between a FactTypeShape and a FactType. Roles
            /// used in the connection are stored with the currently active connect action.
            /// </summary>
            /// <param name="sourceShapeElement">The source of the requested connection</param>
            /// <param name="targetShapeElement">The target of the requested connection</param>
            /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param>
            public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs)
            {
                IConstraint constraint;
                InternalUniquenessConstraintConnectAction action;
                IList <Role> selectedRoles;
                int          rolesCount;

                if ((null != (action = (sourceShapeElement.Diagram as ORMDiagram).InternalUniquenessConstraintConnectAction)) &&
                    (null != (constraint = action.ActiveConstraint)) &&
                    (null != (selectedRoles = action.SelectedRoleCollection)) &&
                    (0 != (rolesCount = selectedRoles.Count)))
                {
                    UniquenessConstraint iuConstraint;
                    if (null != (iuConstraint = constraint as UniquenessConstraint) &&
                        iuConstraint.IsInternal)
                    {
                        // Keep the collection ordered, this ends up as constraint order on objectified FactTypes
                        LinkedElementCollection <Role> roles = iuConstraint.RoleCollection;
                        int existingRolesCount = roles.Count;
                        for (int i = existingRolesCount - 1; i >= 0; --i)
                        {
                            Role testRole = roles[i];
                            if (!selectedRoles.Contains(testRole))
                            {
                                roles.Remove(testRole);
                                --existingRolesCount;
                            }
                        }
                        for (int i = 0; i < rolesCount; ++i)
                        {
                            Role selectedRole  = selectedRoles[i];
                            int  existingIndex = roles.IndexOf(selectedRole);
                            if (existingIndex == -1)
                            {
                                if (i < existingRolesCount)
                                {
                                    roles.Insert(i, selectedRole);
                                }
                                else if (!roles.Contains(selectedRole))
                                {
                                    roles.Add(selectedRole);
                                }
                                ++existingRolesCount;
                            }
                            else if (existingIndex != i)
                            {
                                roles.Move(existingIndex, i);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="FactType"/> with the specified <paramref name="arity"/>.
        /// </summary>
        /// <param name="store">
        /// The <see cref="Store"/> in which the new <see cref="FactType"/> should be created.
        /// </param>
        /// <param name="group">
        /// The <see cref="ElementGroup"/> to which the new <see cref="FactType"/> and its <see cref="Role"/>s should
        /// be added.
        /// </param>
        /// <param name="arity">
        /// The number of <see cref="Role"/>s that the new <see cref="FactType"/> should contain.
        /// </param>
        /// <returns>
        /// The newly created <see cref="FactType"/>.
        /// </returns>
        /// <remarks>
        /// The new <see cref="FactType"/> is added to <paramref name="group"/> as a root element.
        /// </remarks>
        private static FactType AddFactType(Store store, ElementGroup group, int arity)
        {
            FactType factType = new FactType(store, null);

            group.AddGraph(factType, true);
            LinkedElementCollection <RoleBase> roles = factType.RoleCollection;

            for (int i = 0; i < arity; i++)
            {
                Role role = new Role(store);
                roles.Add(role);
                group.AddGraph(role);
            }
            return(factType);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds the extension <see cref="ModelError"/> specified by <paramref name="extensionError"/> to the
        /// <see cref="IORMExtendableElement"/> specified by <paramref name="extendedElement"/>.
        /// </summary>
        public static void AddExtensionModelError(IORMExtendableElement extendedElement, ModelError extensionError)
        {
            if (extendedElement == null)
            {
                throw new ArgumentNullException("extendedElement");
            }
            if (extensionError == null)
            {
                throw new ArgumentNullException("extensionError");
            }
            LinkedElementCollection <ModelError> extensions = extendedElement.ExtensionModelErrorCollection;

            if (extensions != null)
            {
                extensions.Add(extensionError);
            }
        }
Ejemplo n.º 6
0
 private void SetReadingTextValue(string newValue)
 {
     if (!Store.InUndoRedoOrRollback)
     {
         LinkedElementCollection <Reading> readings = ReadingCollection;
         Reading reading;
         if (readings.Count > 0)
         {
             reading = readings[0];
         }
         else
         {
             reading = new Reading(Partition);
             readings.Add(reading);
         }
         reading.Text = newValue;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// ORM diagrams need to connect links to other links, but this is
        /// not supported directly by the framework, so we create a dummy
        /// node shape that tracks the center of the link line and connect
        /// to the shape instead. The currently ORM diagram requirements
        /// are simple: we are only called with an opposite ExternalConstraintShape,
        /// and we can return the same shape for all requests.
        /// Implements <see cref="IProvideConnectorShape.GetUniqueConnectorShape"/>
        /// </summary>
        protected NodeShape GetUniqueConnectorShape(ShapeElement oppositeShape, ModelElement ignoreLinkShapesFor)
        {
            LinkConnectorShape retVal = null;
            LinkedElementCollection <ShapeElement> childShapes = RelativeChildShapes;

            foreach (ShapeElement shape in childShapes)
            {
                retVal = shape as LinkConnectorShape;
                if (retVal != null)
                {
                    return(retVal);
                }
            }
            retVal = new LinkConnectorShape(Partition);
            RectangleD bounds = AbsoluteBoundingBox;

            childShapes.Add(retVal);
            retVal.Location = new PointD(bounds.Width / 2, bounds.Height / 2);
            return(retVal);
        }
        private void MapClrAttributesToAttributes(LinkedElementCollection <ClrAttribute> clrAttributes, LinkedElementCollection <Attribute> attributes, Store store)
        {
            attributes.Clear();

            foreach (var clrAttribute in clrAttributes)
            {
                var attribute = new Attribute(store);
                attribute.Name = clrAttribute.Name;

                foreach (var clrAttributeParameter in clrAttribute.Parameters)
                {
                    var attributeParameter = new AttributeParameter(store);
                    attributeParameter.Name  = clrAttributeParameter.Name;
                    attributeParameter.Value = clrAttributeParameter.Value;

                    attribute.Parameters.Add(attributeParameter);
                }

                attributes.Add(attribute);
            }
        }
Ejemplo n.º 9
0
        public static ElementLink Connect(ModelElement source, ModelElement target, string targetDataElementName)
        {
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(target, "target");

            if (CanAcceptSourceAndTarget(source, target))
            {
                if (source is DataContractBase)
                {
                    if (target is DataContract)
                    {
                        DataContractBase sourceAccepted = (DataContractBase)source;
                        Contract         targetAccepted = (Contract)target;
                        ElementLink      result         = new DataContractBaseCanBeContainedOnContracts(sourceAccepted, targetAccepted);
                        if (DomainClassInfo.HasNameProperty(result))
                        {
                            DomainClassInfo.SetUniqueName(result);
                        }

                        using (Transaction transaction = targetAccepted.Store.TransactionManager.BeginTransaction())
                        {
                            ModelElementReference dataElement = target.Store.ElementFactory.CreateElement(ModelElementReference.DomainClassId) as ModelElementReference;
                            dataElement.ModelElementGuid = result.Id;
                            dataElement.Type             = sourceAccepted.Name;

                            LinkedElementCollection <DataMember> members = ((DataContract)target).DataMembers;

                            dataElement.Name = GetDataElementName(sourceAccepted.Name, targetAccepted.Name, members);
                            members.Add(dataElement);

                            transaction.Commit();
                        }
                        return(result);
                    }
                }
            }

            Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one.");
            throw new InvalidOperationException();
        }
        private void AttributeTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (e.Node == addAttributeNode)
            {
                string newAttributeLabel = e.Label;
                e.CancelEdit = true;

                Attribute attribute = new Attribute(_store)
                {
                    Name = newAttributeLabel
                };
                _attributes.Add(attribute);
                IsDirty = true;

                TreeNode newAttribute = AttributeTree.Nodes.Insert(AttributeTree.Nodes.Count - 1, newAttributeLabel);
                newAttribute.Tag = attribute;
                TreeNode addParameter = CreateAddParameterNode(newAttribute);
                newAttribute.Expand();

                AttributeTree.BeginInvoke((Action)(() =>
                {
                    AttributeTree.SelectedNode = addParameter;
                    AttributeTree.StartLabelEdit();
                }));
            }
            else if (e.Node.IsAddParameterNode())
            {
                TreeNode  addParameter      = e.Node;
                TreeNode  attributeNode     = e.Node.Parent;
                Attribute attribute         = attributeNode.Tag as Attribute;
                string    newParameterLabel = e.Label;
                e.CancelEdit = true;

                AttributeParameter parameter = null;
                NamedPropertyEvaluation(newParameterLabel,
                                        (value) =>
                {
                    newParameterLabel = value;
                    parameter         = new AttributeParameter(_store)
                    {
                        Value = value
                    };
                },
                                        (name, value) =>
                {
                    newParameterLabel = string.Format("{0} = {1}", name, value);
                    parameter         = new AttributeParameter(_store)
                    {
                        Name = name, Value = value
                    };
                }
                                        );
                attribute.Parameters.Add(parameter);
                IsDirty = true;

                TreeNode newParameter = addParameter.Parent.Nodes.Insert(addParameter.Parent.Nodes.Count - 1, newParameterLabel);
                newParameter.Tag = parameter;
                SetParameterIcons(attributeNode.Nodes);

                AttributeTree.BeginInvoke((Action)(() =>
                {
                    AttributeTree.SelectedNode = addParameter;
                    AttributeTree.StartLabelEdit();
                }));
            }
            else
            {
                if (e.Node.Tag is Attribute)
                {
                    ((Attribute)e.Node.Tag).Name = e.Label;
                    e.Node.Text = e.Label;
                }
                else if (e.Node.Tag is AttributeParameter)
                {
                    AttributeParameter property = (AttributeParameter)e.Node.Tag;
                    NamedPropertyEvaluation(e.Label,
                                            (value) =>
                    {
                        e.Node.Text    = value;
                        property.Name  = null;
                        property.Value = value;
                    },
                                            (name, value) =>
                    {
                        e.Node.Text    = string.Format("{0} = {1}", name, value);
                        property.Name  = name;
                        property.Value = value;
                    }
                                            );
                }
                IsDirty = true;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Common place for code to deal with roles that exist in a fact
        /// but do not exist in the ReadingOrder objects that it contains.
        /// This allows it to be used by both the rule and to be called
        /// during post load model fixup.
        /// </summary>
        private static void ValidateReadingOrdersRoleCollection(FactType factType, RoleBase addedRole)
        {
            LinkedElementCollection <ReadingOrder> readingOrders;
            int orderCount;

            if (null == factType.UnaryRole &&
                0 != (orderCount = (readingOrders = factType.ReadingOrderCollection).Count))
            {
                bool            checkedContext = false;
                bool            insertAfter    = false;
                RoleBase        insertBeside   = null;
                IFormatProvider formatProvider = CultureInfo.InvariantCulture;
                for (int i = 0; i < orderCount; ++i)
                {
                    ReadingOrder ord = readingOrders[i];
                    LinkedElementCollection <RoleBase> roles = ord.RoleCollection;
                    if (!roles.Contains(addedRole))
                    {
                        if (!checkedContext)
                        {
                            checkedContext = true;
                            Dictionary <object, object> contextInfo = factType.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
                            object contextRole;
                            if (contextInfo.TryGetValue(FactType.InsertAfterRoleKey, out contextRole))
                            {
                                insertBeside = contextRole as RoleBase;
                                insertAfter  = true;
                            }
                            else if (contextInfo.TryGetValue(FactType.InsertBeforeRoleKey, out contextRole))
                            {
                                insertBeside = contextRole as RoleBase;
                            }
                        }
                        int insertIndex = -1;
                        if (insertBeside != null)
                        {
                            insertIndex = roles.IndexOf(insertBeside);
                        }

                        if (insertIndex != -1)
                        {
                            roles.Insert(insertIndex + (insertAfter ? 1 : 0), addedRole);
                        }
                        else
                        {
                            roles.Add(addedRole);
                        }
                        LinkedElementCollection <Reading> readings = ord.ReadingCollection;
                        int readingCount = readings.Count;
                        if (readingCount != 0)
                        {
                            if (insertIndex == -1)
                            {
                                string appendText = string.Concat("  {", (roles.Count - 1).ToString(CultureInfo.InvariantCulture), "}");
                                for (int j = 0; j < readingCount; ++j)
                                {
                                    Reading reading = readings[j];
                                    reading.SetAutoText(reading.Text + appendText);
                                }
                            }
                            else
                            {
                                for (int j = 0; j < readingCount; ++j)
                                {
                                    Reading reading = readings[j];
                                    reading.SetAutoText(Reading.ReplaceFields(
                                                            reading.Text,
                                                            delegate(int replaceIndex)
                                    {
                                        // UNDONE: Respect leading/trailing hyphen binding and keep them associated
                                        // with the corresponding role. Will require work well beyond the scope of this
                                        // routine.
                                        if (replaceIndex == insertIndex)
                                        {
                                            return(string.Concat("{", insertIndex.ToString(formatProvider), "} {", (insertIndex + 1).ToString(formatProvider), "}"));
                                        }
                                        else if (replaceIndex > insertIndex)
                                        {
                                            return(string.Concat("{", (replaceIndex + 1).ToString(formatProvider), "}"));
                                        }
                                        return(null);                                                // Leave as is
                                    }
                                                            ));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Update the diagram display order
        /// </summary>
        /// <param name="store">The current <see cref="Store"/></param>
        /// <param name="orderedDiagrams">An ordered list of diagrams</param>
        public static void UpdateDiagramDisplayOrder(Store store, IList <Diagram> orderedDiagrams)
        {
            DiagramDisplay         container  = null;
            IList <DiagramDisplay> containers = store.ElementDirectory.FindElements <DiagramDisplay>(false);

            if (containers.Count != 0)
            {
                container = containers[0];
            }
            using (Transaction t = store.TransactionManager.BeginTransaction(FrameworkResourceStrings.DiagramDisplayReorderDiagramsTransactionName))
            {
                int orderCount = orderedDiagrams.Count;
                if (orderCount == 0)
                {
                    if (container != null)
                    {
                        container.OrderedDiagramCollection.Clear();
                    }
                    return;
                }
                else if (container == null)
                {
                    container = new DiagramDisplay(store);
                }
                LinkedElementCollection <Diagram> existingDiagrams = container.OrderedDiagramCollection;
                int existingDiagramCount = existingDiagrams.Count;
                for (int i = existingDiagramCount - 1; i >= 0; --i)
                {
                    Diagram testDiagram = existingDiagrams[i];
                    if (!orderedDiagrams.Contains(testDiagram))
                    {
                        existingDiagrams.RemoveAt(i);
                        --existingDiagramCount;
                    }
                }
                for (int i = 0; i < orderCount; ++i)
                {
                    Diagram orderedDiagram = orderedDiagrams[i];
                    int     existingIndex  = existingDiagrams.IndexOf(orderedDiagram);
                    if (existingIndex == -1)
                    {
                        if (i < existingDiagramCount)
                        {
                            existingDiagrams.Insert(i, orderedDiagram);
                        }
                        else if (!existingDiagrams.Contains(orderedDiagram))
                        {
                            existingDiagrams.Add(orderedDiagram);
                        }
                        ++existingDiagramCount;
                    }
                    else if (existingIndex != i)
                    {
                        existingDiagrams.Move(existingIndex, i);
                    }
                }
                if (t.HasPendingChanges)
                {
                    t.Commit();
                }
            }
        }
Ejemplo n.º 13
0
            public static void ProcessFactType(FactType factType, INotifyElementAdded notifyAdded)
            {
                LinkedElementCollection <RoleBase> roleCollection = factType.RoleCollection;
                int roleCollectionCount = roleCollection.Count;

                if (roleCollectionCount == 1)
                {
                    // If we have a unary, binarize it
                    BinarizeUnary(factType, notifyAdded);
                    return;
                }
                else if (roleCollectionCount == 2)
                {
                    // If we have a binary that has an implicit boolean role in it, make sure it matches the pattern
                    Role implicitBooleanRole = GetImplicitBooleanRole(roleCollection);
                    if (implicitBooleanRole != null)
                    {
                        Role unaryRole = implicitBooleanRole.OppositeRole.Role;
                        Debug.Assert(unaryRole != null);
                        // Make sure the implicit boolean role has the same name as the unary role
                        implicitBooleanRole.Name = unaryRole.Name;
                        string implicitBooleanValueTypeName = GetImplicitBooleanValueTypeName(unaryRole);
                        if (implicitBooleanRole.RolePlayer.Name != implicitBooleanValueTypeName)
                        {
                            Dictionary <object, object> contextInfo = factType.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
                            object duplicateNamesKey         = ORMModel.AllowDuplicateNamesKey;
                            bool   removeDuplicateNamesKey   = false;
                            object duplicateSignaturesKey    = ORMModel.BlockDuplicateReadingSignaturesKey;
                            bool   addDuplicateSignaturesKey = false;
                            try
                            {
                                if (!contextInfo.ContainsKey(duplicateNamesKey))
                                {
                                    contextInfo[duplicateNamesKey] = null;
                                    removeDuplicateNamesKey        = true;
                                }
                                if (contextInfo.ContainsKey(duplicateSignaturesKey))
                                {
                                    contextInfo.Remove(duplicateSignaturesKey);
                                    addDuplicateSignaturesKey = true;
                                }
                                implicitBooleanRole.RolePlayer.Name = implicitBooleanValueTypeName;
                            }
                            finally
                            {
                                if (removeDuplicateNamesKey)
                                {
                                    contextInfo.Remove(duplicateNamesKey);
                                }
                                if (addDuplicateSignaturesKey)
                                {
                                    contextInfo[duplicateSignaturesKey] = null;
                                }
                            }
                        }
                        if (!ValidateConstraints(unaryRole, implicitBooleanRole) || !ValidateImplicitBooleanValueType(implicitBooleanRole.RolePlayer))
                        {
                            LinkedElementCollection <RoleBase> roles = factType.RoleCollection;
                            DebinarizeUnary(roles, false, notifyAdded);
                            // Append to the reading orders
                            LinkedElementCollection <ReadingOrder> readingOrders = factType.ReadingOrderCollection;
                            int readingOrderCount = readingOrders.Count;
                            for (int i = 0; i < readingOrderCount; ++i)
                            {
                                ReadingOrder order = readingOrders[i];
                                LinkedElementCollection <RoleBase> readingRoles = order.RoleCollection;
                                if (!readingRoles.Contains(implicitBooleanRole))
                                {
                                    readingRoles.Add(implicitBooleanRole);
                                    LinkedElementCollection <Reading> readings = order.ReadingCollection;
                                    int readingCount = readings.Count;
                                    for (int j = 0; j < readingCount; ++j)
                                    {
                                        readings[j].SetAutoText(readings[j].Text + " {1}");
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    // If we have an n-ary, remove any implicit boolean roles in it
                    for (int i = roleCollectionCount - 1; i >= 0; --i)
                    {
                        Role implicitBooleanRole = roleCollection[i].Role;
                        if (implicitBooleanRole != null && implicitBooleanRole.RolePlayer != null && implicitBooleanRole.RolePlayer.IsImplicitBooleanValue)
                        {
                            DebinarizeUnary(factType.RoleCollection, true, notifyAdded);
                            break;
                        }
                    }
                }
            }
Ejemplo n.º 14
0
            /// <summary>
            /// Binarizes the unary <see cref="FactType"/> specified by <paramref name="unaryFactType"/>, defaulting
            /// to using open-world assumption. The caller is responsible for making sure <paramref name="unaryFactType"/>
            /// is in fact a unary fact type.
            /// </summary>
            public static void BinarizeUnary(FactType unaryFactType, INotifyElementAdded notifyAdded)
            {
                Partition partition = unaryFactType.Partition;
                Store     store     = partition.Store;
                IHasAlternateOwner <FactType>      toAlternateOwner;
                IAlternateElementOwner <FactType>  alternateFactTypeOwner = (null == (toAlternateOwner = unaryFactType as IHasAlternateOwner <FactType>)) ? null : toAlternateOwner.AlternateOwner;
                LinkedElementCollection <RoleBase> roleCollection         = unaryFactType.RoleCollection;

                Debug.Assert(roleCollection.Count == 1, "Unaries should only have one role.");

                Role   unaryRole = (Role)roleCollection[0];
                string implicitBooleanValueTypeName = GetImplicitBooleanValueTypeName(unaryRole);

                // UNDONE: We are using open-world assumption now
                // Setup the mandatory constraint (for closed-world assumption)
                //MandatoryConstraint mandatoryConstraint = MandatoryConstraint.CreateSimpleMandatoryConstraint(unaryRole);
                //mandatoryConstraint.Model = unaryFactType.Model;
                //if (notifyAdded != null)
                //{
                //    notifyAdded.ElementAdded(mandatoryConstraint, true);
                //}

                // Setup the uniqueness constraint (to make the newly binarized FactType valid)
                if (unaryRole.SingleRoleAlethicUniquenessConstraint == null)
                {
                    UniquenessConstraint uniquenessConstraint = UniquenessConstraint.CreateInternalUniquenessConstraint(unaryFactType);
                    uniquenessConstraint.RoleCollection.Add(unaryRole);
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(uniquenessConstraint, true);
                    }
                }

                // Setup the boolean role (to make the FactType a binary)
                Role implicitBooleanRole = new Role(partition, null);

                implicitBooleanRole.Name = unaryRole.Name;

                // Setup the boolean value type (because the boolean role needs a role player)

                IAlternateElementOwner <ObjectType> alternateObjectTypeOwner = null;
                DomainClassInfo alternateCtor =
                    (null != alternateFactTypeOwner &&
                     null != (alternateObjectTypeOwner = alternateFactTypeOwner as IAlternateElementOwner <ObjectType>)) ?
                    alternateObjectTypeOwner.GetOwnedElementClassInfo(typeof(ObjectType)) :
                    null;
                PropertyAssignment implicitBooleanProperty  = new PropertyAssignment(ObjectType.IsImplicitBooleanValueDomainPropertyId, true);
                ObjectType         implicitBooleanValueType = (alternateCtor != null) ?
                                                              (ObjectType)partition.ElementFactory.CreateElement(alternateCtor, implicitBooleanProperty) :
                                                              new ObjectType(partition, implicitBooleanProperty);
                Dictionary <object, object> contextInfo = store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
                object duplicateNamesKey         = ORMModel.AllowDuplicateNamesKey;
                bool   removeDuplicateNamesKey   = false;
                object duplicateSignaturesKey    = ORMModel.BlockDuplicateReadingSignaturesKey;
                bool   addDuplicateSignaturesKey = false;

                try
                {
                    if (!contextInfo.ContainsKey(duplicateNamesKey))
                    {
                        contextInfo[duplicateNamesKey] = null;
                        removeDuplicateNamesKey        = true;
                    }
                    if (contextInfo.ContainsKey(duplicateSignaturesKey))
                    {
                        contextInfo[duplicateSignaturesKey] = null;
                        addDuplicateSignaturesKey           = true;
                    }
                    implicitBooleanValueType.Name = implicitBooleanValueTypeName;
                    if (alternateCtor != null)
                    {
                        ((IHasAlternateOwner <ObjectType>)implicitBooleanValueType).AlternateOwner = alternateObjectTypeOwner;
                    }
                    else
                    {
                        implicitBooleanValueType.Model = unaryFactType.ResolvedModel;
                    }
                    if (notifyAdded != null)
                    {
                        notifyAdded.ElementAdded(implicitBooleanValueType, true);
                    }
                }
                finally
                {
                    if (removeDuplicateNamesKey)
                    {
                        contextInfo.Remove(duplicateNamesKey);
                    }
                    if (addDuplicateSignaturesKey)
                    {
                        contextInfo[duplicateSignaturesKey] = null;
                    }
                }
                implicitBooleanValueType.DataType = store.ElementDirectory.FindElements <TrueOrFalseLogicalDataType>(false)[0];

                // Set value constraint on implicit boolean ValueType for open-world assumption
                ValueTypeValueConstraint implicitBooleanValueConstraint = implicitBooleanValueType.ValueConstraint
                                                                              = new ValueTypeValueConstraint(partition, null);

                // Add the true-only ValueRange to the value constraint for open-world assumption
                implicitBooleanValueConstraint.ValueRangeCollection.Add(new ValueRange(partition,
                                                                                       new PropertyAssignment(ValueRange.MinValueDomainPropertyId, bool.TrueString),
                                                                                       new PropertyAssignment(ValueRange.MaxValueDomainPropertyId, bool.TrueString)));

                // Make the boolean value type the role player for the implicit boolean role
                implicitBooleanRole.RolePlayer = implicitBooleanValueType;

                // Add the boolean role to the FactType
                roleCollection.Add(implicitBooleanRole);
                if (notifyAdded != null)
                {
                    notifyAdded.ElementAdded(implicitBooleanRole, true);
                }
            }