private void PopulateEvents()
        {
            Cursor = Cursors.WaitCursor;
            var formattedEvents = FormattedEvent.ToFormattedEvents(dataSource.GetEvents(startDate.Value, endDate.Value, null /* country */));

            Cursor        = Cursors.Default;
            updatingUiNow = true;
            Array.Reverse(formattedEvents);
            events.DataSource = formattedEvents;
            if (events.Items.Count > 0)
            {
                events.SelectedIndex = 0;
            }
            PopulateCategories();
            PopulateRunners();
            updatingUiNow = false;
        }
Exemplo n.º 2
0
        private void PopulateEvents()
        {
            WebServices s = new WebServices();

            Cursor = Cursors.WaitCursor;
            FormattedEvent[] events = FormattedEvent.ToFormattedEvents(s.GetEvents(startDate.Value, endDate.Value));
            Cursor        = Cursors.Default;
            updatingUiNow = true;
            Array.Reverse(events);
            winSplitsEvents.DataSource = events;
            if (winSplitsEvents.Items.Count > 0)
            {
                winSplitsEvents.SelectedIndex = 0;
            }
            PopulateCategories();
            PopulateRunners();
            updatingUiNow = false;
        }
Exemplo n.º 3
0
        private void CreateEventFromJson(string content)
        {
            TwitterDataModel.EventData eventData = null;
            try
            {
                eventData = MyCommon.CreateDataFromJson<TwitterDataModel.EventData>(content);
            }
            catch(SerializationException ex)
            {
                MyCommon.TraceOut(ex, "Event Serialize Exception!" + Environment.NewLine + content);
            }
            catch(Exception ex)
            {
                MyCommon.TraceOut(ex, "Event Exception!" + Environment.NewLine + content);
            }

            var evt = new FormattedEvent();
            evt.CreatedAt = MyCommon.DateTimeParse(eventData.CreatedAt);
            evt.Event = eventData.Event;
            evt.Username = eventData.Source.ScreenName;
            evt.IsMe = evt.Username.ToLower().Equals(this.Username.ToLower());
            evt.Eventtype = EventNameToEventType(evt.Event);
            switch (eventData.Event)
            {
                case "access_revoked":
                    return;
                case "follow":
                    if (eventData.Target.ScreenName.ToLower().Equals(_uname))
                    {
                        if (!this.followerId.Contains(eventData.Source.Id)) this.followerId.Add(eventData.Source.Id);
                    }
                    else
                    {
                        return;    //Block後のUndoをすると、SourceとTargetが逆転したfollowイベントが帰ってくるため。
                    }
                    evt.Target = string.Empty;
                    break;
                case "favorite":
                case "unfavorite":
                    evt.Target = "@" + eventData.TargetObject.User.ScreenName + ":" + HttpUtility.HtmlDecode(eventData.TargetObject.Text);
                    evt.Id = eventData.TargetObject.Id;
                    if (AppendSettingDialog.Instance.IsRemoveSameEvent)
                    {
                        if (StoredEvent.Any(ev =>
                                           {
                                               return ev.Username == evt.Username && ev.Eventtype == evt.Eventtype && ev.Target == evt.Target;
                                           })) return;
                    }
                    if (TabInformations.GetInstance().ContainsKey(eventData.TargetObject.Id))
                    {
                        var post = TabInformations.GetInstance()[eventData.TargetObject.Id];
                        if (eventData.Event == "favorite")
                        {
                            if (evt.Username.ToLower().Equals(_uname))
                            {
                                post.IsFav = true;
                                TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
                            }
                            else
                            {
                                post.FavoritedCount++;
                                if (!TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites).Contains(post.StatusId))
                                {
                                    if (AppendSettingDialog.Instance.FavEventUnread && post.IsRead)
                                    {
                                        post.IsRead = false;
                                    }
                                    TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
                                }
                                else
                                {
                                    if (AppendSettingDialog.Instance.FavEventUnread)
                                    {
                                        TabInformations.GetInstance().SetRead(false, TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites).TabName, TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites).IndexOf(post.StatusId));
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (evt.Username.ToLower().Equals(_uname))
                            {
                                post.IsFav = false;
                            }
                            else
                            {
                                post.FavoritedCount--;
                                if (post.FavoritedCount < 0) post.FavoritedCount = 0;
                            }
                        }
                    }
                    break;
                case "list_member_added":
                case "list_member_removed":
                case "list_updated":
                    evt.Target = eventData.TargetObject.FullName;
                    break;
                case "block":
                    if (!TabInformations.GetInstance().BlockIds.Contains(eventData.Target.Id)) TabInformations.GetInstance().BlockIds.Add(eventData.Target.Id);
                    evt.Target = string.Empty;
                    break;
                case "unblock":
                    if (TabInformations.GetInstance().BlockIds.Contains(eventData.Target.Id)) TabInformations.GetInstance().BlockIds.Remove(eventData.Target.Id);
                    evt.Target = string.Empty;
                    break;
                case "user_update":
                    evt.Target = string.Empty;
                    break;
                case "list_created":
                    evt.Target = string.Empty;
                    break;
                default:
                    MyCommon.TraceOut("Unknown Event:" + evt.Event + Environment.NewLine + content);
                    break;
            }
            this.StoredEvent.Insert(0, evt);
            if (UserStreamEventReceived != null)
            {
                UserStreamEventReceived(evt);
            }
        }
Exemplo n.º 4
0
        private void CreateEventFromJson(string content)
        {
            TwitterStreamEvent eventData = null;
            try
            {
                eventData = TwitterStreamEvent.ParseJson(content);
            }
            catch(SerializationException ex)
            {
                MyCommon.TraceOut(ex, "Event Serialize Exception!" + Environment.NewLine + content);
            }
            catch(Exception ex)
            {
                MyCommon.TraceOut(ex, "Event Exception!" + Environment.NewLine + content);
            }

            var evt = new FormattedEvent();
            evt.CreatedAt = MyCommon.DateTimeParse(eventData.CreatedAt);
            evt.Event = eventData.Event;
            evt.Username = eventData.Source.ScreenName;
            evt.IsMe = evt.Username.ToLower().Equals(this.Username.ToLower());

            MyCommon.EVENTTYPE eventType;
            eventTable.TryGetValue(eventData.Event, out eventType);
            evt.Eventtype = eventType;

            TwitterStreamEvent<TwitterStatus> tweetEvent;

            switch (eventData.Event)
            {
                case "access_revoked":
                case "access_unrevoked":
                case "user_delete":
                case "user_suspend":
                    return;
                case "follow":
                    if (eventData.Target.ScreenName.ToLower().Equals(_uname))
                    {
                        if (!this.followerId.Contains(eventData.Source.Id)) this.followerId.Add(eventData.Source.Id);
                    }
                    else
                    {
                        return;    //Block後のUndoをすると、SourceとTargetが逆転したfollowイベントが帰ってくるため。
                    }
                    evt.Target = "";
                    break;
                case "unfollow":
                    evt.Target = "@" + eventData.Target.ScreenName;
                    break;
                case "favorited_retweet":
                case "retweeted_retweet":
                    return;
                case "favorite":
                case "unfavorite":
                    tweetEvent = TwitterStreamEvent<TwitterStatus>.ParseJson(content);
                    evt.Target = "@" + tweetEvent.TargetObject.User.ScreenName + ":" + WebUtility.HtmlDecode(tweetEvent.TargetObject.Text);
                    evt.Id = tweetEvent.TargetObject.Id;

                    if (SettingCommon.Instance.IsRemoveSameEvent)
                    {
                        if (this.StoredEvent.Any(ev => ev.Username == evt.Username && ev.Eventtype == evt.Eventtype && ev.Target == evt.Target))
                            return;
                    }

                    var tabinfo = TabInformations.GetInstance();

                    PostClass post;
                    var statusId = tweetEvent.TargetObject.Id;
                    if (!tabinfo.Posts.TryGetValue(statusId, out post))
                        break;

                    if (eventData.Event == "favorite")
                    {
                        var favTab = tabinfo.GetTabByType(MyCommon.TabUsageType.Favorites);
                        if (!favTab.Contains(post.StatusId))
                            favTab.Add(post.StatusId, post.IsRead, false);

                        if (tweetEvent.Source.Id == this.UserId)
                        {
                            post.IsFav = true;
                        }
                        else if (tweetEvent.Target.Id == this.UserId)
                        {
                            post.FavoritedCount++;

                            if (SettingCommon.Instance.FavEventUnread)
                                tabinfo.SetReadAllTab(post.StatusId, read: false);
                        }
                    }
                    else // unfavorite
                    {
                        if (tweetEvent.Source.Id == this.UserId)
                        {
                            post.IsFav = false;
                        }
                        else if (tweetEvent.Target.Id == this.UserId)
                        {
                            post.FavoritedCount = Math.Max(0, post.FavoritedCount - 1);
                        }
                    }
                    break;
                case "quoted_tweet":
                    if (evt.IsMe) return;

                    tweetEvent = TwitterStreamEvent<TwitterStatus>.ParseJson(content);
                    evt.Target = "@" + tweetEvent.TargetObject.User.ScreenName + ":" + WebUtility.HtmlDecode(tweetEvent.TargetObject.Text);
                    evt.Id = tweetEvent.TargetObject.Id;

                    if (SettingCommon.Instance.IsRemoveSameEvent)
                    {
                        if (this.StoredEvent.Any(ev => ev.Username == evt.Username && ev.Eventtype == evt.Eventtype && ev.Target == evt.Target))
                            return;
                    }
                    break;
                case "list_member_added":
                case "list_member_removed":
                case "list_created":
                case "list_destroyed":
                case "list_updated":
                case "list_user_subscribed":
                case "list_user_unsubscribed":
                    var listEvent = TwitterStreamEvent<TwitterList>.ParseJson(content);
                    evt.Target = listEvent.TargetObject.FullName;
                    break;
                case "block":
                    if (!TabInformations.GetInstance().BlockIds.Contains(eventData.Target.Id)) TabInformations.GetInstance().BlockIds.Add(eventData.Target.Id);
                    evt.Target = "";
                    break;
                case "unblock":
                    if (TabInformations.GetInstance().BlockIds.Contains(eventData.Target.Id)) TabInformations.GetInstance().BlockIds.Remove(eventData.Target.Id);
                    evt.Target = "";
                    break;
                case "user_update":
                    evt.Target = "";
                    break;
                
                // Mute / Unmute
                case "mute":
                    evt.Target = "@" + eventData.Target.ScreenName;
                    if (!TabInformations.GetInstance().MuteUserIds.Contains(eventData.Target.Id))
                    {
                        TabInformations.GetInstance().MuteUserIds.Add(eventData.Target.Id);
                    }
                    break;
                case "unmute":
                    evt.Target = "@" + eventData.Target.ScreenName;
                    if (TabInformations.GetInstance().MuteUserIds.Contains(eventData.Target.Id))
                    {
                        TabInformations.GetInstance().MuteUserIds.Remove(eventData.Target.Id);
                    }
                    break;

                default:
                    MyCommon.TraceOut("Unknown Event:" + evt.Event + Environment.NewLine + content);
                    break;
            }
            this.StoredEvent.Insert(0, evt);

            if (this.UserStreamEventReceived != null)
                this.UserStreamEventReceived(this, new UserStreamEventReceivedEventArgs(evt));
        }
Exemplo n.º 5
0
        private void CreateEventFromJson(string content)
        {
            EventData eventData = null;
            try
            {
                eventData = D.CreateDataFromJson<EventData>(content);
            }
            catch (SerializationException ex)
            {
                MyCommon.TraceOut(ex, "Event Serialize Exception!" + Environment.NewLine + content);
            }
            catch (Exception ex)
            {
                MyCommon.TraceOut(ex, "Event Exception!" + Environment.NewLine + content);
            }

            var evt = new FormattedEvent
            {
                CreatedAt = MyCommon.DateTimeParse(eventData.CreatedAt),
                Event = eventData.Event,
                Username = eventData.Source.ScreenName,
                IsMe = eventData.Source.ScreenName.ToLower().Equals(Username.ToLower()),
                Eventtype = EventNameToEventType(eventData.Event)
            };
            switch (eventData.Event)
            {
                case "access_revoked":
                    return;

                case "follow":
                    if (eventData.Target.ScreenName.ToLower().Equals(_uname))
                    {
                        if (!_followerIds.Contains(eventData.Source.Id))
                        {
                            _followerIds.Add(eventData.Source.Id);
                        }
                    }
                    else
                    {
                        // Block後のUndoをすると、SourceとTargetが逆転したfollowイベントが帰ってくるため。
                        return;
                    }

                    evt.Target = string.Empty;
                    break;

                case "favorite":
                case "unfavorite":
                    evt.Target = "@" + eventData.TargetObject.User.ScreenName + ":" + HttpUtility.HtmlDecode(eventData.TargetObject.Text);
                    evt.Id = eventData.TargetObject.Id;
                    if (Configs.Instance.IsRemoveSameEvent)
                    {
                        if (StoredEvent.Any(ev => ev.Username == evt.Username && ev.Eventtype == evt.Eventtype && ev.Target == evt.Target))
                        {
                            return;
                        }
                    }

                    if (TabInformations.Instance.ContainsKey(eventData.TargetObject.Id))
                    {
                        PostClass post = TabInformations.Instance.Item(eventData.TargetObject.Id);
                        if (eventData.Event == "favorite")
                        {
                            TabClass favTab = TabInformations.Instance.GetTabByType(TabUsageType.Favorites);
                            if (evt.Username.ToLower().Equals(_uname))
                            {
                                post.IsFav = true;
                                favTab.Add(post.StatusId, post.IsRead, false);
                            }
                            else
                            {
                                post.FavoritedCount += 1;
                                if (!favTab.Contains(post.StatusId))
                                {
                                    if (Configs.Instance.FavEventUnread && post.IsRead)
                                    {
                                        post.IsRead = false;
                                    }

                                    favTab.Add(post.StatusId, post.IsRead, false);
                                }
                                else
                                {
                                    if (Configs.Instance.FavEventUnread)
                                    {
                                        TabInformations.Instance.SetRead(false, favTab.TabName, favTab.IndexOf(post.StatusId));
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (evt.Username.ToLower().Equals(_uname))
                            {
                                post.IsFav = false;
                            }
                            else
                            {
                                post.FavoritedCount -= 1;
                                if (post.FavoritedCount < 0)
                                {
                                    post.FavoritedCount = 0;
                                }
                            }
                        }
                    }

                    break;

                case "list_member_added":
                case "list_member_removed":
                case "list_updated":
                    evt.Target = eventData.TargetObject.FullName;
                    break;

                case "block":
                    if (!TabInformations.Instance.BlockIds.Contains(eventData.Target.Id))
                    {
                        TabInformations.Instance.BlockIds.Add(eventData.Target.Id);
                    }

                    evt.Target = string.Empty;
                    break;

                case "unblock":
                    if (TabInformations.Instance.BlockIds.Contains(eventData.Target.Id))
                    {
                        TabInformations.Instance.BlockIds.Remove(eventData.Target.Id);
                    }

                    evt.Target = string.Empty;
                    break;

                case "user_update":
                    evt.Target = string.Empty;
                    break;

                case "list_created":
                    evt.Target = string.Empty;
                    break;

                default:
                    MyCommon.TraceOut("Unknown Event:" + evt.Event + Environment.NewLine + content);
                    break;
            }

            StoredEvent.Insert(0, evt);
            if (UserStreamEventReceived != null)
            {
                UserStreamEventReceived(evt);
            }
        }