private static Model.Excel.Cfp MapToModel(IExcelDataReader reader) { var model = new Cfp { Id = reader.GetString(0), NameContactPerson = reader.GetString(1), EmailContactPerson = reader.GetString(2), NameSpeaker = reader.GetString(3), EmailSpeaker = reader.GetString(4), MobilePhoneSpeaker = reader.GetString(5), ExtraNotesSpeaker = reader.GetString(6), TitleTalk = reader.GetString(7), DescriptionTalk = reader.GetString(8), SessionType = reader.GetString(9), Tracks = reader.GetString(10), Difficulty = reader.GetString(11), TargetGroupDeveloper = reader.GetString(12), TargetGroupArchitect = reader.GetString(13), TargetGroupManagement = reader.GetString(14), TargetGroupDisruptor = reader.GetString(15), TargetGroupExpert = reader.GetString(16), ExtraNotesSession = reader.GetString(17) }; return(model); }
private async Task SendPostNewCfpMessageAsync(Cfp cfpToAdd) { try { await _messageSender.SendTwitterMessageAsync(cfpToAdd, Url.Action("details", "cfp", new { id = cfpToAdd.Id }, "https", "cfp.exchange")); } catch (Exception ex) { _logger.LogError(ex.Message); } }
private async Task PostNewCfpTweet(Cfp cfpToAdd) { // Post to Twitter account try { await _twitterService.PostNewCfpTweet(cfpToAdd, Url.Action("details", "cfp", new { id = cfpToAdd.Id }, "https", "cfp.exchange")); } catch (Exception ex) { _logger.LogError(ex.Message); } }
private async Task PostNewCfpTweet(Cfp cfpToAdd) { // Post to Twitter account try { await _twitterService.PostNewCfpTweet(cfpToAdd, Url.Action("details", "cfp", new { id = cfpToAdd.Id }, "https", "cfp.exchange")); } catch { // Intentionally left blank, we can probably do something // more useful, but for now if Twitter fails ¯\_(ツ)_/¯ } }
private async Task DownloadEventImageLocally(SubmittedCfp submittedCfp, Cfp cfpToAdd) { try { if (ShouldDownloadEventImageLocally()) { await _downloadEventImageMessageSender.Execute(cfpToAdd.Id, submittedCfp.EventImageUrl); } } catch { // Intentionally left blank, we can probably do something // more useful, but for now if download fails ¯\_(ツ)_/¯ } }
private async Task DownloadEventImageLocally(SubmittedCfp submittedCfp, Cfp cfpToAdd) { try { if (ShouldDownloadEventImageLocally()) { await _downloadEventImageMessageSender.Execute(cfpToAdd.Id, submittedCfp.EventImageUrl); } else { _logger.LogInformation("Not downloading event image locally."); } } catch (Exception ex) { _logger.LogError(ex.Message); } }
private async Task <Cfp> CreateCfpToAdd(SubmittedCfp submittedCfp) { var timezone = string.Empty; try { timezone = await GetTimezone(submittedCfp.LocationLat, submittedCfp.LocationLng); } catch { // Intentionally left blank, just for event to calendar // If it fails, sucks for you } var cfpToAddSlug = GetCfpSlug(submittedCfp); var cfpToAdd = new Cfp { Id = Guid.NewGuid(), EventName = submittedCfp.EventTitle, EventUrl = submittedCfp.EventUrl, EventImage = ValidateImageUri(submittedCfp.EventImageUrl), EventDescription = submittedCfp.EventDescription, EventLocationName = submittedCfp.LocationName, EventLocationLat = submittedCfp.LocationLat, EventLocationLng = submittedCfp.LocationLng, CfpEndDate = submittedCfp.CfpEndDate.Date, CfpAdded = DateTime.Now, CfpUrl = submittedCfp.CfpUrl, EventStartDate = submittedCfp.EventStartDate?.Date ?? default(DateTime), EventEndDate = submittedCfp.EventEndDate?.Date ?? default(DateTime), ProvidesAccommodation = submittedCfp.ProvidesAccommodation, ProvidesTravelAssistance = submittedCfp.ProvidesTravelAssistance, SubmittedByName = submittedCfp.SubmittedByName, EventTwitterHandle = submittedCfp.EventTwitterHandle, EventTimezone = timezone, Slug = cfpToAddSlug, EventTags = submittedCfp.EventTags, CfpDecisionDate = submittedCfp.CfpDecisionDate?.Date ?? default(DateTime) }; return(cfpToAdd); }
private async Task SendPostNewCfpMessageAsync(Cfp cfpToAdd) { try { var cfpInfo = new CfpInformation { CfpEndDate = cfpToAdd.CfpEndDate, EventStartDate = cfpToAdd.EventStartDate, EventEndDate = cfpToAdd.EventEndDate, EventLocationLatitude = (decimal)cfpToAdd.EventLocationLat, EventLocationLongitude = (decimal)cfpToAdd.EventLocationLng, EventName = cfpToAdd.EventName, TwitterHandle = cfpToAdd.EventTwitterHandle }; await _messageSender.SendTwitterMessageAsync(cfpInfo, Url.Action("details", "cfp", new { id = cfpToAdd.Id }, "https", "cfp.exchange")); } catch (Exception ex) { _logger.LogError(ex.Message); } }
public async Task SendTwitterMessageAsync(Cfp cfpToAdd, string urlToCfp) { var servicebusConnectionstring = _configuration["ServicebusTwitterQueueConnectionString"]; var queueClient = new QueueClient(new ServiceBusConnectionStringBuilder(servicebusConnectionstring)); var sendTweetMessage = new SendTweetMessage { CfpEndDate = cfpToAdd.CfpEndDate, EventStartDate = cfpToAdd.EventStartDate, EventEndDate = cfpToAdd.EventEndDate, EventLocationLatitude = (decimal)cfpToAdd.EventLocationLat, EventLocationLongitude = (decimal)cfpToAdd.EventLocationLng, EventName = cfpToAdd.EventName, TwitterHandle = cfpToAdd.EventTwitterHandle, UrlToCfp = urlToCfp }; var messageBody = JsonConvert.SerializeObject(sendTweetMessage); var message = new Message(Encoding.UTF8.GetBytes(messageBody)); await queueClient.SendAsync(message); }
public IActionResult Submit(SubmittedCfp submittedCfp) { // TODO // Check validity if (ModelState.IsValid) { // Map var cfpToAddId = Guid.NewGuid(); var cfpToAdd = new Cfp { Id = cfpToAddId, EventName = submittedCfp.EventTitle, EventUrl = submittedCfp.EventUrl, EventImage = submittedCfp.EventImageUrl, EventDescription = submittedCfp.EventDescription, EventLocationName = submittedCfp.LocationName, EventLocationLat = submittedCfp.LocationLat, EventLocationLng = submittedCfp.LocationLng, CfpEndDate = submittedCfp.CfpEndDate, CfpAdded = DateTime.Now }; // Save CFP _cfpContext.Add(cfpToAdd); _cfpContext.SaveChanges(); // Post to Twitter // Send back ID to do whatever at the client-side return(Json(cfpToAddId)); } // Add invalid model return(BadRequest()); }
private async Task PostNewCfpTweet(Cfp cfpToAdd) { var auth = new SingleUserAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = _configuration["TwitterConsumerKey"], ConsumerSecret = _configuration["TwitterConsumerSecret"], OAuthToken = _configuration["TwitterOAuthToken"], OAuthTokenSecret = _configuration["TwitterOAuthTokenSecret"] } }; await auth.AuthorizeAsync(); var ctx = new TwitterContext(auth); var tweetMessageBuilder = new StringBuilder(); if (!string.IsNullOrWhiteSpace(cfpToAdd.EventTwitterHandle)) { var twitterHandle = cfpToAdd.EventTwitterHandle; if (!twitterHandle.StartsWith('@')) { twitterHandle = "@" + twitterHandle; } tweetMessageBuilder.AppendLine($"\U0001F4E2 New CFP: {cfpToAdd.EventName} ({twitterHandle}) "); } else { tweetMessageBuilder.AppendLine($"\U0001F4E2 New CFP: {cfpToAdd.EventName}"); } tweetMessageBuilder.AppendLine($"\U000023F3 Closes: {cfpToAdd.CfpEndDate.ToLongDateString()}"); if (cfpToAdd.EventStartDate != default(DateTime) && cfpToAdd.EventStartDate.Date == cfpToAdd.EventEndDate.Date) { tweetMessageBuilder.AppendLine($"\U0001F5D3 Event: {cfpToAdd.EventStartDate.ToString("MMM dd")}"); } else if (cfpToAdd.EventStartDate != default(DateTime)) { tweetMessageBuilder.AppendLine($"\U0001F5D3 Event: {cfpToAdd.EventStartDate.ToString("MMM dd")} - {cfpToAdd.EventEndDate.ToString("MMM dd")}"); } tweetMessageBuilder.AppendLine($"#cfp #cfpexchange {Url.Action("details", "cfp", new { id = cfpToAdd.Id }, " https ", " cfp.exchange ")}"); var tweetMessage = tweetMessageBuilder.ToString(); if (_hostingEnvironment.IsProduction()) { // TODO substringing is not the best thing, but does the trick for now await ctx.TweetAsync(tweetMessage.Length > 280?tweetMessage.Substring(0, 280) : tweetMessage, (decimal)cfpToAdd.EventLocationLat, (decimal)cfpToAdd.EventLocationLng, true); } else { Debug.WriteLine(tweetMessage); } }
public async Task <IActionResult> Submit([FromForm] SubmittedCfp submittedCfp) { // TODO // Check validity if (ModelState.IsValid) { // Map var cfpToAddId = Guid.NewGuid(); var timezone = string.Empty; try { timezone = await GetTimezone(submittedCfp.LocationLat, submittedCfp.LocationLng); } catch { // Intentionally left blank, just for event to calendar // If it fails, sucks for you } var cfpToAddSlug = FriendlyUrlHelper.GetFriendlyTitle(submittedCfp.EventTitle); var i = 0; // Prevent duplicate slugs while (_cfpContext.Cfps.Any(cfp => cfp.Slug == cfpToAddSlug)) { cfpToAddSlug = $"{cfpToAddSlug}-{++i}"; } var cfpToAdd = new Cfp { Id = cfpToAddId, EventName = submittedCfp.EventTitle, EventUrl = submittedCfp.EventUrl, EventImage = ValidateImageUri(submittedCfp.EventImageUrl), EventDescription = submittedCfp.EventDescription, EventLocationName = submittedCfp.LocationName, EventLocationLat = submittedCfp.LocationLat, EventLocationLng = submittedCfp.LocationLng, CfpEndDate = submittedCfp.CfpEndDate.Date, CfpAdded = DateTime.Now, CfpUrl = submittedCfp.CfpUrl, EventStartDate = submittedCfp.EventStartDate?.Date ?? default(DateTime), EventEndDate = submittedCfp.EventEndDate?.Date ?? default(DateTime), ProvidesAccommodation = submittedCfp.ProvidesAccommodation, ProvidesTravelAssistance = submittedCfp.ProvidesTravelAssistance, SubmittedByName = submittedCfp.SubmittedByName, EventTwitterHandle = submittedCfp.EventTwitterHandle, EventTimezone = timezone, Slug = cfpToAddSlug, EventTags = submittedCfp.EventTags, CfpDecisionDate = submittedCfp.CfpDecisionDate?.Date ?? default(DateTime) }; // Save CFP _cfpContext.Add(cfpToAdd); await _cfpContext.SaveChangesAsync(); if (ShouldDownloadEventImageLocally()) { await _downloadEventImageMessageSender.Execute(cfpToAddId, submittedCfp.EventImageUrl); } // Post to Twitter account try { await PostNewCfpTweet(cfpToAdd); } catch { // Intentionally left blank, we can probably do something // more useful, but for now if Twitter fails ¯\_(ツ)_/¯ } // Send back ID to do whatever at the client-side return(Json(cfpToAddId)); } // Add invalid model return(BadRequest(submittedCfp)); }
public void AddCfp(Cfp cfpToAdd) { _cfpContext.Add(cfpToAdd); }
public async Task AddCfpAsync(Cfp cfpToAdd) { _cfpContext.Add(cfpToAdd); await _cfpContext.SaveChangesAsync(); }