void tobbaseobject_NewStatus(TOBBaseObject from, TOBEventArgs args) { //TOB.Logger.TOBLogger.WriteInfo("NewStatus - " + args.EntityList.Count); //Update internal Collection (Might not be needed at all) foreach (TOBEntityBase item in args.EntityList) { if (args.TweetEnum == TOBEntityEnum.Status) { _statusCollection.Insert(0, item); } else if (args.TweetEnum == TOBEntityEnum.DirectMessages) { _directMessagesCollection.Insert(0, item); } } //Flush out old objects in _statusCollection if (_statusCollection.Count > (int)(MAX_COLLECTION_OBJECTS * 1.1)) { while (_statusCollection.Count > MAX_COLLECTION_OBJECTS) { _statusCollection.RemoveAt(_statusCollection.Count - 1); } } //Flush out old objects in _directMessageCollection if (_directMessagesCollection.Count > (int)(MAX_COLLECTION_OBJECTS * 1.1)) { while (_directMessagesCollection.Count > MAX_COLLECTION_OBJECTS) { _directMessagesCollection.RemoveAt(_directMessagesCollection.Count - 1); } } if (_panelViewDict.Values.Count == 0) { TOB.Logger.TOBLogger.WriteDebugInfo("ERROR - PanelViewDict Values are 0 ... Potential dataloss can occur"); } foreach (KeyValuePair<string,UserAllTweets> catchedPanelPair in _panelViewDict) { // cachedPanel.AddList(args.EntityList,_currentPanel.AccountList); UserAllTweets cachedPanel = catchedPanelPair.Value; if (catchedPanelPair.Key == _currentPanel.PanelName.ToString()) { cachedPanel.AddList(args.EntityList, _currentPanel.AccountList); } else { cachedPanel.AddList(args.EntityList, null); } } }
protected void OnNewStatus(TOBBaseObject current,TOBEventArgs e) { if (NewStatus != null) { NewStatus(current,e); } }
private void DownloadHomeTimeline(bool isFirstRun) { if (isFirstRun) { //Sleep while client loads Thread.Sleep(3000); } //Retrieve the last known max id in the local DB. Status maxObj = LocalStatusBO.GetListBySorting((t => t.AccountId == Acc.Id), (t => t.TwitterStatusId), System.Data.SqlClient.SortOrder.Descending).FirstOrDefault(); TwitterService request = AuthenticateUser(Acc); IEnumerable<TwitterStatus> ftColl = null; if (maxObj != null) { ftColl = request.ListTweetsOnHomeTimelineSince((long)maxObj.TwitterStatusId, 200); } else { ftColl = request.ListTweetsOnHomeTimeline(150); } //Stress test //TwitterResult responce = new TwitterResult(); //System.IO.TextReader tr = new System.IO.StreamReader("Twitter.txt"); //responce.Response = tr.ReadToEnd(); //var ftColl = responce.AsStatuses(); if (ftColl == null) { Logger.TOBLogger.WriteDebugInfo(request.Response.RequestUri.ToString()); MessageNotifier.Instance.NotifyMessage("Error communicating with Twitter Servers"); return; } if (ftColl.Count() == 0) { return; } //TOB.Logger.TOBLogger.WriteInfo("FriendsTimeline objects recieved - " + ftColl.Count()); List<TOBEntityBase> notifyStatusList = new List<TOBEntityBase>(); //Keep default threshold = 5. Means dont accumulate thweets for more than 5 and notify UI for this. int THRESHOLD = 5; if (ftColl.Count() > THRESHOLD * THRESHOLD) { THRESHOLD = ftColl.Count() / THRESHOLD; } else { THRESHOLD = ftColl.Count() + 1; } foreach (TwitterStatus tsTS in ftColl) { Status tobStatus = GetTOBStatusFromTSStatus(tsTS); if (tobStatus == null) continue; LocalStatusBO.Insert(tobStatus); //Add to notifyable list notifyStatusList.Add(tobStatus); //The HACK is that we dont wait for all the tweets to throw onto UI. We will make //count tweets existence if equal to 5 or more than 5. if (notifyStatusList.Count >= THRESHOLD) { //Throw Event notifying appropriate UI's new statuses are available TOBEventArgs eventargs = new TOBEventArgs(); eventargs.EntityList = notifyStatusList.ToList(); eventargs.TOBAccount = Acc; eventargs.TweetEnum = TOBEntityEnum.Status; LocalStatusBO.SaveChanges(); if (!isFirstRun) { TOB.Logger.TOBLogger.WriteInfo("Sending NewStatus notficiation - " + eventargs.EntityList.Count); OnNewStatus(this, eventargs); notifyStatusList.Clear(); //if (isFirstRun) //{ // Thread.Sleep((THRESHOLD * 1000) / 3); //} } } } //Send remaining tweets for the count less than 5 as USUAL. //Throw Event notifying appropriate UI's new statuses are available for the remaing tweets for count less than 5 if (notifyStatusList.Count > 0) { TOBEventArgs eventargs = new TOBEventArgs(); eventargs.EntityList = notifyStatusList; eventargs.TOBAccount = Acc; eventargs.TweetEnum = TOBEntityEnum.Status; LocalStatusBO.SaveChanges(); OnNewStatus(this, eventargs); } }
private void DownloadSentDirectMessages() { List<TOBEntityBase> notifyStatusList = new List<TOBEntityBase>(); //Retrive the last known max id of DirectMessage in the local DB. DirectMessageBO directMessageBo = LocalDirectMessageBO; DirectMessage maxObj = directMessageBo.GetListBySorting((t => t.AccountId == Acc.Id && t.Recieved == false ), (t => t.TwitterId), System.Data.SqlClient.SortOrder.Descending).FirstOrDefault(); //Get all the sent direct messages TwitterService request = AuthenticateUser(Acc); IEnumerable<TwitterDirectMessage> ftCol1 = null; if (maxObj != null && maxObj.Id != 0) { ftCol1 = request.ListDirectMessagesSentSince(maxObj.TwitterId.Value); } else { ftCol1 = request.ListDirectMessagesSent(); } if (ftCol1 == null) { Logger.TOBLogger.WriteDebugInfo(request.Response.RequestUri.ToString()); return; } if (ftCol1.Count() == 0) { return; } foreach (TwitterDirectMessage dm in ftCol1) { DirectMessage tobStatus = GetTOBDMFromTSDM(dm); tobStatus.Recieved = false; directMessageBo.Insert(tobStatus); //Add to notifyable list notifyStatusList.Add(tobStatus); } //Throw Event notifying appropriate UI's new statuses are available if (notifyStatusList.Count > 0) { TOBEventArgs eventargs = new TOBEventArgs(); eventargs.EntityList = notifyStatusList; eventargs.TweetEnum = TOBEntityEnum.DirectMessages; eventargs.TOBAccount = Acc; OnNewStatus(this, eventargs); } directMessageBo.SaveChanges(); }
public void tob_NewStatus(TOBBaseObject from, TOBEventArgs args) { Action action = delegate() { var balloon = new NotifyBaloon(); balloon.GetNotifications(args.EntityList); ShowCustomBalloon(balloon, PopupAnimation.Scroll, 40000); }; Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, action); }