public DownloadFileAuthority Create(int projectId, string userName, DownloadFileAuthorityType authorityType)
        {
            var now       = System.DateTime.Now;
            var authority = new DownloadFileAuthority {
                Guid      = System.Guid.NewGuid().ToString(),
                ProjectId = projectId,
                UserName  = userName,
                DownloadFileAuthorityType = authorityType,
                CreateTime         = now,
                CreateUserName     = UserInfo.UserName,
                LastModifyTime     = now,
                LastModifyUserName = UserInfo.UserName,
                RecordStatus       = Models.RecordStatus.Valid
            };

            authority.Id = (int)m_db.Insert(m_defaultTableName, m_defaultPrimaryKey, true, authority.GetTableObject());
            return(authority);
        }
Esempio n. 2
0
        protected internal ActionResult CnabsFile(string filePathName, string contentType,
                                                  string fileDownloadName, DownloadFileAuthorityType authority)
        {
            if (authority == DownloadFileAuthorityType.AllForbidden)
            {
                //TODO:
                throw new NotImplementedException("暂不支持DownloadFileAuthorityType.AllForbidden");
            }

            if (filePathName.EndsWith("doc", StringComparison.CurrentCultureIgnoreCase) ||
                filePathName.EndsWith("docx", StringComparison.CurrentCultureIgnoreCase))
            {
                if (authority == DownloadFileAuthorityType.Word2PdfWithWatermark)
                {
                    var waterMark = new WaterMarkMultiText()
                    {
                        BigText   = CommUtils.GetWatermarkTitle(),
                        SmallText = "[" + CurrentUserName + "]下载于" + DateTime.Now.ToString()
                    };

                    var pdfUtil = new PdfUtils(waterMark);
                    pdfUtil.PdfPermission = PdfUtils.PdfPermissionEnum.Printing;
                    var ms = pdfUtil.WordToPdfMemoryStream(filePathName);
                    ms.Seek(0, SeekOrigin.Begin);

                    var pdfFileName = FileUtils.ConvertFileExtension(fileDownloadName, FileType.PDF);
                    return(File(ms, contentType, pdfFileName));
                }
                else if (authority == DownloadFileAuthorityType.Word2Pdf)
                {
                    var pdfUtil = new PdfUtils();
                    var ms      = pdfUtil.WordToPdfMemoryStream(filePathName);
                    ms.Seek(0, SeekOrigin.Begin);

                    var pdfFileName = FileUtils.ConvertFileExtension(fileDownloadName, FileType.PDF);
                    return(File(ms, contentType, pdfFileName));
                }
            }

            return(File(filePathName, contentType, fileDownloadName));
        }