private void ProcessChunk(IFileImportEntitiesChunkProcessor chunkProcessor, ImportParameters importParameters, ImportDataChunk <EntityChunkData> chunk)
        {
            EventHandler <ImportEntitySavedEventArgs> successImportEntitySavedHadler = (o, arg) => {
                chunk.Data.SuccessProcessedEntityCount++;
                _importEntitiesChunksDataProvider.SaveProcessedRow(chunk.ChunkId, (int)arg.RowIndex);
            };

            chunkProcessor.ImportEntitySaved += successImportEntitySavedHadler;
            EventHandler <ImportEntitySaveErrorEventArgs> importEntitySavedWithErrorHandler = (o, arg) => {
                chunk.Data.ProcessedWithErrorEntityCount++;
                _importEntitiesChunksDataProvider.SaveProcessedRow(chunk.ChunkId, (int)arg.ImportEntity.RowIndex, false);
            };

            chunkProcessor.ImportEntitySaveError += importEntitySavedWithErrorHandler;

            ImportParameters newImportParameters = PrepareImportParameters(importParameters, chunk);

            SaveProcessedChunk(chunk, ImportChunkState.InProcess);
            chunkProcessor.ProcessChunk(newImportParameters);
            SaveProcessedChunk(chunk, ImportChunkState.Processed);

            _importEntitiesChunksDataProvider.RemoveProcessedRows(chunk.ChunkId);
            chunkProcessor.ImportEntitySaved     -= successImportEntitySavedHadler;
            chunkProcessor.ImportEntitySaveError -= importEntitySavedWithErrorHandler;
        }
        private void ProcessChunks(ImportParameters importParameters,
                                   ImportDataChunk <EntityChunkData> entityChunk)
        {
            if (entityChunk.State == ImportChunkState.Processed)
            {
                return;
            }
            IFileImportEntitiesChunkProcessor chunkProcessor = CreateChunkProcessor();

            SubscribeChunkProcessorEvents(chunkProcessor);
            ProcessChunk(chunkProcessor, importParameters, entityChunk);

            UnsubscribeChunkProcessorEvents(chunkProcessor);
        }
        private void ProcessChunks(ImportParameters importParameters,
                                   IEnumerable <ImportDataChunk <EntityChunkData> > entityChunks)
        {
            var nonProcessionChunks = entityChunks.Where(chunk => chunk.State != ImportChunkState.Processed).ToList();

            if (!nonProcessionChunks.Any())
            {
                return;
            }
            IFileImportEntitiesChunkProcessor chunkProcessor = CreateChunkProcessor();

            SubscribeChunkProcessorEvents(chunkProcessor);
            foreach (var chunk in nonProcessionChunks)
            {
                ProcessChunk(chunkProcessor, importParameters, chunk);
            }
            UnsubscribeChunkProcessorEvents(chunkProcessor);
        }
 private void SubscribeChunkProcessorEvents(IFileImportEntitiesChunkProcessor chunkProcessor)
 {
     chunkProcessor.ImportEntitySaveError += ImportLogger.HandleException;
     chunkProcessor.ImportEntitySaveError += OnImportEntitySaveError;
     chunkProcessor.ImportEntitySaved     += OnImportEntitySaved;
 }