protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { if (this.NavigationContext.QueryString.ContainsKey("tag")) { switch (this.NavigationContext.QueryString["tag"]) { case "latest": this.Type = TweetType.Latest; this.tweetTitle.Text = "最新动弹"; break; case "hottest": this.Type = TweetType.Hottest; this.tweetTitle.Text = "热门动弹"; break; case "my": this.Type = TweetType.My; this.tweetTitle.Text = "我的动弹"; break; } //注意这会导致动弹列表控件强制刷新 this.tweetListControl.tweetType = this.Type; } base.OnNavigatedTo(e); }
private NotificationType PreferencesForType(TweetType type, UserToken user) { if (type == TweetType.Mention) { return(user.Preferences.MentionsPreferences); } else { return(user.Preferences.MessagesPreferences); } }
void AddTweet(int tweetId, TweetType type, int senderId, string message, int imageId, List <int> commentIds, int likes, int retweets) { if (tweetId == -1) { tweetId = message.GetHashCode(); } var tweet = new Tweet(tweetId, type, senderId, message, imageId, new List <int>(commentIds)) { LikesCount = likes, RetweetsCount = retweets }; _allTweets.Add(tweet); }
public void RandomizeTweet(TweetType type) { if (type == TweetType.MEDIA) { int randomTweet = (int)(Random.value * trumpTweets.Length); currentTweet = trumpTweets[randomTweet]; } if (type == TweetType.EVENT) { int randomTweet = Random.Range(0, eventTweets.Count); currentTweet = eventTweets[randomTweet]; } if (type == TweetType.POLICY) { int randomTweet = Random.Range(0, policyTweets.Count); currentTweet = policyTweets[randomTweet]; } }
public static TweetType checkTweetType(string json) { TweetType type = TweetType.Init; if (Json.Deserialize <Tweet>(json).Text != null) { type = TweetType.Normal; } else if (Json.Deserialize <MessageWrapper>(json).Message != null) { type = TweetType.Message; } else if (Json.Deserialize <DeleteWrapper>(json).Delete != null) { type = TweetType.Delete; } return(type); }
private void ReceiveTweetObjects(TweetType type, UserToken user, TwitterObjectCollection statuses, RestResponse response) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); WriteMemUsage("Received " + type.ToString()); if (statuses == null || response.StatusCode != System.Net.HttpStatusCode.OK) { WriteMemUsage(type.ToString() + ": exit with error " + response.StatusDescription); return; } var CheckDate = DateSync.GetLastCheckDate(); var ToastDate = DateSync.GetLastToastNotificationDate(); if (CheckDate > ToastDate) { ToastDate = CheckDate; } var newStatuses = statuses.Where(item => TwitterObjectIsOlderThan(item, CheckDate)); var newToastStatuses = statuses.Where(item => TwitterObjectIsOlderThan(item, ToastDate)); var tileStatuses = newStatuses.Select(item => TwitterObjectToNotification(type, user.ScreenName, item)); var toastStatuses = newToastStatuses.Select(item => TwitterObjectToNotification(type, user.ScreenName, item)); var notPrefs = PreferencesForType(type, user); if (notPrefs == NotificationType.Tile || notPrefs == NotificationType.TileAndToast) { lock (notsSync) tileNotifications.AddRange(tileStatuses); } if (notPrefs == NotificationType.Toast || notPrefs == NotificationType.TileAndToast) { lock (notsSync) toastNotifications.AddRange(toastStatuses); } }
private TileNotification TwitterObjectToNotification(TweetType type, string name, TwitterObject item) { var not = new TileNotification(); string userstring = ""; string from = "no_name"; if (item.TryGetProperty("user", out userstring)) { new TwitterObject(userstring).TryGetProperty("screen_name", out from); } else { item.TryGetProperty("sender_screen_name", out from); } not.From = from; not.Type = type; not.To = name; not.Message = item.GetProperty("text"); return(not); }
protected override void OnNavigatedTo(System. Windows. Navigation. NavigationEventArgs e) { if ( this.NavigationContext.QueryString.ContainsKey("tag") ) { switch ( this.NavigationContext.QueryString["tag"] ) { case "latest": this. Type = TweetType. Latest; this. tweetTitle. Text = "最新动弹"; break; case "hottest": this. Type = TweetType. Hottest; this. tweetTitle. Text = "热门动弹"; break; case "my": this. Type = TweetType. My; this. tweetTitle. Text = "我的动弹"; break; } //注意这会导致动弹列表控件强制刷新 this. tweetListControl. tweetType = this. Type; } base. OnNavigatedTo( e ); }
public TweetInfo(TweetType type, string tweet, string username) { Update(type, tweet, username); }
public TweetType Update(TweetType type, string tweet, string username) { if (string.IsNullOrEmpty(tweet)) { CharsLeft = MaxCharCount; Username = null; return Type = TweetType.Normal; } Match match; if ((match = DirectMessageRegex.Match(tweet)).Success) { CharsLeft = MaxCharCount - tweet.Length + match.Length; Username = '******' + match.Groups[1].Value; return Type = TweetType.DirectMessage; } else { CharsLeft = MaxCharCount - tweet.Length; if ((match = MentionRegex.Match(tweet)).Success) { Username = match.Groups[1].Value; return Type = type == TweetType.Normal ? TweetType.Mention : type; } switch (type) { case TweetType.Reply: case TweetType.Retweet: case TweetType.RT: Username = username; return Type = type; default: Username = null; return Type = TweetType.Normal; } } }
public MakeTweetEventArgs(TwitterMessage message, TweetType type) { Message = message; TweetType = type; }
private TileNotification TwitterObjectToNotification(TweetType type, string name, TwitterObject item) { var not = new TileNotification(); string userstring = ""; string from = "no_name"; if (item.TryGetProperty("user", out userstring)) new TwitterObject(userstring).TryGetProperty("screen_name", out from); else item.TryGetProperty("sender_screen_name", out from); not.From = from; not.Type = type; not.To = name; not.Message = item.GetProperty("text"); return not; }
private void ReceiveTweetObjects(TweetType type, UserToken user, TwitterObjectCollection statuses, RestResponse response) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); WriteMemUsage("Received " + type.ToString()); if (statuses == null || response.StatusCode != System.Net.HttpStatusCode.OK) { WriteMemUsage(type.ToString() + ": exit with error " + response.StatusDescription); return; } var CheckDate = DateSync.GetLastCheckDate(); var ToastDate = DateSync.GetLastToastNotificationDate(); if (CheckDate > ToastDate) ToastDate = CheckDate; var newStatuses = statuses.Where(item => TwitterObjectIsOlderThan(item, CheckDate)); var newToastStatuses = statuses.Where(item => TwitterObjectIsOlderThan(item, ToastDate)); var tileStatuses = newStatuses.Select(item => TwitterObjectToNotification(type, user.ScreenName, item)); var toastStatuses = newToastStatuses.Select(item => TwitterObjectToNotification(type, user.ScreenName, item)); var notPrefs = PreferencesForType(type, user); if (notPrefs == NotificationType.Tile || notPrefs == NotificationType.TileAndToast) lock (notsSync) tileNotifications.AddRange(tileStatuses); if (notPrefs == NotificationType.Toast || notPrefs == NotificationType.TileAndToast) lock (notsSync) toastNotifications.AddRange(toastStatuses); }
private NotificationType PreferencesForType(TweetType type, UserToken user) { if (type == TweetType.Mention) return user.Preferences.MentionsPreferences; else return user.Preferences.MessagesPreferences; }
void LoadTweetsForType(TweetType tweetType) { var path = TweetsContainerPathPrefix + tweetType; var tweetsContainer = Resources.Load <TextAsset>(path); if (!tweetsContainer) { Debug.LogErrorFormat("TweetsController: can't load TweetsContainer on path '{0}'", path); return; } var composedTweetMessage = new StringBuilder(); var tweetId = -1; var tweetSenderId = -1; var tweetImageId = -1; var tweetLikes = Random.Range(10, 1000); var tweetRetweets = Random.Range(2, 100); var tweetCommentIds = new List <int>(); using (var sr = new StringReader(tweetsContainer.text)) { while (true) { var line = sr.ReadLine(); if (line == null) { if (composedTweetMessage.Length > 0) { var message = composedTweetMessage.ToString(); AddTweet(tweetId, tweetType, tweetSenderId, message, tweetImageId, tweetCommentIds, tweetLikes, tweetRetweets); } break; } if (line == Separator) { if (composedTweetMessage.Length > 0) { var message = composedTweetMessage.ToString(); AddTweet(tweetId, tweetType, tweetSenderId, message, tweetImageId, tweetCommentIds, tweetLikes, tweetRetweets); composedTweetMessage.Clear(); tweetId = -1; tweetSenderId = -1; tweetImageId = -1; tweetLikes = Random.Range(10, 1000); tweetRetweets = Random.Range(2, 100); tweetCommentIds.Clear(); } } else { if (tweetSenderId == -1) { if (!int.TryParse(line, out tweetSenderId)) { var split = line.Split('|'); if ((split.Length != 2) || !int.TryParse(split[0], out tweetSenderId) || !int.TryParse(split[1], out tweetImageId)) { Debug.LogErrorFormat("Can't parse first tweet line '{0}'", line); } } } else if (line.StartsWith(TweetIdPrefix)) { if (!int.TryParse(line.Substring(TweetIdPrefix.Length, line.Length - TweetIdPrefix.Length), out tweetId)) { Debug.LogErrorFormat("Can't parse tweet id from line '{0}'", line); } } else if (line.StartsWith(TweetCommentIdsPrefix)) { var split = line.Substring(TweetCommentIdsPrefix.Length, line.Length - TweetCommentIdsPrefix.Length).Split(','); foreach (var commentIdStr in split) { if (!int.TryParse(commentIdStr, out var commentId)) { Debug.LogErrorFormat("Can't parse comment ids from line '{0}'", line); break; } tweetCommentIds.Add(commentId); } } else if (line.StartsWith(TweetLikesPrefix)) { if (!int.TryParse( line.Substring(TweetLikesPrefix.Length, line.Length - TweetLikesPrefix.Length), out tweetLikes)) { Debug.LogErrorFormat("Can't parse tweet likes from line '{0}'", line); } } else if (line.StartsWith(TweetRetweetsPrefix)) { if (!int.TryParse( line.Substring(TweetRetweetsPrefix.Length, line.Length - TweetRetweetsPrefix.Length), out tweetRetweets)) { Debug.LogErrorFormat("Can't parse tweet retweets from line '{0}'", line); } } else { composedTweetMessage.AppendLine(line); } } } } }
//forecast, just do delta from yesterday to today private void doForecast() { //TweetType int[] deltas = new int[numEmotions]; int maxDelta=0; int tmpDelta = 0; int maxIndex=0; for(int i=0;i<numEmotions;i++){ tmpDelta = tweetTypePercentage[i, numDays - 1] - tweetTypePercentage[i, numDays - 2]; if (tmpDelta > maxDelta) { maxDelta = tmpDelta; maxIndex = i; } } //set forecast type forecast = (TweetType)(maxIndex); //set image string imageForecastString = "Images/" + forecast.ToString().ToLower() + "Face.png"; Uri uri = new Uri(imageForecastString, UriKind.Relative); StreamResourceInfo resourceInfo = Application.GetResourceStream(uri); BitmapImage bmp = new BitmapImage(); bmp.SetSource(resourceInfo.Stream); imageForecast.Source = bmp; }