/// <summary> /// 如果是可直接浏览文件格式,直接跳转 /// </summary> /// <param name="fileID"></param> private void ImageDirect(string fileID) { fileID = fileID.ToLower(); //如果附件为图片格式 if (fileID.Contains(".jpg") || fileID.Contains(".png") || fileID.Contains(".gif")) { object fileBytes = null; string fileName = FileStoreHelper.GetFileFullPath(fileID); if (fileName.LastIndexOf('.') > -1) { var suffix = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower(); fileBytes = FileStoreHelper.GetFile(fileID); if (fileBytes != null && fileBytes != DBNull.Value) { this.Response.Clear(); if (suffix == "jpg" || suffix == "png" || suffix == "gif") { this.Response.ContentType = "image/gif"; this.Response.OutputStream.Write(fileBytes as byte[], 0, ((byte[])fileBytes).Length); this.Response.End(); } } } } }
public ActionResult GetPic(string fileId, int?width, int?height) { string fileIdPre = fileId; if (!string.IsNullOrEmpty(fileIdPre)) { var arr = fileIdPre.Split('_'); if (arr.Length > 0) { fileIdPre = arr[0]; } } byte[] fileBytes = FileStoreHelper.GetFile(fileIdPre); Image img = ImageHelper.GetImageFromBytes(fileBytes); if (width != null && height != null) { int fWidth = (int)((double)height.Value * (double)img.Width / (double)img.Height); //纵向布满后后横向超出了给定宽度 //则横向布满 if (fWidth > width.Value) { int fHeight = (int)((double)img.Height * (double)width.Value / (double)img.Width); img = img.GetThumbnailImage(width.Value, fHeight, null, IntPtr.Zero); } else { img = img.GetThumbnailImage(fWidth, height.Value, null, IntPtr.Zero); } } return(new ImageActionResult(img)); }
public ActionResult GetPic(string fileID, int?width, int?height) { byte[] file = FileStoreHelper.GetFile(fileID); if (file != null) { return(new ImageActionResult(file, width, height)); } return(Content(string.Empty)); }
public FileResult GetFile(string fileID) { byte[] file = FileStoreHelper.GetFile(fileID); if (file != null) { return(File(file, "application/pdf")); } else { throw new Formula.Exceptions.WebException("服务器上找不到浏览文件!"); } }
private void RunPlotQueue() { FileRepository repo = new FileRepository(); FileTask task = null; while ((task = repo.GetTask("")) != null) { if (task.ExtName.Equals("dwg", StringComparison.OrdinalIgnoreCase)) { try { label2.Text = string.Format("正在获取文件...[{0}]", task.Name); //1.从filestore获取文件 byte[] bytes = FileStoreHelper.GetFile(task.ID); FileStoreHelper.SaveFileBuffer(bytes, Path.Combine(OfficeHelper.GetFolderPath(task.ID, "Files"), task.Name)); //2.设置文件数据库状态为进行中 repo.StartTask(task.ID); //3.开始进行转换 label2.Text = string.Format("正在进行格式打印...[{0}]", task.Name); var imgDTO = OfficeHelper.InitDTO(task.Name, bytes.Length, task.ID); var result = FileConverter.Exec(imgDTO); bool isSucc = false; if (result != null && result.status) { //4.设置转图层次,并生成json文件 imgDTO.Versions[0].ImageZoomLevel = result.ZoomLevel; OfficeHelper.WriteJsonFile(imgDTO); isSucc = true; } Application.DoEvents(); //5.回置状态 label2.Text = "最近:[" + imgDTO.Name + "]打印" + (isSucc ? "成功":"失败") + ",打印时间(" + DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分") + ")"; repo.EndTask(task.ID, isSucc ? ResultStatus.Success:ResultStatus.Error); //6.删除原文件 if (File.Exists(imgDTO.Versions[0].FullPath)) { File.Delete(imgDTO.Versions[0].FullPath); } } catch (Exception ex) { // 记录日志 LogWriter.Info(string.Format(ex.Message, DateTime.Now.ToString(), task.ID, task.Name, ex.StackTrace)); repo.EndTask(task.ID, ResultStatus.Error); } } } }
public void UpdatePictureFromFileStore(string fileId) { byte[] bytes = FileStoreHelper.GetFile(fileId); var obj = this.S_A_UserImg.SingleOrDefault(c => c.UserID == this.ID); if (obj == null) { obj = new S_A_UserImg(); obj.ID = FormulaHelper.CreateGuid(); obj.UserID = this.ID; this.S_A_UserImg.Add(obj); } obj.Picture = bytes; }
public FileResult GetImgFile(string fileID) { //string fileFullName = GetFileFullName(fileID); //byte[] swfFile = GetViewFile(fileFullName); fileID = fileID.ToLower(); //如果附件为图片格式 if (fileID.Contains(".jpeg") || fileID.Contains(".bmp") || fileID.Contains(".jpg") || fileID.Contains(".png") || fileID.Contains(".gif")) { string fileName = FileStoreHelper.GetFileFullPath(fileID); if (fileName.LastIndexOf('.') > -1) { var suffix = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower(); byte[] fileBytes = FileStoreHelper.GetFile(fileID); if (fileBytes == null) { throw new Formula.Exceptions.WebException("服务器上找不到浏览文件!"); } if (fileBytes != null) { switch (suffix) { case "jpg": return(File(fileBytes, "application/x-jpg/" + Path.GetExtension(fileName))); case "png": return(File(fileBytes, "application/x-png/" + Path.GetExtension(fileName))); case "gif": return(File(fileBytes, "image/gif/" + Path.GetExtension(fileName))); case "jpeg": return(File(fileBytes, "image/jpeg/" + Path.GetExtension(fileName))); case "bmp": return(File(fileBytes, "application/x-bmp/" + Path.GetExtension(fileName))); default: throw new Formula.Exceptions.WebException("文件格式不支持!"); } } } } throw new Formula.Exceptions.WebException("文件格式不正确!"); }
public JsonResult SaveAuditFile(string ProductID, string AuditStep, string FileID, bool IsOverride) { var product = this.GetEntityByID <S_E_Product>(ProductID); if (product == null) { throw new Formula.Exceptions.BusinessException("未能找到指定的成果。"); } var PDFAuditFiles = JsonHelper.ToList(product.PDFAuditFiles); if (IsOverride) { PDFAuditFiles.RemoveWhere(a => a.GetValue("AuditStep") == AuditStep && a.GetValue("SubmitUser") == CurrentUserInfo.UserID); } var dic = new Dictionary <string, object>(); dic.SetValue("AuditStep", AuditStep); dic.SetValue("SubmitUser", CurrentUserInfo.UserID); dic.SetValue("SubmitUserName", CurrentUserInfo.UserName); dic.SetValue("SubmitDate", System.DateTime.Now.ToString("s")); dic.SetValue("Attachment", FileID); PDFAuditFiles.Add(dic); product.PDFAuditFiles = JsonHelper.ToJson(PDFAuditFiles); product.UpdateVersison(); this.entities.SaveChanges(); #region 获取PDF中的校审信息 byte[] bytes = FileStoreHelper.GetFile(FileID); var list = GetAnnots(bytes); #endregion var reslut = new Dictionary <string, object>(); reslut.Add("list", list); reslut.Add("code", product.Code); return(Json(reslut)); }
public ActionResult GetPic(string fieldId, int?width, int?height) { byte[] fileBytes = FileStoreHelper.GetFile(fieldId); Image img = ImageHelper.GetImageFromBytes(fileBytes); if (width != null && height != null) { int fWidth = (int)((double)height.Value * (double)img.Width / (double)img.Height); //纵向布满后后横向超出了给定宽度 //则横向布满 if (fWidth > width.Value) { int fHeight = (int)((double)img.Height * (double)width.Value / (double)img.Width); img = img.GetThumbnailImage(width.Value, fHeight, null, IntPtr.Zero); } else { img = img.GetThumbnailImage(fWidth, height.Value, null, IntPtr.Zero); } } return(new ImageActionResult(img)); }
public JsonResult MultiSaveAuditFile(string AuditID, string ChangeAuditID, string AuditStep, string FileIDs, bool IsOverride) { var productList = new List <S_E_Product>(); if (!string.IsNullOrEmpty(AuditID)) { productList = this.entities.Set <S_E_Product>().Where(a => a.AuditID == AuditID).ToList(); } else if (!string.IsNullOrEmpty(ChangeAuditID)) { productList = this.entities.Set <S_E_Product>().Where(a => a.ChangeAuditID == ChangeAuditID).ToList(); } List <Dictionary <string, object> > errorFiles = new List <Dictionary <string, object> >();//上传的文件解析错误,找到多个成果,未找到对应的成果 List <Dictionary <string, object> > successFiles = new List <Dictionary <string, object> >(); foreach (var FileID in FileIDs.Split(',')) { if (FileID.IndexOf("_") < 0 || FileID.ToLower().IndexOf(".pdf") < 0) { errorFiles.Add(new Dictionary <string, object> { { "name", FileID }, { "message", "文件名解析错误" } }); continue; } var validateProducts = productList.Where(a => !string.IsNullOrEmpty(a.MainFile) && a.MainFile.Split('_')[1] == FileID.Split('_')[1]).ToList(); if (validateProducts.Count > 1) { errorFiles.Add(new Dictionary <string, object> { { "name", FileID.Split('_')[1] }, { "message", "根据成果附件匹配到多个成果" } }); continue; } if (validateProducts.Count == 0) { errorFiles.Add(new Dictionary <string, object> { { "name", FileID.Split('_')[1] }, { "message", "根据成果附件未找到对应的成果" } }); continue; } var product = validateProducts.FirstOrDefault(); var PDFAuditFiles = JsonHelper.ToList(product.PDFAuditFiles); if (IsOverride) { PDFAuditFiles.RemoveWhere(a => a.GetValue("AuditStep") == AuditStep && a.GetValue("SubmitUser") == CurrentUserInfo.UserID); } var dic = new Dictionary <string, object>(); dic.SetValue("AuditStep", AuditStep); dic.SetValue("SubmitUser", CurrentUserInfo.UserID); dic.SetValue("SubmitUserName", CurrentUserInfo.UserName); dic.SetValue("SubmitDate", System.DateTime.Now.ToString("s")); dic.SetValue("Attachment", FileID); PDFAuditFiles.Add(dic); product.PDFAuditFiles = JsonHelper.ToJson(PDFAuditFiles); product.UpdateVersison(); //提取pdf批注信息 byte[] bytes = FileStoreHelper.GetFile(FileID); var list = GetAnnots(bytes); successFiles.Add(new Dictionary <string, object> { { "list", list }, { "code", product.Code } }); } this.entities.SaveChanges(); return(Json(new { successFiles, errorFiles })); }
public void ExecuteQueue() { var queueData = this.SQLHelperInterface.ExecuteObject <I_FileSynQueue>("select top 1 * from I_FileSynQueue where SynState='" + SynState.New.ToString() + "' order by CreateTime"); while (queueData != null) { try { StringBuilder interfaceSb = new StringBuilder(); if (queueData.SynType == SynType.Download.ToString()) { queueData.RequestUrl = this.BaseStorageUrl + "Download?md5=" + queueData.MD5Code + "&filename=" + queueData.FileName; #region 调用api下载文件 var response = HttpHelper.GetResponse(queueData.RequestUrl); if (response.ResponseStatus != RestSharp.ResponseStatus.Completed) { throw new Exception(response.ErrorMessage); } var bs = response.RawBytes; if (bs.Length == 0) { var content = response.Content; if (!string.IsNullOrEmpty(content) && content.StartsWith("{")) { throw new Exception(content); } throw new Exception("没有获得正确得文件流数据"); } #endregion #region filestore queueData.FsFileID = FileStoreHelper.UploadFile(queueData.FileName, bs); if (string.IsNullOrEmpty(queueData.FsFileID)) { throw new Exception("上传FileStore失败:" + queueData.FsFileID); } #endregion ExecuteDownload(queueData, interfaceSb); } else { queueData.RequestUrl = this.BaseStorageUrl + "UploadFileMobile"; #region 载filestore文件 var bs = FileStoreHelper.GetFile(queueData.FsFileID); if (bs.Length == 0) { throw new Exception("从FileStore下载失败:" + queueData.FsFileID); } #endregion #region 调用api上传文件 if (string.IsNullOrEmpty(queueData.FileName)) { queueData.FileName = GetFileName(queueData.FsFileID); } queueData.Response = HttpHelper.PostFile(queueData.RequestUrl, bs, queueData.FileName); #endregion ExecuteUpload(queueData, interfaceSb, bs.Length); } ComplateSync(queueData, interfaceSb); } catch (Exception e) { ErrorSync(queueData, e.Message); } queueData = this.SQLHelperInterface.ExecuteObject <I_FileSynQueue>("select top 1 * from I_FileSynQueue where SynState='" + SynState.New.ToString() + "' order by CreateTime"); } }
public void Convert() { #region 创建esHelper、configHelper var esUrl = ConfigurationManager.AppSettings["EsUrl"]; if (string.IsNullOrEmpty(esUrl)) { LogWriter.Error(string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "配置文件缺少EsUrl")); return; } var esHelper = EsBaseHelper.CreateEsHelper(esUrl); try { if (!esHelper.ExistsIndex(EsConst.defaultEsFileIndex)) { esHelper.CreateIndex <EsFile>(EsConst.defaultEsFileIndex);//创建es索引 } } catch (Exception ex) { LogWriter.Error(ex, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message)); return; } esHelper.DefaultIndex = EsConst.defaultEsFileIndex;//设置es默认索引 SQLHelper configHelper = SQLHelper.CreateSqlHelper("DocConfigCntString"); #endregion string spaceSql = "select * from dbo.S_DOC_Space "; var spaceDt = configHelper.ExecuteDataTable(spaceSql); string nodeConfigSQL = @"select NodeID ConfigID,SpaceID,AttrField Field,DataType,InputType,EnumKey,FulltextProp,AttrSort from S_DOC_NodeAttr where FulltextProp='True' union select FileID ConfigID,SpaceID,FileAttrField Field,DataType,InputType,EnumKey,FulltextProp,AttrSort from S_DOC_FileAttr where FulltextProp='True' order by AttrSort "; var propFieldDt = configHelper.ExecuteDataTable(nodeConfigSQL); var enumFieldDt = propFieldDt.Select("EnumKey is not null"); var enumDic = new Dictionary <string, DataTable>(); var enumService = Formula.FormulaHelper.GetService <Formula.IEnumService>(); foreach (var item in enumFieldDt) { var enumKey = item["EnumKey"].ToString(); if (enumDic.ContainsKey(enumKey)) { continue; } var enumDt = enumService.GetEnumTable(enumKey); enumDic.Add(enumKey, enumDt); } foreach (DataRow space in spaceDt.Rows) { try { string constr = String.Format(conStrTemplate, space["Server"].ToString() , space["UserName"].ToString(), space["Pwd"].ToString(), space["DbName"].ToString()); SQLHelper sqlHepler = new SQLHelper(constr); string sql = @"select S_Attachment.*,S_FileInfo.ConfigID from S_Attachment left join S_FileInfo on S_FileInfo.ID = S_Attachment.FileID where S_Attachment.State='Normal' and CurrentVersion='True' and S_FileInfo.State='Published' and ((MainFile is not null and MainFile!='' ) or (PDFFile is not null and PDFFile!='' )) order by ID"; DataTable dt = sqlHepler.ExecuteDataTable(sql); var SpaceID = space["ID"].ToString(); int i = 1; foreach (DataRow attItem in dt.Rows) { string logSql = string.Empty; var Id = SQLHelper.CreateGuid(); string mainFile = string.Empty; if (attItem["PDFFile"] != DBNull.Value && attItem["PDFFile"] != null && !string.IsNullOrEmpty(attItem["PDFFile"].ToString())) { mainFile = attItem["PDFFile"].ToString(); } if (string.IsNullOrEmpty(mainFile)) { if (attItem["MainFile"] != DBNull.Value && attItem["MainFile"] != null && !string.IsNullOrEmpty(attItem["MainFile"].ToString())) { mainFile = attItem["MainFile"].ToString(); } } var FileID = attItem["FileID"].ToString(); var NodeID = attItem["NodeID"].ToString(); var ConfigID = attItem["ConfigID"].ToString(); var AttrID = attItem["ID"].ToString(); string FormatLogSql = @"INSERT INTO S_DOC_FulltextSearchConvertLog ([ID],[FsFileID],[AttrID] ,[FileID] ,[NodeID] ,[SpaceID] ,[CreateDate] ,[ConvertState],[ErrorMeesage]) VALUES ('" + Id + "' ,'" + mainFile.Replace("'", "''") + "','" + AttrID + "','" + FileID + "' ,'" + NodeID + "' ,'" + SpaceID + "' ,'" + DateTime.Now + "','{0}','{1}')"; string updateSql = "update S_Attachment Set State='Finish' where ID='" + attItem["ID"].ToString() + "'"; Console.WriteLine("文件信息:" + mainFile + " " + DateTime.Now.ToString()); var ext = GetFileExt(mainFile).ToLower(); try { string content = string.Empty; //string fullPath = service.GetFileFullPath(mainFile); var file = FileStoreHelper.GetFile(mainFile); //Console.WriteLine("文件路径:" + fullPath); #region 提取文字 switch (ext) { case "docx": case "doc": content = ExtractHelper.GetWordText(file); break; case "xls": case "xlsx": content = ExtractHelper.GetExcelText(file); break; case "pdf": content = ExtractHelper.GetPdfText_Itextsharp(file); break; case "txt": content = ExtractHelper.GetTxtText(file); break; default: { Console.WriteLine(ext + "文件跳过"); sqlHepler.ExecuteNonQuery(updateSql); Console.Write(ext + " 格式不对跳过" + i.ToString() + "/" + dt.Rows.Count); i++; continue; } } Console.WriteLine("获取信息内容完成"); #endregion #region 属性json、全路径json var fileDt = sqlHepler.ExecuteDataTable(@"select * from S_FileInfo where id='" + FileID + "'"); if (fileDt.Rows.Count == 0) { throw new Exception(string.Format("没有找到ID为【{0}】的S_FileInfo的记录", FileID)); } var nodeFullID = fileDt.Rows[0]["FullNodeID"].ToString(); var nodeDt = sqlHepler.ExecuteDataTable(@"select * from S_NodeInfo where id in ('" + nodeFullID.Replace(".", "','") + "')"); nodeDt.PrimaryKey = new DataColumn[] { nodeDt.Columns["ID"] }; string propertyJson = string.Empty; //属性,空格分隔的string,暂时不存Json string nodePathJson = string.Empty; //全路径Json var nodePathList = new List <Dictionary <string, string> >(); nodePathList.Add(new Dictionary <string, string>() { { "id", SpaceID }, { "name", space["Name"].ToString() }, { "type", "space" } }); foreach (var nid in nodeFullID.Split('.')) { var nodeRow = nodeDt.Rows.Find(nid); if (nodeRow == null) { continue; } //目录属性 var propString = GetPropStrings(propFieldDt, nodeRow, enumDic); propertyJson += propString; //全路径 string nname = nodeRow["Name"].ToString(); nodePathList.Add(new Dictionary <string, string>() { { "id", nid }, { "name", nname }, { "type", "node" } }); } //文件节点目录 nodePathList.Add(new Dictionary <string, string>() { { "id", SpaceID }, { "name", fileDt.Rows[0]["Name"].ToString() }, { "type", "file" } }); nodePathJson = JsonHelper.ToJson(nodePathList); //文件属性 var filePropString = GetPropStrings(propFieldDt, fileDt.Rows[0], enumDic); propertyJson += filePropString; propertyJson = propertyJson.TrimEnd(); #endregion #region 插入Es var esFile = new EsFile(); esFile.Id = FileID; esFile.SpaceID = SpaceID; esFile.NodeID = NodeID; esFile.FileID = FileID; esFile.AttrID = AttrID; esFile.ConfigID = ConfigID; if (!string.IsNullOrEmpty(mainFile)) { esFile.FsFileID = System.Convert.ToInt32(mainFile.Split('_')[0]); } esFile.Title = GetFileName(mainFile); esFile.Content = content; esFile.PropertyJson = propertyJson; esFile.FullPathJson = nodePathJson; if (attItem["CreateDate"] != null && attItem["CreateDate"] != DBNull.Value) { esFile.FileCreateDate = System.Convert.ToDateTime(attItem["CreateDate"]); } else { esFile.FileCreateDate = DateTime.Now; //归档日期 } if (attItem["CreateUserName"] != null && attItem["CreateUserName"] != DBNull.Value) { esFile.FileCreateUser = attItem["CreateUserName"].ToString(); //归档人 } esFile.SecretLevel = string.Empty; //密级 esHelper.AddDocument(esFile); Console.WriteLine("更新Es数据完成"); #endregion sqlHepler.ExecuteNonQuery(updateSql); logSql = String.Format(FormatLogSql, "Success", ""); configHelper.ExecuteNonQuery(logSql); Console.Write(" 成功" + i.ToString() + "/" + dt.Rows.Count); i++; } catch (Exception ex) { logSql = String.Format(FormatLogSql, "Error", ex.Message); configHelper.ExecuteNonQuery(logSql); LogWriter.Error(ex, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message)); Console.WriteLine("失败跳过" + i.ToString() + "/" + dt.Rows.Count); i++; continue; } } } catch (Exception exp) { LogWriter.Error(exp, string.Format("文字提取程序异常:{0},错误:{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), exp.Message)); Console.WriteLine(exp.InnerException); continue; } } }
public void Execute(IJobExecutionContext context) { var taskId = ""; var jobDataTaskId = context.Trigger.JobDataMap["taskId"]; if (jobDataTaskId != null) { taskId = jobDataTaskId.ToString(); } FileRepository repo = new FileRepository(); FileTask task = null; while ((task = repo.GetTask(taskId)) != null) { // 修改开始执行时间 repo.StartTask(task.ID); try { if (!IsConvertFormat(task.ExtName)) { throw new Exception("未知文件类型,没有相关的转换器!"); } string viewMode = AppConfig.GetAppSettings("ViewMode"); if (viewMode != ViewModeDTO.TilePicViewer.ToString()) { string folderPath = OfficeHelper.GetFolderPath(task.ID); var pdfFilePath = Path.Combine(folderPath, task.ID + ".pdf"); var swfFilePath = Path.Combine(folderPath, task.ID + ".swf"); var snapFilePath = Path.Combine(folderPath, task.ID + ".png"); #region 1.转换PDF byte[] pdfBuffer = null; if (!string.IsNullOrEmpty(task.ExtName)) { if (task.ExtName.ToLower() == "pdf") { pdfBuffer = FileStoreHelper.GetFile(task.Name); } else if (task.ExtName.ToLower() == "docx" || task.ExtName.ToLower() == "doc") { // 获取文件 var butter = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Word2PDF(butter, pdfFilePath, task.ExtName.ToLower()); } else if (task.ExtName.ToLower() == "xlsx" || task.ExtName.ToLower() == "xls") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Excel2PDF(buffer); } else if (task.ExtName.ToLower() == "txt") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Txt2PDF(buffer); } else if (task.ExtName.ToLower() == "jpg" || task.ExtName.ToLower() == "jpeg" || task.ExtName.ToLower() == "png") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Img2PDF(buffer); } else if (task.ExtName.ToLower() == "tif" || task.ExtName.ToLower() == "tiff") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Tif2PDF(buffer); } else { throw new Exception("未知文件类型,没有相关的转换器!"); } } else { throw new Exception("未定义文件类型!"); } if (pdfBuffer == null) { throw new Exception("PDF文件不存在!"); } #endregion #region 2.生成SWF var pdfPageCount = FileConverter.GetPageCount(pdfBuffer); if (!File.Exists(pdfFilePath)) { FileConverter.SaveFileBuffer(pdfBuffer, pdfFilePath); FileConverter.PDF2SWF(pdfFilePath, swfFilePath, pdfPageCount); } #endregion #region 3.生成缩略图 byte[] snapBuffer = FileConverter.ConvertToSnap(pdfBuffer, "pdf"); FileConverter.SaveFileBuffer(snapBuffer, snapFilePath); #endregion repo.EndTask(task.ID, ResultStatus.Success); } else { //1.获取文件 byte[] bytes = FileStoreHelper.GetFile(task.ID); string filePath = OfficeHelper.GetFolderPath(task.ID, "Files"); FileStoreHelper.SaveFileBuffer(bytes, Path.Combine(filePath, task.Name)); //2.转图 var imgDTO = OfficeHelper.InitDTO(task.Name, bytes.Length, task.ID); FileConverter fileConverter = new FileConverter(); var result = fileConverter.Exec(imgDTO); if (result == null || !result.status) { throw new Exception("转图失败!"); } //3.生成记录文件 imgDTO.Versions[0].ImageZoomLevel = 18; imgDTO.Versions[0].HighHeightUnit = result.HighHeightUnit; OfficeHelper.WriteJsonFile(imgDTO); //4.设置数据库完成 repo.EndTask(task.ID, ResultStatus.Success); //5.删除原始文件 if (File.Exists(imgDTO.Versions[0].FullPath)) { File.Delete(imgDTO.Versions[0].FullPath); } } } catch (Exception ex) { // 记录日志 repo.EndTask(task.ID, ResultStatus.Error); LogWriter.Info(string.Format(ErrInfo, DateTime.Now.ToString(), task.ID, task.Name, ex.Message, ex.StackTrace)); } } //新增处理关联word、excel进程关闭问题 2019-5-29 CloseExit(); }
public FileResult GetRedFile(string fileID) { byte[] file = FileStoreHelper.GetFile(fileID); return(File(file, "application/msword")); }