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 ActionResult DeliverBook(Guid bookId, BookFormatEnum bookFormat, bool compress = true, string email = null) { var bookSource = DataService.GetBookSource(bookId, User.UserId, User.IsSuperUser); if (bookSource == null) { return(new HttpNotFoundResult()); } try { var target = _convertService.ConvertAndGetTargetFileName(bookSource, bookFormat, compress); if (!string.IsNullOrEmpty(email)) { DataService.AddDownload((Guid)User.UserId, bookId, DownloadTypeEnum.Email); _mailService.DeliverBookToEmail(email, bookSource.Name, target); if (System.IO.File.Exists(target.DownloadFileName)) { System.IO.File.Delete(target.DownloadFileName); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } DataService.AddDownload((Guid)User.UserId, bookId, DownloadTypeEnum.File); return(new FilePathResult(target.FullFileName, System.Net.Mime.MediaTypeNames.Application.Octet) { FileDownloadName = target.DownloadFileName }); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
private void Convert(Guid id, BookFormatEnum outputFormat) { var info = new ProcessStartInfo(string.Format("\"{0}\"", Path.Combine(_settings.Path, ExternalAppName))) { UseShellExecute = true, Arguments = string.Format("\"{0}\" \"{1}\"", GetTempFileName(id, DefaultBookFormat), GetTempFileName(id, outputFormat)), RedirectStandardOutput = false, RedirectStandardError = false, RedirectStandardInput = false, CreateNoWindow = true, }; var process = Process.Start(info); process.WaitForExit(1 * 60 * 1000); }
public ActionResult DeliverBook(Guid bookId, BookFormatEnum bookFormat, bool compress = true, string email = null) { var bookSource = DataService.GetBookSource(bookId, User.UserId, User.IsSuperUser); if (bookSource == null) return new HttpNotFoundResult(); try { var target = _convertService.ConvertAndGetTargetFileName(bookSource, bookFormat, compress); if (!string.IsNullOrEmpty(email)) { DataService.AddDownload((Guid)User.UserId, bookId, DownloadTypeEnum.Email); _mailService.DeliverBookToEmail(email, bookSource.Name, target); if (System.IO.File.Exists(target.DownloadFileName)) System.IO.File.Delete(target.DownloadFileName); return new HttpStatusCodeResult(HttpStatusCode.OK); } DataService.AddDownload((Guid)User.UserId, bookId, DownloadTypeEnum.File); return new FilePathResult(target.FullFileName, System.Net.Mime.MediaTypeNames.Application.Octet) { FileDownloadName = target.DownloadFileName }; } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message); } }
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); }
private string GetTempFileName(Guid identifier, BookFormatEnum outputFormat) { var fileName = string.Format("knigoskop_{0}.{1}", identifier, outputFormat.ToString().ToLower()); return(Path.Combine(Path.GetTempPath(), fileName)); }
private string GetTempFileName(Guid identifier, BookFormatEnum outputFormat) { var fileName = string.Format("knigoskop_{0}.{1}", identifier, outputFormat.ToString().ToLower()); return Path.Combine(Path.GetTempPath(), fileName); }