Пример #1
0
            public TweetCollecterService(long userId)
            {
                UserId = userId;

                NoRetweetIds = new List <long>();
                MuteIds      = new List <long>();
                BlockIds     = new List <long>();

                ScreenNameObjects = new List <string>();
                HashTagObjects    = new List <string>();
                UserObjects       = new List <User>();

                _tweetDeleteDisposableObject = Observable
                                               .FromEvent <EventHandler <TweetDeleteEventArgs>, TweetDeleteEventArgs>(
                    h => (sender, e) => h(e),
                    h => Instance.TweetDeleteCommandExecute += h,
                    h => Instance.TweetDeleteCommandExecute -= h)
                                               .Where(x => x.UserId == UserId)
                                               .Subscribe(
                    e => { TweetDeleteCommandExecute?.Invoke(this, e); },
                    ex => Debug.WriteLine(ex.ToString() + "\nMessage:" + ex.Message),
                    () => Debug.WriteLine(
                        "Flantter.MilkyWay.Models.Services.Connecter.TweetCollecterService.OnCompleted"));


                _tweetReceiveDisposableObject = Observable.FromEvent <EventHandler <TweetEventArgs>, TweetEventArgs>(
                    h => (sender, e) => h(e),
                    h => Instance.TweetReceiveCommandExecute += h,
                    h => Instance.TweetReceiveCommandExecute -= h)
                                                .Where(x => x.UserId == UserId)
                                                .Subscribe(
                    e =>
                {
                    TweetReceiveCommandExecute?.Invoke(this, e);

                    if (SettingService.Setting.EnableDatabase)
                    {
                        switch (e.Type)
                        {
                        case TweetEventArgs.TypeEnum.Status:
                            Database.Database.Instance.InsertTweet(e.Status, e.Parameter, e.UserId);
                            break;

                        case TweetEventArgs.TypeEnum.DirectMessage:
                            Database.Database.Instance.InsertTweet(e.DirectMessage, e.Parameter, e.UserId);
                            break;

                        case TweetEventArgs.TypeEnum.EventMessage:
                            Database.Database.Instance.InsertTweet(e.EventMessage, e.Parameter, e.UserId);
                            break;

                        case TweetEventArgs.TypeEnum.CollectionEntry:
                            Database.Database.Instance.InsertTweet(e.CollectionEntry, e.Parameter,
                                                                   e.UserId);
                            break;
                        }
                    }

                    // Todo : 起動時の軽量化必須?

                    if (e.Type == TweetEventArgs.TypeEnum.Status)
                    {
                        lock (EntitiesObjectsLock)
                        {
                            if (!ScreenNameObjects.Contains(e.Status.User.ScreenName))
                            {
                                ScreenNameObjects.Add(e.Status.User.ScreenName);
                            }

                            if (UserObjects.All(x => x.ScreenName != e.Status.User.ScreenName))
                            {
                                UserObjects.Add(e.Status.User);
                            }

                            if (e.Status.Entities.UserMentions != null)
                            {
                                foreach (var screenName in e.Status.Entities.UserMentions)
                                {
                                    if (!ScreenNameObjects.Contains(screenName.ScreenName))
                                    {
                                        ScreenNameObjects.Add(screenName.ScreenName);
                                    }
                                }
                            }
                            if (e.Status.Entities.HashTags != null)
                            {
                                foreach (var hashTag in e.Status.Entities.HashTags)
                                {
                                    if (!HashTagObjects.Contains(hashTag.Tag))
                                    {
                                        HashTagObjects.Add(hashTag.Tag);
                                    }
                                }
                            }
                        }
                    }
                },
                    ex => Debug.WriteLine(ex.ToString() + "\nMessage:" + ex.Message),
                    () => Debug.WriteLine("TweetServiceProvider.TweetCollecterService.OnCompleted"));
            }
Пример #2
0
 public void TweetReceive_OnCommandExecute(object sender, TweetEventArgs e)
 {
     TweetReceiveCommandExecute?.Invoke(sender, e);
 }