Beispiel #1
0
        public bool ZipCdContentsPerEvent(long eventId)
        {
            var eventCustomers          = _eventCustomerRepository.GetEventCustomersWithCdPurchaseByEventId(eventId);
            var cdPurchasedCount        = eventCustomers.Count();
            var cdContentGeneratedCount = eventCustomers.Select(eventCustomer => _cdContentGeneratorTracking.IsCdContentGenerated(eventCustomer.EventId, eventCustomer.CustomerId)).Count(isCdContentGenerated => isCdContentGenerated);

            if (cdContentGeneratedCount == 0)
            {
                return(false);
            }

            var sourcePath = _mediaRepository.GetCdContentFolderLocation(eventId).PhysicalPath;

            //TODO:Extract zip files for the customer whose cd content folder has been deleted.
            var files = Directory.GetFiles(sourcePath).Where(file => file.EndsWith(".zip"));

            foreach (var file in files)
            {
                string directoryName = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file);

                if (Directory.Exists(directoryName))
                {
                    try
                    {
                        Directory.Delete(directoryName, true);
                        _zipHelper.ExtractZipFiles(file);
                    }
                    catch
                    {
                        throw;
                    }
                }
            }

            var outPutPath = _zipHelper.CreateZipFiles(sourcePath, true);

            var eventPath = _mediaRepository.GetResultPacketMediaLocation(eventId).PhysicalPath;
            var fileName  = eventPath + eventId + ".zip";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.Move(outPutPath, fileName);

            if (cdContentGeneratedCount >= cdPurchasedCount)
            {
                foreach (var dir in Directory.GetDirectories(sourcePath))
                {
                    try
                    {
                        Directory.Delete(dir, true);
                    }
                    catch
                    {
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        public void PollforUploadCompleteResultArchives()
        {
            var tempLogger     = _logManager.GetLogger("jobs");
            var resultArchives = _resultArchiveUploadRepository.Get(ResultArchiveUploadStatus.Uploaded);

            resultArchives = resultArchives.Where(r => r.FileId.HasValue).OrderBy(r => r.UploadEndTime);
            if (resultArchives.Count() > 0)
            {
                tempLogger.Info("Got the uploaded files list.");
            }

            foreach (var resultArchive in resultArchives)
            {
                var     logFileName = "File_" + resultArchive.Id;
                ILogger logger      = new NLogLogManager().GetLogger(logFileName);

                var theEvent = new LogEventInfo(LogLevel.Off, "", logFileName);
                theEvent.Properties["LogFileName"] = logFileName;

                string extractedFilePath = "";
                string zipFilePath       = "";
                logger.Info(
                    "\n\n****************************************************************************************************************** ");
                try
                {
                    // ReSharper disable PossibleInvalidOperationException
                    var file = _fileRepository.GetById(resultArchive.FileId.Value);
                    // ReSharper restore PossibleInvalidOperationException

                    if (file == null)
                    {
                        logger.Info(String.Format("\nFile Information not found for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId));
                        resultArchive.Status = ResultArchiveUploadStatus.FileNotFound;
                        _resultArchiveUploadRepository.Save(resultArchive);
                        continue;
                    }

                    var mediaLocation = _mediaRepository.GetResultArchiveMediaFileLocation(resultArchive.EventId);
                    if (!System.IO.File.Exists(mediaLocation.PhysicalPath + file.Path))
                    {
                        logger.Info(String.Format("\nInvalid File Path for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId));
                        resultArchive.Status = ResultArchiveUploadStatus.FileNotFound;
                        _resultArchiveUploadRepository.Save(resultArchive);
                        continue;
                    }

                    zipFilePath = mediaLocation.PhysicalPath + file.Path;
                }
                catch (Exception ex)
                {
                    logger.Info(String.Format("\nSystem Failure, while fetching File Info for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2}. \nMessage:{3} \n\t {4}", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId, ex.Message, ex.StackTrace));
                    resultArchive.Status = ResultArchiveUploadStatus.FileNotFound;
                    _resultArchiveUploadRepository.Save(resultArchive);
                    continue;
                }

                try
                {
                    resultArchive.ParseStartTime = DateTime.Now;
                    resultArchive.Status         = ResultArchiveUploadStatus.Parsing;
                    _resultArchiveUploadRepository.Save(resultArchive);
                }
                catch (Exception ex)
                {
                    logger.Info("\nSystem Failure, while saving 'Parsing Start Time'! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                    continue;
                }

                try
                {
                    extractedFilePath = _zipHelper.ExtractZipFiles(zipFilePath);
                }
                catch (Exception ex)
                {
                    logger.Info(String.Format("\nSystem Failure, Invalid File Format for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2}. \nMessage:{3} \n\t {4}", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId, ex.Message, ex.StackTrace));
                    resultArchive.Status = ResultArchiveUploadStatus.InvalidFileFormat;
                    _resultArchiveUploadRepository.Save(resultArchive);
                    continue;
                }

                try
                {
                    logger.Info(String.Format("\nParsing Started for Result Archive Id: {0}, uploaded on {1}, for the Event Id: {2} ", resultArchive.Id, resultArchive.UploadEndTime.Value, resultArchive.EventId));

                    _resultParser = new ResultParser(resultArchive.Id, extractedFilePath, _corporateAccountRepository, _mediaRepository, _resultArchiveUploadRepository, _resultArchiveUploadLogRepository, logger, _settings, _customerRepository, _zipHelper,
                                                     _basicBiometricRepository, _eventCustomerRepository, _lipidParserHelper, _endofDayService, _customerService, _eventRepository);
                    _resultParser.Parse();
                    logger.Info("\nParsing completed without any system Failure.");
                    resultArchive.ParseEndTime = DateTime.Now;
                    //Directory.Delete(extractedFilePath, true);
                }
                catch (IOException ex)
                {
                    logger.Info("\nParsing Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace);

                    resultArchive.ParseEndTime = DateTime.Now;
                    resultArchive.Status       = ResultArchiveUploadStatus.ParseFailed;
                    _resultArchiveUploadRepository.Save(resultArchive);
                }
                catch (Exception ex)
                {
                    logger.Info("\nParsing Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace);

                    resultArchive.ParseEndTime = DateTime.Now;
                    resultArchive.Status       = ResultArchiveUploadStatus.ParseFailed;
                    _resultArchiveUploadRepository.Save(resultArchive);
                    Directory.Delete(extractedFilePath, true);
                }
                finally
                {
                    var ecs = _eventCustomerResultRepository.GetByEventId(resultArchive.EventId);

                    if (ecs != null && ecs.Count() > 0)
                    {
                        foreach (var eventCustomerResult in ecs)
                        {
                            _eventCustomerResultRepository.SetEventCustomerResultState(eventCustomerResult.EventId, eventCustomerResult.CustomerId);
                        }
                    }

                    // GC.Collect();
                    //logger.Info("Calling gc collect");
                    Thread.Sleep(2000);
                }

                try
                {
                    var resultArchiveLogs = _resultArchiveUploadLogRepository.GetbyResultArchiveId(resultArchive.Id);
                    var succesFulRecords  = resultArchiveLogs != null?resultArchiveLogs.Where(rl => rl.IsSuccessful).Count() : 0;

                    if (succesFulRecords > 0)
                    {
                        resultArchive.Status = ResultArchiveUploadStatus.Parsed;
                    }
                    else
                    {
                        resultArchive.Status = ResultArchiveUploadStatus.ParseFailed;
                    }

                    var customerCount = resultArchiveLogs != null?resultArchiveLogs.Select(rl => rl.CustomerId).Distinct().Count() : 0;

                    resultArchive.CustomerRecordsFound = customerCount;
                    _resultArchiveUploadRepository.Save(resultArchive);
                }
                catch (Exception ex)
                {
                    logger.Info("/Saving Parse End Data Failed! Message: " + ex.Message + "\n\t" + ex.StackTrace);
                }
            }
        }