private List<RelationshipsOptimization> CreateOptimizations(DomainClass domainClass, ICollection references)
        {
            List<RelationshipsOptimization> opt = new List<RelationshipsOptimization>();
            Dictionary<object, List<DomainRelationship>> dict = GetSortedByBaseClasses(references);

            foreach (object key in dict.Keys)
            {
                List<DomainRelationship> rels = dict[key];
                if (rels.Count <= 1)
                    continue;

                Dictionary<string, List<DomainRelationship>> dict2 = GetSortedByMutliplicity(rels);
                foreach (string key2 in dict2.Keys)
                {
                    rels = dict2[key2];
                    if (rels.Count <= 1)
                        continue;

                    bool bUseIntermediate = false;
                    if (key is DomainClass)
                    {
                        if ((key as DomainClass) == domainClass)
                            continue;

                        bUseIntermediate = UseIntermediate(rels);
                        if (!bUseIntermediate)
                            if ((key as DomainClass).DerivedClasses.Count != rels.Count)
                                bUseIntermediate = true;
                    }

                    RelationshipsOptimization rOpt = new RelationshipsOptimization(this.MetaModel, this.ModelContext);
                    rOpt.Title = "Relationship Optimization";
                    rOpt.InvolvedClasses.Add(domainClass);
                    rOpt.ParentClass = domainClass;
                    rOpt.CreateIntermediate = bUseIntermediate;

                    if (rOpt.CreateIntermediate)
                        rOpt.Description = "Existing references are replaces with one reference to a new base class";
                    else
                        rOpt.Description = "Existing references are replaces with one reference to a base class";

                    if (key is DomainClass)
                    {
                        rOpt.BaseClass = (key as DomainClass);

                        if (!rOpt.InvolvedClasses.Contains(rOpt.BaseClass))
                            rOpt.InvolvedClasses.Add(rOpt.BaseClass);
                    }

                    foreach (DomainRelationship r in rels)
                    {
                        if( !rOpt.InvolvedClasses.Contains(r.Target.RolePlayer as DomainClass) )
                            rOpt.InvolvedClasses.Add(r.Target.RolePlayer as DomainClass);
                        if( !rOpt.InvolvedRelationships.Contains(r) )
                            rOpt.InvolvedRelationships.Add(r);
                    }

                    if (rels[0] is ReferenceRelationship)
                        rOpt.IsEmbedding = false;
                    else
                        rOpt.IsEmbedding = true;

                    opt.Add(rOpt);
                }
            }
           
            return opt;
        }
Ejemplo n.º 2
0
        private List <RelationshipsOptimization> CreateOptimizations(DomainClass domainClass, ICollection references)
        {
            List <RelationshipsOptimization> opt = new List <RelationshipsOptimization>();
            Dictionary <object, List <DomainRelationship> > dict = GetSortedByBaseClasses(references);

            foreach (object key in dict.Keys)
            {
                List <DomainRelationship> rels = dict[key];
                if (rels.Count <= 1)
                {
                    continue;
                }

                Dictionary <string, List <DomainRelationship> > dict2 = GetSortedByMutliplicity(rels);
                foreach (string key2 in dict2.Keys)
                {
                    rels = dict2[key2];
                    if (rels.Count <= 1)
                    {
                        continue;
                    }

                    bool bUseIntermediate = false;
                    if (key is DomainClass)
                    {
                        if ((key as DomainClass) == domainClass)
                        {
                            continue;
                        }

                        bUseIntermediate = UseIntermediate(rels);
                        if (!bUseIntermediate)
                        {
                            if ((key as DomainClass).DerivedClasses.Count != rels.Count)
                            {
                                bUseIntermediate = true;
                            }
                        }
                    }

                    RelationshipsOptimization rOpt = new RelationshipsOptimization(this.MetaModel, this.ModelContext);
                    rOpt.Title = "Relationship Optimization";
                    rOpt.InvolvedClasses.Add(domainClass);
                    rOpt.ParentClass        = domainClass;
                    rOpt.CreateIntermediate = bUseIntermediate;

                    if (rOpt.CreateIntermediate)
                    {
                        rOpt.Description = "Existing references are replaces with one reference to a new base class";
                    }
                    else
                    {
                        rOpt.Description = "Existing references are replaces with one reference to a base class";
                    }

                    if (key is DomainClass)
                    {
                        rOpt.BaseClass = (key as DomainClass);

                        if (!rOpt.InvolvedClasses.Contains(rOpt.BaseClass))
                        {
                            rOpt.InvolvedClasses.Add(rOpt.BaseClass);
                        }
                    }

                    foreach (DomainRelationship r in rels)
                    {
                        if (!rOpt.InvolvedClasses.Contains(r.Target.RolePlayer as DomainClass))
                        {
                            rOpt.InvolvedClasses.Add(r.Target.RolePlayer as DomainClass);
                        }
                        if (!rOpt.InvolvedRelationships.Contains(r))
                        {
                            rOpt.InvolvedRelationships.Add(r);
                        }
                    }

                    if (rels[0] is ReferenceRelationship)
                    {
                        rOpt.IsEmbedding = false;
                    }
                    else
                    {
                        rOpt.IsEmbedding = true;
                    }

                    opt.Add(rOpt);
                }
            }

            return(opt);
        }