Exemplo n.º 1
0
        private List <RelationshipCandidate[]> GetAllPossibleVectors()
        {
            List <RelationshipCandidate[]> candidates = new List <RelationshipCandidate[]>();

            int totalCombinationsCount = 1;

            foreach (var end in this.ends)
            {
                totalCombinationsCount *= end.Candidates.Count;
            }

            for (int i = 0; i < totalCombinationsCount; i++)
            {
                RelationshipCandidate[] relationshipGroup = new RelationshipCandidate[this.ends.Count];
                int factor = 1;
                for (int j = 0; j < this.ends.Count; j++)
                {
                    int index = (i / factor) % this.ends[j].Candidates.Count;
                    factor *= this.ends[j].Candidates.Count;
                    relationshipGroup[j] = this.ends[j].Candidates[index];
                }

                if (!this.usedVectors.Any(c => this.IsSameKey(c, relationshipGroup)))
                {
                    candidates.Add(relationshipGroup);
                }
            }

            return(candidates);
        }
Exemplo n.º 2
0
        private void RemoveCandidate(RelationshipCandidate toRemove)
        {
            toRemove.Parent.Candidates.Remove(toRemove);

            if (this.endsWhichFormTheKey.Contains(toRemove.Parent))
            {
                var rowsToRemove = this.usedVectors.Where(v => v.Contains(toRemove)).ToList();
                foreach (var row in rowsToRemove)
                {
                    this.usedVectors.Remove(row);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Considers the candidate for this relationship.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="key">The entity data key of the candidate.</param>
        public void ConsiderCandidate(EntitySet entitySet, EntityType entityType, EntityDataKey key)
        {
            foreach (RelationshipGroupEnd end in this.ends.Where(e => e.EntitySet == entitySet && entityType.IsKindOf(e.EntityType)))
            {
                CapacityRange capacityRange = end.CapacitySelector();

                if (capacityRange != CapacityRange.Zero)
                {
                    this.RemoveCandidatesOnTargetBasedOnTreshhold(end);

                    RelationshipCandidate candidate = new RelationshipCandidate(end, key, capacityRange);
                    end.Candidates.Add(candidate);
                }
            }
        }
Exemplo n.º 4
0
        private void IncrementRelatedCount(RelationshipCandidate candidate)
        {
            bool isMinimumRequirementAlreadyMet = candidate.IsMinimumRequirementMet;

            candidate.IncrementRelatedCount();

            if (candidate.IsCapacityReached)
            {
                this.RemoveCandidate(candidate);
            }
            else if (!isMinimumRequirementAlreadyMet && candidate.IsMinimumRequirementMet)
            {
                this.RemoveCandidatesOnTargetBasedOnTreshhold(candidate.Parent);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Considers the candidate for this relationship.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="key">The entity data key of the candidate.</param>
        public void ConsiderCandidate(EntitySet entitySet, EntityType entityType, EntityDataKey key)
        {
            foreach (RelationshipGroupEnd end in this.ends.Where(e => e.EntitySet == entitySet && entityType.IsKindOf(e.EntityType)))
            {
                CapacityRange capacityRange = end.CapacitySelector();

                if (capacityRange != CapacityRange.Zero)
                {
                    this.RemoveCandidatesOnTargetBasedOnTreshhold(end);
                    
                    RelationshipCandidate candidate = new RelationshipCandidate(end, key, capacityRange);
                    end.Candidates.Add(candidate);
                }
            }
        }
Exemplo n.º 6
0
        private bool IsSameKey(RelationshipCandidate[] vector1, RelationshipCandidate[] vector2)
        {
            foreach (RelationshipGroupEnd end in this.endsWhichFormTheKey)
            {
                EntityDataKey key1 = vector1.Where(r => r.Parent == end).Select(r => r.EntityDataKey).Single();
                EntityDataKey key2 = vector2.Where(r => r.Parent == end).Select(r => r.EntityDataKey).Single();

                if (key1 != key2)
                {
                    return false;
                }
            }

            return this.endsWhichFormTheKey.Count > 0;
        }
Exemplo n.º 7
0
 private void RegisterAsUsedVectorIfNeeded(RelationshipCandidate[] vector)
 {
     if (this.endsWhichFormTheKey.Count > 0)
     {
         this.usedVectors.Add(vector);
     }
 }
Exemplo n.º 8
0
        private void RemoveCandidate(RelationshipCandidate toRemove)
        {
            toRemove.Parent.Candidates.Remove(toRemove);

            if (this.endsWhichFormTheKey.Contains(toRemove.Parent))
            {
                var rowsToRemove = this.usedVectors.Where(v => v.Contains(toRemove)).ToList();
                foreach (var row in rowsToRemove)
                {
                    this.usedVectors.Remove(row);
                }
            }
        }
Exemplo n.º 9
0
        private void IncrementRelatedCount(RelationshipCandidate candidate)
        {
            bool isMinimumRequirementAlreadyMet = candidate.IsMinimumRequirementMet;

            candidate.IncrementRelatedCount();

            if (candidate.IsCapacityReached)
            {
                this.RemoveCandidate(candidate);
            }
            else if (!isMinimumRequirementAlreadyMet && candidate.IsMinimumRequirementMet)
            {
                this.RemoveCandidatesOnTargetBasedOnTreshhold(candidate.Parent);
            }
        }
Exemplo n.º 10
0
        private IList<RelationshipDescription> GetRelationshipDescriptions(RelationshipCandidate[] group)
        {
            List<RelationshipDescription> relationships = new List<RelationshipDescription>();

            List<KeyValuePair<AssociationSet, AssociationSetEnd>> processedSetEndPairs = new List<KeyValuePair<AssociationSet, AssociationSetEnd>>();
            
            foreach (RelationshipCandidate toSide in group)
            {
                foreach (var setEndPair in toSide.Parent.AssociationSetEnds.Where(p => !processedSetEndPairs.Contains(p)))
                {
                    // Find the "from" side of the relationship
                    foreach (var from in group.Where(c => c != toSide).Select(c => new { FromSide = c, OtherSetEndPair = c.Parent.AssociationSetEnds.Where(p => p.Key == setEndPair.Key).SingleOrDefault() })
                        .Where(a => a.OtherSetEndPair.Key != null))
                    {
                        relationships.Add(new RelationshipDescription(
                            setEndPair.Key,
                            from.FromSide.EntityDataKey,
                            setEndPair.Value.AssociationEnd.RoleName,
                            toSide.EntityDataKey));

                        processedSetEndPairs.Add(setEndPair);
                        processedSetEndPairs.Add(from.OtherSetEndPair);
                    }
                }
            }

            return relationships;
        }
Exemplo n.º 11
0
        private List<RelationshipCandidate[]> GetAllPossibleVectors()
        {
            List<RelationshipCandidate[]> candidates = new List<RelationshipCandidate[]>();

            int totalCombinationsCount = 1;
            foreach (var end in this.ends)
            {
                totalCombinationsCount *= end.Candidates.Count;
            }

            for (int i = 0; i < totalCombinationsCount; i++)
            {
                RelationshipCandidate[] relationshipGroup = new RelationshipCandidate[this.ends.Count];
                int factor = 1;
                for (int j = 0; j < this.ends.Count; j++)
                {
                    int index = (i / factor) % this.ends[j].Candidates.Count;
                    factor *= this.ends[j].Candidates.Count;
                    relationshipGroup[j] = this.ends[j].Candidates[index];
                }

                if (!this.usedVectors.Any(c => this.IsSameKey(c, relationshipGroup)))
                {
                    candidates.Add(relationshipGroup);
                }
            }

            return candidates;
        }