Example #1
0
        public ListModelBase <CustomerCdContentTrackingModel, CustomerCdConentTrackingModelFilter> GetCustomerCdContentTrackingModel(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords)
        {
            var eventCustomers = _eventCustomerRepository.GetEventCustomersWithCdPurchase(pageNumber, pageSize, filter as CustomerCdConentTrackingModelFilter, out totalRecords);

            if (eventCustomers.IsNullOrEmpty())
            {
                return(null);
            }
            var customers = _customerRepository.GetCustomers(eventCustomers.Select(ec => ec.CustomerId).ToArray());

            var orderIds =
                _orderRepository.GetOrderEventCustomerIdPairforEventCustomerIds(
                    eventCustomers.Select(ec => ec.Id).ToArray());

            var cdContentTrackingList =
                _cdContentGeneratorTrackingRepository.GetCdContentGeneratedforEventCustomerIds(
                    eventCustomers.Select(ec => ec.Id).ToArray());

            var orgRoleUserIds = (from cdContentGeneratorTracking in cdContentTrackingList
                                  where cdContentGeneratorTracking.DownloadedByOrgRoleUserId.HasValue
                                  select cdContentGeneratorTracking.DownloadedByOrgRoleUserId.Value).ToArray();

            var idNamePairs = _orgRoleuserRepository.GetNameIdPairofUsers(orgRoleUserIds);

            return(_customerCdContentTrackingModelFactory.Create(eventCustomers, customers, orderIds, cdContentTrackingList,
                                                                 idNamePairs));
        }
Example #2
0
        private void CheckEventCustomerResultStateAndDeleteCdGenTrackRecord(long eventId, long customerId)
        {
            var isCdPurchased = _electronicProductRepository.IsProductPurchased(eventId, customerId, Product.UltraSoundImages);

            if (isCdPurchased)
            {
                return;
            }

            var eventCustomerResult = _eventCustomerResultRepository.GetByCustomerIdAndEventId(customerId, eventId);

            if (eventCustomerResult == null)
            {
                return;
            }
            try
            {
                var cdContent = _cdContentGeneratorTrackingRepository.GetCdContentGeneratedforEventCustomerIds(new[] { eventCustomerResult.Id }).FirstOrDefault();
                if (cdContent != null)
                {
                    _cdContentGeneratorTrackingRepository.Delete(cdContent.Id);
                }
            }
            catch
            {
            }
        }
Example #3
0
        public bool GenerateCdContent(long eventId, long customerId, CorporateAccount corporateAccount)
        {
            //2. Customer who is having CD in the order, pick up those Customer Ids
            var isCdPurchased = _electronicProductRepository.IsProductPurchased(eventId, customerId, Product.UltraSoundImages);

            if (isCdPurchased)
            {
                //3. Check whether cd content is generated or not
                var eventCustomerResult = _eventCustomerResultRepository.GetByCustomerIdAndEventId(customerId, eventId);
                if (eventCustomerResult == null)
                {
                    return(false);
                }

                var cdContentGeneratedRecords     = _cdContentGeneratorTracking.GetCdContentGeneratedforEventCustomerIds(new[] { eventCustomerResult.Id });
                CdContentGeneratorTracking record = cdContentGeneratedRecords != null?cdContentGeneratedRecords.SingleOrDefault() : null;

                var cdContentGenerated = record != null ? record.IsContentGenerated : false;

                if (!cdContentGenerated)
                {
                    //4. Check whether Pdf generated or not
                    if (eventCustomerResult.IsResultPdfGenerated)
                    {
                        //5. Pickup the folder for images
                        var sourceFolderPathforMedia = _mediaRepository.GetResultMediaFileLocation(customerId, eventId).PhysicalPath;
                        //6. Convert the physician evaluation (readonly) page to index page
                        //7. Pick up result Pdf
                        //8. Dump the content as

                        /*
                         * Media-Location
                         *  CdContent
                         *      EventId
                         *          CustomerId
                         *              Media
                         *              ResultPdf
                         *              Index.html
                         *
                         *
                         */
                        var physicalPathForCdContent = _mediaRepository.GetCdContentFolderLocation(eventId, customerId, false).PhysicalPath;
                        try
                        {
                            if (!Directory.Exists(physicalPathForCdContent))
                            {
                                Directory.Delete(physicalPathForCdContent, true);
                            }
                        }
                        catch
                        { }

                        physicalPathForCdContent = _mediaRepository.GetCdContentFolderLocation(eventId, customerId).PhysicalPath;

                        var files = _testResultRepository.GetTestMedia(eventId, customerId);

                        foreach (OrderedPair <string, string> file in files)
                        {
                            var destinationDirectory = Path.Combine(physicalPathForCdContent + @"Media\");
                            if (!Directory.Exists(destinationDirectory))
                            {
                                Directory.CreateDirectory(destinationDirectory);
                            }

                            if (!string.IsNullOrEmpty(file.FirstValue))
                            {
                                file.FirstValue = file.FirstValue.Replace(VideoFileFormat, CDVideoFileFormat);
                                var sourceFile = Path.Combine(sourceFolderPathforMedia, file.FirstValue);
                                var destFile   = Path.Combine(destinationDirectory, file.FirstValue);

                                File.Copy(sourceFile, destFile, true);
                            }

                            if (!string.IsNullOrEmpty(file.SecondValue))
                            {
                                var sourceFile = Path.Combine(sourceFolderPathforMedia, file.SecondValue);
                                var destFile   = Path.Combine(destinationDirectory, file.SecondValue);
                                File.Copy(sourceFile, destFile, true);
                            }
                        }

                        string sourcePdfFile;

                        if (corporateAccount != null && corporateAccount.AddImagesForAbnormal)
                        {
                            sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForResultReport();
                            if (!File.Exists(sourcePdfFile))
                            {
                                sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForPcpResultReport();
                            }
                        }
                        else
                        {
                            sourcePdfFile = _mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).PhysicalPath + _mediaRepository.GetPdfFileNameForResultReport();
                        }

                        if (File.Exists(sourcePdfFile))
                        {
                            var pdfFileName = _mediaRepository.GetPdfFileNameForResultReport();//Path.GetFileName(sourcePdfFile);
                            if (!Directory.Exists(physicalPathForCdContent + @"ResultPdf\"))
                            {
                                Directory.CreateDirectory(physicalPathForCdContent + @"ResultPdf\");
                            }

                            var destPdfFile = Path.Combine(physicalPathForCdContent + @"ResultPdf\", pdfFileName);
                            File.Copy(sourcePdfFile, destPdfFile, true);
                        }

                        ZipCdContentsforEventCustomer(eventId, customerId);

                        var cdContentTracking = new CdContentGeneratorTracking
                        {
                            EventCustomerResultId     = eventCustomerResult.Id,
                            IsContentGenerated        = true,
                            IsContentDownloaded       = false,
                            DownloadedByOrgRoleUserId = null,
                            DownloadedDate            = null,
                            ContentGeneratedDate      = DateTime.Now
                        };

                        if (record != null)
                        {
                            cdContentTracking = record;
                            cdContentTracking.IsContentGenerated   = true;
                            cdContentTracking.ContentGeneratedDate = DateTime.Now;
                        }

                        _cdContentGeneratorTracking.Save(cdContentTracking);
                        //9. Save CD content tracking
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #4
0
        public void CleanUpPastCdContentFolder()
        {
            if (_settings.ResultArchiveWaitDays < 1)
            {
                return;
            }

            const int days = 45;
            var       dateForCleaningUpCdContent = DateTime.Now.Date.AddDays(-1 * days);
            var       filter = new EventBasicInfoViewModelFilter
            {
                DateTo   = dateForCleaningUpCdContent,
                DateFrom = dateForCleaningUpCdContent.AddDays(-1 * days)
            };

            int pageNumber = 1;

            _logger.Info(
                "\n\n ****************************************** Cd Content (Fortnight Loop) ****************************************");

            _logger.Info("\nBatch Started -------------------------------------------------------------------\n");

            while (true)
            {
                int totalRecords = 0;
                var events       = _eventRepository.GetEventsbyFilters(filter, pageNumber++, 100, out totalRecords);

                if (events == null || events.Count() < 1)
                {
                    break;
                }

                foreach (var @event in events)
                {
                    try
                    {
                        var eventCustomerResults = _eventCustomerResultRepository.GetByEventId(@event.Id);
                        if (eventCustomerResults == null || eventCustomerResults.Count() < 1)
                        {
                            continue;
                        }

                        var eventCustomerResultIds = eventCustomerResults.Select(ecr => ecr.Id).ToArray();

                        var cdContentTrackingRecords = _cdContentGeneratorTrackingRepository.GetCdContentGeneratedforEventCustomerIds(eventCustomerResultIds);
                        cdContentTrackingRecords = cdContentTrackingRecords != null?cdContentTrackingRecords.Where(r => r.IsContentGenerated && (!r.ContentGeneratedDate.HasValue || r.ContentGeneratedDate < DateTime.Now.AddDays(-1 * _settings.ResultArchiveWaitDays))) : null;

                        if (cdContentTrackingRecords != null && cdContentTrackingRecords.Count() > 0)
                        {
                            eventCustomerResultIds = cdContentTrackingRecords.Select(cd => cd.EventCustomerResultId).ToArray();
                            eventCustomerResults   = eventCustomerResults.Where(ecr => eventCustomerResultIds.Contains(ecr.Id)).ToArray();

                            CleanUpCdContentForRecords(eventCustomerResults, cdContentTrackingRecords);
                        }

                        var location = _mediaRepository.GetCdContentFolderLocation(@event.Id, false);
                        if (location == null)
                        {
                            continue;
                        }

                        if (Directory.Exists(location.PhysicalPath))
                        {
                            var files = Directory.GetFiles(location.PhysicalPath, "*.zip");
                            if (files.Count() < 1)
                            {
                                Directory.Delete(location.PhysicalPath, true);
                            }
                        }
                        var zipFileName = Path.GetDirectoryName(Path.GetDirectoryName(location.PhysicalPath)) + "\\" + @event.Id + ".zip";
                        if (System.IO.File.Exists(zipFileName))
                        {
                            System.IO.File.Delete(zipFileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error("\n Failed For Event Id [" + @event.Id + "]. Message: " + ex.Message + ".\n\t Stack Trace:  " + ex.StackTrace);
                    }
                }
            }
        }