Example #1
0
        public void DoWork()
        {
            _logger.WriteLog("======================= Running DataPurgeWorker =======================", LogLevel.Info);

            #region Reset warehouse box count

            _dataPurgeService.ResetWarehouseBoxCount(); // always run

            #endregion

            #region Purge data
            var todayDataPurges = _dataPurgeService.GetTodayDataPurge();

            if (todayDataPurges.Count == 0)
            {
                _logger.WriteLog("No data purge found today.");
            }
            else
            {
                foreach (var dataPurge in todayDataPurges)
                {
                    _logger.WriteLog("***Start purging profiles");
                    var purgedProfiles = _profileService.GetProfilesForDataPurge(dataPurge.StartDate, dataPurge.EndDate.EndOfDate());
                    int profilePurgeCount;
                    _dataPurgeService.PurgeProfiles(purgedProfiles, out profilePurgeCount);
                    _logger.WriteLog("***End purging profiles");

                    _logger.WriteLog("***Start purging profile scans");
                    var purgedProfileScans = _profileService.GetProfileScansForDataPurge(dataPurge.StartDate, dataPurge.EndDate.EndOfDate());
                    _dataPurgeService.PurgeProfileScans(purgedProfileScans);
                    _logger.WriteLog("***End purging profile scans");

                    _logger.WriteLog("***Start purging profile boxes");
                    var purgedBoxes = _profileService.GetProfileBoxesForDataPurge(dataPurge.StartDate, dataPurge.EndDate.EndOfDate());
                    _dataPurgeService.PurgeProfileBoxes(purgedBoxes);
                    _logger.WriteLog("***End purging profile boxes");

                    _logger.WriteLog("***Start purging distributors");
                    var purgedDistributors = _distributorService.GetDistributorsForDataPurge(dataPurge.StartDate, dataPurge.EndDate.EndOfDate());
                    _dataPurgeService.PurgeDistributors(purgedDistributors);
                    _logger.WriteLog("***End purging distributors");

                    // Update file count
                    dataPurge.FileCount = profilePurgeCount;
                    _dataPurgeService.Update(dataPurge);
                }
            }
            #endregion

            _logger.WriteLog("======================= Stopping DataPurgeWorker =======================", LogLevel.Info);
        }