public ConvertResult Convert(ref DocumentObject document, ConvertFileType convertType) { try { string path = DocumentSettings.GetStorePath(document.FileName); _storePolicy.Copy(path, document.StorePath); string tmpName = document.Id + convertType.ToSuffix(); var convertPath = DocumentSettings.GetConvertPath(tmpName); int result = _documentConverter.Convert(path, convertPath, convertType); if (File.Exists(tmpName)) { File.Delete(tmpName); } return new ConvertResult{ ErrorCode = result, SourcePath = document.StorePath, TargetPath = convertPath }; } catch (Exception ex) { _logger.Error(ex.Message); _logger.Error(ex.StackTrace); throw; } }
public void should_convert_pdf_file() { string sourcePath = Environment.CurrentDirectory + @"\TestFiles\Guidance_User_Manual_v1.2_cn.pdf"; var document = new DocumentObject { StorePath = sourcePath, DocumentType = DocumentType.PDF, }; var result = _documentConvertService.Convert(ref document, ConvertFileType.PdfToHtml); Assert.AreEqual(result.ErrorCode, ErrorMessages.Success); }
public void Add(DocumentObject document) { List<DocumentObject> documents = GetCache<List<DocumentObject>>(GenerateKey()); if (documents != null && documents.Count > 0) { var result = documents.Find(f => f.Id.ToString() == document.Id.ToString()); if (result == null) { documents.Add(document); _cachePolicy.Set(GenerateKey(), documents); } } }
public void should_pass_add_update_get_delete_process() { int count = _documentService.GetAllDocuments().Count; var document = new DocumentObject { Id = Guid.NewGuid(), FileName = "Test.doc", DisplayPath = @"C:\Test.doc", StorePath = @"C:\Test.swf", FileSize = 1080, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, DocumentType = DocumentType.Word, CreateUserId = "5", CreateUserName = "******", DepId = Guid.NewGuid().ToString(), SpaceId = Guid.NewGuid().ToString(), SpaceSeqNo = Guid.NewGuid().ToString(), SpaceName = Guid.NewGuid().ToString(), UpdateUserId = "5", UpdateUserName = "******", }; Assert.IsNotNull(_documentService.Add(document)); var result = _documentService.GetDocument(document.Id.ToString()); Assert.AreEqual(result.FileName, "Test.doc"); document.StorePath = @"D:\Test.swf"; Assert.IsNotNull(_documentService.Update(document)); document = _documentService.GetDocument(document.Id.ToString()); Assert.AreEqual(document.StorePath, @"D:\Test.swf"); document = _documentService.MoveToTrash(document.Id.ToString()); document = _documentService.GetDocument(document.Id.ToString()); Assert.IsTrue(document.IsDelete); document = _documentService.Recovery(document.Id.ToString()); document = _documentService.GetDocument(document.Id.ToString()); Assert.IsFalse(document.IsDelete); _documentService.Delete(document.Id.ToString()); result = _documentService.GetDocument(document.Id.ToString()); Assert.IsNull(result); int count2 = _documentService.GetAllDocuments().Count; Assert.AreEqual(count, count2); }
public void Update(DocumentObject document) { List<DocumentObject> documents = GetCache<List<DocumentObject>>(GenerateKey()); if (documents != null) { for(int i = 0; i < documents.Count; ++i) { if (documents[i].Id.ToString() == document.Id.ToString()) { documents[i] = document.ToObject<DocumentObject>(); _cachePolicy.Set(GenerateKey(), documents); break; } } } }
/// <summary> /// 添加文档 /// </summary> /// <param name="document"></param> /// <returns></returns> public DocumentObject Add(DocumentObject document) { _logger.Info("DocumentService 添加文档"); GeneratePreviewImage(document); document = _documentRepository.Add(document.ToEntity<Document>()).ToObject<DocumentObject>(); if (document != null) { _cacheService.Add(document); _bus.Send(new CreateDocumentMessage { Content = document }); } _logger.Debug("写入数据库成功"); return document; }
public bool CanConvert(DocumentObject document) { //不是Office文档,不需要转换 if (document.DocumentCategory != DocumentCategory.Office && document.DocumentCategory != DocumentCategory.CAD && document.DocumentCategory != DocumentCategory.Text) { return false; } // 转换后的路径不存在,需要转换 if (string.IsNullOrEmpty(document.ConvertPath) || !File.Exists(document.ConvertPath)) { return true; } return false; }
public static DocumentObject Build(BaseFile fileData, string spaceId, string spaceSeqNo, string spaceName, string userId, string userName, string depId, Visible visible) { var fileName = fileData.FileName; _logger.Debug("存储原始文件..."); var storePath = DocumentSettings.GetStorePath(fileName); _logger.Debug("存储原始文件完成"); var document = new DocumentObject { Id = fileData.Id, FileName = fileData.FileName, StorePath = storePath, FileSize = fileData.ContentLength, CreateTime = DateTime.Now, DocumentType = fileName.ToDocumentType(), UpdateTime = DateTime.Now, CreateUserId = userId, CreateUserName = userName, SpaceId = spaceId, SpaceSeqNo = spaceSeqNo, SpaceName = spaceName, UpdateUserId = userId, UpdateUserName = userName, IsConvert = false, Visible = (int)visible, DepId = depId, }; document.DisplayPath = DocumentSettings.GetDisplayUrl(Path.GetFileName(document.ConvertPath)); return document; }
/// <summary> /// 更新某个文档 /// </summary> /// <param name="document"></param> /// <returns></returns> public DocumentObject Update(DocumentObject document) { _logger.Info("DocumentService 更新文档"); document = _documentRepository.Update(f => f.Id == document.Id,document.ToEntity<Document>()).ToObject<DocumentObject>(); if (document != null) { _cacheService.Update(document); _bus.Send(new UpdateDocumentMessage { Content = document }); } return document; }
/// <summary> /// 转换某个文档 /// </summary> /// <param name="document"></param> /// <returns></returns> public DocumentObject Convert(DocumentObject document) { _logger.Info("DocumentService 转换文档:"); if (_documentConvertService.CanConvert(document)) { var result = _documentConvertService.Convert(ref document, document.DocumentType.ToConvertType()); _logger.Info(ErrorMessages.GetErrorMessages(result.ErrorCode)); } return document; }
private ActionResult GetDisplayView(DocumentObject document) { switch (document.DocumentCategory) { case DocumentCategory.Office: case DocumentCategory.Text: document = _documentService.Convert(document); return View("Html", new DisplayViewModel { Document = document, }); case DocumentCategory.CAD: document = _documentService.Convert(document); return View("Svg", new DisplayViewModel { Document = document, }); case DocumentCategory.Image: return View("Image", new DisplayViewModel { Document = document, ActiveMenuType = CurrentMenu, }); default: return View("Unknow", new DisplayViewModel { Document = document, ActiveMenuType = CurrentMenu, }); } }
public void Update(DocumentObject document) { _cacheService.Update(document); SetCache(GenerateKey(document.Id.ToString()), document); }
public DocumentObject GetOrAdd(string id, DocumentObject document) { return base.GetOrAdd(GenerateKey(id), document); }
private static DocumentObject MakeSimpleDocument() { var document = new DocumentObject { Id = Guid.NewGuid(), FileName = "Test.doc", DisplayPath = @"C:\Test.doc", StorePath = @"C:\Test.swf", FileSize = 1080, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, DocumentType = DocumentType.Word, CreateUserId = "5", DepId = Guid.NewGuid().ToString(), CreateUserName = "******", SpaceId = Guid.NewGuid().ToString(), SpaceSeqNo = Guid.NewGuid().ToString(), SpaceName = Guid.NewGuid().ToString(), UpdateUserId = "5", UpdateUserName = "******", }; return document; }
private static DocumentObject MakeDepDocument(string userId, string depId) { var document = new DocumentObject { Id = Guid.NewGuid(), FileName = "Test.doc", DisplayPath = @"C:\Test.doc", StorePath = @"C:\Test.swf", FileSize = 1080, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, DocumentType = DocumentType.Word, CreateUserId = userId, Visible = (int)Visible.Dep, DepId = depId, CreateUserName = "******", SpaceId = Guid.NewGuid().ToString(), SpaceSeqNo = Guid.NewGuid().ToString(), SpaceName = Guid.NewGuid().ToString(), UpdateUserId = userId, UpdateUserName = "******", }; return document; }
private void GeneratePreviewImage(DocumentObject document) { //图片需要可以预览 if (document.DocumentCategory == DocumentCategory.Image) { _logger.Info("文档为图片,进行图片生成操作"); byte[] bytes = _storePolicy.GetBytes(document.StorePath); Stream stream = new MemoryStream(bytes); var result = _imageService.Upload(stream, document.FileName); document.ThumbUrl = result.ThumbImageUrl; document.DisplayPath = result.CompressImageUrl; //document.DownloadPath = result.ImageUrl; _logger.InfoFormat("图片地址,ThumUrl:{0},DisplayPath:{1},DownloadPath:{2}", document.ThumbUrl, document.DisplayPath, document.DownloadPath); } //CAD图也可以预览 if (document.DocumentCategory == DocumentCategory.CAD) { var convertResult = _documentConvertService.Convert(ref document, ConvertFileType.CadToJpg); var result = _imageService.Upload(convertResult.TargetPath); document.ThumbUrl = result.ThumbImageUrl; convertResult = _documentConvertService.Convert(ref document, ConvertFileType.CadToSvg); document.DisplayPath = DocumentSettings.GetDisplayUrl(Path.GetFileName(document.ConvertPath)); } }
public DocumentViewModel(DocumentObject documentObject, string userId) { DocumentObject = documentObject; UserId = userId; }
public static MvcHtmlString Thumb(this HtmlHelper helper, DocumentObject document) { StringBuilder str = new StringBuilder(); switch (document.DocumentType) { case DocumentType.BMP: str.AppendFormat( "<i class=\"file-small-icon file-small-icon-BMP\"><img src='{0}' alt='{1}' data-displaypath='{2}'> </i>", document.ThumbUrl, document.FileName, document.DisplayPath); break; case DocumentType.JPG: str.AppendFormat( "<i class=\"file-small-icon file-small-icon-JPG\"><img src='{0}' alt='{1}' data-displaypath='{2}'> </i>", document.ThumbUrl, document.FileName, document.DisplayPath); break; case DocumentType.PNG: str.AppendFormat( "<i class=\"file-small-icon file-small-icon-PNG\"><img src='{0}' alt='{1}' data-displaypath='{2}'> </i>", document.ThumbUrl, document.FileName, document.DisplayPath); break; case DocumentType.GIF: str.AppendFormat( "<i class=\"file-small-icon file-small-icon-GIF\"><img src='{0}' alt='{1}' data-displaypath='{2}'> </i>", document.ThumbUrl, document.FileName, document.DisplayPath); break; case DocumentType.PSD: str.Append("<i class=\"file-small-icon file-small-icon-PSD\"></i>"); break; case DocumentType.AI: str.Append("<i class=\"file-small-icon file-small-icon-AI\"></i>"); break; case DocumentType.CAD: str.AppendFormat( "<i class=\"file-small-icon file-small-icon-CAD\"><img src='{0}' alt='{1}' data-displaypath='{2}'> </i>", document.ThumbUrl, document.FileName, document.DisplayPath); break; case DocumentType.TXT: str.Append("<i class=\"file-small-icon file-small-icon-TXT\"></i>"); break; case DocumentType.Word: str.Append("<i class=\"file-small-icon file-small-icon-DOC\"></i>"); break; case DocumentType.Excel: str.Append("<i class=\"file-small-icon file-small-icon-XLS\"></i>"); break; case DocumentType.PPT: str.Append("<i class=\"file-small-icon file-small-icon-PPT\"></i>"); break; case DocumentType.ZIP: str.Append("<i class=\"file-small-icon file-small-icon-ZIP\"></i>"); break; case DocumentType.RAR: str.Append("<i class=\"file-small-icon file-small-icon-RAR\"></i>"); break; case DocumentType.JAR: str.Append("<i class=\"file-small-icon file-small-icon-JAR\"></i>"); break; case DocumentType.DAMAGE: str.Append("<i class=\"file-small-icon file-small-icon-DAMAGE\"></i>"); break; case DocumentType.ISO: str.Append("<i class=\"file-small-icon file-small-icon-ISO\"></i>"); break; case DocumentType.OLD: str.Append("<i class=\"file-small-icon file-small-icon-OLD\"></i>"); break; case DocumentType.Z7: str.Append("<i class=\"file-small-icon file-small-icon-7Z\"></i>"); break; case DocumentType.BAK: str.Append("<i class=\"file-small-icon file-small-icon-BAK\"></i>"); break; case DocumentType.TMP: str.Append("<i class=\"file-small-icon file-small-icon-BAK\"></i>"); break; case DocumentType.HTML: str.Append("<i class=\"file-small-icon file-small-icon-HTML\"></i>"); break; case DocumentType.HTM: str.Append("<i class=\"file-small-icon file-small-icon-HTM\"></i>"); break; case DocumentType.XML: str.Append("<i class=\"file-small-icon file-small-icon-XML\"></i>"); break; case DocumentType.ASP: str.Append("<i class=\"file-small-icon file-small-icon-ASP\"></i>"); break; case DocumentType.PDF: str.Append("<i class=\"file-small-icon file-small-icon-PDF\"></i>"); break; case DocumentType.CHM: str.Append("<i class=\"file-small-icon file-small-icon-CHM\"></i>"); break; case DocumentType.Folder: str.Append("<i class=\"file-small-icon file-small-icon-folders\"></i>"); break; case DocumentType.HLP: str.Append("<i class=\"file-small-icon file-small-icon-HLP\"></i>"); break; case DocumentType.TTF: str.Append("<i class=\"file-small-icon file-small-icon-TTF\"></i>"); break; case DocumentType.TTC: str.Append("<i class=\"file-small-icon file-small-icon-TTC\"></i>"); break; case DocumentType.OTF: str.Append("<i class=\"file-small-icon file-small-icon-OTF\"></i>"); break; case DocumentType.FON: str.Append("<i class=\"file-small-icon file-small-icon-FON\"></i>"); break; case DocumentType.AVI: str.Append("<i class=\"file-small-icon file-small-icon-AVI\"></i>"); break; case DocumentType.ASF: str.Append("<i class=\"file-small-icon file-small-icon-ASF\"></i>"); break; case DocumentType.MP4: str.Append("<i class=\"file-small-icon file-small-icon-MP4\"></i>"); break; case DocumentType.MP3: str.Append("<i class=\"file-small-icon file-small-icon-MP3\"></i>"); break; case DocumentType.GP3: str.Append("<i class=\"file-small-icon file-small-icon-GP3\"></i>"); break; case DocumentType.RMVB: str.Append("<i class=\"file-small-icon file-small-icon-RMVB\"></i>"); break; case DocumentType.WMV: str.Append("<i class=\"file-small-icon file-small-icon-WMV\"></i>"); break; case DocumentType.SWF: str.Append("<i class=\"file-small-icon file-small-icon-SWF\"></i>"); break; case DocumentType.WMA: str.Append("<i class=\"file-small-icon file-small-icon-WMA\"></i>"); break; case DocumentType.WAV: str.Append("<i class=\"file-small-icon file-small-icon-WAV\"></i>"); break; case DocumentType.IPA: str.Append("<i class=\"file-small-icon file-small-icon-IPA\"></i>"); break; case DocumentType.APK: str.Append("<i class=\"file-small-icon file-small-icon-APK\"></i>"); break; case DocumentType.EXE: str.Append("<i class=\"file-small-icon file-small-icon-EXE\"></i>"); break; default: str.Append("<i class=\"file-small-icon file-small-icon-FILE\"></i>"); break; } return new MvcHtmlString(str.ToString()); }