Beispiel #1
0
        /// <summary>
        /// 陆地端查看设备信息
        /// </summary>
        /// <returns></returns>
        private IActionResult LandLoad()
        {
            List <Device> list = new List <Device>();
            //XMQ的组件ID
            string XMQComId = base.user.ShipId;
            string tokenstr = HttpContext.Session.GetString("comtoken");
            //获取XMQ组件里的WEB组件ID
            string webIdentity = ManagerHelp.GetLandToId(tokenstr);
            var    result      = new
            {
                code  = 0,
                data  = list,
                isSet = !string.IsNullOrEmpty(base.user.ShipId) ? base.user.EnableConfigure : false
            };

            if (webIdentity == "")
            {
                return(new JsonResult(result));
            }
            //发送查询设备请求
            assembly.SendDeveiceQuery(XMQComId + ":" + webIdentity);
            bool flag = true;

            new TaskFactory().StartNew(() =>
            {
                while (flag && ManagerHelp.DeviceReponse == "")
                {
                    Thread.Sleep(500);
                }
            }).Wait(timeout);
            flag = false;
            if (ManagerHelp.DeviceReponse != "")
            {
                List <ProtoBuffer.Models.DeviceInfo> devices = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.DeviceInfo> >(ManagerHelp.DeviceReponse);
                ManagerHelp.DeviceReponse = "";
                foreach (var item in devices)
                {
                    Device model = new Device()
                    {
                        Enable   = item.enable,
                        factory  = (Device.Factory)((int)item.factory),
                        Id       = item.did,
                        IP       = item.ip,
                        Name     = item.name,
                        Nickname = item.nickname,
                        Password = item.password,
                        Port     = item.port,
                        type     = (Device.Type)((int)item.type)
                    };
                    var cam = item.camerainfos;
                    model.CameraModelList = new List <Camera>();
                    if (cam != null)
                    {
                        foreach (var it in cam)
                        {
                            model.CameraModelList.Add(new Camera()
                            {
                                Index    = it.index,
                                Id       = it.cid,
                                Enable   = it.enable,
                                IP       = it.ip,
                                NickName = it.nickname,
                                DeviceId = item.did
                            });
                        }
                    }
                    list.Add(model);
                }
            }
            //var result = new
            //{
            //    code = 0,
            //    data = list,
            //    isSet = !string.IsNullOrEmpty(base.user.ShipId) ? base.user.EnableConfigure : false
            //};
            return(new JsonResult(result));
        }
        public IActionResult LandLoad()
        {
            string identtity    = base.user.ShipId;
            string browsertoken = HttpContext.Session.GetString("comtoken");
            string webId        = ManagerHelp.GetLandToId(browsertoken);
            List <AlgorithmViewModel> algorithms = new List <AlgorithmViewModel>();
            List <ProtoBuffer.Models.AlgorithmInfo> protoDate = new List <ProtoBuffer.Models.AlgorithmInfo>();

            if (string.IsNullOrEmpty(webId))
            {
                return(new JsonResult(new { code = 0, data = algorithms }));
            }
            assembly.SendAlgorithmQuery(identtity + ":" + webId);
            assembly.SendDeveiceQuery(identtity + ":" + webId);
            bool flag = true;

            new TaskFactory().StartNew(() =>
            {
                while (flag)
                {
                    if (ManagerHelp.AlgorithmReponse != "" && ManagerHelp.DeviceReponse != "")
                    {
                        flag = false;
                    }
                    Thread.Sleep(100);
                }
            }).Wait(timeout);
            flag = false;
            try
            {
                if (ManagerHelp.AlgorithmReponse != "")
                {
                    protoDate = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.AlgorithmInfo> >(ManagerHelp.AlgorithmReponse);
                }
                if (ManagerHelp.DeviceReponse != "")
                {
                    boatDevices = JsonConvert.DeserializeObject <List <ProtoBuffer.Models.DeviceInfo> >(ManagerHelp.DeviceReponse);
                }
                ManagerHelp.AlgorithmReponse = "";
                ManagerHelp.DeviceReponse    = "";
            }
            catch (Exception)
            {
            }
            cameras = new List <Camera>();
            foreach (var item in boatDevices)
            {
                if (item.camerainfos != null)
                {
                    foreach (var cam in item.camerainfos)
                    {
                        Camera model = new Camera()
                        {
                            Id       = cam.cid,
                            NickName = cam.nickname,
                            DeviceId = item.did,
                            Index    = cam.index
                        };
                        cameras.Add(model);
                    }
                }
            }
            foreach (var item in protoDate)
            {
                string cid      = item.cid;
                string nickName = "";
                if (cameras.Where(c => c.Id == cid).Any())
                {
                    nickName = cameras.FirstOrDefault(c => c.Id == cid).NickName;
                }
                algorithms.Add(new AlgorithmViewModel()
                {
                    Cid           = cid,
                    NickName      = nickName,
                    DectectFirst  = item.dectectfirst,
                    DectectSecond = item.dectectsecond,
                    GPU           = item.gpu,
                    Id            = item.aid,
                    Similar       = item.similar,
                    Track         = item.track,
                    Type          = (int)item.type
                });
            }

            var result = new
            {
                code   = 0,
                data   = algorithms,
                camera = cameras
            };

            return(new JsonResult(result));
        }