public SynchronizedCollection<object> RunAutoMapperMultiThread(IList listRecord,
                                                           int numberOfRecord,
                                                           string sourceTableName,
                                                           string destTableName,
                                                           Type sourceTableType,
                                                           Type destTableType,
                                                           ManualMapping manualMapping)
        {
            //
            // Initialize
            // Calculate, how many thread will we need ?
            // At least, the minimum value for each thread is
            // 100 records / 1 thread
            // Cause we don't want to create too much thread
            this._listNewRecord = new SynchronizedCollection<object>();
            this._listRecord = listRecord;
            this._currentIndex = 0;
            this._numberOfRecords = numberOfRecord;
            int numberOfThread = this._maxSubThread;
            if (this._numberOfRecords == 0)
            {
                return this._listNewRecord;
            }
            if (this._numberOfRecords < this._maxSubThread * this._minTaskForThread)
            {
                numberOfThread = this._numberOfRecords / this._minTaskForThread;
                if (numberOfThread == 0)
                {
                    numberOfThread = 1;
                }
            }

            //
            // Start main sub thread
            // To map from source to destination database first
            int counter = 0;
            bool isDone = false;
            this._listAutoMapperThread = new List<AutoMapperThread>();
            for (counter = 0; counter < numberOfThread; ++counter)
            {
                AutoMapperThread autoMapperThread = new AutoMapperThread(this._manager, this,
                                                                         this._sourceDatabase, this._destinationDatabase, this._databaseSentinel,
                                                                         sourceTableName, destTableName, sourceTableType, destTableType, manualMapping);
                this._listAutoMapperThread.Add(autoMapperThread);
                autoMapperThread.Start();
            }

            //
            // Loop, wait until done
            while (isDone == false)
            {
                isDone = true;
                foreach (AutoMapperThread autoMapperThread in this._listAutoMapperThread)
                {
                    if (autoMapperThread.IsDone == false)
                    {
                        isDone = false;
                        break;
                    }
                }
                LogService.Log.Info(this._currentIndex + " / " + this._numberOfRecords);
                System.Threading.Thread.Sleep(1000);
            }

            //
            // Return result
            return this._listNewRecord;
        }
예제 #2
0
        /// <summary>
        /// Run auto mapper with multi threadings
        /// </summary>
        /// <returns></returns>
        public SynchronizedCollection <object> RunAutoMapperMultiThread(IList listRecord,
                                                                        int numberOfRecord,
                                                                        string sourceTableName,
                                                                        string destTableName,
                                                                        Type sourceTableType,
                                                                        Type destTableType)
        {
            //
            // Initialize
            // Calculate, how many thread will we need ?
            // At least, the minimum value for each thread is
            // 100 records / 1 thread
            // Cause we don't want to create too much thread
            this._listNewRecord   = new SynchronizedCollection <object>();
            this._listRecord      = listRecord;
            this._currentIndex    = 0;
            this._numberOfRecords = numberOfRecord;
            int numberOfThread = this._maxSubThread;

            if (this._numberOfRecords == 0)
            {
                return(this._listNewRecord);
            }
            if (this._numberOfRecords < this._maxSubThread * this._minTaskForThread)
            {
                numberOfThread = this._numberOfRecords / this._minTaskForThread;
                if (numberOfThread == 0)
                {
                    numberOfThread = 1;
                }
            }


            //
            // Start main sub thread
            // To map from source to destination database first
            int  counter = 0;
            bool isDone  = false;

            this._listAutoMapperThread = new List <AutoMapperThread>();
            for (counter = 0; counter < numberOfThread; ++counter)
            {
                AutoMapperThread autoMapperThread = new AutoMapperThread(this._manager, this,
                                                                         this._sourceDatabase, this._destinationDatabase, this._databaseSentinel,
                                                                         sourceTableName, destTableName, sourceTableType, destTableType);
                autoMapperThread.Start();
                this._listAutoMapperThread.Add(autoMapperThread);
            }


            //
            // Loop, wait until done
            while (isDone == false)
            {
                isDone = true;
                foreach (AutoMapperThread autoMapperThread in this._listAutoMapperThread)
                {
                    if (autoMapperThread.IsDone == false)
                    {
                        isDone = false;
                        break;
                    }
                }
                LogService.Log.Info(this._currentIndex + " / " + this._numberOfRecords);
                System.Threading.Thread.Sleep(1000);
            }


            //
            // Return result
            return(this._listNewRecord);
        }