Пример #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);
        }