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 })); }
public void SaveAdd(int postId) { ContentPost post = postService.GetById(postId, ctx.owner.Id); HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { errors.Join(result); run(Add, postId); return; } ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = ctx.Post("Name"); uploadFile.AppId = ctx.app.Id; uploadFile.PostId = postId; attachService.Create(uploadFile, (User)ctx.viewer.obj, ctx.owner.obj); echoToParentPart(lang("opok")); }
public void SaveRename(int postId) { ContentPost post = postService.GetById(postId, ctx.owner.Id); int id = ctx.GetInt("aid"); String name = ctx.Post("Name"); if (strUtil.IsNullOrEmpty(name)) { errors.Add(lang("exName")); run(Rename, id); return; } ContentAttachment attachment = attachService.GetById(id); if (attachment == null) { echoRedirect(alang("exAttrachment")); return; } attachService.UpdateName(attachment, name); echoToParentPart(lang("opok")); }
public void SaveUpload(int postId) { ContentPost post = postService.GetById(postId, ctx.owner.Id); int id = ctx.GetInt("aid"); ContentAttachment attachment = attachService.GetById(id); if (attachment == null) { echoRedirect(alang("exAttrachment")); return; } HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { errors.Join(result); run(Upload, id); return; } String toDeleteFile = attachment.FileUrl; attachment.FileSize = postedFile.ContentLength; attachment.Type = postedFile.ContentType; attachment.Name = result.Info.ToString(); attachService.UpdateFile(attachment, toDeleteFile); echoToParentPart(lang("opok")); }
public virtual void SaveSort(int postId) { int id = ctx.PostInt("id"); String cmd = ctx.Post("cmd"); ContentAttachment data = attachService.GetById(id); ContentPost post = postService.GetById(postId, ctx.owner.Id); List <ContentAttachment> list = attachService.GetAttachmentsByPost(postId); if (cmd == "up") { new SortUtil <ContentAttachment>(data, list).MoveUp(); echoRedirect("ok"); } else if (cmd == "down") { new SortUtil <ContentAttachment>(data, list).MoveDown(); echoRedirect("ok"); } else { echoError(lang("exUnknowCmd")); } }
public virtual void UpdateAtachments(long[] arrAttachmentIds, ContentPost post) { if (post == null || arrAttachmentIds.Length == 0) { return; } foreach (int id in arrAttachmentIds) { ContentAttachment a = ContentAttachment.findById(id); if (a == null) { continue; } a.OwnerId = post.OwnerId; a.OwnerType = post.OwnerType; a.OwnerUrl = post.OwnerUrl; a.Creator = post.Creator; a.CreatorUrl = post.CreatorUrl; a.PostId = post.Id; a.AppId = post.AppId; a.update(); } int count = ContentAttachment.count("PostId=" + post.Id); post.Attachments = count; post.update(); }
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 void SaveFlashFile() { HttpFile postedFile = ctx.GetFileSingle(); Result result = attachService.SaveFile(postedFile); Dictionary <String, String> dic = new Dictionary <String, String>(); if (result.HasErrors) { dic.Add("FileName", ""); dic.Add("DeleteLink", ""); dic.Add("Msg", result.ErrorsText); echoText(JsonString.ConvertDictionary(dic)); } else { ContentAttachment att = result.Info as ContentAttachment; String deleteLink = to(DeleteAttachment, att.Id); dic.Add("FileName", att.Description); dic.Add("DeleteLink", deleteLink); dic.Add("Id", att.Id.ToString()); echoText(JsonString.ConvertDictionary(dic)); } }
public virtual void DeleteByPost(long postId) { List <ContentAttachment> attachments = this.GetAttachmentsByPost(postId); foreach (ContentAttachment attachment in attachments) { Img.DeleteImgAndThumb(attachment.FileUrl); } ContentAttachment.deleteBatch("PostId=" + postId); }
public virtual void UpdateFile( ContentAttachment a, String oldFilePath ) { a.update(); if (a.IsImage) Img.DeleteImgAndThumb( oldFilePath ); else Img.DeleteFile( oldFilePath ); }
public virtual ContentAttachment GetById(long id, string guid) { ContentAttachment a = db.findById <ContentAttachment>(id); if (a != null && a.Guid != guid) { return(null); } return(a); }
/// <summary> /// Add attachment files. /// </summary> /// <param name="files">The http file collection.</param> /// <param name="service">The INetDriveService object.</param> public void AttachFiles(HttpFileCollectionBase files, INetDriveService service) { if (files.Count == 0) { return; } if (service == null) { throw new ArgumentNullException("service"); } var attchUri = Parent.AttachmentsPath; if (!service.Exists(attchUri)) { service.CreatePath(attchUri); } var itemUri = new Uri(attchUri.ToString() + "/" + this.ID.ToString()); if (!service.Exists(itemUri)) { service.CreatePath(itemUri); } var itemPath = service.MapPath(itemUri); for (int i = 0; i < files.Count; i++) { var file = files[i]; if (file.ContentLength > 0) { var fileName = System.IO.Path.GetFileName(file.FileName); file.SaveAs(itemPath + (!itemPath.EndsWith("\\") ? "\\" : "") + fileName); var webFile = new WebResourceInfo(itemUri.ToString() + (!itemPath.EndsWith("\\") ? "\\" : "") + fileName); var attach = new ContentAttachment() { ContentType = webFile.ContentType, Extension = webFile.Extension, ItemID = this.ID, Size = file.ContentLength, Name = fileName, Uri = webFile.Url.ToString() }; Context.Add(attach); } } Context.SaveChanges(); Model.TotalAttachments = Context.Count <ContentAttachment>(c => c.ItemID.Equals(this.ID)); this.TotalAttachments = Model.TotalAttachments; Context.SaveChanges(); }
private static void refreshAttachmentCount(ContentAttachment at) { ContentPost post = ContentPost.findById(at.PostId); if (post == null) { return; } int count = ContentAttachment.count("PostId=" + post.Id); post.Attachments = count; post.update(); }
public virtual void UpdateFile(ContentAttachment a, String oldFilePath) { a.update(); if (a.IsImage) { Img.DeleteImgAndThumb(oldFilePath); } else { Img.DeleteFile(oldFilePath); } }
public void Upload(int postId) { int id = ctx.GetInt("aid"); ContentAttachment attachment = attachService.GetById(id); if (attachment == null) { echoRedirect(alang("exAttrachment")); return; } set("ActionLink", to(SaveUpload, postId) + "?aid=" + id); }
//-------------------------------------------------------------------------------------------------------------- public virtual void Delete(long id) { ContentAttachment at = ContentAttachment.findById(id); if (at == null) { return; } at.delete(); Img.DeleteImgAndThumb(strUtil.Join(sys.Path.DiskPhoto, at.Name)); // 重新统计所属主题的附件数 refreshAttachmentCount(at); }
public virtual Result Create(ContentAttachment a, User user, IMember owner) { a.OwnerId = owner.Id; a.OwnerType = owner.GetType().FullName; a.OwnerUrl = owner.Url; a.Creator = user; a.CreatorUrl = user.Url; a.Guid = Guid.NewGuid().ToString(); Result result = db.insert(a); refreshAttachmentCount(a); return(result); }
public virtual Result Create( ContentAttachment a, User user, IMember owner ) { a.OwnerId = owner.Id; a.OwnerType = owner.GetType().FullName; a.OwnerUrl = owner.Url; a.Creator = user; a.CreatorUrl = user.Url; a.Guid = Guid.NewGuid().ToString(); Result result = db.insert( a ); refreshAttachmentCount( a ); return result; }
//-------------------------------------------------------------------------------------------------------------- public void Rename(int postId) { int id = ctx.GetInt("aid"); set("ActionLink", to(SaveRename, postId) + "?aid=" + id); ContentAttachment attachment = attachService.GetById(id); if (attachment == null) { echoRedirect(alang("exAttrachment")); return; } set("name", attachment.GetFileShowName()); }
private async Task <Item> CreateCommentItem(CommentDataFB comment, string pageId, Item postItem, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata) { Item commentItem = new Item() { SchemaVersion = new Version(1, 0), Id = comment.Id, ContainerId = pageId, ContainerName = postItem.ContainerName, SourceType = "Facebook", ItemType = "Comment", ContentType = ContentType.Text, Content = comment.Message, ParentId = postItem.Id, ThreadId = postItem.Id, SentTimeUtc = DateTime.Parse(comment.CreatedTime), Sender = ToItemUser(comment.From), NumOfLikes = comment.LikeCount, MessagePreviewText = postItem.Content, Recipients = Array.Empty <User>(), PreContext = new List <Item>() { postItem }, }; if (comment.Attachment != null) { commentItem.ContentAttachments = new List <ContentAttachment>(); string attachmentType = comment.Attachment.Type; string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(comment.Attachment.Media?.Image?.Src); ContentAttachment attachment = new ContentAttachment() { AttachmentFileName = attachmentType.Contains("share") ? "safe_image.jpg" : FetchNameFromUri(attachmentType.Contains("video") ? comment.Attachment.Media?.Source : comment.Attachment.Media?.Image?.Src), AttachmentType = attachmentType, Content = downloadedContent, Uri = new Uri(attachmentType.Contains("video") ? comment.Attachment.Url : comment.Attachment.Media?.Image?.Src), }; commentItem.ContentAttachments.Add(attachment); } string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, commentItem); itemMetadata.Add(new ItemMetadata(commentItem.Id, commentItem.SentTimeUtc, fileName)); return(commentItem); }
public void Delete(int postId) { ContentPost post = postService.GetById(postId, ctx.owner.Id); int id = ctx.GetInt("aid"); ContentAttachment attachment = attachService.GetById(id); if (attachment == null) { echoRedirect(alang("exAttrachment")); return; } attachService.Delete(id); echoRedirectPart(lang("opok")); }
public virtual void CreateByTemp(String ids, ContentPost post) { int[] arrIds = cvt.ToIntArray(ids); if (arrIds.Length == 0) { return; } int attachmentCount = 0; foreach (int id in arrIds) { ContentAttachmentTemp at = ContentAttachmentTemp.findById(id); if (at == null) { continue; } ContentAttachment a = new ContentAttachment(); a.AppId = at.AppId; a.Guid = at.Guid; a.FileSize = at.FileSize; a.Type = at.Type; a.Name = at.Name; a.Description = at.Description; a.PostId = post.Id; a.OwnerId = post.OwnerId; a.OwnerType = post.OwnerType; a.OwnerUrl = post.OwnerUrl; a.Creator = post.Creator; a.CreatorUrl = post.CreatorUrl; a.insert(); at.delete(); attachmentCount++; } post.Attachments = attachmentCount; post.update("Attachments"); }
public virtual Result SaveFile( HttpFile postedFile ) { Result result = Uploader.SaveFileOrImage( postedFile ); if (result.HasErrors)return result; ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = System.IO.Path.GetFileName( postedFile.FileName ); uploadFile.Guid = Guid.NewGuid().ToString(); uploadFile.insert(); result.Info = uploadFile; return result; }
public void CreateByTemp( String ids, ContentPost post ) { int[] arrIds = cvt.ToIntArray( ids ); if (arrIds.Length == 0) return; int attachmentCount = 0; foreach (int id in arrIds) { ContentAttachmentTemp at = ContentAttachmentTemp.findById( id ); if (at == null) continue; ContentAttachment a = new ContentAttachment(); a.AppId = at.AppId; a.Guid = at.Guid; a.FileSize = at.FileSize; a.Type = at.Type; a.Name = at.Name; a.Description = at.Description; a.PostId = post.Id; a.OwnerId = post.OwnerId; a.OwnerType = post.OwnerType; a.OwnerUrl = post.OwnerUrl; a.Creator = post.Creator; a.CreatorUrl = post.CreatorUrl; a.insert(); at.delete(); attachmentCount++; } post.Attachments = attachmentCount; post.update( "Attachments" ); }
private List <ContentAttachment> MapAttachments(Tweet tweet) { List <ContentAttachment> attachments = null; if (!String.IsNullOrEmpty(tweet.Entities.MediaObjects?.ToList().FirstOrDefault()?.MediaUrlHttps)) { foreach (var mediaObjects in tweet.Entities.MediaObjects.ToList()) { if (attachments == null) { attachments = new List <ContentAttachment>(); } ContentAttachment attachment = new ContentAttachment() { AttachmentType = "media", Content = mediaObjects.Content, Uri = new Uri(mediaObjects.MediaUrlHttps), }; attachments.Add(attachment); } foreach (var mediaObjects in tweet.ExtendedEntities.ExtendedMediaObjects.ToList()) { if (!attachments.Where(attachment => attachment.Uri.ToString().Equals(mediaObjects.MediaUrlHttps)).Any()) { ContentAttachment attachment = new ContentAttachment() { AttachmentType = "media", Content = mediaObjects.Content, Uri = new Uri(mediaObjects.MediaUrlHttps), }; attachments.Add(attachment); } } } return(attachments); }
public virtual Result SaveFile(HttpFile postedFile) { Result result = Uploader.SaveFileOrImage(postedFile); if (result.HasErrors) { return(result); } ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = System.IO.Path.GetFileName(postedFile.FileName); uploadFile.Guid = Guid.NewGuid().ToString(); uploadFile.insert(); result.Info = uploadFile; return(result); }
/// <summary> /// Serialize to a JSON object /// </summary> public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } ((Fhir.R4.Models.BackboneElement) this).SerializeJson(writer, options, false); if (!string.IsNullOrEmpty(ContentString)) { writer.WriteString("contentString", (string)ContentString !); } if (_ContentString != null) { writer.WritePropertyName("_contentString"); _ContentString.SerializeJson(writer, options); } if (ContentAttachment != null) { writer.WritePropertyName("contentAttachment"); ContentAttachment.SerializeJson(writer, options); } if (ContentReference != null) { writer.WritePropertyName("contentReference"); ContentReference.SerializeJson(writer, options); } if (includeStartObject) { writer.WriteEndObject(); } }
public void Show(int id) { String guid = ctx.Get("id"); ContentAttachment attachment = attachmentService.GetById(id, guid); if (attachment == null) { echoRedirect(lang("exDataNotFound")); return; } attachmentService.AddHits(attachment); // 检查盗链 if (isDownloadValid() == false) { echoRedirect(alang("exDownload")); return; } // 转发 redirectUrl(attachment.FileUrl); }
private static void refreshAttachmentCount( ContentAttachment at ) { ContentPost post = ContentPost.findById( at.PostId ); if (post == null) return; int count = ContentAttachment.count( "PostId=" + post.Id ); post.Attachments = count; post.update(); }
public virtual void AddHits( ContentAttachment attachment ) { attachment.Downloads++; db.update( attachment, "Downloads" ); }
public virtual void UpdateName( ContentAttachment attachment, string name ) { attachment.Description = name; attachment.update( "Description" ); }
private Boolean isImage(ContentAttachment attachment) { return(Uploader.IsImage(attachment.Type)); }
public void SaveAdd( int postId ) { ContentPost post = postService.GetById( postId, ctx.owner.Id ); HttpFile postedFile = ctx.GetFileSingle(); Result result = Uploader.SaveFileOrImage( postedFile ); if (result.HasErrors) { errors.Join( result ); run( Add, postId ); return; } ContentAttachment uploadFile = new ContentAttachment(); uploadFile.FileSize = postedFile.ContentLength; uploadFile.Type = postedFile.ContentType; uploadFile.Name = result.Info.ToString(); uploadFile.Description = ctx.Post( "Name" ); uploadFile.AppId = ctx.app.Id; uploadFile.PostId = postId; attachService.Create( uploadFile, (User)ctx.viewer.obj, ctx.owner.obj ); echoToParentPart( lang( "opok" ) ); }
public virtual void UpdateName(ContentAttachment attachment, string name) { attachment.Description = name; attachment.update("Description"); }
public virtual void AddHits(ContentAttachment attachment) { attachment.Downloads++; db.update(attachment, "Downloads"); }
public virtual ContentAttachment GetById(long id) { return(ContentAttachment.findById(id)); }
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 }); }
private Boolean isImage( ContentAttachment attachment ) { return Uploader.IsImage( attachment.Type ); }
private async Task <Item> CreatePostItem(PostFB post, string pageId, string pageName, ConnectorTask taskInfo, List <ItemMetadata> itemMetadata) { Item postItem = new Item() { SchemaVersion = new Version(1, 0), Id = post.Id, ContainerId = pageId, ContainerName = pageName, SourceType = "Facebook", ItemType = "Post", ContentType = ContentType.Text, Content = post.Message, ParentId = string.Empty, ThreadId = post.Id, SentTimeUtc = DateTime.Parse(post.CreatedTime), Sender = ToItemUser(post.From), NumOfLikes = post.Likes?.Summary?.TotalCount ?? 0, MessagePreviewText = post.Message, Recipients = Array.Empty <User>(), }; if (post.Attachments != null) { postItem.ContentAttachments = new List <ContentAttachment>(); if (post.Attachments.Data?[0]?.Media == null) { AttachmentDataFB[] attachmentData = post.Attachments.Data?[0]?.Subattachments?.Data; foreach (AttachmentDataFB attachmentItem in attachmentData) { string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(attachmentItem.Media?.Image?.Src); ContentAttachment attachment = new ContentAttachment() { AttachmentFileName = FetchNameFromUri(attachmentItem.Media?.Image?.Src), AttachmentType = attachmentItem.Type, Content = downloadedContent, Uri = new Uri(attachmentItem.Media?.Image?.Src), }; postItem.ContentAttachments.Add(attachment); } } else { // only one video allowed per post, checking attachment type string attachmentType = post.Attachments.Data[0].Type; string downloadedContent = await this.downloader.DownloadFileAsBase64EncodedString(post.Attachments.Data[0].Media?.Image?.Src); ContentAttachment attachment = new ContentAttachment() { AttachmentFileName = attachmentType.Contains("share") ? "safe_image.jpg" : FetchNameFromUri(attachmentType.Contains("video") ? post.Attachments.Data[0].Media?.Source : post.Attachments.Data[0].Media?.Image?.Src), AttachmentType = attachmentType, Content = downloadedContent, Uri = new Uri(attachmentType.Contains("video") ? post.Attachments.Data[0].Url : post.Attachments.Data[0].Media?.Image?.Src), }; postItem.ContentAttachments.Add(attachment); } } string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, postItem); itemMetadata.Add(new ItemMetadata(postItem.Id, postItem.SentTimeUtc, fileName)); return(postItem); }
public virtual List <ContentAttachment> GetAttachmentsByPost(long postId) { return(ContentAttachment.find("PostId=" + postId + " order by OrderId desc, Id asc").list()); }