src/Misc/EFTools/EntityDesignModel/Commands/UpdateConceptualAndMappingModelsCommand.cs
/// <summary>
///     Determines whether we should create an Association in the existing artifact given
///     the ReferentialConstraint and AssociationEnd info from the temp artifact
/// </summary>
Determines whether we should create an Association in the existing artifact given
the ReferentialConstraint and AssociationEnd info from the temp artifact
Determines whether we should create an Association in the existing artifact given the ReferentialConstraint and AssociationEnd info from the temp artifact
private static bool ShouldCreateAssociationGivenReferentialConstraint(
            ReferentialConstraint refConstraintInTempArtifact,
            AssociationEnd end1InTempArtifact, AssociationEnd end2InTempArtifact,
            ConceptualEntityType end1EntityTypeInExistingArtifact, ConceptualEntityType end2EntityTypeInExistingArtifact,
            out bool end1IsPrincipalEnd, out List<Property> principalPropertiesInExistingArtifact,
            out List<Property> dependentPropertiesInExistingArtifact, out List<string> unfoundPrincipalProperties,
            out List<string> unfoundDependentProperties)
        {
            end1IsPrincipalEnd = true;
            principalPropertiesInExistingArtifact = new List<Property>();
            unfoundPrincipalProperties = new List<string>();
            dependentPropertiesInExistingArtifact = new List<Property>();
            unfoundDependentProperties = new List<string>();
            ConceptualEntityType principalEndEntityType = null;
            ConceptualEntityType dependentEndEntityType = null;
            if (refConstraintInTempArtifact == null)
            {
                Debug.Fail("Should not have null ReferentialConstraint");
                return false;
            }
            if (refConstraintInTempArtifact.Principal.Role.Target == end1InTempArtifact)
            {
                Debug.Assert(
                    refConstraintInTempArtifact.Dependent.Role.Target == end2InTempArtifact,
                    "Unexpected end value for Dependent Role of ReferentialConstraint when Principal Role matches end1 from temp artifact");
                end1IsPrincipalEnd = true;
                principalEndEntityType = end1EntityTypeInExistingArtifact;
                dependentEndEntityType = end2EntityTypeInExistingArtifact;
            }
            else if (refConstraintInTempArtifact.Principal.Role.Target == end2InTempArtifact)
            {
                Debug.Assert(
                    refConstraintInTempArtifact.Dependent.Role.Target == end1InTempArtifact,
                    "Unexpected end value for Dependent Role of ReferentialConstraint when Principal Role matches end2 from temp artifact");
                end1IsPrincipalEnd = false;
                principalEndEntityType = end2EntityTypeInExistingArtifact;
                dependentEndEntityType = end1EntityTypeInExistingArtifact;
            }
            else
            {
                Debug.Fail("Couldn't identify principal & dependent end");
                return false;
            }
            foreach (var tempProp in refConstraintInTempArtifact.Principal.Properties)
            {
                var prop = FindMatchingPropertyInExistingArtifactEntityType(tempProp, principalEndEntityType);
                if (prop != null)
                {
                    principalPropertiesInExistingArtifact.Add(prop);
                }
                else
                {
                    unfoundPrincipalProperties.Add(tempProp.LocalName.Value);
                }
            }
            foreach (var tempProp in refConstraintInTempArtifact.Dependent.Properties)
            {
                var prop = FindMatchingPropertyInExistingArtifactEntityType(tempProp, dependentEndEntityType);
                if (prop != null)
                {
                    dependentPropertiesInExistingArtifact.Add(prop);
                }
                else
                {
                    unfoundDependentProperties.Add(tempProp.LocalName.Value);
                }
            }
            if (unfoundDependentProperties.Count == 0
                && unfoundPrincipalProperties.Count == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
private static bool ShouldCreateAssociationGivenReferentialConstraint ( ReferentialConstraint refConstraintInTempArtifact , AssociationEnd end1InTempArtifact , AssociationEnd end2InTempArtifact , ConceptualEntityType end1EntityTypeInExistingArtifact , ConceptualEntityType end2EntityTypeInExistingArtifact , out bool end1IsPrincipalEnd , out List < Property > principalPropertiesInExistingArtifact , out List < Property > dependentPropertiesInExistingArtifact , out List < string > unfoundPrincipalProperties , out List < string > unfoundDependentProperties ) { end1IsPrincipalEnd = true ; principalPropertiesInExistingArtifact = new List < Property > ( ) ; unfoundPrincipalProperties = new List < string > ( ) ; dependentPropertiesInExistingArtifact = new List < Property > ( ) ; unfoundDependentProperties = new List < string > ( ) ; ConceptualEntityType principalEndEntityType = null ; ConceptualEntityType dependentEndEntityType = null ; if ( refConstraintInTempArtifact == null ) { Debug . Fail ( " " ) ; return false ; } if ( refConstraintInTempArtifact . Principal . Role . Target == end1InTempArtifact ) { Debug . Assert ( refConstraintInTempArtifact . Dependent . Role . Target == end2InTempArtifact , " " ) ; end1IsPrincipalEnd = true ; principalEndEntityType = end1EntityTypeInExistingArtifact ; dependentEndEntityType = end2EntityTypeInExistingArtifact ; } else if ( refConstraintInTempArtifact . Principal . Role . Target == end2InTempArtifact ) { Debug . Assert ( refConstraintInTempArtifact . Dependent . Role . Target == end1InTempArtifact , " " ) ; end1IsPrincipalEnd = false ; principalEndEntityType = end2EntityTypeInExistingArtifact ; dependentEndEntityType = end1EntityTypeInExistingArtifact ; } else { Debug . Fail ( " " ) ; return false ; } foreach ( var tempProp in refConstraintInTempArtifact . Principal . Properties ) { var prop = FindMatchingPropertyInExistingArtifactEntityType ( tempProp , principalEndEntityType ) ; if ( prop != null ) { principalPropertiesInExistingArtifact . Add ( prop ) ; } else { unfoundPrincipalProperties . Add ( tempProp . LocalName . Value ) ; } } foreach ( var tempProp in refConstraintInTempArtifact . Dependent . Properties ) { var prop = FindMatchingPropertyInExistingArtifactEntityType ( tempProp , dependentEndEntityType ) ; if ( prop != null ) { dependentPropertiesInExistingArtifact . Add ( prop ) ; } else { unfoundDependentProperties . Add ( tempProp . LocalName . Value ) ; } } if ( unfoundDependentProperties . Count == 0 && unfoundPrincipalProperties . Count == 0 ) { return true ; } else { return false ; } }
Determines whether we should create an Association in the existing artifact given
the ReferentialConstraint and AssociationEnd info from the temp artifact
Determines whether we should create an Association in the existing artifact given the ReferentialConstraint and AssociationEnd info from the temp artifact
// no ReferentialConstraint in temp artifact to clone // determine which end is principal and which dependent // find the principal properties in the existing doc to include in the referential constraint // find the dependent properties in the existing doc to include in the referential constraint // return true if we found matching properties for all the properties in // both the principal and dependent ends, false otherwise
refConstraintInTempArtifact
ReferentialConstraint
end1InTempArtifact
AssociationEnd
end2InTempArtifact
AssociationEnd
end1EntityTypeInExistingArtifact
ConceptualEntityType
end2EntityTypeInExistingArtifact
ConceptualEntityType
bool
out
List<Property>
out
List<string>
out