private static Sql.Conversation GetConversationByID(ConversationId id) { using (var ctx = new EmailMonitorContext()) { Sql.Conversation conversation = ctx.Conversation.Find(id.ToString()); return(conversation); } }
/// <summary> /// 必须下创建会话,然后再来初始化 /// </summary> public async Task <string> CreateConversationAsync(string reciverId) { try { var conversationId = await this._conversationService.CreateConversationAsync(_userInfo.UserId, reciverId, _userInfo.AccessToken); ConversationId = conversationId; ConversationType = ConversationType.P2P; return(ConversationId.ToString()); } catch (Exception e) { return(e.ToString()); } }
public async Task <string> SendTextAsync(string reciverId, string message) { try { var result = await this._conversationService.SendTextAsync(ConversationId.ToString(), _userInfo.UserId, message, _userInfo.AccessToken, ConversationType); if (result.Success) { this.OnSendMessageEvent?.Invoke(reciverId, message); } return(JsonConvert.SerializeObject(result)); } catch (Exception e) { return(e.ToString()); } }
public async Task <string> GetMessageHistoryAsync() { try { var history = await this._conversationService.GetMessageHistryAsync(new MessageNotifyDto() { LatestMsgId = LastMsgId, Target = NotifyTargetType.Conversation, TargetId = ConversationId.ToString(), TargetCategory = (int)ConversationType }, this._userInfo.AccessToken); return(JsonConvert.SerializeObject(history)); } catch (Exception ex) { return(ex.ToString()); } }
private async Task <byte[]> SendMessageInternal(string routingKeyOrTopicName, byte[] message, IDictionary <string, object> headers, MessageType messageType, MessageParameters p = null) { if (EndpointType != EndpointTypeEnum.Publisher) { var e = new InvalidOperationException("Attempt to send a message on a consumer prohibited."); VerboseLoggingHandler.Log(e); throw e; } p ??= DefaultMessageParameters; if (string.IsNullOrEmpty(routingKeyOrTopicName)) { routingKeyOrTopicName = RoutingKeyOrTopicName; } VerboseLoggingHandler.Log($"SendMessageInternal sending message, type='{messageType}', routingKeyOrTopicName='{routingKeyOrTopicName}', durable='{p.Durable}', mandatory='{p.Mandatory}', persistent='{p.Persistent}', priority='{p.Priority}', autoAck='{p.AutoAck}', resilient='{p.Resilient}', timeout='{p.TimeOut}' (ms)"); headers ??= new Dictionary <string, object>(); byte[] ret = null; var messageTypeText = new StringBuilder(); var messageProperties = Channel.CreateBasicProperties(); messageProperties.Type = MessageTypeFragmentsChat; messageProperties.Timestamp = AmqpTimestampNow; messageProperties.Priority = p.Priority; messageProperties.Persistent = p.Persistent; messageProperties.Expiration = p.TimeOut.ToString(); if (p.Durable) { messageProperties.DeliveryMode = 2; } messageProperties.CorrelationId = ConversationId.ToString(); if (!p.AutoAck) { messageTypeText.Append((MessageTypeFragmentsRequestAmqAck)); } if ((messageType & MessageType.RequireAck) == MessageType.RequireAck) { messageTypeText.Append(MessageTypeFragmentsRequestAck); } if ((messageType & MessageType.RequireResponse) == MessageType.RequireResponse) { messageTypeText.Append(MessageTypeFragmentsRequestReply); } headers.Add(DictionaryKey_PassedQueueTtl, ReturnChannelQueueTtl); messageProperties.Type = messageTypeText.ToString(); messageProperties.Headers = headers; try { ReturnData = null; messageProperties.ReplyTo = ReturnChannelQueueName; VerboseLoggingHandler.Log($"Publishing now"); Channel.BasicPublish(ExchangeName, routingKeyOrTopicName, p.Mandatory, messageProperties, message); //_channel.WaitForConfirmsOrDie(new TimeSpan(0, 0, 0, 0, timeout.Value)); if (((PublisherParameters)(ChannelParameters)).EnableConfirmSelect) { try { Channel.WaitForConfirms(); } catch (InvalidOperationException e1) { if (e1.Message == "Confirms not selected") { var e = new InvalidOperationException("Invalid configuration. WaitForConfirms behavior requested, but Exchange not configured for them.", e1); VerboseLoggingHandler.Log(e); throw e; } else { VerboseLoggingHandler.Log(e1); throw e1; } } } if (messageType == MessageType.Normal) { return(null); } VerboseLoggingHandler.Log($"Published. LatchCount='{ReturnChannelLatch.CurrentCount}', timeout='{p.TimeOut}' (ms)"); await ReturnChannelLatch.WaitAsync(p.TimeOut, LocalCancellationToken); VerboseLoggingHandler.Log($"Released. LatchCount='{ReturnChannelLatch.CurrentCount}'"); } finally { if (messageType != MessageType.Normal) { VerboseLoggingHandler.Log($"Completed. LatchCount='{ReturnChannelLatch.CurrentCount}'"); ret = ReturnData; } } return(ret); }
internal static IDictionary <string, string> ExtractDeliveryDetails(StoreSession session, Item item) { IDictionary <string, string> customProperties = null; ActivityLogHelper.CatchNonFatalExceptions(delegate { MessageItem messageItem = item as MessageItem; if (messageItem == null) { return; } bool flag = false; bool flag2 = false; string value = null; ConversationId conversationId = null; string value2 = null; bool?flag3 = null; if (((IDirectPropertyBag)messageItem.PropertyBag).IsLoaded(InternalSchema.InferenceClassificationResult)) { InferenceClassificationResult?valueAsNullable = messageItem.GetValueAsNullable <InferenceClassificationResult>(InternalSchema.InferenceClassificationResult); flag3 = new bool?(valueAsNullable != null && valueAsNullable.Value.HasFlag(InferenceClassificationResult.IsClutterFinal)); } string value3 = string.Empty; if (flag3 != null) { value3 = (flag3.Value ? bool.TrueString : bool.FalseString); } bool?flag4 = new bool?(messageItem.IsGroupEscalationMessage); string value4 = string.Empty; if (flag4 != null) { value4 = (flag4.Value ? bool.TrueString : bool.FalseString); } StoreObjectId parentId = messageItem.ParentId; DefaultFolderType defaultFolderType = DefaultFolderType.None; bool flag5 = false; if (parentId != null) { StoreObjectId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.Inbox); flag = parentId.Equals(defaultFolderId); StoreObjectId defaultFolderId2 = session.GetDefaultFolderId(DefaultFolderType.Clutter); flag2 = (defaultFolderId2 != null && parentId.Equals(defaultFolderId2)); MailboxSession mailboxSession = session as MailboxSession; if (mailboxSession != null) { defaultFolderType = mailboxSession.IsDefaultFolderType(parentId); flag5 = true; } } value = messageItem.InternetMessageId; ConversationIndex index; if (ConversationIndex.TryCreate(messageItem.ConversationIndex, out index)) { conversationId = ConversationId.Create(index); } string value5 = string.Empty; if (((IDirectPropertyBag)messageItem.PropertyBag).IsLoaded(InternalSchema.InferenceMessageIdentifier)) { value5 = messageItem.GetValueAsNullable <Guid>(InternalSchema.InferenceMessageIdentifier).ToString(); } if (messageItem.Sender != null) { value2 = messageItem.Sender.SmtpEmailAddress; } List <string> list = null; List <string> list2 = null; foreach (Recipient recipient in messageItem.Recipients) { if (recipient.Participant != null) { if (recipient.IsDistributionList() == true) { if (list == null) { list = new List <string>(2); } list.Add(recipient.SmtpAddress()); } else if (recipient.IsGroupMailbox() == true) { if (list2 == null) { list2 = new List <string>(2); } list2.Add(recipient.SmtpAddress()); } } } Dictionary <string, string> dictionary = new Dictionary <string, string> { { "IsClutter", value3 }, { "DeliveredToInbox", flag ? bool.TrueString : bool.FalseString }, { "DeliveredToClutter", flag2 ? bool.TrueString : bool.FalseString }, { "IsGroupEscalationMessage", value4 }, { "InternetMessageId", value }, { "ConversationId", (conversationId == null) ? string.Empty : conversationId.ToString() }, { "MessageGuid", value5 }, { "SenderSmtpAddress", value2 } }; if (list != null && list.Count > 0) { dictionary.Add("DLRecipients", string.Join(";", list)); } if (list2 != null) { dictionary.Add("GMRecipients", string.Join(";", list2)); } if (flag5) { Dictionary <string, string> dictionary2 = dictionary; string key = "DeliveredFolderType"; int num = (int)defaultFolderType; dictionary2.Add(key, num.ToString()); if (defaultFolderType == DefaultFolderType.None && parentId != null) { dictionary.Add("DeliveredFolderId", parentId.ToString()); } } customProperties = dictionary; }, null); return(customProperties); }