コード例 #1
0
ファイル: HomeController.cs プロジェクト: AnalogJ/ReBind
        public ActionResult Convert(Uri postedUrl, String outputExtension)
        {
            String extension;
            ConversionOptions options = new ConversionOptions();
            options.EbookUrl = postedUrl;
            options.Extension = outputExtension;
            options.isAsync = false;
            options.isStarted = true;

            if (!ModelState.IsValid || ( options.EbookUrl == null))
            {
                throw new HttpException(500, "Posted Data Invalid. Please provide an Ebook Url or File");
            }

            try
            {
                extension = System.IO.Path.GetExtension(options.EbookUrl.GetLeftPart(UriPartial.Path));
            }
            catch (Exception ex)
            {
                extension = ".epub"; //assuming epub.
            }
            CheckExtension(extension, options.OutputExtension);
            String root = HttpContext.Server.MapPath("~/");
            EbookConvert converter = new EbookConvert(root, options);
            String localPath = converter.Start(extension);

            options.isStarted = true;

            Uri outputLocation = new Uri(HttpContext.Request.Url,
                                         @"/uploads/" + options.Guid + @"/" + Path.GetFileName(localPath));
            return Redirect(outputLocation.ToString());
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: AnalogJ/ReBind
        public ActionResult Index(ConversionOptions options)
        {
            //Handle the file upload.
            if (!ModelState.IsValid || (options.EbookFile == null && options.EbookUrl == null))
            {
                throw new HttpException(500, "Posted Data Invalid. Please provide an Ebook Url or File");
            }

            String extension = "";

            //Validate extensions
            if (options.EbookFile != null)
            {
                extension = Path.GetExtension(options.EbookFile.FileName);
                CheckExtension(extension, options.OutputExtension);
            }
            else
            {
                try
                {
                    extension = System.IO.Path.GetExtension(options.EbookUrl.GetLeftPart(UriPartial.Path));
                }
                catch (Exception ex)
                {
                    extension = ".epub"; //assuming epub.
                }
                CheckExtension(extension, options.OutputExtension);
            }

            String root = HttpContext.Server.MapPath("~/");
            EbookConvert converter = new EbookConvert(root, options);
            String localPath = converter.Start(extension);

            options.isStarted = true;

            return View(options);
        }