Пример #1
0
 /// <summary>
 /// Subclasses should call this, instead of "Callback()" directly.
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dest"></param>
 protected void RaiseCallbackEvent(ConversionFile src, IEnumerable<ConversionFile> dest)
 {
     if (this.Callback != null)
     {
         Task.Run(() => this.Callback(src, dest));
     }
 }
Пример #2
0
 /// <summary>
 /// Subclasses should call this, instead of "Callback()" directly.
 /// </summary>
 /// <param name="src"></param>
 /// <param name="dest"></param>
 protected void RaiseCallbackEvent(ConversionFile src, IEnumerable <ConversionFile> dest)
 {
     if (this.Callback != null)
     {
         Task.Run(() => this.Callback(src, dest));
     }
 }
        private string GetOutputDir(ConversionFile toBeConverted)
        {
            if (toBeConverted == null)
            {
                return(string.Empty);
            }

            //string hash = Hash.GetEncodedHash(toBeConverted.RowId);
            return(Path.Combine(
                       _rootOutputPath,
                       toBeConverted.GetHashBasedOfRowId(),
                       "images"));
        }
        private string GetOutputDir(ConversionFile toBeConverted)
        {
            if (toBeConverted == null)
            {
                return string.Empty;
            }

            //string hash = Hash.GetEncodedHash(toBeConverted.RowId);
            return Path.Combine(
                _rootOutputPath,
                toBeConverted.GetHashBasedOfRowId(),
                "images");
        }
Пример #5
0
        public override void Execute(ConversionFile toBeConverted)
        {
            File   file   = this.UploadFile(toBeConverted.GetStream(), toBeConverted.FileName, toBeConverted.MimeType, true);
            Stream stream = this.DownloadPdf(file.Id);

            //TODO: I wonder what the effect would be if the converter callback used QueueBackgroundWorkItem too...
            if (this.Callback != null)
            {
                var dir = Path.GetDirectoryName(toBeConverted.Path);
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    var output = ConversionFile.SaveAs(stream,
                                                       Path.Combine(dir, Path.GetFileNameWithoutExtension(toBeConverted.Path) + ".pdf"));
                    Callback(toBeConverted, new List <ConversionFile>(new[] { output }).AsEnumerable());
                }
            }
        }
Пример #6
0
        public override void Execute(ConversionFile toBeConverted)
        {
            File file = this.UploadFile(toBeConverted.GetStream(), toBeConverted.FileName, toBeConverted.MimeType, true);
            Stream stream = this.DownloadPdf(file.Id);

            //TODO: I wonder what the effect would be if the converter callback used QueueBackgroundWorkItem too...
            if (this.Callback != null)
            {
                var dir = Path.GetDirectoryName(toBeConverted.Path);
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    var output = ConversionFile.SaveAs(stream,
                    Path.Combine(dir, Path.GetFileNameWithoutExtension(toBeConverted.Path) + ".pdf"));
                    Callback(toBeConverted, new List<ConversionFile>(new[] { output }).AsEnumerable());
                }

            }
        }
        public override void Execute(ConversionFile toBeConverted)
        {
            var outputDir = GetOutputDir(toBeConverted);
            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            var fileNames = PdfToImages(toBeConverted.Path, outputDir, 120);

            List<ConversionFile> outputFiles = new List<ConversionFile>();
            foreach (string file in fileNames)
            {
                ConversionFile f = new ConversionFile
                {
                    Path = file
                };
                outputFiles.Add(f);
            }

            this.RaiseCallbackEvent(toBeConverted, outputFiles);
        }
        public override void Execute(ConversionFile toBeConverted)
        {
            var outputDir = GetOutputDir(toBeConverted);

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            var fileNames = PdfToImages(toBeConverted.Path, outputDir, 120);

            List <ConversionFile> outputFiles = new List <ConversionFile>();

            foreach (string file in fileNames)
            {
                ConversionFile f = new ConversionFile
                {
                    Path = file
                };
                outputFiles.Add(f);
            }

            this.RaiseCallbackEvent(toBeConverted, outputFiles);
        }
Пример #9
0
 public static ConversionFile SaveAs(Stream stream, string path)
 {
     try
     {
         using (var fileStream = System.IO.File.Create(path))
         {
             stream.Seek(0, SeekOrigin.Begin);
             stream.CopyTo(fileStream);
         }
         ConversionFile f = new ConversionFile
         {
             Path = path,
             Type = FileType.Local
         };
         return(f);
     }
     // ReSharper disable once RedundantCatchClause
     catch (Exception ex)
     {
         //TODO: log File.SaveAs errors
         System.Diagnostics.Debug.WriteLine("SaveAs() Exception: " + ex.Message);
         throw;
     }
 }
Пример #10
0
 public abstract void Execute(ConversionFile toBeConverted);
Пример #11
0
 public abstract void Execute(ConversionFile toBeConverted);
Пример #12
0
 public static ConversionFile SaveAs(Stream stream, string path)
 {
     try
     {
         using (var fileStream = System.IO.File.Create(path))
         {
             stream.Seek(0, SeekOrigin.Begin);
             stream.CopyTo(fileStream);
         }
         ConversionFile f = new ConversionFile
         {
             Path = path,
             Type = FileType.Local
         };
         return f;
     }
     // ReSharper disable once RedundantCatchClause
     catch (Exception ex)
     {
         //TODO: log File.SaveAs errors
         System.Diagnostics.Debug.WriteLine("SaveAs() Exception: " + ex.Message);
         throw;
     }
 }