示例#1
0
        public List <Model.TableMainModel> GenerateQueries(List <Model.TablePathModel> requestedPath)
        {
            InitiateMainObject(requestedPath);

            RegExHelper re = new RegExHelper(@"(?<left>.*)\/" + SQLToolMain.InputTable.Replace(".", "\\.") + "\\/(?<right>.*)");
            List <Model.TablePathModel> dividedPath;
            List <int> uniquePath = requestedPath.Select(x => x.PathID).Distinct().ToList();



            for (int i = 0; i < uniquePath.Count; i++)
            {
                Console.WriteLine("--------------------------------------------------");
                Console.WriteLine("Looping " + (i + 1).ToString() + "/" + uniquePath.Count);
                Console.WriteLine("");

                dividedPath = new List <Model.TablePathModel>();
                dividedPath = this.TablePathModelList.Where(x => x.PathID == uniquePath[i]).OrderBy(y => y.Sequence).ToList();
                this.PendingPathtoTravers = dividedPath;

                this.ContinueTraversingCheck = i == 0 ? true : false; //stop
                if (dividedPath.Count > 0)
                {
                    Vertex <string> startingVertex = new Vertex <string>(SQLToolMain.InputTable);
                    this.adjacencyList = new AdjacencyList <string>(startingVertex, this.OnVertexTraverse);


                    List <string> l = re.GetMatchList(dividedPath[0].EntirePath);
                    if (l.Count == 2)
                    {
                        string[] leftTableNamesArray = l[0].Split(new char[] { '/' });

                        // Reverse the left table names to convert from right-to-left to left-to-right
                        // which UpdateGraph uses.
                        var leftTableNamesList = leftTableNamesArray.Reverse().ToList();

                        string[] rightTableNamesArray = l[1].Split(new char[] { '/' });

                        var rightableNamesList = rightTableNamesArray.ToList();

                        List <string> combinedList = new List <string>(leftTableNamesList.Count + rightableNamesList.Count);

                        combinedList.AddRange(rightableNamesList);
                        combinedList.AddRange(leftTableNamesList);

                        this.adjacencyList.AddPath(combinedList);
                    }

                    this.adjacencyList.Traverse();



                    //list<string> with parent chilf
                    //start with last parent chhild in current path
                    //see if is already exists in traversed path
                    //if exists then skip and continue
                    //if not add value in traversed path
                    //set some flag so traversed again

                    //List<string> TraversedTable = new List<string>();
                    //TraversedTable.AddRange(TraversedPath.Select(x=>x.TableName).Except(dividedPath.Select(y=>y.TableName).ToList()));

                    ////find table from divided path
                    ////get max index of table
                    ////and start divided path from there

                    //TraversedPath.AddRange(dividedPath);


                    Console.WriteLine("Input level - " + dividedPath.Count.ToString() + " -----Create Queries level - " + this.PendingPathtoTravers.Count.ToString());

                    CreateQueries(this.PendingPathtoTravers);
                }
                Console.WriteLine("--------------------------------------------------");
            }
#if DEBUG
            string xmlOutput = XMLConversionHelper.Serialize(this.objMainTableModel);
#endif

            return(this.objMainTableModel);
        }