public IHttpActionResult GetChatHistory(NumberOfRecord <ChatHistoryRequest> chatRequest) { StringBuilder traceLog = null; ServiceResponse <Total <List <SocketSentChatVM> > > objResponse = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetChatHistory with" + chatRequest.Param.SenderCredId); objResponse = new ServiceResponse <Total <List <SocketSentChatVM> > >(); objResponse.jsonData = ChatHistoryApiBL.GetChatHistory(chatRequest.Param, chatRequest.StartIndex, chatRequest.EndIndex); objResponse.IsResultTrue = true; return(Ok(objResponse)); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(BadRequest(ex.Message)); } finally { traceLog.AppendLine("End:GetChatHistory() Response Result Status-" + objResponse.IsResultTrue + ",Fetched DateTime" + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } }
/// <summary> /// Do ChatOperation /// </summary> /// <param name="senderId"></param> /// <param name="receiverId"></param> /// <param name="message"></param> /// <param name="operationId"></param> /// <param name="chatclientHashcode"></param> /// <returns></returns> private bool DoChatOperation(string senderId, string receiverId, string message, int operationId, int chatclientHashcode) { StringBuilder traceLog = null; SocketSentChatVM objChatHistoryVM = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: start DoChatOperation" + senderId + receiverId + message + operationId + chatclientHashcode); bool IsOffine = false; switch (operationId) { case 1001: senderId = senderId.ToLower(); receiverId = receiverId.ToLower(); senderEmailId = senderId; if (!LinksMediaCorpChatServer.Program.connectByClientEmailId.ContainsKey(senderId)) { Console.WriteLine("Start: Join chat room"); LinksMediaCorpChatServer.Program.connectByClientEmailId.TryAdd(senderId, chatclientHashcode); } else { int oldTCPClientId = LinksMediaCorpChatServer.Program.connectByClientEmailId[senderId]; if (oldTCPClientId > 0) { if (LinksMediaCorpChatServer.Program.connectByClientId.ContainsKey(oldTCPClientId)) { HandleClientRequest objHandleClientRequest; LinksMediaCorpChatServer.Program.connectByClientId.TryRemove(oldTCPClientId, out objHandleClientRequest); } } Console.WriteLine("Start: Again Join chat room"); LinksMediaCorpChatServer.Program.connectByClientEmailId[senderId] = chatclientHashcode; } break; case 1002: if (!string.IsNullOrEmpty(message)) { receiverEmailId = string.Empty; senderEmailId = string.Empty; int receiverHashcode = 0; if (!string.IsNullOrEmpty(receiverId)) { receiverId = receiverId.ToLower(CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(senderId)) { senderId = senderId.ToLower(CultureInfo.InvariantCulture); } senderEmailId = senderId; if (LinksMediaCorpChatServer.Program.connectByClientEmailId.ContainsKey(receiverId)) { receiverHashcode = LinksMediaCorpChatServer.Program.connectByClientEmailId[receiverId]; receiverEmailId = receiverId.ToLower(CultureInfo.InvariantCulture); } var sentDateTime = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff"); if (receiverHashcode > 0) { //Save to database for History string messagetxt = "1003#" + senderId + "#" + receiverId + "#" + message + "#" + sentDateTime; string receiversdetails = string.Empty; receiversdetails = SendMsgToClientId(receiverHashcode, messagetxt, receiverId); //Findout the sender and receiver if (!string.IsNullOrEmpty(receiversdetails)) { var receiverdata = receiversdetails.Split('#'); if (receiverdata != null && receiverdata.Length > 1) { if (receiverdata[0] != "NA" && receiverdata[1] != "NA" && string.Compare(senderEmailId, receiverdata[1], StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(receiverEmailId, receiverdata[0], StringComparison.OrdinalIgnoreCase) == 0) { IsOffine = false; } else { IsOffine = true; } } } messagetxt = string.Empty; } else { IsOffine = true; } //string ceritifcatePath = Path.Combine(Environment.CurrentDirectory, "Resources\\CertificatesDev.p12"); string ceritifcatePath = Path.Combine(Environment.CurrentDirectory, "Resources\\Dist_Certificates.p12"); objChatHistoryVM = new SocketSentChatVM() { Message = message, ReceiverEmailId = receiverId, SenderEmailId = senderId, TrasactionDateTime = sentDateTime, IsOffine = IsOffine, CeritifcatePath = ceritifcatePath }; //// Save data in background ChatHistoryApiBL.SaveChatHistoryFromSocket(objChatHistoryVM); message = string.Empty; ceritifcatePath = string.Empty; } break; case 1003: if (!string.IsNullOrEmpty(senderId)) { senderEmailId = senderId.ToLower(CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(receiverId)) { receiverEmailId = receiverId.ToLower(CultureInfo.InvariantCulture); } break; case 1004: receiverEmailId = string.Empty; break; case 1005: if (!string.IsNullOrEmpty(senderId)) { senderId = senderId.ToLower(CultureInfo.InvariantCulture); } RemoveClientChatUser(chatclientHashcode, senderId); // closeConectionStatus = false; break; } traceLog.AppendLine("End:DoChatOperation()-" + DateTime.Now.ToLongDateString()); return(true); } catch (OutOfMemoryException e) { Console.WriteLine("Out of Memory: {0}", e.Message); } catch { } finally { LogManager.LogManagerInstance.WriteTraceLog(traceLog); objChatHistoryVM = null; traceLog = null; } return(false); }