Exemple #1
0
        public void PollForSendTestMediaFiles()
        {
            try
            {
                var testIds = _settings.IpSendMediaFilesForTestIds;
                if (!testIds.Any())
                {
                    _logger.Info("No Test id found in config, please provide TestIds.");
                    return;
                }

                var customSettings = _customSettingManager.Deserialize(_settings.SendTestMediaFilesSettings);

                DateTime exportToTime   = DateTime.Now;
                DateTime exportFromTime = DateTime.Now;
                if (customSettings.LastTransactionDate == null)
                {
                    exportFromTime = _settings.SendTestMediaFilesCutoffDate;
                    exportToTime   = DateTime.Now;
                }
                else
                {
                    exportFromTime = customSettings.LastTransactionDate.Value.AddMinutes(-20);
                    exportToTime   = customSettings.LastTransactionDate.Value.AddMinutes(-10);
                }

                customSettings.LastTransactionDate = DateTime.Now;
                _customSettingManager.SerializeandSave(_settings.SendTestMediaFilesSettings, customSettings);

                var eventCustomerResults = _eventCustomerResultRepository.GetEventCustomerResultByTestIds(testIds, exportFromTime, exportToTime);
                if (!eventCustomerResults.Any())
                {
                    _logger.Info("No Customers found.");
                    return;
                }

                _logger.Info(string.Format("Found {0} customers for Media file copy. ", eventCustomerResults.Count()));

                foreach (var ecr in eventCustomerResults)
                {
                    _logger.Info("\n************************************************************************************************************ \n");
                    _logger.Info("**************************************** Starting for Customer Id: " + ecr.CustomerId + " and Event Id: " + ecr.EventId + " **************************************** \n");
                    var mediaFiles = _eventCustomerResultRepository.GetMediaByEventIdAndCustomerId(ecr.EventId, ecr.CustomerId, testIds);
                    if (mediaFiles.IsNullOrEmpty())
                    {
                        _logger.Info("There is not any media file availble for Customer Id: " + ecr.CustomerId + " and Event Id: " + ecr.EventId);
                        continue;
                    }
                    CopyMediaFile(ecr.CustomerId, ecr.EventId, mediaFiles);
                    _logger.Info("**************************************** Media File Copied for Customer Id: " + ecr.CustomerId + " and Event Id: " + ecr.EventId + " **************************************** \n");
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Message:" + ex.Message);
                _logger.Error("StackTrace:" + ex.StackTrace);
            }
        }