private void ExecuteSendTextCommand(string strText) { var MessageCollection = ConnectionHelper.DB.GetCollection <MessageEntity>("MessageEntity"); var NewMessage = new MessageEntity(this.RoomSID, strText, (int)MsgStatus.Sending, (int)ContentType.Text, AuthRepository.MQKeyInfo.UserSid, 0, null); MessageCollection.Save(NewMessage); var SendMessage = new ChatMsg(NewMessage.Id.ToString(), null, this.RoomSID, strText, ContentType.Text, 0, MsgStatus.Sending, 0, AuthRepository.MQKeyInfo.NickName, AuthRepository.MQKeyInfo.ThumbnailPath, this.m_AnonymousThumbnailDictionary[AuthRepository.MQKeyInfo.UserSid]); this.Messages.Add(SendMessage); this.EndSendTextCommand(SendMessage); Task.Run(() => { var RoomCollection = ConnectionHelper.DB.GetCollection <RoomEntity>("RoomEntity"); var FindRoomQuery = Query <RoomEntity> .EQ(r => r.Sid, this.RoomSID); var FindedRoom = RoomCollection.FindOne(FindRoomQuery); if (null != FindedRoom) { var ActiveMemberSids = FindedRoom.ActiveMemberSids; ActiveMemberSids.Remove(AuthRepository.MQKeyInfo.UserSid); SendingMsg WillSendMsg = new SendingMsg(ActiveMemberSids, this.RoomSID, (int)ContentType.Text, strText, AuthRepository.MQKeyInfo.UserSid, SendMessage); var Result = this.m_SendMessageService.SendMessage(WillSendMsg); this.UpdateSendMessage(Result, SendMessage, MessageCollection, strText, NewMessage.Id.ToString()); } }); }
public SendingMsgResult SendMessage(SendingMsg sendingMsg) { try { using (var httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromSeconds(10); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthRepository.AccessInfo.TokenType, AuthRepository.AccessInfo.AccessToken); //TransmitMsgRequest.Headers.Add(HttpRequestHeader.Authorization, string.Format("{0} {1}", accessInfo.Token_Type, accessInfo.Access_Token)); //string postData = String.Format(BeautifulTalkProtocolSet.PublishFormat, BeautifulTalkProtocolSet.OS, BeautifulTalkProtocolSet.ReleaseVersion, //BeautifulTalkProtocolSet.SdkVersion, Environment.UserName, strToSIDs, strRoomSID, nContentType, strContent); dynamic Parameters = new JObject(); Parameters.tosids = new JArray(sendingMsg.ToSIDs.ToArray()); Parameters.fromsid = sendingMsg.FromSID; Parameters.roomsid = sendingMsg.RoomSID; Parameters.contenttype = sendingMsg.ContentType; Parameters.content = sendingMsg.Content; var JsonParameters = JsonConvert.SerializeObject(Parameters); var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json"); var responseMessage = httpClient.PostAsync( string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.SendMsgURI), postdataString).Result; if (responseMessage.IsSuccessStatusCode) { var JResult = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result); return(JsonConvert.DeserializeObject <SendingMsgResult>(JResult.ToString())); } } } catch (Exception unExpectedException) { GlobalLogger.Log(unExpectedException.Message); } return(new SendingMsgResult()); }
private void ExecuteReSendCommand(CommunicationMsg resendMsg) { Task.Run(() => { var MessageCollection = ConnectionHelper.DB.GetCollection <MessageEntity>("MessageEntity"); var RoomCollection = ConnectionHelper.DB.GetCollection <RoomEntity>("RoomEntity"); var FindRoomQuery = Query <RoomEntity> .EQ(r => r.Sid, this.RoomSID); var FindedRoom = RoomCollection.FindOne(FindRoomQuery); if (null != FindedRoom) { resendMsg.MsgStatus = MsgStatus.Sending; var ActiveMemberSids = FindedRoom.ActiveMemberSids; ActiveMemberSids.Remove(AuthRepository.MQKeyInfo.UserSid); SendingMsg WillSendMsg = new SendingMsg(ActiveMemberSids, resendMsg.RoomSid, (int)resendMsg.ContentType, resendMsg.Content, AuthRepository.MQKeyInfo.UserSid, resendMsg); var Result = this.m_SendMessageService.SendMessage(WillSendMsg); this.UpdateSendMessage(Result, resendMsg, MessageCollection, resendMsg.Content, resendMsg.Id.ToString()); } }); }
public SendingMsgResult SendMessage(SendingMsg sendMsg) { throw new NotImplementedException(); }