public IHttpActionResult ReadMsg([FromBody] dynamic value) { RetJsonModel result = new RetJsonModel(); try { string UserId = Convert.ToString(value.user_id); List <string> msgIds = JsonConvert.DeserializeObject <List <string> >(Convert.ToString(value.msg_ids)); RunVerify VD = new RunVerify(); VD.Run(UserId, new VerifyUser()); MessageDomain MD = new MessageDomain(); result = MD.ReadMsg(UserId, msgIds); return(Json(result)); } catch (Exception ex) { //记录失败日志 FunctionHelper.SaveFailLog("Message", "ReadMsg", "api/message/read", "阅读通知接口", Convert.ToString(value), ex.Message.ToString(), "POST"); result.status = 0; result.time = FunctionHelper.GetTimestamp(); result.msg = "请求失败,请重试"; return(Json(result)); } }
public IHttpActionResult GetUnreadMessage(string userid) { RetJsonModel result = new RetJsonModel(); try { //数据校验 RunVerify VD = new RunVerify(); VD.Run(userid, new VerifyUser()); MessageDomain MD = new MessageDomain(); result = MD.UnreadMessage(userid); return(Json(result)); } catch (Exception ex) { //记录失败日志 FunctionHelper.SaveFailLog("Message", "GetUnreadMessage", "api/message/getunread", "获取用户未读通知数量", $"用户ID:{userid}", ex.Message.ToString(), "GET"); result.status = 0; result.time = FunctionHelper.GetTimestamp(); result.msg = "数据异常,请重试"; return(Json(result)); } }
public IHttpActionResult GetMessageInfo(string userid, int cursor, int count) { RetJsonModel result = new RetJsonModel(); try { //数据校验 RunVerify VD = new RunVerify(); VD.Run(userid, new VerifyUser()); MessageDomain MD = new MessageDomain(); result = MD.GetMessageInfo(userid, cursor, count); return(Json(result)); } catch (Exception ex) { //记录失败日志 FunctionHelper.SaveFailLog("Message", "GetMessageInfo", "api/message/getmsg", "获取用户收到的通知", $"用户ID:{userid};已下发数:{cursor};本次请求数:{count}", ex.Message.ToString(), "GET"); result.status = 0; result.time = FunctionHelper.GetTimestamp(); result.msg = "数据异常,请重试"; return(Json(result)); } }
internal static void SaveMessage(this MessageDomain message) { UnitOfWork unitOfWork = new UnitOfWork(new CSContext()); unitOfWork.MessageRepository.Write(message.ToTO()); unitOfWork.Commit(); unitOfWork.Dispose(); }
public void NewDomainsHaveKnowFirstMessageInDomain() { TestMessage message = new TestMessage(); MessageDomain.CreateNewDomainsFor(message); Assert.AreEqual(message, message.MessageDomain.Root); }
public void TerminatedDomainParentsForgetChildren() { TestMessage message = new TestMessage(); MessageDomain.CreateNewDomainsFor(message); MessageDomain.TerminateDomainsOf(message); message.MessageDomain.Parent.Children.Should().NotContain(message.MessageDomain); }
public void CreateDomainSwitchesDomainForMessageHierarchy() { TestMessage message1 = new TestMessage(); TestMessageDecorator decorator = TestMessageDecorator.Decorate(message1); MessageDomain.CreateNewDomainsFor(message1); Assert.AreEqual(message1.MessageDomain, decorator.MessageDomain, "Whole hierarchy should have the new domain."); }
public void NewDomainsKnowTheirSiblings() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(new[] { message1, message2 }); Assert.AreEqual(2, message2.MessageDomain.SiblingDomainRootMessages.Count, "Domain should know the sibling messages, which includes the message itself."); }
public void DecoratorAdaptsMessageDomain() { TestMessage message = new TestMessage(Array.Empty <Message>()); MessageDomain.CreateNewDomainsFor(message); TestDecorator decorator = new TestDecorator(message); Assert.AreEqual(message.MessageDomain, decorator.MessageDomain, "Decorator should be in same domain as message."); }
public void CannotPropagateDomainForSiblingDomains() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(new[] { message1, message2 }); Assert.Throws <InvalidOperationException>(() => new TestMessage(new[] { message1, message2 }), "Exception should be thrown to indicate error."); }
public void CreateDomainCreatesNewDomain() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); Assert.IsNotNull(message1.MessageDomain); Assert.AreNotEqual(message1.MessageDomain, message2.MessageDomain, "Domains should be equal."); }
public void ReplaceMessageInheritsMessageDomain() { TestMessage context = new TestMessage(); MessageDomain.CreateNewDomainsFor(context); TestMessage replacing = new TestMessage(); context.ReplaceWith(replacing); replacing.ToMessageLog().Domain.Should().Be(context.ToMessageLog().Domain); }
public void PropagateMostSpecificDomain() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); TestMessage nextMessage = new TestMessage(new [] { message1, message2 }); Assert.AreEqual(nextMessage.MessageDomain, message1.MessageDomain, "Specific domains need to be propagated."); }
public void TerminatedDomainsDoNotPropagate() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); MessageDomain.TerminateDomainsOf(message1); TestMessage nextMessage = new TestMessage(message1); Assert.AreEqual(nextMessage.MessageDomain, message2.MessageDomain, "Propagate parent message domain of terminated domains."); }
public void CreatingNewDomainsIgnoreTerminatedDomains() { TestMessage message1 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); TestMessage message2 = new TestMessage(message1); MessageDomain.TerminateDomainsOf(message1); MessageDomain.CreateNewDomainsFor(message2); Assert.AreEqual(message2.MessageDomain.Parent, MessageDomain.DefaultMessageDomain, "Terminated domains should be skipped when creating new domains."); }
public void DontPropagateDomainForTerminatedSiblingDomainIfParentIsStillSibling() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(new [] { message1, message2 }); MessageDomain.CreateNewDomainsFor(message2); MessageDomain.TerminateDomainsOf(message2); Assert.Throws <InvalidOperationException>(() => new TestMessage(new[] { message1, message2 }), "Exception should be thrown to indicate error."); }
public void PropagateDomainForTerminatedSiblingDomain() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(new [] { message1, message2 }); MessageDomain.TerminateDomainsOf(message2); TestMessage message3 = new TestMessage(new [] { message1, message2 }); Assert.AreEqual(message1.MessageDomain, message3.MessageDomain, "Non terminated domain should have been used."); }
public void PropagateMessageDomain() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); TestMessage nextMessage1 = new TestMessage(message1); TestMessage nextMessage2 = new TestMessage(message2); Assert.AreEqual(nextMessage1.MessageDomain, message1.MessageDomain, "Domains need to be propagated."); Assert.AreEqual(nextMessage2.MessageDomain, message2.MessageDomain, "Domains need to be propagated."); }
public void MessageIsDisposedIfRemovedFromCollectorByDomainTermination() { MessageCollector <TestMessage, DisposableMessage> collector = new(); DisposableMessage message = new(); MessageDomain.CreateNewDomainsFor(message); message.SetUserCount(1); collector.Push(message); message.Used(); MessageDomain.TerminateDomainsOf(message); message.IsDisposed.Should().BeTrue("the it was removed from the collector."); }
public void NewDomainIsChildOfParentDomain() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(message1); TestMessage nextMessage = new TestMessage(message1); MessageDomain.CreateNewDomainsFor(nextMessage); Assert.AreEqual(nextMessage.MessageDomain.Parent, message1.MessageDomain, "Parent should be default in this case."); Assert.AreEqual(1, message1.MessageDomain.Children.Count, $"Expected 1 child domain. Actual: {message2.MessageDomain.Children.Select(d => d.Root.Id)}; Default domain: {message2.MessageDomain.Root.Id}"); Assert.AreEqual(nextMessage.MessageDomain, message1.MessageDomain.Children.First(), "Child domain should be new domain."); }
public MessageTestScope(IDbConnection dbc, JwtProvider jwtProvider, IConnectionMultiplexer redis) { ScopedDbConn = dbc; SingletonRedis = redis; this.JWTProvider = jwtProvider; UserRepo = new UserRepository(new UserCacheRepository(SingletonRedis), new UserDbRepository(ScopedDbConn), Mock.Of <IOnlineUserRepository>()); var transactionScopeFactory = new TransactionScopeFactory(ScopedDbConn); UserAccountDomain = new UserDomain(UserRepo, null, JWTProvider, null, transactionScopeFactory); MessageRepo = new MessageDbRepository(ScopedDbConn); FriendRepo = new FriendshipDbRepository(ScopedDbConn); MessageDomain = new MessageDomain(MessageRepo, UserAccountDomain, null, transactionScopeFactory); }
public void TerminateDomainsSetsTheTerminatedFlag() { TestMessage message1 = new TestMessage(); TestMessage message2 = new TestMessage(); MessageDomain.CreateNewDomainsFor(new[] { message1, message2 }); Assert.IsFalse(message1.MessageDomain.IsTerminated, "message1.MessageDomain.IsTerminated"); Assert.IsFalse(message2.MessageDomain.IsTerminated, "message2.MessageDomain.IsTerminated"); MessageDomain.TerminateDomainsOf(new[] { message1, message2 }); Assert.IsTrue(message1.MessageDomain.IsTerminated, "message1.MessageDomain.IsTerminated"); Assert.IsTrue(message2.MessageDomain.IsTerminated, "message2.MessageDomain.IsTerminated"); }
public void DontExecuteMultipleMessagesIfOneIsMissing() { bool executed = false; MessageAggregator <TestMessage> aggregator = new MessageAggregator <TestMessage>(set => { executed = true; }); TestMessage[] messages = new[] { new TestMessage(), new TestMessage(), new TestMessage() }; MessageDomain.CreateNewDomainsFor(messages); aggregator.Aggregate(messages[0]); aggregator.Aggregate(messages[1]); executed.Should().BeFalse("not all messages were added to the aggregator."); }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static List <MessageDomain> GetMessagesByUserId(string userId) { //- Retrieve List<MessageDomain> var messageList = new List <MessageDomain>(); try { DataProvider.ExecuteCmd(GetConnection, "dbo.SystemMessage_GetByUserId" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@userId", userId); }, map : delegate(IDataReader reader, short set) { MessageDomain singleMessage = new MessageDomain(); int startingIndex = 0; //startingOrdinal //- Default human credentials as Sender info. This will be reviewed soon. singleMessage.MessageId = reader.GetSafeInt32(startingIndex++); singleMessage.SenderId = reader.GetSafeString(startingIndex++); singleMessage.Content = reader.GetSafeString(startingIndex++); singleMessage.CreateDate = reader.GetSafeDateTime(startingIndex++); singleMessage.SenderFullName = reader.GetSafeString(startingIndex++); singleMessage.SenderUrl = reader.GetSafeString(startingIndex++); bool isSender = reader.GetSafeBool(startingIndex++); //- For each message supply appropriate "autor" identity values. Either Human or bot. MessageDomain messageToAdd = BuildMessageDomain(singleMessage, isSender); if (messageList == null) { messageList = new List <MessageDomain>(); } messageList.Add(messageToAdd); }); } catch (Exception ex) { throw ex; } return(messageList); }
public bool SendMessage(MessageTO message) { MessageDomain _message = message.ToDomain(); if (!_message.IsEmpty) { switch (_message.Message.MessageType) { case MessageType.chat: return(_message.SendMessage()); case MessageType.email: return(_message.SendMail()); } } return(false); }
public void AggregateMultipleMessagesInDifferentDomains() { bool executed = false; MessageAggregator <TestMessage> aggregator = new MessageAggregator <TestMessage>(set => { executed = true; }); TestMessage[] messages = new[] { new TestMessage(), new TestMessage(), new TestMessage() }; MessageDomain.CreateNewDomainsFor(messages); foreach (TestMessage message in messages) { aggregator.Aggregate(message); } executed.Should().BeTrue("all messages were added to the aggregator."); }
public void DoNotTerminateMessageDomainWhenParameterIsFalse() { MessageAggregator <TestMessage> aggregator = new MessageAggregator <TestMessage>(set => { }, false); TestMessage[] messages = new[] { new TestMessage(), new TestMessage(), new TestMessage() }; MessageDomain.CreateNewDomainsFor(messages); foreach (TestMessage message in messages) { aggregator.Aggregate(message); } foreach (TestMessage message in messages) { message.MessageDomain.IsTerminated.Should().BeFalse("message domain should not have been terminated."); } }
public void TerminateMessageDomainAutomatically() { MessageAggregator <TestMessage> aggregator = new MessageAggregator <TestMessage>(set => { }); TestMessage[] messages = new[] { new TestMessage(), new TestMessage(), new TestMessage() }; MessageDomain.CreateNewDomainsFor(messages); foreach (TestMessage message in messages) { aggregator.Aggregate(message); } foreach (TestMessage message in messages) { message.MessageDomain.IsTerminated.Should().BeTrue("message domain should have been terminated."); } }
public void TimeoutIfExceptionMessageIsOutsideOfMessageDomain() { TestMessage startMessage = new(); MessageGate <TestMessage, OtherMessage> gate = new(); bool executed = false; using Timer timer = new(state => { ExceptionMessage exception = new("Error", Array.Empty <Message>(), new HelloAgent(Substitute.For <IMessageBoard>())); MessageDomain.CreateNewDomainsFor(exception); gate.Check(exception); executed = true; }, null, 200, Timeout.Infinite); MessageGateResult <OtherMessage> result = gate.SendAndAwait(startMessage, m => {}, 500); executed.Should().BeTrue("otherwise there is a timing issue."); result.Result.Should().Be(MessageGateResultKind.Timeout); }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static List <MessageDomain> GetMessageByConversationId(int id) { List <MessageDomain> messageList = null; try { DataProvider.ExecuteCmd(GetConnection, "dbo.Message_GetByConversationId" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@conversation_id", id); }, map : delegate(IDataReader reader, short set) { MessageDomain SingleMessage = new MessageDomain(); int startingIndex = 0; //startingOrdinal SingleMessage.ConversationId = reader.GetSafeInt32(startingIndex++); SingleMessage.MessageId = reader.GetSafeInt32(startingIndex++); SingleMessage.SenderId = reader.GetSafeString(startingIndex++); SingleMessage.ReceiverId = reader.GetSafeString(startingIndex++); SingleMessage.Content = reader.GetSafeString(startingIndex++); SingleMessage.CreateDate = reader.GetSafeDateTime(startingIndex++); SingleMessage.SenderFullName = reader.GetSafeString(startingIndex++); SingleMessage.ReceiverFullName = reader.GetSafeString(startingIndex++); SingleMessage.SenderUrl = reader.GetSafeString(startingIndex++); SingleMessage.ReceiverUrl = reader.GetSafeString(startingIndex++); SingleMessage.IsRead = reader.GetSafeBool(startingIndex++); if (messageList == null) { messageList = new List <MessageDomain>(); } messageList.Add(SingleMessage); }); } catch (Exception ex) { throw ex; } return(messageList); }