Beispiel #1
0
        /// <summary>
        /// Get list reference of table
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public List <ReferenceInformation> GetListReference(string tableName)
        {
            //
            // Initialize result
            List <ReferenceInformation> result = new List <ReferenceInformation>();

            //
            // Get list reference
            MapTable table = this.GetMapTable(tableName);

            if (table != null)
            {
                result = table.GetReference();
            }

            //
            // Return result
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Tracking circle references
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="tracking"></param>
        /// <returns></returns>
        public bool HasCircleReference(string tableName, List <string> tracking)
        {
            //
            // First, try to get table information
            // and try to get table's reference
            MapTable table = this.GetMapTable(tableName);
            List <ReferenceInformation> listReference = table.GetReference();
            bool result = false;


            //
            // If we can not detect circle reference in this level
            // Try to access deeper level (using recursion algorithm)
            List <string> listTableHasCheck = new List <string>();

            listTableHasCheck.Add(tableName);
            foreach (ReferenceInformation reference in listReference)
            {
                bool response = HasCircleReference(tableName, reference, listTableHasCheck, tracking);
                if (response == true)
                {
                    //
                    // Add tracking if needed
                    if (tracking != null)
                    {
                        tracking.Add(tableName);
                    }
                    result = true;
                    break;
                }
            }


            //
            // Return result
            return(result);
        }
        /// <summary>
        /// Check we can map this table right now or not
        /// </summary>
        /// <param name="table"></param>
        protected virtual bool CanMap(MapTable table)
        {
            //
            // Initialize result
            bool result = true;


            //
            // Already mapped or not ?
            // If it is already mapped
            // Return false
            if (table.IsMapped)
            {
                result = false;
            }
            else
            {
                //
                // Get config maporder
                // And config ingore reference for this table
                List <string> configMapOrder        = null;
                List <string> configIngoreReference = null;
                if (this._configMapOrder.ContainsKey(table.Name))
                {
                    configMapOrder = this._configMapOrder[table.Name];
                }
                if (this._configIgnoreReference.ContainsKey(table.Name))
                {
                    configIngoreReference = this._configIgnoreReference[table.Name];
                }


                //
                // Check map order configuration first
                if (configMapOrder != null)
                {
                    foreach (string prerequisiteTable in configMapOrder)
                    {
                        if (this.GetMapTable(prerequisiteTable).IsMapped == false)
                        {
                            return(false);
                        }
                    }
                }


                //
                // Check
                List <ReferenceInformation> listReferences = table.GetReference();
                foreach (ReferenceInformation reference in listReferences)
                {
                    //
                    // Do we ignore this reference ?
                    if (configIngoreReference != null && configIngoreReference.Contains(reference.PKTableName))
                    {
                        continue;
                    }


                    //
                    // If not, try to check
                    // Referenced table is mapped or not
                    // If not, we can not map this table right now
                    MapTable referencedTable = this.GetMapTable(reference.PKTableName);
                    if (referencedTable != null && referencedTable.IsMapped == false)
                    {
                        result = false;
                        break;
                    }
                }
            }


            //
            // Return result
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Has circle reference
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="referenceTable"></param>
        /// <param name="listTableHasCheck"></param>
        /// <returns></returns>
        private bool HasCircleReference(string tableName, ReferenceInformation reference, List <string> listTableHasCheck, List <string> tracking)
        {
            //
            // Initialize result
            bool result = false;

            //
            // Check current reference
            if (reference.PKTableName.Equals(tableName))
            {
                result = true;
            }
            else
            {
                //
                // Try to get referenced table
                // And go deeper (using recursion algorithm)
                MapTable referencedTable = this.GetMapTable(reference.PKTableName);
                List <ReferenceInformation> listReference = referencedTable.GetReference();
                listTableHasCheck.Add(referencedTable.Name);
                foreach (ReferenceInformation childReference in listReference)
                {
                    //
                    // Check
                    if (childReference.PKTableName.Equals(tableName))
                    {
                        // Add to tracking list if needed
                        if (tracking != null)
                        {
                            tracking.Add(referencedTable.Name);
                        }
                        result = true;
                        break;
                    }


                    //
                    // If referenced table is checked
                    // We don't need to go further
                    if (listTableHasCheck.Contains(childReference.PKTableName))
                    {
                        continue;
                    }


                    //
                    // Else try to go deeper
                    bool response = this.HasCircleReference(tableName, childReference, listTableHasCheck, tracking);
                    if (response)
                    {
                        // Add to tracking list if needed
                        if (tracking != null)
                        {
                            tracking.Add(referencedTable.Name);
                        }
                        result = true;
                        break;
                    }
                }
            }



            //
            // Return result
            return(result);
        }
        /// <summary>
        /// Check we can map this table right now or not
        /// </summary>
        /// <param name="table"></param>
        protected virtual bool CanMap(MapTable table)
        {
            //
            // Initialize result
            bool result = true;

            //
            // Already mapped or not ?
            // If it is already mapped
            // Return false
            if (table.IsMapped)
            {
                result = false;
            }
            else
            {
                //
                // Get config maporder
                // And config ingore reference for this table
                List<string> configMapOrder = null;
                List<string> configIngoreReference = null;
                if (this._configMapOrder.ContainsKey(table.Name))
                {
                    configMapOrder = this._configMapOrder[table.Name];
                }
                if (this._configIgnoreReference.ContainsKey(table.Name))
                {
                    configIngoreReference = this._configIgnoreReference[table.Name];
                }

                //
                // Check map order configuration first
                if (configMapOrder != null)
                {
                    foreach (string prerequisiteTable in configMapOrder)
                    {
                        if (this.GetMapTable(prerequisiteTable).IsMapped == false)
                        {
                            return false;
                        }
                    }
                }

                //
                // Check
                List<ReferenceInformation> listReferences = table.GetReference();
                foreach (ReferenceInformation reference in listReferences)
                {
                    //
                    // Do we ignore this reference ?
                    if (configIngoreReference != null && configIngoreReference.Contains(reference.PKTableName))
                    {
                        continue;
                    }

                    //
                    // If not, try to check
                    // Referenced table is mapped or not
                    // If not, we can not map this table right now
                    MapTable referencedTable = this.GetMapTable(reference.PKTableName);
                    if (referencedTable != null && referencedTable.IsMapped == false)
                    {
                        result = false;
                        break;
                    }
                }
            }

            //
            // Return result
            return result;
        }