public List<Objects.Notification> TestForNotifications(List<Objects.Option> options) { var notifications = new List<Objects.Notification>(options.Count); if (options.Count(x => x.Active) > 0) { if (appClient == null) { var appAccessTokenLong = System.Configuration.ConfigurationManager.AppSettings.Get("fbAppIdLong"); var appAccessToken = System.Configuration.ConfigurationManager.AppSettings.Get("fbAppId"); appClient = new FacebookClient(appAccessTokenLong); dynamic userResult = appClient.Post(string.Format("{0}/accounts/test-users", appAccessToken), new { installed = true, name = "Fritz Test", permissions = "manage_notifications" }); userClient = new FacebookClient((string)(userResult["access_token"])); userId = userResult["id"]; } try { DateTime currentDate = DateTime.Now; foreach (Objects.Option option in options.Where(x => x.Active)) { switch ((FacebookOptionId)option.OptionId) { case FacebookOptionId.NewNotification: DateTime ePoch = new DateTime(1970, 1, 1, 0, 0, 0); //var unixTimestampLastAccessed = System.Convert.ToInt64((option.LastAccessed - ePoch).TotalSeconds); var unixTimestampLastAccessed = System.Convert.ToInt64((DateTime.Now.AddDays(-10) - ePoch).TotalSeconds); //dynamic result = userClient.Get("fql", new { q = "SELECT author_id, body, source FROM message" }); dynamic result = userClient.Get("fql", new { q = "SELECT title_text, updated_time FROM notification WHERE recipient_id = " + userId }); if (result["data"].Count > 0) { if (result["data"]["updated_time"] > unixTimestampLastAccessed.ToString()) { var newMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, "New Facebook notification.", result["data"]["title_text"], currentDate); option.LastAccessed = currentDate; notifications.Add(newMessageNotification); } } break; } } } catch (System.Net.WebException wex) { Console.WriteLine("Facebook did not recognize the credentials. Response from Facebook: " + wex.Message); } } return notifications; }
public List<Objects.Notification> TestForNotifications(List<Objects.Option> options) { var notifications = new List<Objects.Notification>(options.Count); //if (options.Count(x => x.Active) > 0) { var auth = new LinqToTwitter.SingleUserAuthorizer { Credentials = new LinqToTwitter.SingleUserInMemoryCredentials { ConsumerKey = System.Configuration.ConfigurationManager.AppSettings.Get("consumerKey"), ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings.Get("consumerSecret"), //AccessToken = "accessToken", //AccessTokenSecret = "accessTokenSecret" TwitterAccessToken = System.Configuration.ConfigurationManager.AppSettings.Get("accessToken"), TwitterAccessTokenSecret = System.Configuration.ConfigurationManager.AppSettings.Get("accessTokenSecret") } }; auth.Authorize(); using (var ctx = new LinqToTwitter.TwitterContext(auth)) { //try //{ // //Account account = accounts.SingleOrDefault(); // Account account = ctx.Account.Single(acct => acct.Type == AccountType.VerifyCredentials && acct.SkipStatus == true); // //var account = twitterCtx.Account // // .Where(t => t.Type == AccountType.VerifyCredentials) // // .FirstOrDefault(t => t.SkipStatus == true); // User user = account.User; // Status tweet = user.Status ?? new Status(); // Console.WriteLine("User (#" + user.Identifier.ID // + "): " + user.Identifier.ScreenName // + "\nTweet: " + tweet.Text // + "\nTweet ID: " + tweet.StatusID + "\n"); // Console.WriteLine("Account credentials are verified."); //} //catch (System.Net.WebException wex) //{ // Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message); //} var testMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, "Test sender" + " sent message " + "message 1", "New message from " + "Test sender", DateTime.Now); var testSimpleMessage = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, "simple notification", null, DateTime.Now); notifications.Add(testMessageNotification); notifications.Add(testSimpleMessage); return notifications; try { DateTime currentDate = DateTime.Now; foreach (Objects.Option option in options.Where(x => x.Active)) { switch ((TwitterOptionId)option.OptionId) { case TwitterOptionId.TweetCount: // if enough time has passed since we last accessed this if ((currentDate - option.LastAccessed).TotalMinutes > option.Numerics[0]) { int tweetCount = (from tweet in ctx.Status where tweet.Type == StatusType.Home && tweet.CreatedAt > option.LastAccessed select tweet).Count(); var newTweetCountNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, tweetCount.ToString() + " new tweets.", tweetCount.ToString() + " new tweets.", currentDate); option.LastAccessed = currentDate; notifications.Add(newTweetCountNotification); } break; case TwitterOptionId.DirectMessage: var directMsgs = (from dm in ctx.DirectMessage where dm.Type == DirectMessageType.SentTo && dm.CreatedAt > option.LastAccessed select dm).ToList(); foreach (var directMsg in directMsgs) { // handle appropriately var newDirectMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, 0, directMsg.Sender.Name + " sent message " + directMsg.Text, "New message from " + directMsg.Sender.Name, currentDate); notifications.Add(newDirectMessageNotification); option.LastAccessed = currentDate; } break; } } } catch (System.Net.WebException wex) { Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message); } } } return notifications; }
public List<Objects.Notification> TestForNotifications(List<Objects.Option> options) { var notifications = new List<Objects.Notification>(options.Count); if (options.Count(x => x.Active) > 0) { DateTime currentDate = DateTime.Now.ToUniversalTime(); foreach (Objects.Option option in options.Where(x => x.Active)) { switch ((PrototypeOptionId)option.OptionId) { case PrototypeOptionId.CountOption: // if enough time has passed since we last accessed this if ((currentDate - option.LastAccessed).TotalMinutes > option.Numerics[0]) { int count = sr.Next(51); if (count > 0) { var newTweetCountNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, count.ToString() + " special notifications.", count.ToString() + " special notifications.", currentDate); option.LastAccessed = currentDate; notifications.Add(newTweetCountNotification); } } break; case PrototypeOptionId.CheckedOnlyOption: int messageCount = sr.Next(3); // between 0 and 2 possible messages for (int i = 0; i < messageCount; i++) { string msg = string.Empty; switch (sr.Next(3)) { case 0: msg = "Message 1 occurred."; break; case 1: msg = "Message 2 occurred."; break; case 2: msg = "Message 3 occurred."; break; } var newDirectMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, msg, "Alert: " + msg, currentDate); notifications.Add(newDirectMessageNotification); option.LastAccessed = currentDate; } break; case PrototypeOptionId.GestureOption: if (sr.Next(5) < 3) // 3 out of 4 will make notification { string emotion = "(neutral)"; Plugins.Gesture gesture = Plugins.Gesture.Neutral; switch (sr.Next(4)) { case 1: emotion = "Happy"; gesture = Plugins.Gesture.Happy; break; case 2: emotion = "Awkward"; gesture = Plugins.Gesture.Awkward; break; case 3: emotion = "Surprised"; gesture = Plugins.Gesture.Surprised; break; } FritzNotifier.Objects.Notification newMessageNotification = null; newMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, (int) gesture, emotion + " gesture received", null, currentDate); option.LastAccessed = currentDate; notifications.Add(newMessageNotification); } break; } } } return notifications; }
public List<Objects.Notification> TestForNotifications(List<Objects.Option> options) { var notifications = new List<Objects.Notification>(options.Count); if (options.Count(x => x.Active) > 0) { if (appClient == null) { var appAccessTokenLong = System.Configuration.ConfigurationManager.AppSettings.Get("fbAppIdLong"); var appAccessToken = System.Configuration.ConfigurationManager.AppSettings.Get("fbAppId"); appClient = new FacebookClient(appAccessTokenLong); dynamic userResult = appClient.Post(string.Format("{0}/accounts/test-users", appAccessToken), new { installed = true, name = "Fritz Test", permissions = "manage_notifications" }); userClient = new FacebookClient((string)(userResult["access_token"])); userId = userResult["id"]; } try { DateTime currentDateLocal = DateTime.Now; DateTime currentDate = currentDateLocal.ToUniversalTime(); //DateTime currentDate = DateTime.Now.ToUniversalTime(); foreach (Objects.Option option in options.Where(x => x.Active)) { switch ((FacebookOptionId)option.OptionId) { case FacebookOptionId.NewNotification: DateTime ePoch = new DateTime(1970, 1, 1, 0, 0, 0); // Unix timestamp is seconds past epoch var unixTimestampLastAccessed = DateTimeConvertor.ToUnixTime(option.LastAccessed); //dynamic result = userClient.Get("fql", new { q = "SELECT author_id, body, source FROM message" }); dynamic result = userClient.Get("fql", new { q = "SELECT title_text, updated_time FROM notification WHERE recipient_id = " + userId }); if (result["data"].Count > 0) { int index = 0; foreach (dynamic data in result["data"]) { if (data["updated_time"] > unixTimestampLastAccessed) { var newMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, (int)option.Gestures[0], "New Facebook notification: " + data["title_text"], null, currentDateLocal); option.LastAccessed = currentDate; Console.WriteLine("Setting last {0}", option.LastAccessed); notifications.Add(newMessageNotification); } index++; } } break; } } } catch (System.Net.WebException wex) { Console.WriteLine("Facebook did not recognize the credentials. Response from Facebook: " + wex.Message); } } return notifications; }