Beispiel #1
0
        public ConversionResultModel ConvertAndGetTargetFileName(BookSourceModel source, BookFormatEnum outputFormat,
                                                                 bool compress = true)
        {
            Guid id = ExtractBook(source.FileName, source.Body);

            if (outputFormat != DefaultBookFormat)
            {
                Convert(id, outputFormat);
                var sourceFile = GetTempFileName(id, DefaultBookFormat);
                if (File.Exists(sourceFile))
                {
                    File.Delete(sourceFile);
                }
            }

            var result = new ConversionResultModel
            {
                DownloadFileName = string.Format("{0}.{1}",
                                                 Transliterator.FromCyrillicToTransliteration(TextHelper.CleanCharacters(source.Name)),
                                                 outputFormat).ToLower(),
                FullFileName = GetTempFileName(id, outputFormat)
            };

            if (compress)
            {
                result = Compress(result);
            }

            return(result);
        }
        public static ConversionResultModel MapConversionRequestToConversionResult(
            ConversionRequestModel conversionRequest)
        {
            if (conversionRequest == null)
            {
                return(null);
            }

            var conversionResultModel = new ConversionResultModel()
            {
                FromConversion = new FromConversion()
                {
                    Amount       = conversionRequest.Amount,
                    CurrencyCode = conversionRequest.FromCurrency
                },
                ToConversion = new ToConversion()
                {
                    CurrencyCode = conversionRequest.ToCurrency
                }
            };

            if (!string.IsNullOrWhiteSpace(conversionRequest.Date))
            {
                conversionResultModel.Date = conversionRequest.Date;
            }

            return(conversionResultModel);
        }
Beispiel #3
0
        public void DeliverBookToEmail(string toEmail, string name, ConversionResultModel source)
        {
            var result  = GetSender();
            var message = new MailMessage
            {
                From    = new MailAddress(MailController.MailSettings.NoReplyEmail),
                Subject = string.Format(Text.BookSent, name)
            };

            message.To.Add(new MailAddress(toEmail));
            message.Attachments.Add(new Attachment(source.FullFileName)
            {
                Name = source.DownloadFileName
            });
            result.MailSender.Send(message);
        }
Beispiel #4
0
        public ConversionResultModel Compress(ConversionResultModel source)
        {
            var fileName = string.Format("{0}.zip", source.FullFileName);

            using (var zip = ZipFile.Create(fileName))
            {
                zip.BeginUpdate();
                zip.Add(source.FullFileName, source.DownloadFileName);
                zip.CommitUpdate();
            }
            if (File.Exists(source.FullFileName))
            {
                File.Delete(source.FullFileName);
            }
            source.FullFileName     = fileName;
            source.DownloadFileName = string.Format("{0}.zip", source.DownloadFileName);
            return(source);
        }
Beispiel #5
0
        public static CurrencyConversionModelResponse MapConversionResultToCurrencyConversion(ConversionResultModel conversionResult)
        {
            if (conversionResult == null)
            {
                return(null);
            }

            var conversionResponse = new CurrencyConversionModelResponse()
            {
                FromConversion = new FromConversion(),
                ToConversion   = new ToConversion()
            };

            if (conversionResult.FromConversion != null)
            {
                conversionResponse.FromConversion.CurrencyCode = conversionResult?.FromConversion?.CurrencyCode;
                conversionResponse.FromConversion.Amount       = conversionResult.FromConversion.Amount;
            }

            if (conversionResult.ToConversion != null)
            {
                conversionResponse.ToConversion.CurrencyCode = conversionResult?.ToConversion?.CurrencyCode;
                conversionResponse.ToConversion.Amount       = conversionResult.ToConversion.Amount;
            }

            if (string.IsNullOrWhiteSpace(conversionResult.Date))
            {
                conversionResponse.Date = conversionResult.Date;
            }

            return(conversionResponse);
        }