Ejemplo n.º 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 }));
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        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"));
        }
Ejemplo n.º 5
0
        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"));
            }
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
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, "成功删除了附件")));
        }
Ejemplo n.º 8
0
        //--------------------------------------------------------------------------------------------------------------

        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));
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public virtual void UpdateFile( ContentAttachment a, String oldFilePath ) {

            a.update();

            if (a.IsImage)
                Img.DeleteImgAndThumb( oldFilePath );
            else
                Img.DeleteFile( oldFilePath );

        }
Ejemplo n.º 11
0
        public virtual ContentAttachment GetById(long id, string guid)
        {
            ContentAttachment a = db.findById <ContentAttachment>(id);

            if (a != null && a.Guid != guid)
            {
                return(null);
            }
            return(a);
        }
Ejemplo n.º 12
0
        /// <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();
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
        public virtual void UpdateFile(ContentAttachment a, String oldFilePath)
        {
            a.update();

            if (a.IsImage)
            {
                Img.DeleteImgAndThumb(oldFilePath);
            }
            else
            {
                Img.DeleteFile(oldFilePath);
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        //--------------------------------------------------------------------------------------------------------------

        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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;
        }
Ejemplo n.º 19
0
        //--------------------------------------------------------------------------------------------------------------

        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());
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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"));
        }
Ejemplo n.º 22
0
        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");
        }
Ejemplo n.º 23
0
        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;
        }
Ejemplo n.º 24
0
        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" );
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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);
        }
Ejemplo n.º 27
0
        /// <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();
            }
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
 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();
 }
Ejemplo n.º 30
0
 public virtual void AddHits( ContentAttachment attachment ) {
     attachment.Downloads++;
     db.update( attachment, "Downloads" );
 }
Ejemplo n.º 31
0
 public virtual void UpdateName( ContentAttachment attachment, string name ) {
     attachment.Description = name;
     attachment.update( "Description" );
 }
Ejemplo n.º 32
0
 private Boolean isImage(ContentAttachment attachment)
 {
     return(Uploader.IsImage(attachment.Type));
 }
Ejemplo n.º 33
0
        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" ) );
        }
Ejemplo n.º 34
0
 public virtual void UpdateName(ContentAttachment attachment, string name)
 {
     attachment.Description = name;
     attachment.update("Description");
 }
Ejemplo n.º 35
0
 public virtual void AddHits(ContentAttachment attachment)
 {
     attachment.Downloads++;
     db.update(attachment, "Downloads");
 }
Ejemplo n.º 36
0
 public virtual ContentAttachment GetById(long id)
 {
     return(ContentAttachment.findById(id));
 }
Ejemplo n.º 37
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 });
        }
Ejemplo n.º 38
0
 private Boolean isImage( ContentAttachment attachment )
 {
     return Uploader.IsImage( attachment.Type );
 }
Ejemplo n.º 39
0
        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);
        }
Ejemplo n.º 40
0
 public virtual List <ContentAttachment> GetAttachmentsByPost(long postId)
 {
     return(ContentAttachment.find("PostId=" + postId + " order by OrderId desc, Id asc").list());
 }