private async Task <FacebookPostStatus> GetFacebookPostStatusForSqlTable(TableEvent tableEvent) { if (tableEvent is null) { return(null); } FacebookPostStatus facebookPostStatus = null; switch (tableEvent.TableName) { case SourceSystems.Engagements: var engagement = await _engagementManager.GetAsync(tableEvent.PartitionKey.To <int>()); facebookPostStatus = GetFacebookPostStatusForEngagement(engagement); break; case SourceSystems.Talks: var talk = await _engagementManager.GetTalkAsync(tableEvent.PartitionKey.To <int>()); facebookPostStatus = GetFacebookPostStatusForTalk(talk); break; } return(facebookPostStatus); }
private FacebookPostStatus GetFacebookPostStatusForEngagement(Engagement engagement) { // TODO: Account for custom images for engagement // TODO: Account for custom message for engagement // i.e: Join me tomorrow, Join me next week // TODO: Maybe handle timezone? if (engagement is null) { return(null); } var statusText = $"I'm speaking at {engagement.Name} ({engagement.Url}) starting on {engagement.StartDateTime:f}\n"; var comments = engagement.Comments; statusText += comments; if (statusText.Length + comments.Length + 1 >= MaxFacebookStatusText) { var newLength = MaxFacebookStatusText - statusText.Length - comments.Length - 1; statusText = statusText.Substring(0, newLength - 4) + "..."; } var facebookPostStatus = new FacebookPostStatus { StatusText = statusText, LinkUri = engagement.Url }; _logger.LogDebug( "Composed Facebook Status: StatusText='{facebookPostStatus.StatusText}', LinkUrl='{facebookPostStatus.LinkUri}'", facebookPostStatus.StatusText, facebookPostStatus.LinkUri); return(facebookPostStatus); }
private async Task <FacebookPostStatus> GetFacebookPostStatusForSourceData(TableEvent tableEvent) { if (tableEvent is null) { return(null); } var statusText = "ICYMI: "; var sourceData = await _sourceDataRepository.GetAsync(tableEvent.PartitionKey, tableEvent.RowKey); if (sourceData is null) { _logger.LogWarning($"Record for '{tableEvent.PartitionKey}', '{tableEvent.RowKey}' was not found."); return(null); } statusText = sourceData.SourceSystem switch { SourceSystems.SyndicationFeed => "Blog Post: ", SourceSystems.YouTube => "Video: ", _ => statusText }; var url = sourceData.ShortenedUrl ?? sourceData.Url; var postTitle = sourceData.Title; var hashTagList = HashTagList(sourceData.Tags); if (statusText.Length + url.Length + postTitle.Length + 3 + hashTagList.Length >= MaxFacebookStatusText) { var newLength = MaxFacebookStatusText - statusText.Length - url.Length - hashTagList.Length - 1; postTitle = postTitle.Substring(0, newLength - 4) + "..."; } var facebookPostStatus = new FacebookPostStatus { StatusText = $"{statusText} {postTitle} {hashTagList}", LinkUri = url }; _logger.LogDebug( "Composed Facebook Status: StatusText='{facebookPostStatus.StatusText}', LinkUrl='{facebookPostStatus.LinkUri}'", facebookPostStatus.StatusText, facebookPostStatus.LinkUri); return(facebookPostStatus); }
private FacebookPostStatus ComposeStatus(SourceData sourceData) { if (sourceData == null) { return(null); } const int maxFacebookStatusText = 2000; // Build Facebook Status var statusText = sourceData.SourceSystem switch { nameof(SourceSystems.SyndicationFeed) => sourceData.UpdatedOnDate > sourceData.PublicationDate ? "Updated Blog Post: " : "New Blog Post: ", nameof(SourceSystems.YouTube) => sourceData.UpdatedOnDate > sourceData.PublicationDate ? "Updated Video: " : "New Video: ", _ => "" }; var url = sourceData.ShortenedUrl ?? sourceData.Url; var postTitle = sourceData.Title; var hashTagList = HashTagList(sourceData.Tags); if (statusText.Length + url.Length + postTitle.Length + 3 + hashTagList.Length >= maxFacebookStatusText) { var newLength = maxFacebookStatusText - statusText.Length - url.Length - hashTagList.Length - 1; postTitle = postTitle.Substring(0, newLength - 4) + "..."; } var facebookPostStatus = new FacebookPostStatus { StatusText = $"{statusText} {postTitle} {hashTagList}", LinkUri = url }; _logger.LogDebug( "Composed Facebook Status: StatusText='{facebookPostStatus.StatusText}', LinkUrl='{facebookPostStatus.LinkUri}'", facebookPostStatus.StatusText, facebookPostStatus.LinkUri); return(facebookPostStatus); }
private FacebookPostStatus GetFacebookPostStatusForTalk(Talk talk) { if (talk is null) { return(null); } // TODO: Account for custom images for talk // TODO: Account for custom message for talk // i.e: Join me tomorrow, Join me next week, "Up next in room...", "Join me today..." // TODO: Maybe handle timezone? var statusText = $"Talk: {talk.Name} ({talk.UrlForTalk}) starting on {talk.StartDateTime:f} to {talk.EndDateTime:t}"; if (talk.TalkLocation is not null) { statusText += $" in room {talk.TalkLocation}"; } var comments = " Comments: {engagement.Comments}"; statusText += comments; if (statusText.Length + comments.Length + 1 >= MaxFacebookStatusText) { var newLength = MaxFacebookStatusText - statusText.Length - comments.Length - 1; statusText = statusText.Substring(0, newLength - 4) + "..."; } var facebookPostStatus = new FacebookPostStatus { StatusText = statusText, LinkUri = talk.UrlForConferenceTalk }; _logger.LogDebug( "Composed Facebook Status: StatusText='{facebookPostStatus.StatusText}', LinkUrl='{facebookPostStatus.LinkUri}'", facebookPostStatus.StatusText, facebookPostStatus.LinkUri); return(facebookPostStatus); }