Exemplo n.º 1
0
        private static void CheckCanDeleteSafe(IBusinessObject bo, List <IBusinessObject> alreadyChecked,
                                               MatchList matchList, string currentRelationshipPath, ref Dictionary <string, int> results)
        {
            if (alreadyChecked.Contains(bo))
            {
                return;
            }
            alreadyChecked.Add(bo);
            if (currentRelationshipPath.Length > 0)
            {
                currentRelationshipPath += ".";
            }
            var listOfPaths = matchList;

            foreach (var pair in listOfPaths)
            {
                var relationshipName = pair.Key;
                if (!bo.Relationships.Contains(relationshipName))
                {
                    return;
                }
                var thisRelationshipPath = currentRelationshipPath + relationshipName;
                var relationship         = bo.Relationships[relationshipName] as IMultipleRelationship;
                if (relationship == null)
                {
                    continue;
                }
                if (pair.Value == null)
                {
                    var businessObjects = relationship.BusinessObjectCollection;
                    if (businessObjects.Count > 0)
                    {
                        if (!results.ContainsKey(thisRelationshipPath))
                        {
                            results.Add(thisRelationshipPath, businessObjects.Count);
                        }
                        else
                        {
                            results[thisRelationshipPath] += businessObjects.Count;
                        }
                    }
                }
                else if (pair.Value.Count > 0)
                {
                    var boCol = relationship.BusinessObjectCollection;
                    foreach (BusinessObject businessObject in boCol)
                    {
                        CheckCanDeleteSafe(businessObject, alreadyChecked, pair.Value, thisRelationshipPath, ref results);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static MatchList FindRelationshipsSafe <TRelationshipDef>(IRelationshipDefCol relationshipDefCol,
                                                                          MatchesConditionDelegate <TRelationshipDef> matchesConditionDelegate, List <IRelationshipDefCol> alreadyChecked)
            where TRelationshipDef : RelationshipDef
        {
            var listOfPaths = new MatchList();

            if (matchesConditionDelegate == null)
            {
                return(listOfPaths);
            }
            if (relationshipDefCol == null)
            {
                return(listOfPaths);
            }
            if (alreadyChecked.Contains(relationshipDefCol))
            {
                return(listOfPaths);
            }
            alreadyChecked.Add(relationshipDefCol);
            foreach (var relationshipDef in relationshipDefCol)
            {
                var relationshipName      = relationshipDef.RelationshipName;
                var castedRelationshipDef = relationshipDef as TRelationshipDef;
                if (castedRelationshipDef == null)
                {
                    continue;
                }
                var matchesCondition = matchesConditionDelegate(castedRelationshipDef);
                if (matchesCondition)
                {
                    listOfPaths.Add(relationshipName, null);
                }
                else
                {
                    var classDef = (ClassDef)relationshipDef.RelatedObjectClassDef;
                    if (classDef != null)
                    {
                        var results = FindRelationshipsSafe(classDef.RelationshipDefCol, matchesConditionDelegate, alreadyChecked);
                        if (results.Count > 0)
                        {
                            listOfPaths.Add(relationshipName, results);
                        }
                    }
                }
            }
            return(listOfPaths);
        }