Inheritance: IDisposable
        /// <summary>
        /// コメント部屋に接続します。
        /// </summary>
        /// <param name="liveUrl"></param>
        private void JoinRoom(String liveUrl)
        {
            if (String.IsNullOrWhiteSpace(liveUrl)) {
                return;
            }

            Mouse.OverrideCursor = Cursors.Wait;

            this.LeaveRoom();

            // コメントクライアントを生成します。
            if (this.commentClient != null) {
                this.commentClient.Dispose();
            }

            this.commentClient = ACommentClient.CreateInstance(liveUrl);
            if (this.commentClient == null) {
                Mouse.OverrideCursor = null;
                MessageBox.Show("不正なURLです。");
                return;
            }

            try {
                this.commentClient.OnJoin += this.OnJoin;
                this.commentClient.OnNewMessage += this.OnReceiveMessage;
                this.commentClient.OnUpdateMember += this.OnUpdateMember;
                this.commentClient.OnBan += this.OnBanUser;
                this.commentClient.OnUnBan += this.OnUnBanUser;
                this.commentClient.OnAdminShout += this.OnAdminShout;
                this.commentClient.OnNotifyLiveClose += this.OnNotifyLiveClose;
                this.commentClient.OnError += this.OnError;
                this.commentClient.Connect();

                var room = this.commentClient.GetRoom(liveUrl);
                if (room == null) {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("接続に失敗しました。");
                    return;
                }

                var roomId = room.Summary.RoomId;
                if (String.IsNullOrWhiteSpace(roomId)) {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("接続に失敗しました。");
                    return;
                }

                // URLを部屋名に更新します。
                this.LiveUrl = roomId;

                room.Messages.ForEach(m => {
                    var message = new Message(room.Summary, m);
                    message.OnBanUser += this.BanUser;
                    message.OnUnBanUser += this.UnBanUser;
                    message.OnShowId += this.ShowId;
                    message.OnHideId += this.HideId;
                    this.MessageList.Insert(0, message);
                });

                this.commentClient.JoinRoom(roomId);
            } catch (CommentException e) {
                Mouse.OverrideCursor = null;
                MessageBox.Show(e.Message);
                logger.Error(e);
                return;
            }
        }
Beispiel #2
0
		/// <summary>
		/// コメント部屋に接続します。
		/// </summary>
		/// <param name="liveUrl"></param>
		private async void JoinRoom(String liveUrl) {
			if (String.IsNullOrWhiteSpace(liveUrl)) {
				return;
			}

			Mouse.OverrideCursor = Cursors.Wait;

			this.LeaveRoom();

			// コメントクライアントを生成します。
			if (this.commentClient != null) {
				this.commentClient.Dispose();
			}

			try {
				this.commentClient = await ACommentClient.CreateInstance(liveUrl);
			} catch(ArgumentException) {
				Mouse.OverrideCursor = null;
				MessageBox.Show("URLが正しくありません。");
				return;
			} catch(InvalidOperationException) {
				Mouse.OverrideCursor = null;
				MessageBox.Show("接続に失敗しました。");
				return;
			}

			try {
				this.commentClient.OnJoin += this.OnJoin;
				this.commentClient.OnNewMessage += this.AddComment;
				this.commentClient.OnNewMessage += this.SpeakMessage;
				this.commentClient.OnNewMessage += this.NotifyMessageToFlashCommentGenerator;
				this.commentClient.OnUpdateMember += this.UpdateMember;
				this.commentClient.OnBan += this.CommentStatusChange;
				this.commentClient.OnUnBan += this.CommentStatusChange;
				this.commentClient.OnHideComment += this.CommentStatusChange;
				this.commentClient.OnShowComment += this.CommentStatusChange;
				this.commentClient.OnInstantMessage += this.NotifyInstantMessage;
				this.commentClient.OnAdminShout += this.NotifyAdminShout;
				this.commentClient.OnNotifyLiveClose += this.NotifyLiveClose;
				this.commentClient.OnError += this.LogError;
				this.commentClient.Connect();

				var room = await this.commentClient.GetRoomAsync(liveUrl);
				if (room == null) {
					Mouse.OverrideCursor = null;
					MessageBox.Show("接続に失敗しました。");
					return;
				}

				var roomId = room.Summary.RoomId;
				if (String.IsNullOrWhiteSpace(roomId)) {
					Mouse.OverrideCursor = null;
					MessageBox.Show("接続に失敗しました。");
					return;
				}

				// URLを部屋名に更新します。
				this.LiveUrl = roomId;

				room.Messages.ForEach(m => {
					var message = new Message(room.Summary, m);
					message.OnBanUser += this.BanUser;
					message.OnUnBanUser += this.UnBanUser;
					message.OnShowId += this.ShowId;
					message.OnHideId += this.HideId;
					message.OnShowComment += this.ShowComment;
					message.OnHideComment += this.HideComment;
					message.OnAllowInstantMessage += this.AllowInstantMessage;
					if (this.SortDirection == ListSortDirection.Ascending) {
						this.MessageList.Add(message);
					} else {
						this.MessageList.Insert(0, message);
					}
				});

				await this.commentClient.JoinRoomGenAsync(roomId);
			} catch (CommentException e) {
				Mouse.OverrideCursor = null;
				MessageBox.Show(e.Message);
				logger.Error(e);
				return;
			}
		}