private List<SessionsResult> SessionsToTweetBeforeBigEvent(out StringBuilder sbText) { var codeCampYearResult = CodeCampYearManager.I.Get(new CodeCampYearQuery {Id = Utils.CurrentCodeCampYear}).FirstOrDefault(); if (codeCampYearResult != null) { DateTime startTweetsAfter = codeCampYearResult. CampStartDate.Subtract(new TimeSpan(12, 0, 0, 0)); if (startTweetsAfter.CompareTo(DateTime.Now) > 0) { sbText = new StringBuilder("No Tweeting because too soon for SessionsToTweetBeforeBigEvent()"); return new List<SessionsResult>(); } } else { sbText = new StringBuilder("No Tweeting because no code camp year found"); return new List<SessionsResult>(); } // if got here, then we should start tweeting all sessions again var sessionsToTweet = SessionsManager.I.Get(new SessionsQuery { TweetLineTweetedPreCamp = false, WithSchedule = true, WithSpeakers = true, CodeCampYearId = Utils.CurrentCodeCampYear // Id = 953 // test for just scottgu and email comes to me }).Where(a => !a.SessionTime.Equals("Agenda Not Set Yet")). OrderBy(a => a.SessionTimesResult.StartTime.HasValue ? a.SessionTimesResult.StartTime.Value : DateTime.Now).Take(_tweetsToProcessAtOnce). ToList(); sbText = new StringBuilder(); foreach (var session in sessionsToTweet) { DateTime sessionTime; string sessionTimeFriendly; string speakerNames; string speakerHandles; string hashTags; Utils.GetSessionHandlesHashTagsTime(session, out speakerNames, out speakerHandles,out hashTags, out sessionTime, out sessionTimeFriendly); string sessionTitle = Utils.ClearSpecialCharacters(session.Title); string sessionUrl = String.Format("http://siliconvalley-codecamp.com/Sessions.aspx?sessionid={0}", session.Id); string sessionUrlShort = API.Bit(_bitLyApiUsername, _bitLyApiKey, HttpContext.Current.Server.HtmlEncode(sessionUrl), "Shorten"); // "at 9:45AM 10/6 Speaker Douglas Crockford @dougc Title: Gonads and Ponads #svcc #json http://dkfjdkf string template = "{0} {1} {2} \"{{0}}\" #svcc {3} {4} ReTweet!"; string tweetFirstPart = String.Format(template, sessionTimeFriendly, speakerNames, speakerHandles, hashTags, sessionUrlShort).Trim(); int spaceLeftForTitle = 130 - tweetFirstPart.Length; int titleLen = Math.Min(sessionTitle.Length, spaceLeftForTitle); string tweet = String.Format(tweetFirstPart, sessionTitle.Substring(0, titleLen)).Trim(); // finally, do the tweet string credentialString = _twitterCredential; var credentials = new SessionStateCredentials(); credentials.Load(credentialString); var auth = new WebAuthorizer { Credentials = credentials }; var twitterCtx = new TwitterContext(auth); const decimal lattitude = (decimal)37.362056; const decimal longitude = (decimal)122.131056; if (!testMode) { Status tweetInfo = twitterCtx.UpdateStatus(tweet, lattitude, longitude); Label1.Text = tweetInfo.Text; // not sure if this helps } sbText.AppendLine(tweet); // update session.TweetLinePreCamp = tweet; session.TweetLineTweetedDatePreCamp = DateTime.Now; session.TweetLineTweetedPreCamp = true; if (!testMode) { SessionsManager.I.Update(session); } // finally, send the emails. foreach (var rec in session.SpeakersList) { SendEmailToSpeakerJustBeforeEvent(rec.UserFirstName, rec.UserLastName, rec.Email, session.Title, tweet); } } return sessionsToTweet; }
private List<SessionsResult> SessionsToTweetAfterSignup(out StringBuilder sbText) { //DateTime compareDateTime = DateTime.Now.Subtract(new TimeSpan(0, 1, 0, 0)); // do a max of 2 at a time. these go every 30 minutes var sessionsToTweet = SessionsManager.I.Get(new SessionsQuery { TweetLineTweeted = false, WithSpeakers = true, WithSchedule = true, CodeCampYearId = Utils.CurrentCodeCampYear }).Where( a => a.Createdate != null && a.Createdate.Value.CompareTo( DateTime.Now.Subtract(new TimeSpan(0, 48, 0, 0))) < 0). OrderByDescending(a => a.Id).Take(_tweetsToProcessAtOnce).ToList(); sbText = new StringBuilder(); foreach (var session in sessionsToTweet) { var speakers = Utils.GetSpeakersBySessionId(session.Id); var sb = new StringBuilder(); foreach (var speaker in speakers) { string speakerName = string.Format("{0} {1},", speaker.UserFirstName, speaker.UserLastName); sb.Append(speakerName); } string speakerList = sb.ToString(); if (speakerList.Length > 0 && speakerList.EndsWith(",")) { speakerList = speakerList.Substring(0, speakerList.Length - 1); } string sessionUrl = String.Format("http://siliconvalley-codecamp.com/Sessions.aspx?sessionid={0}", session.Id); string sessionUrlShort = API.Bit(_bitLyApiUsername, _bitLyApiKey, HttpContext.Current.Server.HtmlEncode(sessionUrl), "Shorten"); string template = "NEW SESSION: {0} Speaker: {1} #svcc Title: \"{2}\""; if (speakerList.Length > 0 && speakers.Count > 1) { template = "NEW SESSION: {0} Speakers: {1} #svcc Title: \"{2}\""; } string tweet = String.Format(template, sessionUrlShort, speakerList, session.Title); if (tweet.Length > 139) { tweet = tweet.Substring(0, 136) + "..."; } // finally, do the tweet string credentialString = _twitterCredential; var credentials = new SessionStateCredentials(); credentials.Load(credentialString); var auth = new WebAuthorizer { Credentials = credentials }; var twitterCtx = new TwitterContext(auth); const decimal lattitude = (decimal) 37.362056; const decimal longitude = (decimal) 122.131056; if (!testMode) { Status tweetInfo = twitterCtx.UpdateStatus(tweet, lattitude, longitude); Label1.Text = tweetInfo.Text; // not sure if this helps } sbText.AppendLine(tweet); // update session.TweetLine = tweet; session.TweetLineTweetedDate = DateTime.Now; session.TweetLineTweeted = true; if (!testMode) { SessionsManager.I.Update(session); } // finally, send the emails. foreach (var rec in speakers) { SendEmailToSpeaker(rec.UserFirstName, rec.UserLastName, rec.Email, session.Title, tweet); } } return sessionsToTweet; }