コード例 #1
0
        public IActionResult Load()
        {
            List <ComponentViewModel> list = new List <ComponentViewModel>();
            string identity = "";

            if (base.user.IsLandHome)
            {
                identity = base.user.ShipId;
            }
            List <Models.Component> components = new List <Models.Component>();
            SendDataMsg             assembly   = new SendDataMsg();

            assembly.SendComponentQuery(identity);
            ProtoBuffer.Models.ComponentResponse response = new ProtoBuffer.Models.ComponentResponse();
            //Task.WhenAny();
            bool flag = true;

            new TaskFactory().StartNew(() =>
            {
                while (ManagerHelp.ComponentReponse == "" && flag)
                {
                    Thread.Sleep(100);
                }
            }).Wait(3000);
            flag = false;
            try
            {
                if (ManagerHelp.ComponentReponse != "")
                {
                    response = JsonConvert.DeserializeObject <ProtoBuffer.Models.ComponentResponse>(ManagerHelp.ComponentReponse);
                    ManagerHelp.ComponentReponse = "";
                    if (response.result == 0 && response.componentinfos != null && response.componentinfos.Count > 0)
                    {
                        SaveData(response.componentinfos);
                        foreach (var item in response.componentinfos)
                        {
                            if (item.componentid == ManagerHelp.ComponentId)
                            {
                                continue;
                            }
                            ComponentViewModel model = new ComponentViewModel()
                            {
                                Id   = item.componentid,
                                name = item.cname,
                                type = (int)item.type
                            };
                            list.Add(model);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            var data = new
            {
                code = 0,
                data = list
            };

            return(new JsonResult(data));
        }
コード例 #2
0
        /// <summary>
        /// 设备界面显示
        /// </summary>
        /// <param name="isShow"></param>
        /// <param name="id">不为空时是陆地端跳转</param>
        /// <param name="shipName"></param>
        /// <returns></returns>
        public IActionResult Index(bool isShow = false, string id = "", string shipName = "")
        {
            if (!string.IsNullOrEmpty(id))
            {
                string browsertoken = HttpContext.Request.Cookies["token"];
                if (browsertoken != null)
                {
                    string urlstr = HttpContext.Session.GetString(browsertoken);
                    user            = JsonConvert.DeserializeObject <UserToken>(urlstr);
                    user.ShipId     = id;
                    user.IsLandHome = true;
                    user.ShipName   = shipName;
                    string userStr = JsonConvert.SerializeObject(user);
                    //将请求的url注册
                    HttpContext.Session.SetString(browsertoken, userStr);
                    //写入浏览器token
                    HttpContext.Response.Cookies.Append("token", browsertoken);
                }
                //陆地端过来不显示报警信息
                ManagerHelp.IsShowAlarm = false;
                ManagerHelp.isInit      = false;
                ViewBag.LoginName       = base.user.Name;
                ViewBag.ShipName        = base.user.ShipName;
                ViewBag.src             = "/Device/Index";
                ViewBag.layuithis       = "device";

                #region 缓存当前船下的组件信息,提供给设备,算法,船员,船状态操作
                assembly.SendComponentQuery(id);
                bool flag = true;
                new TaskFactory().StartNew(() =>
                {
                    while (ManagerHelp.ComponentReponse == "" && flag)
                    {
                        Thread.Sleep(1000);
                    }
                    if (ManagerHelp.ComponentReponse != "")
                    {
                        ProtoBuffer.Models.ComponentResponse response = JsonConvert.DeserializeObject <ProtoBuffer.Models.ComponentResponse>(ManagerHelp.ComponentReponse);
                        ManagerHelp.ComponentReponse = "";
                        List <ComponentToken> tokens = new List <ComponentToken>();
                        if (response.result == 0 && response.componentinfos != null)
                        {
                            foreach (var item in response.componentinfos)
                            {
                                ComponentToken token = new ComponentToken()
                                {
                                    Id = item.componentid,
                                    //CommId = item.commid,
                                    Name = item.cname,
                                    Type = (ComponentType)item.type
                                };
                                tokens.Add(token);
                            }
                        }
                        string com = JsonConvert.SerializeObject(tokens);
                        HttpContext.Session.SetString("comtoken", com);
                    }
                }).Wait(timeout);
                flag = false;
                #endregion
            }
            ViewBag.IsLandHome   = base.user.IsLandHome;
            ViewBag.IsShowLayout = isShow;
            ViewBag.IsSet        = base.user.EnableConfigure;
            return(View());
        }