public static DependencyItem[] GetDependsOnSelected(this IDatabaseStructure db, DependencyItem selected, bool processReferences)
        {
            var res = new List <DependencyItem>();

            if (selected != null)
            {
                foreach (var spec in db.GetAllSpecificObjects())
                {
                    if (spec.DependsOn != null && spec.DependsOn.Contains(selected))
                    {
                        res.Add(new DependencyItem
                        {
                            Name       = spec.ObjectName,
                            ObjectType = spec.ObjectType,
                        });
                    }
                }
                if (processReferences && selected.ObjectType == "table")
                {
                    var tbl = db.FindTable(selected.Name);
                    if (tbl != null)
                    {
                        foreach (var fk in tbl.GetReferencedFrom())
                        {
                            res.Add(new DependencyItem
                            {
                                Name       = fk.Table.FullName,
                                ObjectType = "table",
                            });
                        }
                    }
                }
            }
            return(res.ToArray());
        }
        private List <IAbstractObjectStructure> GetEqualObjs()
        {
            var grps = new HashSetEx <string>();
            var objs = new List <IAbstractObjectStructure>();

            foreach (var elem in m_diff.Actions.Elements)
            {
                grps.Add(elem.GroupId);
            }

            foreach (var obj in m_src.Tables)
            {
                if (grps.Contains(obj.GroupId))
                {
                    continue;
                }
                objs.Add(obj);
            }
            foreach (var spec in m_src.GetAllSpecificObjects())
            {
                if (grps.Contains(spec.GroupId))
                {
                    continue;
                }
                objs.Add(spec);
            }
            return(objs);
        }
        public static IEnumerable <ISpecificObjectStructure> GetSpecObjectsOrderByDependency(this IDatabaseStructure db)
        {
            List <ISpecificObjectStructure> all = new List <ISpecificObjectStructure>();

            all.AddRange(db.GetAllSpecificObjects());
            while (all.Count > 0)
            {
                ISpecificObjectStructure selected = null;
                foreach (var obj in all)
                {
                    bool objIndependent = true;
                    var  deps           = obj.DependsOn;
                    if (deps == null && db.Dialect != null)
                    {
                        deps = db.Dialect.DetectDependencies(obj);
                    }
                    if (deps != null)
                    {
                        foreach (var dep in deps)
                        {
                            if (DepInList(dep, all))
                            {
                                objIndependent = false;
                                break;
                            }
                        }
                    }
                    if (objIndependent)
                    {
                        selected = obj;
                        break;
                    }
                }
                if (selected == null)
                {
                    // throw new Exception("Object dependency cycle");
                    selected = all[0];
                }
                yield return(selected);

                all.Remove(selected);
            }
        }
 public static IEnumerable <DependencyItem> GetAllDepItems(this IDatabaseStructure db)
 {
     foreach (var tbl in db.Tables)
     {
         yield return(new DependencyItem
         {
             Name = tbl.FullName,
             ObjectType = "table"
         });
     }
     foreach (var spec in db.GetAllSpecificObjects())
     {
         yield return(new DependencyItem
         {
             Name = spec.ObjectName,
             ObjectType = spec.ObjectType,
         });
     }
 }