/// <summary> /// Handles Twitter Tweet /// </summary> /// <param name="twitterItemMapper">Transforms Twitter data to Item Schema</param> /// <param name="tweet">Twitter tweet</param> private async Task <ItemMetadata> UploadTweet(TwitterSchemaToItemMapper twitterItemMapper, Tweet tweet, ConnectorTask taskInfo) { Item item = twitterItemMapper.MapTweetToItem(tweet); string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, item); Trace.TraceInformation("Tweet Uploaded to Azure Blobs"); return(new ItemMetadata(item.Id, item.SentTimeUtc, fileName)); }
/// <summary> /// Handles Twitter Tweet /// </summary> /// <param name="twitterItemMapper">Transforms Twitter data to Item Schema</param> /// <param name="tweet">Twitter tweet</param> private async Task <List <ItemMetadata> > UploadTweet(TwitterSchemaToItemMapper twitterItemMapper, Tweet tweet, ConnectorTask taskInfo) { List <Item> postItem = await twitterItemMapper.MapTweetToItemList(tweet); List <ItemMetadata> itemMetaDataList = new List <ItemMetadata>(); foreach (var item in postItem) { string fileName = await uploader.UploadItem(taskInfo.JobId, taskInfo.TaskId, item); Trace.TraceInformation("Tweet Uploaded to Azure Blobs"); itemMetaDataList.Add(new ItemMetadata(item.Id, item.SentTimeUtc, fileName)); } return(itemMetaDataList); }
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); }