예제 #1
0
        public ActionResult UploadContentAttachment()
        {
            IUser user = UserContext.CurrentUser;

            if (user == null)
            {
                return(new EmptyResult());
            }

            ContentAttachmentService attachementService = new ContentAttachmentService();
            long   userId          = user.UserId;
            string userDisplayName = user.DisplayName;
            long   attachmentId    = 0;

            if (Request.Files.Count > 0 && Request.Files["Filedata"] != null)
            {
                HttpPostedFileBase postFile = Request.Files["Filedata"];
                string             fileName = postFile.FileName;

                string            contentType = MimeTypeConfiguration.GetMimeType(postFile.FileName);
                ContentAttachment attachment  = new ContentAttachment(postFile, contentType);
                attachment.UserId          = userId;
                attachment.UserDisplayName = userDisplayName;

                using (Stream stream = postFile.InputStream)
                {
                    attachementService.Create(attachment, stream);
                }

                attachmentId = attachment.AttachmentId;
            }
            return(Json(new { AttachmentId = attachmentId }));
        }
예제 #2
0
        public ActionResult _DeleteContentAttachments(List <long> attachmentIds)
        {
            if (attachmentIds == null || attachmentIds.Count <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "没有找到需要删除的附件")));
            }

            var ContentAttachmentService = new ContentAttachmentService();

            foreach (long attachmentId in attachmentIds)
            {
                ContentAttachment contentAttachment = ContentAttachmentService.Get(attachmentId);
                if (contentAttachment == null)
                {
                    continue;
                }

                if (authorizer.CMS_DeleteContentAttachment(contentAttachment))
                {
                    ContentAttachmentService.Delete(contentAttachment);
                }
                else
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "您没有删除此附件的权限")));
                }
            }

            return(Json(new StatusMessageData(StatusMessageType.Success, "成功删除了附件")));
        }
        public override void ProcessRequest(HttpContext context)
        {
            long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0);
            if (attachmentId <= 0)
            {
                WebUtility.Return404(context);
                return;
            }

            ContentAttachmentService contentAttachmentService = new ContentAttachmentService();
            ContentAttachment attachment = contentAttachmentService.Get(attachmentId);
            if (attachment == null)
            {
                WebUtility.Return404(context);
                return;
            }

            IUser currentUser = UserContext.CurrentUser;

            //下载计数
            CountService countService = new CountService(TenantTypeIds.Instance().ContentAttachment());
            countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false);

            bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true);

            context.Response.Status = "302 Object Moved";
            context.Response.StatusCode = 302;

            LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve<ISettingsManager<LinktimelinessSettings>>().Get();
            string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId);
            context.Response.Redirect(SiteUrls.Instance().ContentAttachmentTempUrl(attachment.AttachmentId, token, enableCaching), true);
            context.Response.Flush();
            context.Response.End();
        }
예제 #4
0
        /// <summary>
        /// 附件上传编辑页面
        /// </summary>
        /// <returns></returns>
        public ActionResult _PreviewVideo(long attachmentId)
        {
            ContentAttachment contentAttachment = new ContentAttachmentService().Get(attachmentId);

            if (contentAttachment == null)
            {
                return(new EmptyResult());
            }
            return(View(contentAttachment));
        }
예제 #5
0
        public ActionResult ManageContentAttachments(string userId = null, string keyword = null, DateTime?startDate = null, DateTime?endDate = null, MediaType?mediaType = null, int pageSize = 20, int pageIndex = 1)
        {
            long?id = null;

            if (!string.IsNullOrEmpty(userId))
            {
                userId = userId.Trim(',');
                if (!string.IsNullOrEmpty(userId))
                {
                    id = long.Parse(userId);
                }
            }
            ViewData["userId"] = id;

            PagingDataSet <ContentAttachment> attachments = new ContentAttachmentService().Gets(id, keyword, startDate, endDate, mediaType, pageSize, pageIndex);

            pageResourceManager.InsertTitlePart("附件管理");
            return(View(attachments));
        }
예제 #6
0
        /// <summary>
        /// 附件列表
        /// </summary>
        public ActionResult _ListContentAttachments(string keyword = null, DateTime?startDate = null, DateTime?endDate = null, MediaType?mediaType = null, int pageIndex = 1)
        {
            IUser user = UserContext.CurrentUser;

            if (user == null)
            {
                return(new EmptyResult());
            }

            long?userId = null;

            if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
            {
                userId = user.UserId;
            }
            keyword = WebUtility.UrlDecode(keyword);
            PagingDataSet <ContentAttachment> attachments = new ContentAttachmentService().Gets(userId, keyword, startDate, endDate, mediaType, 12, pageIndex);

            return(View(attachments));
        }
예제 #7
0
        public string Process(string body, string tenantTypeId, long associateId, long userId)
        {
            if (string.IsNullOrEmpty(body) || !body.Contains("[attach:"))
                return body;

            List<long> attachmentIds = new List<long>();

            Regex rg = new Regex(@"\[attach:(?<id>[\d]+)\]", RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matches = rg.Matches(body);

            if (matches != null)
            {
                foreach (Match m in matches)
                {
                    if (m.Groups["id"] == null || string.IsNullOrEmpty(m.Groups["id"].Value))
                        continue;
                    long attachmentId = 0;
                    long.TryParse(m.Groups["id"].Value, out attachmentId);
                    if (attachmentId > 0 && !attachmentIds.Contains(attachmentId))
                        attachmentIds.Add(attachmentId);
                }
            }

            IEnumerable<ContentAttachment> attachments = new ContentAttachmentService().Gets(attachmentIds);
            if (attachments != null && attachments.Count() > 0)
            {
                IList<BBTag> bbTags = new List<BBTag>();
                string htmlTemplate = "<div class=\"tn-annexinlaid\"><a href=\"{3}\" rel=\"nofollow\">{0}</a>(<em>{1}</em>,<em>下载次数:{2}</em>)<a href=\"{3}\" rel=\"nofollow\">下载</a> </div>";

                //解析文本中附件
                foreach (var attachment in attachments)
                {
                    bbTags.Add(AddBBTag(htmlTemplate, attachment));
                }

                body = HtmlUtility.BBCodeToHtml(body, bbTags);
            }
            return body;
        }
        public override void ProcessRequest(HttpContext context)
        {
            long attachmentId = context.Request.QueryString.Get<long>("attachmentId", 0);
            if (attachmentId <= 0)
            {
                WebUtility.Return404(context);
                return;
            }

            //检查链接是否过期
            string token = context.Request.QueryString.GetString("token", string.Empty);
            bool isTimeout = true;
            long attachmentIdInToken = Utility.DecryptTokenForAttachmentDownload(token, out isTimeout);
            if (isTimeout || attachmentIdInToken != attachmentId)
            {
                WebUtility.Return403(context);
                return;
            }

            ContentAttachmentService contentAttachmentService = new ContentAttachmentService();
            ContentAttachment attachment = contentAttachmentService.Get(attachmentId);
            if (attachment == null)
            {
                WebUtility.Return404(context);
                return;
            }

            bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true);
            DateTime lastModified = attachment.DateCreated.ToUniversalTime();
            if (enableCaching && IsCacheOK(context, lastModified))
            {
                WebUtility.Return304(context);
                return;
            }

            //输出文件流
            IStoreFile storeFile = storeProvider.GetFile(attachment.GetRelativePath(), attachment.FileName);
            if (storeFile == null)
            {
                WebUtility.Return404(context);
                return;
            }

            context.Response.Clear();
            //context.Response.ClearHeaders();
            //context.Response.Cache.VaryByParams["attachmentId"] = true;
            string fileExtension = attachment.FileName.Substring(attachment.FileName.LastIndexOf('.') + 1);
            string friendlyFileName = attachment.FriendlyFileName + (attachment.FriendlyFileName.EndsWith(fileExtension) ? "" : "." + fileExtension);
            SetResponsesDetails(context, attachment.ContentType, friendlyFileName, lastModified);

            DefaultStoreFile fileSystemFile = storeFile as DefaultStoreFile;
            if (!fileSystemFile.FullLocalPath.StartsWith(@"\"))
            {
                //本地文件下载
                context.Response.TransmitFile(fileSystemFile.FullLocalPath);
                context.Response.End();
            }
            else
            {
                context.Response.AddHeader("Content-Length", storeFile.Size.ToString("0"));
                context.Response.Buffer = false;
                context.Response.BufferOutput = false;

                using (Stream stream = fileSystemFile.OpenReadStream())
                {
                    if (stream == null)
                    {
                        WebUtility.Return404(context);
                        return;
                    }
                    long bufferLength = fileSystemFile.Size <= DownloadFileHandlerBase.BufferLength ? fileSystemFile.Size : DownloadFileHandlerBase.BufferLength;
                    byte[] buffer = new byte[bufferLength];

                    int readedSize;
                    while ((readedSize = stream.Read(buffer, 0, (int)bufferLength)) > 0 && context.Response.IsClientConnected)
                    {
                        context.Response.OutputStream.Write(buffer, 0, readedSize);
                        context.Response.Flush();
                    }

                    stream.Close();
                }
                context.Response.End();
            }
        }
        public ActionResult ManageContentAttachments(string userId = null, string keyword = null, DateTime? startDate = null, DateTime? endDate = null, MediaType? mediaType = null, int pageSize = 20, int pageIndex = 1)
        {
            long? id = null;
            if (!string.IsNullOrEmpty(userId))
            {
                userId = userId.Trim(',');
                if (!string.IsNullOrEmpty(userId))
                {
                    id = long.Parse(userId);
                }
            }
            ViewData["userId"] = id;

            PagingDataSet<ContentAttachment> attachments = new ContentAttachmentService().Gets(id, keyword, startDate, endDate, mediaType, pageSize, pageIndex);
            pageResourceManager.InsertTitlePart("附件管理");
            return View(attachments);
        }
예제 #10
0
 /// <summary>
 /// 附件上传编辑页面
 /// </summary>
 /// <returns></returns>
 public ActionResult _PreviewVideo(long attachmentId)
 {
     ContentAttachment contentAttachment = new ContentAttachmentService().Get(attachmentId);
     if (contentAttachment == null)
         return new EmptyResult();
     return View(contentAttachment);
 }
예제 #11
0
        /// <summary>
        /// 附件列表
        /// </summary>
        public ActionResult _ListContentAttachments(string keyword = null, DateTime? startDate = null, DateTime? endDate = null, MediaType? mediaType = null, int pageIndex = 1)
        {
            IUser user = UserContext.CurrentUser;
            if (user == null)
            {
                return new EmptyResult();
            }

            long? userId = null;
            if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId))
                userId = user.UserId;
            keyword = WebUtility.UrlDecode(keyword);
            PagingDataSet<ContentAttachment> attachments = new ContentAttachmentService().Gets(userId, keyword, startDate, endDate, mediaType, 12, pageIndex);
            return View(attachments);
        }
예제 #12
0
        public ActionResult _DeleteContentAttachments(List<long> attachmentIds)
        {
            if (attachmentIds == null || attachmentIds.Count <= 0)
                return Json(new StatusMessageData(StatusMessageType.Success, "没有找到需要删除的附件"));

            var ContentAttachmentService = new ContentAttachmentService();
            foreach (long attachmentId in attachmentIds)
            {
                ContentAttachment contentAttachment = ContentAttachmentService.Get(attachmentId);
                if (contentAttachment == null)
                    continue;

                if (authorizer.CMS_DeleteContentAttachment(contentAttachment))
                    ContentAttachmentService.Delete(contentAttachment);
                else
                    return Json(new StatusMessageData(StatusMessageType.Error, "您没有删除此附件的权限"));
            }

            return Json(new StatusMessageData(StatusMessageType.Success, "成功删除了附件"));
        }
예제 #13
0
        public ActionResult UploadContentAttachment()
        {
            IUser user = UserContext.CurrentUser;

            if (user == null)
            {
                return new EmptyResult();
            }

            ContentAttachmentService attachementService = new ContentAttachmentService();
            long userId = user.UserId;
            string userDisplayName = user.DisplayName;
            long attachmentId = 0;
            if (Request.Files.Count > 0 && Request.Files["Filedata"] != null)
            {
                HttpPostedFileBase postFile = Request.Files["Filedata"];
                string fileName = postFile.FileName;

                string contentType = MimeTypeConfiguration.GetMimeType(postFile.FileName);
                ContentAttachment attachment = new ContentAttachment(postFile, contentType);
                attachment.UserId = userId;
                attachment.UserDisplayName = userDisplayName;

                using (Stream stream = postFile.InputStream)
                {
                    attachementService.Create(attachment, stream);
                }

                attachmentId = attachment.AttachmentId;
            }
            return Json(new { AttachmentId = attachmentId });
        }