コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            exampleExplorer.VersionTitle = "v" + VideoUltimateConfiguration.AssemblyInfo.FileVersion;

            exampleExplorer.Examples = new ExampleBase[]
            {
                new Example
                {
                    Title           = "Overview",
                    Url             = "Overview.aspx",
                    SourceFiles     = new[] { "Overview.aspx", "Overview.aspx.cs" },
                    DescriptionFile = "Descriptions/Overview.html"
                },
                new Example
                {
                    Title           = "Reading video frames",
                    Url             = "Reading.aspx",
                    SourceFiles     = new[] { "Reading.aspx", "Reading.aspx.cs" },
                    DescriptionFile = "Descriptions/Reading.html"
                }
            };

            exampleExplorer.ExampleProjectName = "ASP.NET Web Forms (C#)";
            exampleExplorer.ExampleProjects    = ExamplesCoreConfiguration.LoadExampleProjects(Server.MapPath("~/App_Data/ExampleProjects.json"));
        }
コード例 #2
0
        public ActionResult Overview()
        {
            var model = new OverviewViewModel
            {
                ExampleFileSelector = new ExampleFileSelector
                {
                    ID          = "exampleFileSelector",
                    InitialFile = "Default.pdf"
                }
            };

            var inputDocument = model.ExampleFileSelector.SelectedFile;
            var fileInfo      = new FileInfo(inputDocument);
            var inputFormat   = DocumentFormatInfo.Get(inputDocument);

            model.InputFormat = inputFormat != null ? inputFormat.Description : "(not supported)";

            PopulatePossibleOutputFormats(inputDocument, model);

            model.ConvertHandlerUrl = ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                ConvertHandlerName,
                new NameValueCollection
            {
                { "inputDocument", ExamplesCoreConfiguration.ProtectString(inputDocument) },
                { "version", fileInfo.LastWriteTimeUtc.Ticks + "-" + fileInfo.Length }
            });

            return(View(model));
        }
コード例 #3
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>");
        }
コード例 #4
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);
        }
コード例 #5
0
 private static string GetZipDownloadLink(DirectoryInfo directoryInfo)
 {
     return(string.Format(
                "<a href=\"{0}\">Download as Zip</a>",
                ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                    ZipDownloadHandlerName,
                    new NameValueCollection
     {
         { "path", ExamplesCoreConfiguration.ProtectString(directoryInfo.FullName) },
         { "version", directoryInfo.LastWriteTimeUtc.Ticks.ToString() },
     })));
 }
コード例 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PopulateInputFormats();
            PopulateOutputFormats();

            ResultHandlerUrl = ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                ResultHandlerName,
                new NameValueCollection
            {
                { "version", DateTime.UtcNow.Ticks.ToString() }
            });
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var videoPath         = exampleFileSelector.SelectedFile;
            var fileInfo          = new FileInfo(videoPath);
            var thumbnailCacheKey = new DiskCacheKey(new DiskCacheSourceKey(fileInfo.Name, fileInfo.Length, fileInfo.LastWriteTimeUtc), "jpg");

            ThumbnailUrl = ExamplesCoreConfiguration.GetDownloadUrl(
                ThumbnailCache.GetOrAdd(
                    thumbnailCacheKey,
                    thumbnailPath => GetAndSaveThumbnail(videoPath, thumbnailPath)
                    ).FilePath,
                thumbnailCacheKey.FullValue
                );

            VideoInfo = GetVideoInfo(videoPath);
        }
コード例 #8
0
        public ActionResult Possible()
        {
            var model = new PossibleViewModel();

            PopulateInputFormats(model);
            PopulateOutputFormats(model);

            model.ResultHandlerUrl = ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                ResultHandlerName,
                new NameValueCollection
            {
                { "version", DateTime.UtcNow.Ticks.ToString() }
            });

            return(View(model));
        }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var videoPath = exampleFileSelector.SelectedFile;
            var fileInfo  = new FileInfo(videoPath);

            FrameDownloaderUrl = ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                FrameDownloaderHandlerName,
                new NameValueCollection
            {
                { "videoPath", ExamplesCoreConfiguration.ProtectString(videoPath) },
                { "version", fileInfo.LastWriteTimeUtc.Ticks + "-" + fileInfo.Length },
                { "frameTime", "0" }
            });

            var duration = GetDuration(videoPath);

            TotalSeconds = ((int)duration.TotalSeconds).ToString(CultureInfo.InvariantCulture);
        }
コード例 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var inputDocument = exampleFileSelector.SelectedFile;
            var fileInfo      = new FileInfo(inputDocument);

            var inputFormat = DocumentFormatInfo.Get(inputDocument);

            InputFormat = inputFormat != null ? inputFormat.Description : "(not supported)";

            PopulatePossibleOutputFormats(inputDocument);

            ConvertHandlerUrl = ExamplesCoreConfiguration.GetDynamicDownloadUrl(
                ConvertHandlerName,
                new NameValueCollection
            {
                { "inputDocument", ExamplesCoreConfiguration.ProtectString(inputDocument) },
                { "version", fileInfo.LastWriteTimeUtc.Ticks + "-" + fileInfo.Length }
            });
        }
コード例 #11
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);
                }
        }
コード例 #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            exampleExplorer.VersionTitle = "v" + DocumentUltimateConfiguration.AssemblyInfo.FileVersion;

            exampleExplorer.Examples = new ExampleBase[]
            {
                new ExampleFolder
                {
                    Title    = "Document Viewer",
                    Children = new ExampleBase[]
                    {
                        new Example
                        {
                            Title           = "Overview",
                            Url             = "DocumentViewer/Overview.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Overview.aspx", "DocumentViewer/Overview.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Overview.html"
                        },
                        new Example
                        {
                            Title           = "Copy protection (DRM)",
                            Url             = "DocumentViewer/Protection.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Protection.aspx", "DocumentViewer/Protection.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Protection.html"
                        },
                        new Example
                        {
                            Title           = "Highlighting keywords",
                            Url             = "DocumentViewer/Highlight.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Highlight.aspx", "DocumentViewer/Highlight.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Highlight.html"
                        },
                        new Example
                        {
                            Title           = "Watermarking pages",
                            Url             = "DocumentViewer/Watermark.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Watermark.aspx", "DocumentViewer/Watermark.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Watermark.html"
                        },
                        new Example
                        {
                            Title           = "Using with a stream",
                            Url             = "DocumentViewer/Stream.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Stream.aspx", "DocumentViewer/Stream.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Stream.html"
                        },
                        new Example
                        {
                            Title           = "Events",
                            Url             = "DocumentViewer/Events.aspx",
                            SourceFiles     = new[] { "DocumentViewer/Events.aspx", "DocumentViewer/Events.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentViewer/Events.html"
                        }
                    }
                },
                new ExampleFolder
                {
                    Title    = "Document Converter",
                    Children = new ExampleBase[]
                    {
                        new Example
                        {
                            Title           = "Overview",
                            Url             = "DocumentConverter/Overview.aspx",
                            SourceFiles     = new[] { "DocumentConverter/Overview.aspx", "DocumentConverter/Overview.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentConverter/Overview.html"
                        },
                        new Example
                        {
                            Title           = "Possible conversions",
                            Url             = "DocumentConverter/Possible.aspx",
                            SourceFiles     = new[] { "DocumentConverter/Possible.aspx", "DocumentConverter/Possible.aspx.cs" },
                            DescriptionFile = "Descriptions/DocumentConverter/Possible.html"
                        }
                    }
                }
            };

            exampleExplorer.ExampleProjectName = "ASP.NET Web Forms (C#)";
            exampleExplorer.ExampleProjects    = ExamplesCoreConfiguration.LoadExampleProjects(Server.MapPath("~/App_Data/ExampleProjects.json"));
        }
コード例 #13
0
 private static string GetDownloadLink(FileInfo fileInfo)
 {
     return(string.Format(
                "<a href=\"{0}\">Download</a>",
                ExamplesCoreConfiguration.GetDownloadUrl(fileInfo.FullName, fileInfo.LastWriteTimeUtc.Ticks.ToString())));
 }