public void Get_Connect(String username, String userid, String connectionid) { string msg = ""; var id = Context.ConnectionId; // check if user is admin Member admin = db.Members.Where(m => m.Username == username && m.RoleId == 3).FirstOrDefault(); if (admin != null) { msg = "Admin " + username + " is online"; LiveChat livechat = new LiveChat(); livechat.AdminId = admin.Id; livechat.ContextId = userid; db.LiveChats.Add(livechat); db.SaveChanges(); string[] Exceptional = new string[1]; Exceptional[0] = id; Clients.Caller.receiveMessage("RU", msg, ""); Clients.AllExcept(Exceptional).receiveMessage("AdminOnline", username, id); } else { msg = "Welcome to Waterway Hospital Live Chat!"; string[] Exceptional = new string[1]; Exceptional[0] = id; //Clients.Caller.receiveMessage("RU", msg, ""); Clients.AllExcept(Exceptional).receiveMessage("NewConnection", username, id); } }
//取消息 private void RefreshTabInfo() { if (tabChats.TabPages.Count > 0) { TabPage tab = tabChats.TabPages[tabChats.SelectedIndex]; LiveChat lc = (LiveChat)tab.Controls[0]; string visitorIP = lc.ChatRequest.VisitorIP; if (currentVisitors.ContainsKey(visitorIP)) { RequestInfo req = currentVisitors[visitorIP] as RequestInfo; // Clear the panel info control splitContainer1.Panel1.Controls.Clear(); TabInfo tabInfo = null; foreach (TabInfo t in chatInfo) { if (t.ChatId == lc.ChatRequest.ChatId) { tabInfo = t; tabInfo.RequestEntity = req; tabInfo.Dock = DockStyle.Fill; break; } } splitContainer1.Panel1.Controls.Add(tabInfo); } } }
public void EndChat(TabPage tab, string chatId) { if (tab == null) { LiveChat lc = null; // Get the tab page by chat id foreach (TabPage t in tabChats.TabPages) { lc = t.Controls[0] as LiveChat; if (lc.ChatRequest.ChatId == chatId) { tab = t; break; } } } tabChats.TabPages.Remove(tab); myChats.Remove(chatId); splitContainer1.Panel1.Controls.Clear(); for (int i = 0; i < chatInfo.Count; i++) { if (chatId == chatInfo[i].ChatId) { chatInfo.RemoveAt(i); break; } } }
//接受请求 private void btnAccept_Click(object sender, EventArgs e) { if (drpChatRequest.SelectedItem != null) { //声音 player.Stop(); //请求信息 ChatRequestInfo req = (ChatRequestInfo)drpChatRequest.SelectedItem; drpChatRequest.Items.Remove(req); drpChatRequest.Text = string.Empty; TabPage tab = new TabPage(req.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = req; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = req.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(req.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[req.VisitorIP] as RequestInfo; } //添加请求信息 chatInfo.Add(tabInfo); RefreshTabInfo(); //修改客服编号 ws.AcceptChatRequest(req.ChatId, Program.CurrentOperator.Id);//服务人员 } }
public override System.Threading.Tasks.Task OnConnected() { string clientId = Context.ConnectionId; LiveChat admin = db.LiveChats.OrderByDescending(l => l.Id).FirstOrDefault(); string adminId = (admin != null) ? admin.ContextId : ""; Clients.Caller.receiveMessage("ChatHub", clientId, adminId); return(base.OnConnected()); }
public ActionResult PostToLiveChat(string id, string post) { var chat = new LiveChat(); chat.PersonID = Crypto.DecryptID(id); chat.Post = post; chat.DateAdded = DateTime.Now; chat.Save(); var data = new { }; return(Json(data, JsonRequestBehavior.AllowGet)); }
public override System.Threading.Tasks.Task OnDisconnected(bool stopCalled) { string clientId = Context.ConnectionId; LiveChat livechat = db.LiveChats.Where(l => l.ContextId == clientId).FirstOrDefault(); if (livechat != null) { db.LiveChats.Remove(livechat); db.SaveChanges(); } string[] Exceptional = new string[1]; Exceptional[0] = clientId; Clients.AllExcept(Exceptional).receiveMessage("ConnectionLost", clientId + " leave", clientId); return(base.OnDisconnected(stopCalled)); }
public IActionResult Post(ChatDto dto) { var message = new LiveChat() { Sender = User.Identity.Name, Message = dto.Message, DateCreated = DateTime.Now }; try { _context.LiveChat.Add(message); _context.SaveChanges(); return(Ok()); } catch { return(BadRequest()); } }
private async Task ConnectInternalAsync(IInput input, IBrowserProfile browserProfile) { var resolver = new VidResolver(); var vidResult = await resolver.GetVid(_server, input); string vid; switch (vidResult) { case VidResult single: vid = single.Vid; break; case MultiVidsResult multi: SendSystemInfo("このチャンネルでは複数のライブが配信中です。", InfoType.Notice); foreach (var v in multi.Vids) { SendSystemInfo(v, InfoType.Notice); //titleも欲しい } return; case NoVidResult no: SendSystemInfo("このチャンネルでは生放送をしていないようです", InfoType.Error); return; default: throw new NotImplementedException(); } _cc = CreateCookieContainer(browserProfile); await InitElapsedTimer(vid); _chatProvider = new ChatProvider2(_siteOptions, _logger); _chatProvider.MessageReceived += ChatProvider_MessageReceived; _chatProvider.LoggedInStateChanged += _chatProvider_LoggedInStateChanged; _chatProvider.InfoReceived += ChatProvider_InfoReceived; var metaProvider = new MetaDataYoutubeiProvider(_server, _logger); metaProvider.InfoReceived += MetaProvider_InfoReceived; metaProvider.MetadataReceived += MetaProvider_MetadataReceived; reload: var liveChatHtml = await GetLiveChat(vid, _cc); var liveChat = LiveChat.Parse(liveChatHtml); var ytCfgStr = Tools.ExtractYtCfg(liveChatHtml); //var ytCfg = new YtCfgOld(ytCfgStr); var ytCfg = liveChat.YtCfg; var ytInitialData = Tools.ExtractYtInitialData(liveChatHtml); if (!ytInitialData.CanChat) { SendSystemInfo("このライブストリームではチャットは無効です。", InfoType.Notice); return; } var loginInfo = Tools.CreateLoginInfo(liveChat.YtCfg.IsLoggedIn); //ログイン済みユーザの正常にコメントが取得できるようになったら以下のコードは不要 //---ここから--- if (loginInfo is LoggedIn) { var k = Tools.GetSapiSid(_cc); if (k == null) { //SIDが無い。ログイン済み判定なのにSIDが無い場合が散見されるが原因不明。強制的に未ログインにする。 var cookies = Tools.ExtractCookies(_cc); var cver = ytInitialData.Cver; var keys = string.Join(",", cookies.Select(c => c.Name)); _logger.LogException(new Exception(), "", $"cver={cver},keys={keys}"); _cc = new CookieContainer(); goto reload; } } //---ここまで--- SetLoggedInState(liveChat.YtCfg.IsLoggedIn); _postCommentCoodinator = new DataCreator(ytInitialData, liveChat.YtCfg.InnertubeApiKey, liveChat.YtCfg.DelegatedSessionId, _cc); foreach (var action in liveChat.YtInitialData.Actions) { OnMessageReceived(action, true); } //var initialActions = ytInitialData.GetActions(); //foreach (var action in initialActions) //{ // OnMessageReceived(action, true); //} var chatTask = _chatProvider.ReceiveAsync(vid, liveChat.YtInitialData, ytCfg, _cc, loginInfo); var metaTask = metaProvider.ReceiveAsync(ytCfg, vid, _cc); var tasks = new List <Task> { chatTask, metaTask }; while (tasks.Count > 0) { var t = await Task.WhenAny(tasks); if (t == chatTask) { metaProvider.Disconnect(); try { await metaTask; } catch (Exception ex) { _logger.LogException(ex); } tasks.Remove(metaTask); try { await chatTask; } catch (GetLiveChatException ex) { _isDisconnectedExpected = true; string html; try { html = await GetLiveChat(vid, _cc); } catch { html = ""; } _logger.LogException(ex, "", $"input={input.Raw},html={html}"); SendSystemInfo($"エラーが発生したため、これ以上コメントを取得できません{Environment.NewLine}{ex.Message}", InfoType.Notice); } catch (ContinuationNotExistsException) { break; } catch (ChatUnavailableException ex) { _isDisconnectedExpected = true; _logger.LogException(ex); SendSystemInfo("配信が終了したか、チャットが無効です。", InfoType.Notice); } catch (ReloadException) { } catch (SpecChangedException ex) { SendSystemInfo("YouTubeの仕様変更に未対応のためコメント取得を継続できません", InfoType.Error); _logger.LogException(ex); _isDisconnectedExpected = true; } catch (Exception ex) { SendSystemInfo(ex.Message, InfoType.Error); //意図しない切断 //ただし、サーバーからReloadメッセージが来た場合と違って、単純にリロードすれば済む問題ではない。 _logger.LogException(ex); await Task.Delay(1000); } tasks.Remove(chatTask); if (_isDisconnectedExpected == false) { //何らかの原因で意図しない切断が発生した。 SendSystemInfo("エラーが発生したためサーバーとの接続が切断されましたが、自動的に再接続します", InfoType.Notice); goto reload; } } else { try { await metaTask; } catch (Exception ex) { _logger.LogException(ex); } tasks.Remove(metaTask); } } _chatProvider.MessageReceived -= ChatProvider_MessageReceived; _chatProvider.LoggedInStateChanged -= _chatProvider_LoggedInStateChanged; _chatProvider.InfoReceived -= ChatProvider_InfoReceived; metaProvider.InfoReceived -= MetaProvider_InfoReceived; metaProvider.MetadataReceived -= MetaProvider_MetadataReceived; }
//�������� private void btnAccept_Click(object sender, EventArgs e) { if (drpChatRequest.SelectedItem != null) { //���� player.Stop(); //������Ϣ ChatRequestInfo req = (ChatRequestInfo)drpChatRequest.SelectedItem; drpChatRequest.Items.Remove(req); drpChatRequest.Text = string.Empty; TabPage tab = new TabPage(req.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = req; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = req.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(req.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[req.VisitorIP] as RequestInfo; } //���������Ϣ chatInfo.Add(tabInfo); RefreshTabInfo(); //�Ŀͷ���� ws.AcceptChatRequest(req.ChatId,Program.CurrentOperator.Id);//������Ա } }
private void ����Ի�ToolStripMenuItem_Click(object sender, EventArgs e) { if (lstVisitors.SelectedItems.Count>0) { if (IsIP == lstVisitors.SelectedItems[0].SubItems[2].Text) { DialogResult choice = MessageBox.Show("��������û���������", "�Ƿ��ط�?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (choice == DialogResult.OK) { RequestInfo info = this.lstVisitors.SelectedItems[0].Tag as RequestInfo; ChatRequestInfo requestinfo = new ChatRequestInfo(); requestinfo.ChatId = Guid.NewGuid().ToString();//chatid requestinfo.AccountId = info.AccoutId.ToString(); requestinfo.VisitorIP = lstVisitors.SelectedItems[0].SubItems[2].Text;//IP requestinfo.AcceptByOpereratorId = Program.CurrentOperator.Id; //������Ա requestinfo.RequestDate = DateTime.Now; requestinfo.VisitorName = ""; requestinfo.VisitorEmail = ""; requestinfo.VisitorUserAgent = lstVisitors.SelectedItems[0].SubItems[4].Text;//����� requestinfo.WasAccept = false; //��Ϣ��ʾ TabPage tab = new TabPage(requestinfo.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = requestinfo; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = requestinfo.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(requestinfo.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[requestinfo.VisitorIP] as RequestInfo; } //��������Ϣ chatInfo.Add(tabInfo); RefreshTabInfo(); IsIP = lstVisitors.SelectedItems[0].SubItems[2].Text; ws.TransferChat(requestinfo); //�Ŀͷ���� ws.AcceptChatRequest(requestinfo.ChatId, Program.CurrentOperator.Id);//������Ա } } else { DialogResult choice = MessageBox.Show("�Ƿ�ȷ�Ϸ�������", "YesNo?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (choice == DialogResult.Yes) { RequestInfo info = this.lstVisitors.SelectedItems[0].Tag as RequestInfo; ChatRequestInfo requestinfo = new ChatRequestInfo(); requestinfo.ChatId = Guid.NewGuid().ToString();//chatid requestinfo.AccountId = info.AccoutId.ToString(); requestinfo.VisitorIP = lstVisitors.SelectedItems[0].SubItems[2].Text;//IP requestinfo.AcceptByOpereratorId = Program.CurrentOperator.Id; //������Ա requestinfo.RequestDate = DateTime.Now; requestinfo.VisitorName = ""; requestinfo.VisitorEmail = ""; requestinfo.VisitorUserAgent = lstVisitors.SelectedItems[0].SubItems[4].Text;//����� requestinfo.WasAccept = false; ws.TransferChat(requestinfo); IsIP = lstVisitors.SelectedItems[0].SubItems[2].Text; //��Ϣ��ʾ TabPage tab = new TabPage(requestinfo.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = requestinfo; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = requestinfo.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(requestinfo.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[requestinfo.VisitorIP] as RequestInfo; } //��������Ϣ chatInfo.Add(tabInfo); RefreshTabInfo(); } } } else { MessageBox.Show("�㻹û��ѡ���˭���жԻ�","��ѡ��",MessageBoxButtons.OK,MessageBoxIcon.Stop); } }
public bool UserOnlineStatus(string Id, bool Status) { LiveChat liveChat = new LiveChat(); DataProvider.ExecuteNonQuery(GetConnection, "dbo.IsUserOnline_UpdateOnlineStatus" , inputParamMapper: delegate (SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", Id); paramCollection.AddWithValue("@OnlineStatus", Status); } , returnParameters: delegate (SqlParameterCollection param) { } ); if (CheckUserRole() && !Status) { liveChat.AdminOnlineStatus(CheckAdminIsOnline()); } else if (CheckUserRole() && Status) { liveChat.AdminOnlineStatus(Status); } return Status; }
private void 邀请对话ToolStripMenuItem_Click(object sender, EventArgs e) { if (lstVisitors.SelectedItems.Count > 0) { if (IsIP == lstVisitors.SelectedItems[0].SubItems[2].Text) { DialogResult choice = MessageBox.Show("你已向该用户发出请求", "是否重发?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (choice == DialogResult.OK) { RequestInfo info = this.lstVisitors.SelectedItems[0].Tag as RequestInfo; ChatRequestInfo requestinfo = new ChatRequestInfo(); requestinfo.ChatId = Guid.NewGuid().ToString(); //chatid requestinfo.AccountId = info.AccoutId.ToString(); requestinfo.VisitorIP = lstVisitors.SelectedItems[0].SubItems[2].Text; //IP requestinfo.AcceptByOpereratorId = Program.CurrentOperator.Id; //服务人员 requestinfo.RequestDate = DateTime.Now; requestinfo.VisitorName = ""; requestinfo.VisitorEmail = ""; requestinfo.VisitorUserAgent = lstVisitors.SelectedItems[0].SubItems[4].Text;//浏览器 requestinfo.WasAccept = false; //信息显示 TabPage tab = new TabPage(requestinfo.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = requestinfo; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = requestinfo.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(requestinfo.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[requestinfo.VisitorIP] as RequestInfo; } //修改请求信息 chatInfo.Add(tabInfo); RefreshTabInfo(); IsIP = lstVisitors.SelectedItems[0].SubItems[2].Text; ws.TransferChat(requestinfo); //修改客服编号 ws.AcceptChatRequest(requestinfo.ChatId, Program.CurrentOperator.Id);//服务人员 } } else { DialogResult choice = MessageBox.Show("是否确认发出邀请", "YesNo?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (choice == DialogResult.Yes) { RequestInfo info = this.lstVisitors.SelectedItems[0].Tag as RequestInfo; ChatRequestInfo requestinfo = new ChatRequestInfo(); requestinfo.ChatId = Guid.NewGuid().ToString(); //chatid requestinfo.AccountId = info.AccoutId.ToString(); requestinfo.VisitorIP = lstVisitors.SelectedItems[0].SubItems[2].Text; //IP requestinfo.AcceptByOpereratorId = Program.CurrentOperator.Id; //服务人员 requestinfo.RequestDate = DateTime.Now; requestinfo.VisitorName = ""; requestinfo.VisitorEmail = ""; requestinfo.VisitorUserAgent = lstVisitors.SelectedItems[0].SubItems[4].Text;//浏览器 requestinfo.WasAccept = false; ws.TransferChat(requestinfo); IsIP = lstVisitors.SelectedItems[0].SubItems[2].Text; //信息显示 TabPage tab = new TabPage(requestinfo.VisitorIP); LiveChat lc = new LiveChat(); lc.Tag = tabChats; lc.ChatRequest = requestinfo; lc.Dock = DockStyle.Fill; tab.Controls.Add(lc); tabChats.TabPages.Add(tab); tab.Focus(); TabInfo tabInfo = new TabInfo(); tabInfo.ChatId = requestinfo.ChatId; tabInfo.Dock = DockStyle.Fill; if (currentVisitors.ContainsKey(requestinfo.VisitorIP)) { tabInfo.RequestEntity = currentVisitors[requestinfo.VisitorIP] as RequestInfo; } //修改请求信息 chatInfo.Add(tabInfo); RefreshTabInfo(); } } } else { MessageBox.Show("你还没有选择跟谁进行对话", "请选择", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }