public void Init()
 {
     _coreDataRepository = new CoreDataRepository();
     _loggingRepository = new LoggingRepository();
     AutoMapperConfig.RegisterMappings();
     batchId = Guid.NewGuid();
 }
        public void RunBeforeEachTest()
        {
            _coreDataRepository = new CoreDataRepository();
            AutoMapperConfig.RegisterMappings();

            batchId = Guid.NewGuid();
        }
 public WorkerTestBase()
 {
     CoreDataRepository = new CoreDataRepository();
     LoggingRepository = new LoggingRepository();
     JobRepository = new UploadJobRepository();
     ErrorRepository = new UploadJobErrorRepository();
 }
 public UploadManager(IFusUploadRepository fusUploadRepository, CoreDataRepository coreDataRepository,
     LoggingRepository loggingRepository)
 {
     _fusUploadRepository = fusUploadRepository;
     _coreDataRepository = coreDataRepository;
     _loggingRepository = loggingRepository;
     _profilesReader = ReaderFactory.GetProfilesReader();
     var config = new MapperConfiguration(c => c.CreateMap<CoreDataSet, CoreDataSetArchive>().ReverseMap());
 }
        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (inProgress)
            {
                return;
            }

            inProgress = true;

            Init();

            try
            {
                _fusUploadRepository = new UploadJobRepository();
                _coreDataRepository = new CoreDataRepository();
                _loggingRepository = new LoggingRepository();
                _uploadManager = new UploadManager(_fusUploadRepository, _coreDataRepository, _loggingRepository);
                _logger.Debug("...");
            }
            catch (Exception ex)
            {
                LogException(ex);
                _logger.Info("--- Initialisation failed ---");
                inProgress = false;
                return;
            }


            try
            {
                _uploadManager.ProcessUploadJobs();
            }
            catch (Exception ex)
            {
                LogException(ex);
                _logger.Info("--- Process jobs failed ---");
            }
            finally
            {
                _fusUploadRepository = null;
                _coreDataRepository = null;
                _loggingRepository = null;
                _uploadManager = null;
                ReaderFactory.DisposeStatic();
            }

            inProgress = false;

        }
        public List<DuplicateRowInDatabaseError> GetDuplicates(List<UploadDataModel> data, CoreDataRepository repository, UploadJobType jobType)
        {
            var lastIndicatorId = -1;
            var rowIndex = 1;
            var duplicateRowInDatabaseErrors = new List<DuplicateRowInDatabaseError>();

            foreach (UploadDataModel row in data)
            {
                rowIndex++;

                if (row.IndicatorId != lastIndicatorId)
                {
                    lastIndicatorId = row.IndicatorId;
                }

                if (jobType == UploadJobType.Simple)
                {
                    row.CategoryId = -1;
                    row.CategoryTypeId = -1;
                }

                var duplicates = repository.GetDuplicateCoreDataSetForAnIndicator(row);

                if (duplicates.Count > 0)
                {
                    var duplicateDataError = new DuplicateRowInDatabaseError
                    {
                        ErrorMessage = "Data already exists for Indicator Id: " + row.IndicatorId,
                        RowNumber = rowIndex,
                        DbValue = duplicates.First().Value,
                        ExcelValue = row.Value,
                        IndicatorId = row.IndicatorId,
                        AgeId = row.AgeId,
                        SexId = row.SexId,
                        AreaCode = row.AreaCode,
                        Uid = duplicates.First().Uid
                    };

                    duplicateRowInDatabaseErrors.Add(duplicateDataError);
                    row.DuplicateExists = true;
                }
            }
            return duplicateRowInDatabaseErrors;
        }
 public SimpleWorksheetDataProcessor(CoreDataRepository coreDataRepository, LoggingRepository loggingRepository)
 {
     _coreDataRepository = coreDataRepository;
     _loggingRepository = loggingRepository;
 }