Esempio n. 1
0
        public void TestSendBinDataCmd()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //todo:待测
            var fp     = @"../../files/test.txt";
            var fi     = new FileInfo(fp);
            var len    = fi.Length;
            var fs     = new FileStream(fp, FileMode.Open);
            var buffer = new byte[len];

            fs.Read(buffer, 0, (int)len);
            fs.Close();

            var req = new SendCmdRequest {
                DeviceID = 3081523, Protocol = Scheme.HTTP, CmdContent = buffer, IsByte = true
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            var body = JsonConvert.DeserializeObject <CmdSendResp>(rsp.Body);

            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(body.Data.Cmd_uuid);
        }
Esempio n. 2
0
        public void TestSendCmd()
        {
            var client = new DefaultOneNETClient(url, appkey, "");
            //todo:待测
            var req = new SendCmdRequest {
                DeviceID = 768719, Protocol = Scheme.HTTP, CmdContent = new { testpara = "test" }
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Cmd_uuid);
        }
Esempio n. 3
0
        public ActionResult CancelWarning(string code)
        {
            SmokeDetector detector = SmokeDetectorServices.LoadSmokeDetail(code);

            if (detector == null)
            {
                throw new BusinessException(string.Format("编号为【{0}】的设备不存在", code));
            }
            if (detector.Status != SmokeDetectorStatus.Warning && detector.Status != SmokeDetectorStatus.TestWarning)
            {
                throw new BusinessException(string.Format("编号为【{0}】的设备不是报警状态", code));
            }

            if (detector.Status == SmokeDetectorStatus.TestWarning)
            {
                //更新本地设备状态
                SmokeDetectorStatusLog lastLog   = SmokeDetectorServices.LoadSmokeDetectorStatusLogByDeviceCode(detector.Code);
                SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog()
                {
                    PreStatus         = detector.Status.Value,
                    Status            = SmokeDetectorStatus.CancelWarning,
                    BeginTime         = DateTimeHelper.GetTimeZoneNow(),
                    ReceivedJsonData  = "",
                    SmokeDetectorCode = detector.Code
                };
                detector.Status = SmokeDetectorStatus.CancelWarning;
                if (lastLog != null && statusLog.BeginTime.HasValue && lastLog.BeginTime.HasValue)
                {
                    statusLog.DurationSeconds = (int)(statusLog.BeginTime.Value - lastLog.BeginTime.Value).TotalSeconds;
                }
                //更新本地设备状态
                SmokeDetectorServices.UpdateSmokeDetector(detector);

                //更新首页数据
                (new MapDataService(detector.CompanySysNo)).DataChangeAsync();

                //写设备状态更改日志
                SmokeDetectorServices.InsertSmokeDetectorStatusLog(statusLog);
                return(Json(new AjaxResult()
                {
                    Success = true
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                SendCmdRequest send = new SendCmdRequest()
                {
                    Imei = detector.Code
                };
                SendCmdResponse sendRes = ONENETService.SendCmd(send);
                if (sendRes.IsSuccess)
                {
                    //更新本地设备状态
                    SmokeDetectorStatusLog lastLog   = SmokeDetectorServices.LoadSmokeDetectorStatusLogByDeviceCode(detector.Code);
                    SmokeDetectorStatusLog statusLog = new SmokeDetectorStatusLog()
                    {
                        PreStatus         = detector.Status.Value,
                        Status            = SmokeDetectorStatus.CancelWarning,
                        BeginTime         = DateTimeHelper.GetTimeZoneNow(),
                        ReceivedJsonData  = "",
                        SmokeDetectorCode = detector.Code
                    };
                    detector.Status = SmokeDetectorStatus.CancelWarning;
                    if (lastLog != null && statusLog.BeginTime.HasValue && lastLog.BeginTime.HasValue)
                    {
                        statusLog.DurationSeconds = (int)(statusLog.BeginTime.Value - lastLog.BeginTime.Value).TotalSeconds;
                    }
                    //更新本地设备状态
                    SmokeDetectorServices.UpdateSmokeDetector(detector);

                    //更新首页数据
                    (new MapDataService(detector.CompanySysNo)).DataChangeAsync();

                    //写设备状态更改日志
                    SmokeDetectorServices.InsertSmokeDetectorStatusLog(statusLog);
                    return(Json(new AjaxResult()
                    {
                        Success = true
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new AjaxResult()
                    {
                        Success = false, Message = "取消失败!"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
        }