Ejemplo n.º 1
0
        public override bool CanExecute()
        {
            if (!(schemaGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMSchema>(schemaGuid) &&
                  associationGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMAssociation>(associationGuid)))
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }

            PSMAssociation a = Project.TranslateComponent <PSMAssociation>(associationGuid);

            if (a.Interpretation != null)
            {
                return(true);
            }

            if (a.Child != null && a.Child is PSMClass && (a.Child as PSMClass).Interpretation != null)
            {
                return(true);
            }

            PSMAssociationMember c = a.Child; //Uninterpreted child

            IEnumerable <PSMClass> unInterpretedSubClasses = c.UnInterpretedSubClasses(true);

            //PSM attributes within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .SelectMany <PSMClass, PSMAttribute>(cl => cl.PSMAttributes)
                .All <PSMAttribute>(at => at.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ATTRIBUTES_INTERPRETED;
                return(false);
            }

            //PSM associations within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .Select <PSMClass, PSMAssociation>(cl => cl.ParentAssociation)
                .All <PSMAssociation>(assoc => assoc.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ASSOCIATIONS_INTERPRETED;
                return(false);
            }

            return(true);
        }