Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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 static DocumentObject Build(UploadedFile fileData,
                                           string spaceId,
                                           string spaceSeqNo,
                                           string spaceName,
                                           string userId,
                                           string userName,
                                           string depId,
                                           Visible visible)
        {
            var fileName = fileData.ClientName;

            _logger.Debug("存储原始文件...");


            Guid fileId = Guid.NewGuid();

            _logger.Debug("存储原始文件完成");
            var document = new DocumentObject
            {
                Id             = fileId,
                FileName       = fileName,
                StorePath      = fileData.ServerLocation,
                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);
        }