Esempio n. 1
0
    private static AttachmentInfo SaveAsAttachment(object doc, AttachmentInfo attachment, SaveDocument saveDocument)
    {
        string fileId   = AttachmentManager.GetNewFileID();
        string savePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);

        Directory.CreateDirectory(savePath.Substring(0, savePath.LastIndexOf(@"\")));
        saveDocument.Invoke(doc, savePath);

        attachment.FileID = fileId;
        if (String.IsNullOrEmpty(attachment.Name))
        {
            attachment.Name = fileId + attachment.Ext;
        }

        //attachment.Name = fileName;
        //attachment.Ext = fileExt;
        //attachment.Size = fileSize;
        attachment.LastUpdate   = DateTime.Now;
        attachment.OwnerAccount = YZAuthHelper.LoginUserAccount;
        FileInfo fileInfo = new FileInfo(savePath);

        attachment.Size = fileInfo.Length;

        using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
        {
            using (IDbConnection cn = provider.OpenConnection())
            {
                provider.Insert(cn, attachment);
            }
        }

        return(attachment);
    }
Esempio n. 2
0
        protected virtual string GetVideoOutputFile(AttachmentInfo attachment, ScaleMode scale, int width, int height, ImageFormat format, string emptyFile)
        {
            string fileName    = attachment.Name;
            string fileExt     = attachment.Ext;
            string srcFilePath = AttachmentInfo.FileIDToPath(attachment.FileID, AttachmentManager.AttachmentRootPath);

            if (File.Exists(srcFilePath))
            {
                if (scale != ScaleMode.None)
                {
                    string imgFilePath = this.MakeVideoThumbnail(srcFilePath);

                    Mode   mode          = new Mode(String.Format("{0}x{1}", width, height), scale, width, height, format);
                    string thumbnailPath = this.GetThumbnailPath(imgFilePath, mode);
                    if (!File.Exists(thumbnailPath))
                    {
                        thumbnailPath = this.MakeThumbnail(imgFilePath, mode);
                    }

                    return(thumbnailPath);
                }
                else
                {
                    return(this.MakeVideoThumbnail(srcFilePath));
                }
            }
            else
            {
                return(emptyFile);
            }
        }
Esempio n. 3
0
        private static File TryLoad(IYZDbProvider provider, IDbConnection cn, string fileid, out Exception exp)
        {
            string filePath = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);

            exp = null;
            if (!System.IO.File.Exists(filePath))
            {
                exp = new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileid));
                return(null);
            }

            JObject jProcess;

            using (System.IO.StreamReader rd = new System.IO.StreamReader(filePath))
                jProcess = JObject.Parse(rd.ReadToEnd());

            AttachmentInfo attachment = AttachmentManager.GetAttachmentInfo(provider, cn, fileid);

            File file = jProcess.ToObject <File>();

            file.FileID         = fileid;
            file.FileName       = attachment != null ? attachment.Name : "";
            file.AttachmentInfo = attachment;

            return(file);
        }
Esempio n. 4
0
        public virtual void SaveProcess(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    fileid  = request.GetString("fileid");

            JObject jPost    = request.GetPostData <JObject>();
            JObject jProcess = (JObject)jPost["process"];
            JObject jChart   = (JObject)jPost["chart"];

            string savePath = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);

            if (jProcess["Property"] == null)
            {
                jProcess["Property"] = new JObject();
            }

            if (jProcess["Property"]["CreateAt"] != null)
            {
                jProcess["Property"]["CreateAt"] = DateTime.Parse((string)jProcess["Property"]["CreateAt"]);
            }

            jProcess["Property"]["LastChange"] = DateTime.Now;
            jProcess["Property"]["ChangeBy"]   = YZAuthHelper.LoginUserAccount;

            System.IO.Directory.CreateDirectory(savePath.Substring(0, savePath.LastIndexOf(@"\")));

            using (System.IO.StreamWriter ws = new System.IO.StreamWriter(savePath, false, System.Text.Encoding.UTF8))
            {
                ws.Write(jProcess.ToString());
            }

            AttachmentInfo attachment;
            File           bpafile = jProcess.ToObject <File>();

            bpafile.FileID = fileid;
            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    attachment            = AttachmentManager.GetAttachmentInfo(provider, cn, fileid);
                    attachment.LastUpdate = DateTime.Now;
                    //AttachmentManager.(provider, cn, attachment);

                    bpafile.FileName = attachment.Name;
                    bpafile.UpdateSpritesIdentityAndLink(provider, cn);
                }
            }

            this.SaveChart(savePath, jChart);
        }
Esempio n. 5
0
        public virtual void GetProcessThumbnail(HttpContext context)
        {
            YZRequest request       = new YZRequest(context);
            string    fileid        = request.GetString("fileid");
            string    filePath      = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);
            string    thumbnailPath = AttachmentManager.GetThumbnailPath(filePath, "thumbnail", "png");

            if (String.IsNullOrEmpty(thumbnailPath) || !File.Exists(thumbnailPath))
            {
                thumbnailPath = context.Server.MapPath("~/YZSoft/Attachment/img/Empty-ProcessThumbnail.png");
            }

            this.ProcessResponseHeader(context, Path.GetFileName(thumbnailPath), true);
            context.Response.TransmitFile(thumbnailPath);
        }
Esempio n. 6
0
        public object GetFileSize(HttpContext context)
        {
            YZRequest request  = new YZRequest(context);
            string    fileId   = request.GetString("fileid");
            string    filePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);

            if (!File.Exists(filePath))
            {
                throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileId));
            }

            FileInfo fileInfo = new FileInfo(filePath);

            return(new
            {
                size = fileInfo.Length
            });
        }
Esempio n. 7
0
    public static string GetNewFileID()
    {
        using (BPMConnection cn = new BPMConnection())
        {
            cn.WebOpen();

            //确保不覆盖已存在的物理文件
            string fileId;
            string savePath;
            do
            {
                fileId = cn.GetSerialNum("yz_sys_att" + DateTime.Today.ToString("yyyyMMdd"), 4, 1, 1);
                fileId = fileId.Substring("yz_sys_att".Length);

                savePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);
            } while (File.Exists(savePath));

            return(fileId);
        }
    }
Esempio n. 8
0
        public static string AddFileFromFileSystem(IYZDbProvider provider, IDbConnection cn, string folderPath, string fileid, bool thumbnail)
        {
            AttachmentInfo attachmentInfo = AttachmentManager.GetAttachmentInfo(provider, cn, fileid);

            string attachmentPath = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);
            string newFilePath    = GetUniqueFileName(Path.Combine(folderPath, attachmentInfo.Name + attachmentInfo.Ext));

            System.IO.File.Copy(attachmentPath, newFilePath, false);
            if (thumbnail)
            {
                string attachmentThumbnailPath = AttachmentManager.GetThumbnailPath(attachmentPath, "thumbnail", "png");
                string newFileThumbnailPath    = AttachmentManager.GetThumbnailPath(newFilePath, "thumbnail", "png");

                if (System.IO.File.Exists(attachmentThumbnailPath))
                {
                    System.IO.File.Copy(attachmentThumbnailPath, newFileThumbnailPath, true);
                }
            }

            return(newFilePath);
        }
Esempio n. 9
0
    public static AttachmentInfo CloneFile(IYZDbProvider provider, IDbConnection cn, AttachmentInfo attachmentInfo, string newFileName)
    {
        string srcfileid   = attachmentInfo.FileID;
        string srcfilePath = AttachmentInfo.FileIDToPath(srcfileid, AttachmentManager.AttachmentRootPath);
        string srcFolder   = Path.GetDirectoryName(srcfilePath);
        string srcfilename = Path.GetFileName(srcfilePath);

        string newfileId   = AttachmentManager.GetNewFileID();
        string tagfilePath = AttachmentInfo.FileIDToPath(newfileId, AttachmentManager.AttachmentRootPath);
        string tagFolder   = Path.GetDirectoryName(tagfilePath);
        string tagfilename = Path.GetFileName(tagfilePath);

        Directory.CreateDirectory(tagFolder);

        DirectoryInfo srcDir = new DirectoryInfo(srcFolder);

        FileInfo[] files = srcDir.GetFiles(srcfilename + "*");

        foreach (FileInfo fileInfo in files)
        {
            if ((fileInfo.Attributes & FileAttributes.Directory) == 0 &&
                (fileInfo.Attributes & FileAttributes.System) == 0 &&
                (fileInfo.Attributes & FileAttributes.Hidden) == 0)
            {
                string srcfile = fileInfo.FullName;
                string tagfile = Path.Combine(tagFolder, tagfilename + fileInfo.Name.Substring(srcfilename.Length));
                File.Copy(srcfile, tagfile, true);
            }
        }

        attachmentInfo.FileID       = newfileId;
        attachmentInfo.Name         = newFileName;
        attachmentInfo.OwnerAccount = YZAuthHelper.LoginUserAccount;
        provider.Insert(cn, attachmentInfo);

        return(attachmentInfo);
    }
Esempio n. 10
0
        public virtual object GetProcessDefine(HttpContext context)
        {
            YZRequest request  = new YZRequest(context);
            string    fileid   = request.GetString("fileid");
            string    filePath = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);
            string    uid      = YZAuthHelper.LoginUserAccount;

            AttachmentInfo attachment;
            JObject        jProcess;

            if (!System.IO.File.Exists(filePath))
            {
                throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileid));
            }

            using (System.IO.StreamReader rd = new System.IO.StreamReader(filePath))
                jProcess = JObject.Parse(rd.ReadToEnd());

            bool writable;

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    attachment = AttachmentManager.GetAttachmentInfo(provider, cn, fileid);

                    //文件夹
                    if (attachment.LParam1 == -1)
                    {
                        FileSystem.Folder folder = new FileSystem.Folder();
                        folder.FolderType = "BPAFileAttachments";
                        folder.ParentID   = -1;
                        folder.Name       = "";
                        folder.Desc       = "";
                        folder.Owner      = uid;
                        folder.CreateAt   = DateTime.Now;
                        folder.OrderIndex = 1;

                        FileSystem.DirectoryManager.Insert(provider, cn, folder);
                        folder.RootID = folder.FolderID;
                        FileSystem.DirectoryManager.Update(provider, cn, folder);

                        FileSystem.DirectoryManager.Insert(provider, cn, folder);
                        attachment.LParam1 = folder.FolderID;
                        AttachmentManager.Update(provider, cn, attachment);
                    }

                    this.ApplyLinkText(provider, cn, jProcess["Nodes"] as JArray);

                    using (BPMConnection bpmcn = new BPMConnection())
                    {
                        bpmcn.WebOpen();
                        writable = BPAManager.ISBPAFileWritable(provider, cn, bpmcn, fileid);
                    }
                }
            }

            JObject jProperty = jProcess["Property"] as JObject;

            if (jProperty != null)
            {
                using (BPMConnection cn = new BPMConnection())
                {
                    cn.WebOpen();

                    string account;
                    account = (string)jProperty["Creator"];
                    if (!String.IsNullOrEmpty(account))
                    {
                        User user = User.TryGetUser(cn, account);
                        jProperty["CreatorShortName"] = user != null ? user.ShortName : account;
                    }

                    account = (string)jProperty["ChangeBy"];
                    if (!String.IsNullOrEmpty(account))
                    {
                        User user = User.TryGetUser(cn, account);
                        jProperty["ChangeByShortName"] = user != null ? user.ShortName : account;
                    }
                }
            }

            return(new
            {
                attachment = attachment,
                writable = writable,
                processDefine = jProcess
            });
        }
Esempio n. 11
0
        public virtual object SaveProcessAs(HttpContext context)
        {
            YZRequest request      = new YZRequest(context);
            int       folder       = request.GetInt32("folder");
            string    fileid       = request.GetString("fileid");
            int       filefolderid = request.GetInt32("filefolderid");
            string    processName  = request.GetString("processName");
            string    ext          = request.GetString("ext");

            JObject jPost    = request.GetPostData <JObject>();
            JObject jProcess = (JObject)jPost["process"];
            JObject jChart   = (JObject)jPost["chart"];

            if (jProcess["Property"] == null)
            {
                jProcess["Property"] = new JObject();
            }

            jProcess["Property"]["CreateAt"]   = DateTime.Now;
            jProcess["Property"]["Creator"]    = YZAuthHelper.LoginUserAccount;
            jProcess["Property"]["LastChange"] = DateTime.Now;
            jProcess["Property"]["ChangeBy"]   = YZAuthHelper.LoginUserAccount;

            string savePath = AttachmentInfo.FileIDToPath(fileid, AttachmentManager.AttachmentRootPath);

            System.IO.Directory.CreateDirectory(savePath.Substring(0, savePath.LastIndexOf(@"\")));

            using (System.IO.StreamWriter ws = new System.IO.StreamWriter(savePath, false, System.Text.Encoding.UTF8))
                ws.Write(jProcess.ToString());

            AttachmentInfo attachment = new AttachmentInfo();

            attachment.FileID       = fileid;
            attachment.Name         = processName;
            attachment.Ext          = ext;
            attachment.Size         = 101;
            attachment.LastUpdate   = DateTime.Now;
            attachment.OwnerAccount = YZAuthHelper.LoginUserAccount;
            attachment.LParam1      = filefolderid;

            YZSoft.FileSystem.File file = new YZSoft.FileSystem.File();
            file.FolderID = folder;
            file.FileID   = fileid;
            file.AddBy    = YZAuthHelper.LoginUserAccount;
            file.AddAt    = DateTime.Now;
            file.Comments = "";

            File bpafile = jProcess.ToObject <File>();

            bpafile.FileID   = fileid;
            bpafile.FileName = attachment.Name;

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    AttachmentManager.Delete(provider, cn, attachment.FileID);
                    AttachmentManager.Insert(provider, cn, attachment);
                    file.OrderIndex = YZSoft.FileSystem.DirectoryManager.GetFileNextOrderIndex(provider, cn, folder);
                    FileSystem.DirectoryManager.Insert(provider, cn, file);

                    bpafile.UpdateSpritesIdentityAndLink(provider, cn);
                }
            }

            this.SaveChart(savePath, jChart);

            return(new
            {
                success = true,
                fileid = file.FileID
            });
        }
Esempio n. 12
0
        public virtual void VideoStreamFromFileID(HttpContext context)
        {
            //System.Threading.Thread.Sleep(6000);
            YZRequest request = new YZRequest(context);
            string    fileId  = request.GetString("fileid");
            BPMObjectNameCollection supports = BPMObjectNameCollection.FromStringList(request.GetString("supports", null), ',');

            AttachmentInfo attachment;

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    attachment = AttachmentManager.GetAttachmentInfo(provider, cn, fileId);
                }
            }

            string fileName     = attachment.Name;
            string fileExt      = attachment.Ext;
            string fileExtNoDot = fileExt == null ? "" : fileExt.TrimStart('.');
            long   fileSize     = attachment.Size;
            string filePath     = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);

            if (!File.Exists(filePath))
            {
                throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileId));
            }

            //有请求格式并且请求格式非元文件格式
            if (supports.Count != 0 && !supports.Contains(fileExtNoDot))
            {
                //发现已有转换文件
                string existFile = null;
                foreach (string format in supports)
                {
                    string outputFile = Path.Combine(Path.GetDirectoryName(filePath), String.Format("{0}.{1}", Path.GetFileNameWithoutExtension(filePath), format));
                    if (File.Exists(outputFile))
                    {
                        existFile = outputFile;
                        break;
                    }
                }

                if (!String.IsNullOrEmpty(existFile))
                {
                    filePath = existFile;
                }
                else
                {
                    //转换文件
                    string targetExt  = supports[0];
                    string outputFile = Path.Combine(Path.GetDirectoryName(filePath), String.Format("{0}.{1}", Path.GetFileNameWithoutExtension(filePath), targetExt));

                    var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                    ffMpeg.ConvertMedia(filePath, fileExtNoDot, outputFile, targetExt, null);
                    filePath = outputFile;
                }
            }

            this.ProcessResponseHeader(context, fileName, true);
            context.Response.TransmitFile(filePath);
        }
Esempio n. 13
0
        public virtual void Download(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            bool      osfile  = request.GetBool("osfile", false);

            //if (context.Request.Headers["If-None-Match"] != null || context.Request.Headers["If-Modified-Since"] != null)
            //{
            //    context.Response.Status = "304 Not Modified";
            //    context.Response.Cache.AppendCacheExtension("max-age=" + 365 * 24 * 60 * 60);
            //    context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
            //    context.Response.AppendHeader("ETag", "Never_Modify");
            //    context.Response.Cache.SetETag("Never_Modify");
            //    context.Response.Cache.SetLastModified(DateTime.Now.AddMinutes(-1));
            //    context.Response.End();
            //    return;
            //}

            string filePath;
            string fileName;
            long   fileSize;
            string fileExt;

            if (osfile)
            {
                string root = request.GetString("root");
                string path = request.GetString("path");
                fileName = request.GetString("name");
                string rootPath = context.Server.MapPath(YZSoft.FileSystem.OSDirectoryManager.GetRootPath(root));
                filePath = Path.Combine(rootPath, path, fileName);

                if (!File.Exists(filePath))
                {
                    throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileName));
                }

                FileInfo fileInfo = new FileInfo(filePath);
                fileSize = fileInfo.Length;
                fileExt  = fileInfo.Extension;
            }
            else
            {
                string fileId = request.GetString("fileid");

                AttachmentInfo attachment;
                using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                {
                    using (IDbConnection cn = provider.OpenConnection())
                    {
                        attachment = AttachmentManager.GetAttachmentInfo(provider, cn, fileId);
                    }
                }

                fileName = attachment.Name;
                fileExt  = attachment.Ext;
                fileSize = attachment.Size;
                filePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);

                if (!File.Exists(filePath))
                {
                    throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileId));
                }
            }

            string fileExtNoDot = fileExt == null ? "" : fileExt.TrimStart('.');

            bool   contentDisposition = true;
            string range       = context.Request.Headers["Range"];
            string contentType = YZMimeMapping.GetMimeType(fileExt);

            context.Response.AppendHeader("Content-Type", contentType);

            if (contentDisposition)
            {
                context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode(fileName));
            }

            context.Response.AppendHeader("Accept-Ranges", "bytes");

            if (range == null)
            {
                FileInfo fileinfo = new FileInfo(filePath);

                //全新下载
                context.Response.AppendHeader("Content-Length", fileinfo.Length.ToString());
                //context.Response.CacheControl = HttpCacheability.Public.ToString();
                //context.Response.Cache.AppendCacheExtension("max-age=" + 365 * 24 * 60 * 60);
                //context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
                //context.Response.AppendHeader("ETag", "Never_Modify");
                //context.Response.Cache.SetETag("Never_Modify");
                //context.Response.Cache.SetLastModified(DateTime.Now.AddMinutes(-1));

                context.Response.TransmitFile(filePath);
            }
            else
            {
                //断点续传以及多线程下载支持
                string[] file_range = range.Substring(6).Split(new char[1] {
                    '-'
                });
                if (string.IsNullOrEmpty(file_range[0]))
                {
                    file_range[0] = "0";
                }
                if (string.IsNullOrEmpty(file_range[1]))
                {
                    file_range[1] = fileSize.ToString();
                }
                context.Response.Status = "206 Partial Content";
                context.Response.AppendHeader("Content-Range", "bytes " + file_range[0] + "-" + file_range[1] + "/" + fileSize.ToString());
                context.Response.AppendHeader("Content-Length", (Int32.Parse(file_range[1]) - Int32.Parse(file_range[0])).ToString());
                context.Response.TransmitFile(filePath, long.Parse(file_range[0]), (long)(Int32.Parse(file_range[1]) - Int32.Parse(file_range[0])));
            }
        }
Esempio n. 14
0
        public virtual void Preview(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            bool      osfile  = request.GetBool("osfile", false);
            BPMObjectNameCollection supports = BPMObjectNameCollection.FromStringList(request.GetString("supports", null), ',');

            string filePath;
            string fileName;
            long   fileSize;
            string fileExt;

            if (osfile)
            {
                string root = request.GetString("root");
                string path = request.GetString("path");
                fileName = request.GetString("name");
                string rootPath = context.Server.MapPath(YZSoft.FileSystem.OSDirectoryManager.GetRootPath(root));
                filePath = Path.Combine(rootPath, path, fileName);

                if (!File.Exists(filePath))
                {
                    throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileName));
                }

                FileInfo fileInfo = new FileInfo(filePath);
                fileSize = fileInfo.Length;
                fileExt  = fileInfo.Extension;
            }
            else
            {
                string fileId = request.GetString("fileid");

                AttachmentInfo attachment;
                using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
                {
                    using (IDbConnection cn = provider.OpenConnection())
                    {
                        attachment = AttachmentManager.GetAttachmentInfo(provider, cn, fileId);
                    }
                }

                fileName = attachment.Name;
                fileExt  = attachment.Ext;
                fileSize = attachment.Size;
                filePath = AttachmentInfo.FileIDToPath(fileId, AttachmentManager.AttachmentRootPath);

                if (!File.Exists(filePath))
                {
                    throw new Exception(String.Format(Resources.YZStrings.Aspx_Upload_FileIDNotFount, fileId));
                }
            }

            string fileExtNoDot = fileExt == null ? "" : fileExt.TrimStart('.');

            //有请求格式并且请求格式非元文件格式
            if (supports.Count != 0 && !supports.Contains(fileExtNoDot))
            {
                //发现已有转换文件
                string existFile = null;
                foreach (string format in supports)
                {
                    string outputFile = Path.Combine(Path.GetDirectoryName(filePath), String.Format("{0}.{1}", Path.GetFileNameWithoutExtension(filePath), format));
                    if (File.Exists(outputFile))
                    {
                        existFile = outputFile;
                        break;
                    }
                }

                if (!String.IsNullOrEmpty(existFile))
                {
                    filePath = existFile;
                }
                else
                {
                    //转换文件
                    string         targetExt    = supports[0];
                    DocumentFormat targetFormat = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), targetExt, true);
                    string         outputFile   = Path.Combine(Path.GetDirectoryName(filePath), String.Format("{0}.{1}", Path.GetFileNameWithoutExtension(filePath), targetExt));
                    DocumentFormat srcFormat    = (DocumentFormat)Enum.Parse(typeof(DocumentFormat), fileExtNoDot, true);

                    if (srcFormat == DocumentFormat.Pdf && targetFormat == DocumentFormat.Html)
                    {
                        YZSoft.Web.File.FileConvert.Pdf2Html(filePath);
                        filePath = outputFile;
                    }
                    else
                    {
                        DocumentConverterResult result = DocumentConverter.Convert(
                            new GleamTech.IO.BackSlashPath(filePath),
                            new InputOptions(srcFormat),
                            new GleamTech.IO.BackSlashPath(outputFile),
                            targetFormat
                            );
                        filePath = result.OutputFiles[0];
                    }
                }

                fileExt = Path.GetExtension(filePath);
            }

            string range       = context.Request.Headers["Range"];
            string contentType = YZMimeMapping.GetMimeType(fileExt);

            context.Response.AppendHeader("Content-Type", contentType);
            context.Response.AppendHeader("Accept-Ranges", "bytes");

            if (range == null)
            {
                FileInfo fileinfo = new FileInfo(filePath);

                //全新下载
                context.Response.AppendHeader("Content-Length", fileinfo.Length.ToString());
                //context.Response.CacheControl = HttpCacheability.Public.ToString();
                //context.Response.Cache.AppendCacheExtension("max-age=" + 365 * 24 * 60 * 60);
                //context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
                //context.Response.AppendHeader("ETag", "Never_Modify");
                //context.Response.Cache.SetETag("Never_Modify");
                //context.Response.Cache.SetLastModified(DateTime.Now.AddMinutes(-1));

                context.Response.TransmitFile(filePath);
            }
            else
            {
                //断点续传以及多线程下载支持
                string[] file_range = range.Substring(6).Split(new char[1] {
                    '-'
                });
                context.Response.Status = "206 Partial Content";
                context.Response.AppendHeader("Content-Range", "bytes " + file_range[0] + "-" + file_range[1] + "/" + fileSize.ToString());
                context.Response.AppendHeader("Content-Length", (Int32.Parse(file_range[1]) - Int32.Parse(file_range[0]) + 1).ToString());
                context.Response.TransmitFile(filePath, long.Parse(file_range[0]), (long)(Int32.Parse(file_range[1]) - Int32.Parse(file_range[0]) + 1));
            }
        }