Exemplo n.º 1
0
        public static void ConvertHandler(HttpContext context)
        {
            DocumentConverterResult result;

            try
            {
                var inputDocument  = new BackSlashPath(ExamplesCoreConfiguration.UnprotectString(context.Request["inputDocument"]));
                var outputFormat   = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), context.Request["outputFormat"]);
                var fileName       = inputDocument.FileNameWithoutExtension + "." + DocumentFormatInfo.Get(outputFormat).DefaultExtension;
                var outputPath     = ConvertedPath.Append(context.Session.SessionID).Append(fileName);
                var outputDocument = outputPath.Append(fileName);

                if (Directory.Exists(outputPath))
                {
                    Directory.Delete(outputPath, true);
                }
                Directory.CreateDirectory(outputPath);
                result = DocumentUltimate.DocumentConverter.Convert(inputDocument, outputDocument, outputFormat);
            }
            catch (Exception exception)
            {
                context.Response.Write("<span style=\"color: red; font-weight: bold\">Conversion failed</span><br/>");
                context.Response.Write(exception.Message);
                return;
            }

            context.Response.Write("<span style=\"color: green; font-weight: bold\">Conversion successful</span>");
            context.Response.Write("<br/>Conversion time: " + result.ElapsedTime);
            context.Response.Write("<br/>Output files:");

            if (result.OutputFiles.Length > 1)
            {
                context.Response.Write(" - " + GetZipDownloadLink(new FileInfo(result.OutputFiles[0]).Directory));
            }

            context.Response.Write("<br/><ol>");
            foreach (var outputFile in result.OutputFiles)
            {
                if (outputFile.EndsWith("\\"))
                {
                    var directoryInfo = new DirectoryInfo(outputFile);
                    context.Response.Write(string.Format(
                                               "<br/><li><b>{0}\\</b> - {1}</li>",
                                               directoryInfo.Name,
                                               GetZipDownloadLink(directoryInfo))
                                           );
                }
                else
                {
                    var fileInfo = new FileInfo(outputFile);
                    context.Response.Write(string.Format(
                                               "<br/><li><b>{0}</b> ({1} bytes) - {2}</li>",
                                               fileInfo.Name,
                                               fileInfo.Length,
                                               GetDownloadLink(fileInfo))
                                           );
                }
            }
            context.Response.Write("<br/></ol>");
        }
Exemplo n.º 2
0
        public static void ZipDownloadHandler(HttpContext context)
        {
            var path = new BackSlashPath(ExamplesCoreConfiguration.UnprotectString(context.Request["path"])).RemoveTrailingSlash();

            var fileResponse = new FileResponse(context, 0);

            fileResponse.Transmit((targetStream, copyFileCallback) =>
            {
                QuickZip.Zip(targetStream, Directory.EnumerateFileSystemEntries(path));
            }, path.FileName + ".zip", 0);
        }
Exemplo n.º 3
0
        public static void DownloadVideoFrame(HttpContext context)
        {
            var videoPath = ExamplesCoreConfiguration.UnprotectString(context.Request["videoPath"]);
            var frameTime = int.Parse(context.Request["frameTime"]);

            using (var bitmap = GetFrame(videoPath, frameTime))
                using (var stream = new MemoryStream())
                {
                    bitmap.Save(stream, ImageFormat.Jpeg);
                    stream.Position = 0;

                    var fileResponse = new FileResponse(context);
                    fileResponse.Transmit(
                        stream,
                        "frame.jpg",
                        File.GetLastWriteTimeUtc(videoPath),
                        stream.Length,
                        neverExpires: true);
                }
        }