public IEnumerable <EntityMapping> CreateMapping(ManualMapping manualMapping) { // var succesFulInserts = 0; var mappings = new List <EntityMapping>(); var mappingOrigin = _originRepository.GetAll().First(t => t.Name.Equals("Manual")); foreach (var mapping in manualMapping.Mappings) { try { var sourceEntity = _entityRepository.GetAll().First(t => t.SystemId == manualMapping.SourceId && t.Name.Equals(mapping.Source)); var destinationEntity = _entityRepository.GetAll().First(t => t.SystemId == manualMapping.DestinationId && t.Name.Equals(mapping.Destination)); var entityMapping = new EntityMapping { Source = sourceEntity, SourceId = sourceEntity.Id, Destination = destinationEntity, DestinationId = destinationEntity.Id, Confirmed = false, Correct = null, MappingOrigin = mappingOrigin, MappingOriginId = mappingOrigin.Id }; _repository.Add(entityMapping); mappings.Add(entityMapping); //succesFulInserts++; } catch (Exception ex) { _logger.Write(ex); } } return(mappings); }
IEnumerable <EntityMapping> IMappingRepository.CreateMapping(ManualMapping manualMapping) { throw new NotImplementedException(); }
public int CreateMapping(ManualMapping manualMapping) { throw new NotImplementedException(); }
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; }
/// <summary> /// Create auto mapper thread /// </summary> /// <param name="manager"></param> /// <param name="multiThreadMapper"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="databaseSentinel"></param> /// <param name="sourceTableName"></param> /// <param name="destTableName"></param> /// <param name="sourceTableType"></param> /// <param name="destTableType"></param> public AutoMapperThread(MappingManager manager, MultiThreadManager multiThreadMapper, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, DatabaseSentinel databaseSentinel, string sourceTableName, string destTableName, Type sourceTableType, Type destTableType) { this._multiThreadMapper = multiThreadMapper; this._sourceDatabase = sourceDatabase; this._destinationDatabase = destinationDatabase; this._databaseSentinel = databaseSentinel; this._destTableType = destTableType; this._sourceTableType = sourceTableType; this._sourceTableName = sourceTableName; this._destTableName = destTableName; this._manualMapping = null; this._sourceDatabase = null; }
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); }
/// <summary> /// Create auto mapper thread /// </summary> /// <param name="manager"></param> /// <param name="multiThreadMapper"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="databaseSentinel"></param> /// <param name="sourceTableName"></param> /// <param name="destTableName"></param> /// <param name="sourceTableType"></param> /// <param name="destTableType"></param> /// <param name="manualMapping"></param> public AutoMapperThread(MappingManager manager, MultiThreadManager multiThreadMapper, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, DatabaseSentinel databaseSentinel, string sourceTableName, string destTableName, Type sourceTableType, Type destTableType, ManualMapping manualMapping) { this._multiThreadMapper = multiThreadMapper; this._sourceDatabase = sourceDatabase; this._destinationDatabase = destinationDatabase; this._databaseSentinel = databaseSentinel; this._sourceTableName = sourceTableName; this._destTableType = destTableType; this._sourceTableType = sourceTableType; this._destTableName = destTableName; this._manualMapping = manualMapping; }