コード例 #1
0
        public static void ConvertHandler(IHttpContext context)
        {
            DocumentConverterResult result;

            try
            {
                var inputDocument  = new BackSlashPath(ExamplesConfiguration.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.Id).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.Output.Write("<span style=\"color: red; font-weight: bold\">Conversion failed</span><br/>");
                context.Response.Output.Write(exception.Message);
                return;
            }

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

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

            context.Response.Output.Write("<br/><ol>");
            foreach (var outputFile in result.OutputFiles)
            {
                if (outputFile.EndsWith("\\"))
                {
                    var directoryInfo = new DirectoryInfo(outputFile);
                    context.Response.Output.Write(string.Format(
                                                      "<br/><li><b>{0}\\</b> - {1}</li>",
                                                      directoryInfo.Name,
                                                      GetZipDownloadLink(directoryInfo))
                                                  );
                }
                else
                {
                    var fileInfo = new FileInfo(outputFile);
                    context.Response.Output.Write(string.Format(
                                                      "<br/><li><b>{0}</b> ({1} bytes) - {2}</li>",
                                                      fileInfo.Name,
                                                      fileInfo.Length,
                                                      GetDownloadLink(fileInfo))
                                                  );
                }
            }
            context.Response.Output.Write("<br/></ol>");
        }
コード例 #2
0
        private void PopulatePossibleOutputFormats(string inputDocument)
        {
            var outputFormats = new Dictionary <string, List <ListItem> >();

            foreach (var format in DocumentUltimate.DocumentConverter.EnumeratePossibleOutputFormats(inputDocument))
            {
                var formatInfo = DocumentFormatInfo.Get(format);

                List <ListItem> groupData;
                if (!outputFormats.TryGetValue(formatInfo.Group.Description, out groupData))
                {
                    groupData = new List <ListItem>();
                    outputFormats.Add(formatInfo.Group.Description, groupData);
                }
                groupData.Add(new ListItem(formatInfo.Description, formatInfo.Value.ToString()));
            }

            if (outputFormats.Count == 0)
            {
                outputFormats.Add("(not supported)", new List <ListItem>());
            }

            OutputFormats.DataSource = outputFormats;
            OutputFormats.DataBind();
        }
        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 = ExamplesConfiguration.GetDynamicDownloadUrl(
                ConvertHandlerName,
                new NameValueCollection
            {
                { "inputDocument", ExamplesConfiguration.ProtectString(inputDocument) },
                { "version", fileInfo.LastWriteTimeUtc.Ticks + "-" + fileInfo.Length }
            });

            return(View(model));
        }
コード例 #4
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 = ExamplesConfiguration.GetDynamicDownloadUrl(
                ConvertHandlerName,
                new NameValueCollection
            {
                { "inputDocument", ExamplesConfiguration.ProtectString(inputDocument) },
                { "version", fileInfo.LastWriteTimeUtc.Ticks + "-" + fileInfo.Length }
            });
        }
        private void PopulatePossibleOutputFormats(string inputDocument, OverviewViewModel model)
        {
            foreach (var format in DocumentConverter.EnumeratePossibleOutputFormats(inputDocument))
            {
                var formatInfo = DocumentFormatInfo.Get(format);

                List <SelectListItem> groupData;
                if (!model.OutputFormats.TryGetValue(formatInfo.Group.Description, out groupData))
                {
                    groupData = new List <SelectListItem>();
                    model.OutputFormats.Add(formatInfo.Group.Description, groupData);
                }
                groupData.Add(new SelectListItem
                {
                    Text  = formatInfo.Description,
                    Value = formatInfo.Value.ToString()
                });
            }

            if (model.OutputFormats.Count == 0)
            {
                model.OutputFormats.Add("(not supported)", new List <SelectListItem>());
            }
        }