private void LoadLog() { if (!File.Exists(CommentLogFileName)) { return; } IList <string> lines = new List <string>(); using (var sr = new System.IO.StreamReader(CommentLogFileName)) { while (!sr.EndOfStream) { string line = sr.ReadLine(); lines.Add(line); } } int startIndex = 0; if (lines.Count > MaxOldCommentLodingCount) { startIndex = lines.Count - MaxOldCommentLodingCount; } for (int iLine = startIndex; iLine < lines.Count; iLine++) { string line = lines[iLine]; string[] tokens = line.Split('\t'); if (tokens.Length != 2) { continue; } string userName = tokens[0]; string commentText = tokens[1]; // コメントの追加 UiCommentData uiCommentData = new UiCommentData(); uiCommentData.UserThumbUrl = ""; uiCommentData.UserName = userName; uiCommentData.CommentStr = commentText; ViewModel viewModel = this.DataContext as ViewModel; ObservableCollection <UiCommentData> uiCommentDatas = viewModel.UiCommentDataCollection; uiCommentDatas.Add(uiCommentData); } // データグリッドを自動スクロール DataGridScrollToEnd(); }
/// <summary> /// チャンネルメッセージ受信イベントハンドラ /// </summary> /// <param name="sender"></param> /// <param name="channelName">チャンネル名</param> /// <param name="nickName">ニックネーム</param> /// <param name="host">ホスト</param> /// <param name="message">チャンネルメッセージ</param> private void TwitchChatClient_OnChannelMessage( TwitchChatClient sender, string channelName, string nickName, string host, string message) { string date = DateTime.Now.ToString("HH:mm"); // 現在時刻 /* * ChannelUser channelUser; * * channelUser = TwitchChatClient.GetChannelUser(channelName, nickName); * if (channelUser == null) * { * return; * } */ // 配信者判定 bool isBc = TwitchChatClient.IsBc(channelName, nickName); // コメントの追加 UiCommentData uiCommentData = new UiCommentData(); uiCommentData.UserThumbUrl = ""; uiCommentData.UserName = nickName; uiCommentData.CommentStr = message; System.Diagnostics.Debug.WriteLine("UserThumbUrl " + uiCommentData.UserThumbUrl); System.Diagnostics.Debug.WriteLine("UserName " + uiCommentData.UserName); System.Diagnostics.Debug.WriteLine("CommentStr " + uiCommentData.CommentStr); ViewModel viewModel = this.DataContext as ViewModel; ObservableCollection <UiCommentData> uiCommentDatas = viewModel.UiCommentDataCollection; uiCommentDatas.Add(uiCommentData); // データグリッドを自動スクロール DataGridScrollToEnd(); // コメントログを記録 WriteLog(uiCommentData.UserName, uiCommentData.CommentStr); // 棒読みちゃんへ送信 BouyomiChan.Talk(uiCommentData.CommentStr); }