Example #1
0
        private static void RemoveTweetSink(AccountInfo info, long tweetId)
        {
            var tweet = ApiHelper.ExecApi(() => info.DestroyStatus(tweetId));

            if (tweet != null)
            {
                if (tweet.Id != tweetId)
                {
                    NotifyStorage.Notify("削除には成功しましたが、ツイートIDが一致しません。(" + tweetId.ToString() + " -> " + tweet.Id.ToString() + ")");
                }
                else
                {
                    if (tweet.InReplyToStatusId != 0)
                    {
                        var s = TweetStorage.Get(tweet.InReplyToStatusId);
                        if (s != null)
                        {
                            s.RemoveInReplyToThis(tweetId);
                        }
                    }
                    TweetStorage.Remove(tweetId);
                    NotifyStorage.Notify("削除しました:" + tweet.ToString());
                }
            }
            else
            {
                NotifyStorage.Notify("ツイートを削除できませんでした(@" + info.ScreenName + ")");
            }
        }
Example #2
0
        private void Loaded()
        {
            if (AccountStorage.Accounts.Count() == 0)
            {
                this.InputBlockViewModel.ShowConfig();
            }
            var n = NotifyStorage.NotifyManually("タブとカラムを読み込んでいます。しばらくお待ちください...");

            DispatcherHelper.BeginInvoke(() =>
            {
                try
                {
                    if (Setting.Instance.StateProperty.TabInformations != null)
                    {
                        Setting.Instance.StateProperty.TabInformations.ForEach(c =>
                        {
                            var column = this.ColumnOwnerViewModel.CreateColumn();
                            c.ForEach(p => column.AddTab(p));
                        });
                        this.ColumnOwnerViewModel.GCColumn();
                    }
                }
                finally
                {
                    n.Dispose();
                    Initializer.StandbyApp();
                }
            });
        }
Example #3
0
 public void RetweetThisTabAll()
 {
     Task.Factory.StartNew(() =>
     {
         IEnumerable <TabDependentTweetViewModel> tweets;
         using (NotifyStorage.NotifyManually("タイムラインの内容を取得しています..."))
         {
             tweets = this.CurrentForegroundTimeline.CoreViewModel.TweetsSource.ToArrayVolatile();
         }
         var msg = new ConfirmationMessage(
             "このタブに含まれるすべてのツイートをRetweetします。" + Environment.NewLine +
             "(対象ツイート: " + tweets.Count() + "件)" + Environment.NewLine +
             "よろしいですか?", "全てRetweet",
             System.Windows.MessageBoxImage.Warning,
             System.Windows.MessageBoxButton.OKCancel,
             "Confirm");
         this.Parent.Messenger.Raise(msg);
         if (msg.Response.GetValueOrDefault())
         {
             var lai = this.TabProperty.LinkAccountInfos.ToArray();
             tweets.OrderBy(t => t.Tweet.CreatedAt)
             .ForEach(t => PostOffice.Retweet(lai, t.Tweet));
         }
     });
 }
Example #4
0
 private void RefreshIndividualInfo()
 {
     Task.Factory.StartNew(() =>
     {
         using (var n = NotifyStorage.NotifyManually("アカウント情報を取得、更新しています..."))
         {
             AccountStorage.Accounts.ForEach(i => Communication.UserInformationManager.ReceiveInidividualInfo(i));
         }
     });
 }
Example #5
0
        private static void UnretweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはUnretweetできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Retweet オリジナルデータが見つかりません。");
                return;
            }

            bool success = true;

            Parallel.ForEach(infos,
                             d =>
            {
                // リツイート状態更新
                var ud = d.UserViewModel;
                if (ud != null)
                {
                    status.RegisterRetweeted(ud);
                }
                try
                {
                    unretweetInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    if (ud != null)
                    {
                        status.RemoveRetweeted(ud);
                    }
                    success = false;
                    NotifyStorage.Notify("Retweetキャンセルに失敗しました: @" + d.ScreenName);
                    if (!(ex is ApplicationException))
                    {
                        ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                  "Retweetキャンセル操作時にエラーが発生しました");
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Retweetをキャンセルしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Example #6
0
        private static void AddUnderControlled(AccountInfo info)
        {
            if (underControls.ContainsKey(info))
            {
                NotifyStorage.Notify("[規制管理: @" + info.ScreenName + " は規制されています。解除予想時刻: " + underControls[info].ToString("HH:mm:ss"));
                return;
            }

            var timestamp = DateTime.Now.Subtract(TwitterDefine.UnderControlTimespan);

            // APIを利用してツイートを遡り受信
            var notify = NotifyStorage.NotifyManually("[規制管理: @" + info.ScreenName + " の直近のツイートを受信しています...]");

            try
            {
                ApiHelper.ExecApi(() => info.GetUserTimeline(count: 150, includeRts: true))
                .Guard()
                .ForEach(i => TweetStorage.Register(i));

                notify.Message = "[規制管理:規制開始時刻を割り出しています...]";

                // 127tweet/3hours
                var originate = TweetStorage.GetAll(
                    t => t.Status.User.ScreenName == info.ScreenName && DateTime.Now.Subtract(t.CreatedAt) < TwitterDefine.UnderControlTimespan)
                                .OrderByDescending((t) => t.Status.CreatedAt)
                                .Skip(TwitterDefine.UnderControlCount - 1)
                                .FirstOrDefault();

                if (originate == null)
                {
                    originate = TweetStorage.GetAll(
                        t => t.Status.User.ScreenName == info.ScreenName && DateTime.Now.Subtract(t.CreatedAt) < TwitterDefine.UnderControlTimespan)
                                .OrderByDescending((t) => t.Status.CreatedAt)
                                .LastOrDefault();
                }

                if (originate == null)
                {
                    NotifyStorage.Notify("[規制管理: @" + info.ScreenName + " はPOST規制されていますが、解除時刻を予想できません。しばらく置いて試してみてください。]");
                }
                else
                {
                    var release = (originate.Status.CreatedAt + TwitterDefine.UnderControlTimespan);
                    NotifyStorage.Notify("[規制管理: @" + info.ScreenName +
                                         " はPOST規制されています。解除予想時刻は " + release.ToString("HH:mm:ss") + " です。]");
                    underControls.AddOrUpdate(info, release);
                    OnOnUnderControlChanged(new UnderControlEventArgs(info, true));
                }
            }
            finally
            {
                notify.Dispose();
            }
        }
Example #7
0
        private static void UpdateDirectMessageSink(AccountInfo info, string target, string body)
        {
            var status = info.SendDirectMessage(target, body);

            if (status == null || status.Id == 0)
            {
                throw new WebException("Timeout or failure sending tweet.", WebExceptionStatus.Timeout);
            }

            TweetStorage.Register(status);
            NotifyStorage.Notify("DMを送信しました: @" + info.ScreenName + " -> @" + target + ": " + body);
        }
Example #8
0
        private static void UpdateTweetSink(AccountInfo info, string text, long?inReplyToId = null)
        {
            var status = info.UpdateStatus(text, inReplyToId);

            if (status == null || status.Id == 0)
            {
                throw new WebException("Timeout or failure sending tweet.", WebExceptionStatus.Timeout);
            }

            TweetStorage.Register(status);
            NotifyStorage.Notify("ツイートしました:@" + info.ScreenName + ": " + text);
        }
Example #9
0
        public static void RemoveTweet(AccountInfo info, long tweetId)
        {
            var result = Task.Factory.StartNew(() =>
                                               removeInjection.Execute(new Tuple <AccountInfo, long>(info, tweetId)));
            var ex = result.Exception;

            if (ex != null)
            {
                NotifyStorage.Notify("ツイートを削除できませんでした(@" + info.ScreenName + ")");
                ExceptionStorage.Register(ex, ExceptionCategory.TwitterError, "ツイート削除時にエラーが発生しました");
            }
        }
Example #10
0
        private static void UnfavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Unfav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RemoveFavored(ud);
                }
                try
                {
                    unfavoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RegisterFavored(ud);
                    }
                    NotifyStorage.Notify("Unfavに失敗しました: @" + d.ScreenName);
                    if (!(ex is ApplicationException))
                    {
                        ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                  "Unfav操作時にエラーが発生しました");
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Unfavしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Example #11
0
 private void CopyClipboard(string text)
 {
     try
     {
         Clipboard.SetText(text);
         NotifyStorage.Notify("コピーしました: " + text);
     }
     catch (Exception ex)
     {
         ExceptionStorage.Register(ex, ExceptionCategory.InternalError,
                                   "コピーに失敗しました");
     }
 }
Example #12
0
 /// <summary>
 /// タイムラインの再構築を行います。
 /// </summary>
 public void InvalidateCache()
 {
     cacheInvalidator.Enqueue(() =>
     {
         var stopwatch = new System.Diagnostics.Stopwatch();
         stopwatch.Start();
         using (var n = NotifyStorage.NotifyManually(this.TabProperty.Name + " - タイムラインを構築しています..."))
         {
             this.StackingTimelines.ToArray().ForEach(f => f.InvalidateCache());
         }
         stopwatch.Stop();
         NotifyStorage.Notify(this.TabProperty.Name + " - タイムライン構築完了(" + stopwatch.ElapsedMilliseconds + "msec)");
     });
 }
Example #13
0
        public void R4S()
        {
            var cm = new ConfirmationMessage(
                "ユーザー @" + User.TwitterUser.ScreenName + " をスパム報告します。",
                "スパム報告", System.Windows.MessageBoxImage.Warning, System.Windows.MessageBoxButton.OKCancel,
                "Confirm");

            if (this.Messenger.GetResponse(cm).Response.GetValueOrDefault())
            {
                this.Messenger.Raise(new WindowActionMessage("WindowAction", WindowAction.Close));
                Task.Factory.StartNew(() =>
                {
                    AccountStorage.Accounts.ForEach(i => ReportForSpam(i, User.TwitterUser));
                    NotifyStorage.Notify("@" + User.TwitterUser.ScreenName + " をスパム報告しました。");
                });
            }
        }
Example #14
0
        public void Save()
        {
            Instance.KernelProperty.LastWriteVersion = Define.GetNumericVersion();
            var temp = Path.GetTempFileName();

            try
            {
                XMLSerializer.SaveXML <Setting>(temp, this);
                File.Delete(settingFilePath);
                File.Move(temp, settingFilePath);
                File.Delete(temp);
            }
            catch (Exception e)
            {
                NotifyStorage.Notify("設定保存ができません:" + e.Message);
            }
        }
Example #15
0
        private static void RemoveDMSink(AccountInfo info, long tweetId)
        {
            var tweet = ApiHelper.ExecApi(() => info.DestroyDirectMessage(tweetId));

            if (tweet != null)
            {
                if (tweet.Id != tweetId)
                {
                    NotifyStorage.Notify("削除には成功しましたが、ダイレクトメッセージIDが一致しません。(" + tweetId.ToString() + " -> " + tweet.Id.ToString() + ")");
                }
                else
                {
                    TweetStorage.Remove(tweetId);
                    NotifyStorage.Notify("削除しました:" + tweet.ToString());
                }
            }
            else
            {
                NotifyStorage.Notify("ダイレクトメッセージを削除できませんでした(@" + info.ScreenName + ")");
            }
        }
Example #16
0
 public void UnfavoriteThisTabAll()
 {
     Task.Factory.StartNew(() =>
     {
         IEnumerable <TabDependentTweetViewModel> tweets;
         using (NotifyStorage.NotifyManually("タイムラインの内容を取得しています..."))
         {
             tweets = this.CurrentForegroundTimeline.CoreViewModel.TweetsSource.ToArrayVolatile();
         }
         var msg = new ConfirmationMessage(
             "このタブに含まれるすべてのツイートをUnfavoriteします。" + Environment.NewLine +
             "(対象ツイート: " + tweets.Count() + "件)" + Environment.NewLine +
             "よろしいですか?", "全てUnfavorite",
             System.Windows.MessageBoxImage.Warning,
             System.Windows.MessageBoxButton.OKCancel,
             "Confirm");
         this.Parent.Messenger.Raise(msg);
         if (msg.Response.GetValueOrDefault())
         {
             tweets.ForEach(t => t.Unfavorite());
         }
     });
 }
Example #17
0
 public void Loaded()
 {
     KernelService.AddMenu("Import JSON", () =>
     {
         var dialog         = new OpenFileDialog();
         dialog.Filter      = "JSON Format|*.json|すべてのファイル|*.*";
         dialog.Multiselect = true;
         var result         = dialog.ShowDialog();
         if (result.HasValue && result.Value)
         {
             Task.Factory.StartNew(() =>
             {
                 dialog.FileNames.AsParallel().ForAll(file =>
                 {
                     var fileName = Path.GetFileName(file);
                     using (var notify = NotifyStorage.NotifyManually(fileName + " を読み込んでいます"))
                     {
                         try
                         {
                             using (var reader = JsonReaderWriterFactory.CreateJsonReader(new FileStream(file, FileMode.Open, FileAccess.Read), XmlDictionaryReaderQuotas.Max))
                             {
                                 XElement.Load(reader).Elements()
                                 .Select(TwitterStatus.FromNode)
                                 .ForEach(s => TweetStorage.Register(s));
                             }
                         }
                         catch (Exception ex)
                         {
                             ExceptionStorage.Register(ex, ExceptionCategory.UserError, fileName + " を読み込めませんでした");
                         }
                     }
                 });
             });
         }
     });
 }
Example #18
0
        public void Loaded()
        {
            Task.Factory.StartNew(() =>
            {
                NotifyStorage.Notify("YACQ スクリプトの読み込みを開始しました");
                try
                {
                    Directory.EnumerateFiles(
                        Path.Combine(
                            Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                            "yacq_lib"
                            ),
                        "*.yacq",
                        SearchOption.TopDirectoryOnly
                        )
                    .Where(file => !file.EndsWith("\\rc.yacq"))
                    .ForEach(this.RunCode);
                }
                catch { }
                NotifyStorage.Notify("YACQ スクリプトの読み込みが完了しました");
            });

            KernelService.AddMenu("YACQ コンソール", () => new ReplWindow().Show());
        }
Example #19
0
 private void ShowMemory()
 {
     NotifyStorage.Notify("Memory: " + GC.GetTotalMemory(false).ToString());
 }
Example #20
0
 private void Copy()
 {
     Clipboard.SetText(desc.Exception.ToString());
     NotifyStorage.Notify("コピーしました");
 }
Example #21
0
        /// <summary>
        /// ストリーミングAPIへ接続します。<para />
        /// 接続に失敗した場合、規定アルゴリズムに沿って自動で再接続を試みます。<para />
        /// それでも失敗する場合はfalseを返します。この場合、再接続を試みてはいけません。
        /// </summary>
        /// <param name="track">トラック対象キーワード</param>
        private void ConnectCore(AccountInfo info, string track)
        {
            try
            {
                int failureWaitSec = 0;
                while (true)
                {
                    // 接続
                    try
                    {
                        using (var n = NotifyStorage.NotifyManually("@" + info.ScreenName + ": インターネットへの接続を確認しています..."))
                        {
                            while (!NetworkInterface.GetIsNetworkAvailable())
                            {
                                info.ConnectionState = ConnectionState.WaitNetwork;
                                ConnectionManager.OnConnectionStateChanged(EventArgs.Empty);
                                // ネットワークが利用可能になるまでポーリング
                                Thread.Sleep(10000);
                            }
                        }

                        using (var n = NotifyStorage.NotifyManually("@" + info.ScreenName + ": 接続しています..."))
                        {
                            info.ConnectionState = ConnectionState.TryConnection;
                            ConnectionManager.OnConnectionStateChanged(EventArgs.Empty);
                            System.Diagnostics.Debug.WriteLine(info.ScreenName + " - User Streams Connection with Track: " + track);
                            connection = streamingCore.ConnectNew(
                                info, StreamingDescription.ForUserStreams(TwitterDefine.UserStreamsTimeout,
                                                                          track: track, repliesAll: info.AccountProperty.UserStreamsRepliesAll));
                        }
                    }
                    catch (WebException we)
                    {
                        if ((int)we.Status == 420)
                        {
                            // 多重接続されている
                            throw new WebException("@" + info.ScreenName + ": 多重接続されています。接続できません。");
                        }

                        if (we.Status == WebExceptionStatus.Timeout) // タイムアウト例外なら再試行する
                        {
                            NotifyStorage.Notify("@" + info.ScreenName + ": User Streams接続がタイムアウトしました。再試行します...");
                        }
                        else
                        {
                            string descText = we.Status.ToString();
                            if (we.Status == WebExceptionStatus.UnknownError)
                            {
                                descText = we.Message;
                            }
                            if (we.Status == WebExceptionStatus.ProtocolError)
                            {
                                var hwr = we.Response as HttpWebResponse;
                                if (hwr != null)
                                {
                                    descText += " - " + hwr.StatusCode + " : " + hwr.StatusDescription;
                                }
                            }
                            throw new WebException("接続に失敗しました。(" + descText + ")");
                        }
                    }
                    catch
                    {
                        throw;
                    }

                    if (connection != null)
                    {
                        // Connection successful
                        info.ConnectionState = ConnectionState.Connected;
                        ConnectionManager.OnConnectionStateChanged(EventArgs.Empty);
                        return;
                    }

                    if (failureWaitSec > 0)
                    {
                        if (failureWaitSec > Setting.Instance.ConnectionProperty.UserStreamsConnectionFailedMaxWaitSec)
                        {
                            throw new WebException("User Streamsへの接続に失敗しました。");
                        }
                        else
                        {
                            NotifyStorage.Notify("@" + info.ScreenName + ": User Streamsへの接続に失敗。再試行まで" + failureWaitSec.ToString() + "秒待機...", failureWaitSec / 1000);

                            // ウェイトカウント
                            Thread.Sleep(failureWaitSec * 1000);
                            NotifyStorage.Notify("@" + info.ScreenName + ": User Streamsへの接続を再試行します...");
                        }
                    }
                    else
                    {
                        NotifyStorage.Notify("@" + info.ScreenName + ": User Streamsへの接続に失敗しました。再試行します...");
                    }

                    // 最初に失敗したらすぐに再接続
                    // 2回目以降はその倍に増やしていく
                    // 300を超えたら接続失敗で戻る
                    if (failureWaitSec == 0)
                    {
                        failureWaitSec = Setting.Instance.ConnectionProperty.UserStreamsConnectionFailedInitialWaitSec;
                    }
                    else
                    {
                        failureWaitSec *= 2;
                    }
                }
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception e)
            {
                this.AccountInfo.ConnectionState = ConnectionState.Disconnected;
                ConnectionManager.OnConnectionStateChanged(EventArgs.Empty);
                throw new WebException("User Streamsへの接続に失敗しました。", e);
            }
        }
Example #22
0
        public static void FavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Fav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RegisterFavored(ud);
                }
                try
                {
                    favoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RemoveFavored(ud);
                    }
                    if (ex is FavoriteSuspendedException && Setting.Instance.InputExperienceProperty.EnableFavoriteFallback)
                    {
                        // ふぁぼ規制 -> フォールバック
                        AccountInfo fallback = null;
                        if (!String.IsNullOrEmpty(d.AccountProperty.FallbackAccount) &&
                            (fallback = AccountStorage.Get(d.AccountProperty.FallbackAccount)) != null &&
                            !status.FavoredUsers.Contains(fallback.UserViewModel))
                        {
                            NotifyStorage.Notify("Fav fallbackします: @" + d.ScreenName + " >> @");
                            FavTweetSink(new[] { fallback }, status);
                        }
                    }
                    else
                    {
                        NotifyStorage.Notify("Favに失敗しました: @" + d.ScreenName);
                        if (!(ex is ApplicationException))
                        {
                            ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                      "Fav操作時にエラーが発生しました");
                        }
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Favしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }