Esempio n. 1
0
        public void Send(string path, object obj, string messageTypeName)
        {
            var message  = _mapper.Map(obj, messageTypeName);
            var fullPath = CreateFullPath(path);

            _actorSystem.ActorSelection(fullPath).Tell(message);
        }
Esempio n. 2
0
        public void CanMapActiveMessageToDtoObject()
        {
            //Arange
            var activityMessage = new ActivityMessage();
            //Act
            var dtoObject = messageMapper.Map(activityMessage);

            //Assert
            Assert.That(dtoObject, Is.Not.Null);
        }
Esempio n. 3
0
        public void Create(string filePath)
        {
            var newMessage = FileService.ReadMessage(filePath);

            var messageDto = MessageMapper.Map(newMessage);

            _chatRepository.Create(messageDto);
        }
Esempio n. 4
0
        public GenericListModel <MessageModel> GetMyMessagesByOtherUser(string userID, int page, int pageSize)
        {
            GenericListModel <MessageModel> baseListModel = new GenericListModel <MessageModel>();

            try
            {
                IQueryable <LMYFrameWorkMVC.Common.DAL.Message> messages = dbContext.Messages.Where(x =>
                                                                                                    (x.FromUserID == contextInfo.UserID && x.ToUserID == userID) ||
                                                                                                    (x.FromUserID == userID && x.ToUserID == contextInfo.UserID)
                                                                                                    ).OrderByDescending(x => x.CreatedAt);

                baseListModel.Total = messages.Count();

                messages = messages.Skip(pageSize * (page - 1)).Take(pageSize);

                MessageMapper.Map(dbContext, contextInfo.UserID, messages.ToList(), baseListModel.List);

                //Action action = (() =>
                //{
                //    using (var transaction = dbContext.Database.BeginTransaction())
                //    {
                //        try
                //        {
                //            //update all other users messages
                //            messages.Where(x => x.FromUserID != contextInfo.UserID).ToList().ForEach(x => x.Read = true);

                //            base.SaveChanges();
                //        }
                //        catch (Exception ex)
                //        {
                //            this.HandleError(null, CommonLayer.LookUps.ErrorType.Exception, ex);
                //        }
                //        transaction.Commit();
                //    }
                //});
                //base.AddWaitingAction(action);
            }
            catch (Exception ex)
            {
                base.HandleError(baseListModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }

            return(baseListModel);
        }
        public async Task <IEnumerable <Message> > Get()
        {
            var searchResponse = await client.SearchAsync <ElasticMessage>(s => s
                                                                           .From(0)
                                                                           .Query(q => q
                                                                                  .Match(m => m)));

            //  Result from elastic index. List of ElasticMessage I guess ;p
            var elasticlist = searchResponse.Documents;

            var messagelist = new List <Message>();

            foreach (var message in elasticlist)
            {
                // Mapping every element of ElaticMessage list to Message list
                messagelist.Add(MessageMapper.Map(message));
            }
            return(messagelist);
        }
        public void Map_TransformsEntityObjectToMessageContract()
        {
            // Arrange
            var          messageId           = Guid.NewGuid();
            const string receiverPhoneNumber = "0412345678";
            const string sms     = "123456";
            var          message = new Message {
                Id = 1, MessageId = messageId, ReceiverPhone = receiverPhoneNumber, Sms = sms
            };

            // Act
            var parsedMessage = _mapper.Map(message);

            // Assert
            Assert.AreEqual(typeof(MessageResponse), parsedMessage.GetType());
            Assert.AreEqual(messageId, parsedMessage.MessageId);
            Assert.AreEqual(receiverPhoneNumber, parsedMessage.ReceiverPhoneNumber);
            Assert.AreEqual(sms, parsedMessage.Sms);
        }
Esempio n. 7
0
        public void Create(MessageModel messageModel)
        {
            try
            {
                if (Validate(messageModel))
                {
                    return;
                }

                // Action action = (() =>
                // {
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        LMYFrameWorkMVC.Common.DAL.Message message = new LMYFrameWorkMVC.Common.DAL.Message();
                        messageModel.ID = Guid.NewGuid().ToString();
                        MessageMapper.Map(dbContext, messageModel, message);

                        dbContext.Messages.Add(message);

                        base.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        this.HandleError(null, CommonLayer.LookUps.ErrorType.Exception, ex);
                    }
                    transaction.Commit();
                }

                messageModel.AddSuccess(Resources.MessageSent, LookUps.SuccessType.Full);

                // });
                //base.AddWaitingAction(action);
            }
            catch (Exception ex)
            {
                base.HandleError(messageModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
Esempio n. 8
0
        public void GetMessageModel(MessageModel messageModel, string MessageViewRequestUserID)
        {
            try
            {
                //the below include is because a bug in EF6
                LMYFrameWorkMVC.Common.DAL.Message message = dbContext.Messages.Where(x => x.ID == messageModel.ID).FirstOrDefault();

                if (message == null)
                {
                    base.HandleError(messageModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                }
                else
                {
                    MessageMapper.Map(dbContext, MessageViewRequestUserID, message, messageModel);
                }
            }
            catch (Exception ex)
            {
                base.HandleError(messageModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }
        }
Esempio n. 9
0
        public GenericListModel <UserModel> ListUsersWithLastMessageByCurrentUser()
        {
            GenericListModel <UserModel> baseListModel = new GenericListModel <UserModel>();

            try
            {
                //all users that have conversations with current user
                IQueryable <AspNetUser> aspNetUsers = dbContext.AspNetUsers.Where(x =>
                                                                                  x.Id != contextInfo.UserID &&
                                                                                  (
                                                                                      x.Messages.Any(c => c.ToUserID == contextInfo.UserID || c.FromUserID == contextInfo.UserID) ||
                                                                                      x.Messages1.Any(c => c.ToUserID == contextInfo.UserID || c.FromUserID == contextInfo.UserID)
                                                                                  )
                                                                                  );

                UserMapper.Map(dbContext, aspNetUsers.ToList(), baseListModel.List);

                foreach (UserModel userModel in baseListModel.List)
                {
                    //get last message between two users
                    LMYFrameWorkMVC.Common.DAL.Message message = dbContext.Messages.Where(x =>
                                                                                          (x.FromUserID == contextInfo.UserID || x.ToUserID == contextInfo.UserID) &&
                                                                                          (x.FromUserID == userModel.Id || x.ToUserID == userModel.Id)
                                                                                          ).OrderByDescending(x => x.CreatedAt).FirstOrDefault();

                    MessageMapper.Map(dbContext, contextInfo.UserID, message, userModel.LastMessageModel);
                }

                baseListModel.List  = baseListModel.List.OrderByDescending(x => x.LastMessageModel.CreatedAt).ToList();
                baseListModel.Total = aspNetUsers.Count();
            }
            catch (Exception ex)
            {
                base.HandleError(baseListModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }

            return(baseListModel);
        }
Esempio n. 10
0
        public List <BllMessage> GetMessages(int UserFrom, int UserTo)
        {
            var temp = uow.Messages.GetMessages(UserFrom, UserTo);

            return(MessageMapper.Map(temp).ToList());
        }