Example #1
0
        /// <summary>
        /// 保存消息(同步)
        /// </summary>
        /// <param name="parameter"></param>
        public void Save(MessageParameter parameter)
        {
            var message = Mapper.Map <Message>(parameter);

            context.Messages.Add(message);
            context.SaveChanges();
        }
Example #2
0
 internal Message(int id, MessageType action, MessageParameter parameter)
 {
     this.ID = id;
     this.Action = action;
     this.Parameter = parameter;
     this.Time = DateTime.UtcNow;
 }
Example #3
0
        /// <summary>
        /// 保存消息
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public async Task SaveAsync(MessageParameter parameter)
        {
            var message = Mapper.Map <Message>(parameter);

            context.Messages.Add(message);
            await context.SaveChangesAsync();
        }
Example #4
0
 internal Message(int id, MessageType action, MessageParameter parameter, DateTime time)
 {
     this.ID = id;
     this.Action = action;
     this.Parameter = parameter;
     this.Time = time;
 }
Example #5
0
        public object List(bool?hasRead = false, int formId = 0, string action = "receive", int page = 1, int rows = 20)
        {
            var parameter = new MessageParameter
            {
                Page       = new Loowoo.Common.PageParameter(page, rows),
                HasRead    = hasRead,
                FromUserId = action == "send" ? Identity.ID : 0,
                ToUserId   = action == "receive" ? Identity.ID : 0,
                FormId     = formId,
            };
            var list = Core.MessageManager.GetList(parameter).ToList();

            return(new PagingResult
            {
                List = list.Select(e => new
                {
                    e.ID,
                    e.Message.InfoId,
                    e.MessageId,
                    e.Message.Content,
                    e.Message.CreateTime,
                    e.HasRead,
                    e.Message.CreatorId,
                    FromUser = e.Message.Creator == null ? null : e.Message.Creator.RealName,
                    e.UserId,
                    ToUser = e.User == null ? null : e.User.RealName,

                    FormId = e.Message.Info == null ? 0 : e.Message.Info.FormId,
                    Title = e.Message.Info == null ? null : e.Message.Info.Title,
                }),
                Page = parameter.Page
            });
        }
Example #6
0
 /// <summary>
 /// Check mandatory field
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="R"></typeparam>
 /// <param name="obj"></param>
 /// <param name="param"></param>
 public static void CheckMandatoryField <T, R>(T obj, MessageParameter param = null)
     where T : class
     where R : new()
 {
     try
     {
         R cond = CommonUtil.CloneObject <T, R>(obj);
         CheckMandatoryField(cond, param);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #7
0
        //this recieves a list of selected product children Ids from MessageParameter and then gets the
        //product children and returns them
        private List <ProductChild> getProductChildrenFromCheckItem(MessageParameter msgParam)
        {
            List <ProductChild> selectedList = new List <ProductChild>();

            if (!msgParam.GetProductChildrenAddyFromCheckItems().IsNullOrEmpty())
            {
                foreach (string pChildAddy in msgParam.GetProductChildrenAddyFromCheckItems())
                {
                    ProductChild productChild = ProductChildBiz.Find(pChildAddy);
                    productChild.IsNullThrowException("productChild");
                    selectedList.Add(productChild);
                }
            }

            return(selectedList);
        }
Example #8
0
        /// <summary>
        /// Saves service call into the database..
        /// </summary>
        /// <param name="serviceCall">Service call that you would like to save to the database</param>
        private void Create(ServiceCall serviceCall)
        {
            var message = new Message
            {
                Text        = JsonConvert.SerializeObject(serviceCall),
                Type        = serviceCall.GetType().FullName,
                Status      = MessageStatus.Incomplete,
                WifiOnly    = serviceCall.WifiOnly,
                RecurringId = serviceCall.RecurringMessageId
            };

            if (serviceCall.Parameters != null)
            {
                for (var index = 0; index < serviceCall.Parameters.Length; index++)
                {
                    MessageParameter parameter = null;
                    if (serviceCall.Parameters[index] != null)
                    {
                        parameter = new MessageParameter
                        {
                            Sequence = index + 1,
                            Type     = serviceCall.Parameters[index].GetType().FullName,
                            Text     = JsonConvert.SerializeObject(serviceCall.Parameters[index])
                        };
                        _logger.Debug("in ServiceProxy.Create, paramType is: " + parameter.Type);
                        _logger.Debug("in ServiceProxy.Create, paramText is: " + parameter.Text);
                    }
                    message.Parameters.Add(parameter);
                }
            }

            try
            {
                _logger.Debug("in ServiceProxy.Create, about to invoke lock");
                Messages.Instance.AddNewMessage(message);
                serviceCall.MessageId = message.Id;
                _logger.Debug("in ServiceProxy.Create, AddNewMessage completed");
            }
            catch (Exception e)
            {
                _logger.Error("Error Creating Message", e);
            }
        }
Example #9
0
 /// <summary>
 /// Check mandatory field
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="validator"></param>
 /// <param name="param"></param>
 public static void CheckMandatoryField(object obj, ValidatorUtil validator, MessageParameter param = null)
 {
     try
     {
         ObjectResultData result = ValidatorUtil.BuildErrorMessage(validator, new object[] { obj }, param);
         if (result != null)
         {
             if (result.IsError)
             {
                 ApplicationErrorException error = new ApplicationErrorException();
                 error.ErrorResult = result;
                 throw error;
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #10
0
        /// <summary>
        /// 回复消息
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> ReplayMessage(long messageId, string content)
        {
            var message = await messageManager.GetMessageByIdAsync(messageId);

            //构建发送消息
            MessageParameter sendMessage = new MessageParameter
            {
                ToUserId     = message.FromUserId,
                Type         = EMsgType.Text,
                Content      = content,
                FromUserName = message.ToUserName,
                ToUserName   = message.FromUserName,
                ToUserNick   = message.FromUserNick,
                CreateTime   = DateTime.Now
            };
            //获取accessToken
            var accessToken = AccessTokenContainer.TryGetAccessToken(WeixinConfig.AppId, WeixinConfig.AppSecret);
            //发送消息
            var data = new
            {
                touser  = sendMessage.ToUserName,
                msgtype = "text",
                text    = new
                {
                    content = content
                }
            };
            var result = await CommonJsonSend.SendAsync(accessToken, WeixinConfig.URL_FORMAT, data);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Json(new ReturnResult {
                    IsSuccess = false, Message = result.errmsg
                }));
            }
            //保存发送消息
            await messageManager.SaveAsync(sendMessage);

            return(Json(new ReturnResult()));
        }
        /// <summary>
        /// 接收文本
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            var responseMessage = CreateResponseMessage <ResponseMessageText>();

            responseMessage.Content = string.Format("您好,我们已接收到您发送的消息,很快会给您回复!");
            //获取发送用户信息
            var customer = customerManager.GetCustomerByOpenId(requestMessage.FromUserName);
            //存储消息
            MessageParameter parameter = new MessageParameter
            {
                Type         = EMsgType.Text,
                Content      = requestMessage.Content,
                FromUserId   = customer == null ? 0 : customer.Id,
                FromUserName = requestMessage.FromUserName,
                ToUserName   = requestMessage.ToUserName,
                FromUserNick = customer.Nick,
                CreateTime   = DateTime.Now
            };

            messageManager.Save(parameter);
            return(responseMessage);
        }
Example #12
0
        public IEnumerable <UserMessage> GetList(MessageParameter parameter)
        {
            var query = DB.UserMessages.Where(e => !e.Deleted);

            if (parameter.FromUserId > 0)
            {
                query = query.Where(e => e.Message.CreatorId == parameter.FromUserId);
            }
            if (parameter.ToUserId > 0)
            {
                query = query.Where(e => e.UserId == parameter.ToUserId);
            }
            if (parameter.HasRead.HasValue)
            {
                query = query.Where(e => e.HasRead == parameter.HasRead.Value);
            }
            if (parameter.FormId > 0)
            {
                query = query.Where(e => e.Message.InfoId > 0 && e.Message.Info.FormId == parameter.FormId);
            }
            return(query.OrderByDescending(e => e.ID).SetPage(parameter.Page));
        }
Example #13
0
 internal Message(int id, MessageType action, MessageParameter parameter, FrameSpan elapsed)
     : this(id, action, parameter)
 {
     this.Elapsed = elapsed;
 }
Example #14
0
 internal Message(MessageType action, MessageParameter parameter)
     : this(NoID,action,parameter)
 {
 }
Example #15
0
 /// <summary>
 /// Creates and saves the message
 /// </summary>
 /// <param name="fromUserId"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="menuPathMainId"></param>
 /// <param name="productId"></param>
 /// <param name="productChildId"></param>
 /// <param name="messageEnum"></param>
 /// <param name="menuEnum"></param>
 public void CreateMessageAndSave(MessageParameter param)
 {
     CreateMessageAndSave(param.Subject, param.Body, param.MenuPathMainId, param.ProductId, param.ProductChildId, param.MessageEnum, param.MenuEnum);
 }
Example #16
0
        /// <summary>
        /// This method assumes the current user is the sender.
        /// </summary>
        /// <param name="menuPathMainId"></param>
        /// <param name="productId"></param>
        /// <param name="productChildId"></param>
        /// <param name="menuEnum"></param>
        /// <returns></returns>
        //public MessageParameter GetPeopleListCount(string menuPathMainId, string productId, string productChildId, MenuENUM menuEnum)
        //{

        //    return makePeopleLists(productId, productChildId, menuEnum, menuPathMainId);
        //}

        /// <summary>
        /// This method assumes current user is sender. Note all parameters will not have value. It depends which menu level they are sent from
        /// </summary>
        /// <param name="menuPathMainId"></param>
        /// <param name="productId"></param>
        /// <param name="productChildId"></param>
        /// <param name="menuEnum"></param>
        /// <returns></returns>
        public MessageParameter GetPeopleListCount(string menuPathMainId, string productId, string productChildId, MenuENUM menuEnum)
        {
            countIsSet = false;
            if (menuEnum == MenuENUM.Unknown)
            {
                throw new Exception("MenuENUM.Unknown");
            }

            Person fromPerson = UserBiz.GetPersonFor(UserId);

            fromPerson.IsNullThrowException("fromPerson");


            //initialize the lists
            initializeHashSets();

            MenuPathMain mpm;

            switch (menuEnum)
            {
            case MenuENUM.IndexMenuPath1:
                mpm = getMpm(menuPathMainId);
                getPeopeFromMp1Etc(mpm.MenuPath1Id);
                break;


            case MenuENUM.IndexMenuPath2:
                mpm = getMpm(menuPathMainId);
                getPeopleFromMp2Etc(mpm.MenuPath1Id, mpm.MenuPath2Id);
                break;


            case MenuENUM.IndexMenuPath3:
                mpm = getMpm(menuPathMainId);
                getPeopleFromMp3Etc(mpm);
                break;


            case MenuENUM.IndexMenuProduct:
                getPeopleFromProductEtc(productId);
                break;


            case MenuENUM.IndexMenuProductChild:
                getPeopleFromProductChildOwners(productChildId);
                break;


            case MenuENUM.IndexDefault:
            default:
                break;
            }


            //Add to total people
            addupAllListsIntoTotalPeopleAndClean(fromPerson);

            MessageParameter msgParam = new MessageParameter();

            msgParam.FromPerson = fromPerson;

            msgParam.NumberOfProductPeople    = NumberOfProductPeople;
            msgParam.NumberOfLikeUnlikePeople = NumberOfPeopleInLikeUnlike;
            msgParam.NumberOfTotalPeople      = NumberOfTotalPeople;
            msgParam.NumberOfChildProductsBelongingToUserFrom = NumberOfChildProductsBelongingToUserFrom;
            msgParam.NumberOfProductsBelongingToUserFrom      = NumberOfProductsBelongingToUserFrom;

            msgParam.ProductChildPeople                 = peopleInProductChildren;
            msgParam.ProductPeople                      = peopleInProducts;
            msgParam.LikeUnlikePeople                   = peopleInLikeUnlike;
            msgParam.TotalPeople                        = totalPeopleHashSet;
            msgParam.ProductsBelongingToUserFrom        = productsBelongingToUserFrom;
            msgParam.ProductChildrenBelongingToUserFrom = childProductsBelongingToUserFrom;
            msgParam.ChildProductCheckItems             = loadChildProductsIntoCheckItems(childProductsBelongingToUserFrom);
            //msgParam.OwnersChildProductsWithLinks = loadOwnersChildProductsWithLinks(childProductsBelongingToUserFrom);

            return(msgParam);
        }
Example #17
0
 internal Message(int id, MessageType action, MessageParameter parameter, DateTime time, FrameSpan elapsed, string info)
     : this(id, action, parameter, time)
 {
     this.Elapsed = elapsed;
     this.Info = info;
 }
Example #18
0
 internal Message(MessageType action, MessageParameter parameter, FrameSpan elapsed, string info)
     : this(NoID, action, parameter)
 {
     this.Elapsed = elapsed;
     this.Info = info;
 }
Example #19
0
 internal Message(int id, MessageType action, MessageParameter parameter, DateTime time, string info)
     : this(id, action, parameter, time)
 {
     this.Info = info;
 }
Example #20
0
 internal Message(MessageType action, MessageParameter parameter, string info)
     : this(NoID, action, parameter)
 {
     this.Info = info;
 }
        private static void receiveMessage(Object parameters)
        {
            // Parse Parameters
            MessageParameter       messageParameters = (MessageParameter)parameters;
            TcpClient              client            = messageParameters.client;
            Func <String[], bool>  messageHandler    = messageParameters.messageHandler;
            Func <Exception, bool> timeoutHandler    = messageParameters.timeoutHandler;
            Func <bool>            disconnectHandler = messageParameters.disconnectHandler;
            int maxMessageSize = messageParameters.maxMessageSize;

            // Check Parameters
            if (client == null)
            {
                return;
            }
            if (messageHandler == null)
            {
                messageHandler = (String[] s) => { return(true); }
            }
            ;
            if (timeoutHandler == null)
            {
                timeoutHandler = (Exception e) => { return(true); }
            }
            ;
            if (disconnectHandler == null)
            {
                disconnectHandler = () => { return(true); }
            }
            ;

            // Initialize Variables
            ASCIIEncoding encoder = new ASCIIEncoding();
            String        oldBuffer = "", buffer = "", message = "";

            byte[] packet = new byte[maxMessageSize];
            int    packetSize, start, end;

            // Run Loop
            while (true)
            {
                // Check if Client is Connected
                if ((client == null || !client.Connected) && !disconnectHandler())
                {
                    return;
                }

                // Read Message
                packetSize = 0;
                try { packetSize = client.GetStream().Read(packet, 0, maxMessageSize); }

                // Check for Disconnect
                catch (Exception e) { if (!timeoutHandler(e))
                                      {
                                          return;
                                      }
                }

                //messageHandler(new string[] {"Read " + packetSize + " bytes."});

                // Check for Empty Message
                if (packetSize <= 0)
                {
                    if (!timeoutHandler(null))
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }

                // Parse Message
                buffer = oldBuffer + encoder.GetString(packet, 0, packetSize);

                start = end = 0;
                while (true)
                {
                    start = buffer.IndexOf("[", end);
                    if (start == -1)
                    {
                        oldBuffer = "";
                        break;
                    }

                    end = buffer.IndexOf("]", start + 1);
                    if (end == -1)
                    {
                        oldBuffer = buffer.Substring(start);
                        break;
                    }

                    message = buffer.Substring(start + 1, end - start - 1);

                    if (!messageHandler(message.Split(',')))
                    {
                        return;
                    }
                }
            }
        }
Example #22
0
 internal Message(MessageType action, MessageParameter parameter, DateTime time, FrameSpan elapsed)
     : this(NoID, action, parameter, time)
 {
     this.Elapsed = elapsed;
 }