Esempio n. 1
0
        public JsonResult GetWarnings()
        {
            IEnumerable <Warning> warnList = warningService.GetWarning().ToList();
            var warning = from warn in warnList
                          select new
            {
                GoodsId        = warn.GoodsId,
                GoodName       = warn.Goods.Name,
                MinStorage     = warn.Goods.minNum,
                CurrentStorage = warn.Goods.GoodsStorages.Sum(g => g.Quantity)
            };

            return(Json(warning, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public static void SendWarnings(IWarningService warningService)
        {
            IEnumerable <Warning> warnList = warningService.GetWarning().ToList();
            var warning = from warn in warnList
                          select new
            {
                GoodsId        = warn.GoodsId,
                GoodName       = warn.Goods.Name,
                MinStorage     = warn.Goods.minNum,
                CurrentStorage = warn.Goods.GoodsStorages.Sum(g => g.Quantity)
            };
            string warningMessage = JsonConvert.SerializeObject(warning);
            var    buffer         = new ArraySegment <byte>(Encoding.UTF8.GetBytes(warningMessage));

            foreach (WebSocket socket in CONNECT_POOL.Values)
            {
                if (socket.State == WebSocketState.Open)
                {
                    socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
                }
            }
        }