コード例 #1
0
 /// <summary>
 /// 组件初使化
 /// 发送组件注册
 /// 发送组件查询
 /// 收到开启组件后发送船状态设置
 /// 发送设备信息
 /// 收到设备成功消息后发送算法配置
 /// 发送船员信息
 /// </summary>
 public void InitData()
 {
     //发送组件注册请求
     assembly.SendComponentSign("WEB", "");
     Task.Factory.StartNew(state =>
     {
         while (ManagerHelp.Cid == "")
         {
             Thread.Sleep(1000);
         }
         //发送查询请求
         assembly.SendComponentQuery(ManagerHelp.Cid);
         Task.Factory.StartNew(state =>
         {
             while (ManagerHelp.ComponentReponse == "")
             {
                 Thread.Sleep(1000);
             }
             InitStatus();
             InitDevice();
             ManagerHelp.ComponentReponse = "";
             if (ManagerHelp.isInit)
             {
                 Task.Factory.StartNew(t =>
                 {
                     while (ManagerHelp.DeviceResult == "")
                     {
                         Thread.Sleep(1000);
                     }
                     //发送算法信息
                     InitAlgorithm();
                     //发送船员信息
                     InitCrew();
                     ManagerHelp.isInit       = false;
                     ManagerHelp.DeviceResult = "";
                 }, TaskCreationOptions.LongRunning);
             }
         }, TaskCreationOptions.LongRunning);
     }, TaskCreationOptions.LongRunning);
     ManagerHelp.isInit  = true;
     ManagerHelp.atWorks = new List <AtWork>();
     ManagerHelp.UpSend  = new List <string>();
 }
コード例 #2
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));
        }
コード例 #3
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());
        }
コード例 #4
0
ファイル: ShipController.cs プロジェクト: Colinwang531/web
        /// <summary>
        /// 陆地端获取船信息
        /// </summary>
        /// <returns></returns>
        public IActionResult LoadAll()
        {
            try
            {
                List <ShipViewModel> list = new List <ShipViewModel>();
                //var compents = _context.Component.Where(c => c.Type == ComponentType.XMQ).ToList();
                var compents = from a in _context.Component
                               join b in _context.Ship on a.ShipId equals b.Id into c
                               from d in c.DefaultIfEmpty()
                               where a.Type == ComponentType.XMQ
                               select new
                {
                    a.Cid,
                    a.ShipId,
                    a.Line,
                    d.Name,
                    d.Flag
                };

                foreach (var item in compents)
                {
                    ShipViewModel model = new ShipViewModel()
                    {
                        Id   = item.Cid,
                        Name = item.Name,
                        flag = item.Flag,
                        Line = item.Line == 0 ? true : false//默认离线
                    };
                    list.Add(model);
                }
                var comLine = compents.Where(c => c.Line == 0).ToList();
                Console.WriteLine("异步执行开始:" + DateTime.Now);
                new TaskFactory().StartNew(() =>
                {
                    Console.WriteLine("异步执行方法:" + DateTime.Now);
                    foreach (var item in comLine)
                    {
                        //根据当前XMQ的ID
                        assembly.SendComponentQuery(item.Cid);
                        Task.Factory.StartNew(state => {
                            while (ManagerHelp.ComponentReponse == "")
                            {
                                Thread.Sleep(10);
                            }
                            var webcom   = JsonConvert.DeserializeObject <ProtoBuffer.Models.ComponentResponse>(ManagerHelp.ComponentReponse);
                            string webId = "";
                            if (webcom != null && webcom.componentinfos.Count > 0)
                            {
                                var web = webcom.componentinfos.FirstOrDefault(c => c.type == ComponentInfo.Type.WEB);
                                if (web != null)
                                {
                                    webId = web.componentid;
                                }
                            }
                            if (webId != "")
                            {
                                assembly.SendStatusQuery(item.Cid + ":" + webId);
                                Task.Factory.StartNew(ss => {
                                    while (ManagerHelp.StatusReponse == "")
                                    {
                                        Thread.Sleep(10);
                                    }
                                    var response = JsonConvert.DeserializeObject <StatusResponse>(ManagerHelp.StatusReponse);
                                    if (response != null)
                                    {
                                        list.FirstOrDefault(c => c.Id == item.Cid).flag = response.flag;
                                        LandSave(response, item.ShipId);
                                    }
                                }, TaskCreationOptions.LongRunning);
                            }
                        }, TaskCreationOptions.LongRunning);
                    }
                    Console.WriteLine("结束:" + DateTime.Now);
                }).Wait(5000);
                Console.WriteLine("完成:" + DateTime.Now);
                var result = new
                {
                    code  = 0,
                    data  = list,
                    isSet = base.user.EnableConfigure
                };
                return(new JsonResult(result));
            }
            catch (Exception ex)
            {
                _logger.LogError("陆地端获取船信息异常【LoadAll】" + ex.Message);
                return(new JsonResult(new { code = 1, msg = "获取数据失败!" + ex.Message }));
            }
        }