public async Task <Result> Handle(ListInstructionQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                Expression <Func <Instruction, bool> > filter = null;
                int?skip = request.Skip.ToNullableInt();
                int?top  = request.Top.ToNullableInt();

                var instructionDomains = await _instructionReadRepository.ListAsync(filter, skip, top);

                var instructionModels = _mapper.Map <IEnumerable <InstructionModel> >(instructionDomains);
                var count             = instructionModels.Count();
                var sourcesModel      = new InstructionsModel {
                    Value = instructionModels, Count = count, NextLink = null
                };

                result = Result.Ok(sourcesModel);
            }
            catch (FilterODataException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.InvalidQueryFilter.Name,
                        Message = HandlerFailures.InvalidQueryFilter,
                        Target  = "$filter"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.ListInstructionFailure);
            }
            return(result);
        }
Exemplo n.º 2
0
 public ProgramManager(string pathBase, string urlDownload)
 {
     PathBase     = System.IO.Path.Combine(pathBase, "Data");
     UrlDownload  = urlDownload;
     Instructions = new InstructionsModel(this);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 推送指令
        /// </summary>
        public void PushRoutersAndInst(string clientId, int level = 1, string token = "", string routerName = "", int groupId = 0, string groupName = "", int pageIndex = 1, string commands = "")
        {
            //Connect connect = _connections.FirstOrDefault(c => c.ClientId == clientId);
            //if (connect == null)
            //{
            //    if (_connections.Count > 10)
            //    {
            //        _connections.RemoveAt(0);
            //    }
            //    connect = new Connect() { ClientId = clientId, ConnectionId = Context.ConnectionId };
            //    _connections.Add(connect);
            //}

            PushRouterInstModel model = new PushRouterInstModel();

            try
            {
                InstructionsModel inst = new InstructionsModel();

                inst.Total              = PubLib.当前总指令数;
                inst.Querys             = PubLib.当前查询指令数;
                inst.Coins              = PubLib.当前币业务指令数;
                inst.ICCardCoinRepeats  = PubLib.当前IC卡进出币指令重复数;
                inst.ICCardQueryRepeats = PubLib.当前IC卡查询重复指令数;
                inst.Receipts           = PubLib.当前小票指令数;
                inst.Errors             = PubLib.当前错误指令数;
                inst.Returns            = PubLib.当前返还指令数;
                model.Instructions      = inst;

                model.CurrVar = new CurrVar()
                {
                    Level = level, CurrRouterToken = token, CurrRouterName = routerName, CurrGroupId = groupId, CurrGroupName = groupName
                };

                GetDeviceInfo(model, level, token, groupId);

                List <string> msgList = UDPServer.当前消息列表;
                model.Messages = msgList.Select(t => new InstMessage {
                    MsgContent = t
                }).ToList();
                UDPServer.MessageStore("", false);

                string date = DateTime.Now.ToString("HH:mm:ss");
                model.SendLength = new DataLength()
                {
                    y = PubLib.SendDataLength, name = date
                };
                model.RecvLength = new DataLength()
                {
                    y = PubLib.RecvDataLength, name = date
                };

                if (SendLengthList.Count >= 50)
                {
                    SendLengthList.RemoveAt(0);
                    RecvLengthList.RemoveAt(0);
                }
                SendLengthList.Add(model.SendLength);
                RecvLengthList.Add(model.RecvLength);

                model.SendLengthList = SendLengthList;
                model.RecvLengthList = RecvLengthList;

                model.PerMinuteCount = UDPServer.PerMinuteCount;

                PubLib.SendDataLength = 0;
                PubLib.RecvDataLength = 0;

                //Clients.Client(connect.ConnectionId).PullInst(model);
                Clients.All.PullInst(model);
            }
            catch (Exception ex)
            {
                model.status = 0;
                model.msg    = ex.Message;
                Clients.All.PullInst(model);
            }
        }