Ejemplo n.º 1
0
        //定时器轮询方法
        public void Run()
        {
            /*
             * if (setterDao.ListAll() == null)
             * {
             *  //网路不通 或 未注册 不上传
             *  return;
             * }*/

            //Console.WriteLine("大数据线程实例化run方法-执行:");
            var result = uploadManagementService.ListLimit20();

            if (result == null)
            {
                ;//Console.WriteLine("大数据线程RUN方法-result==null");
            }
            foreach (var uploadManagementone in result)
            {
                SendMsgDTO       sendMsgDto       = new SendMsgDTO();
                UploadManagement uploadManagement = new UploadManagement();
                uploadManagement = uploadManagementone;


                //选择是那一个类,将类名进行赋值
                switch (uploadManagement.UM_DataTable)
                {
                case "bdl_activity":
                    sendMsgDto.dataType = "ActivityEntity";
                    break;

                case "bdl_member":
                    sendMsgDto.dataType = "MemberEntity";
                    break;

                case "bdl_personal_setting":
                    sendMsgDto.dataType = "PersonalSettingEntity";
                    break;

                case "bdl_skeleton_length":
                    sendMsgDto.dataType = "SkeletonLengthEntity";
                    break;

                case "bdl_system_setting":
                    sendMsgDto.dataType = "SystemSettingEntity";
                    break;

                case "bdl_training_activity_record":
                    sendMsgDto.dataType = "TrainingActivityRecordEntity";
                    break;

                case "bdl_training_course":
                    sendMsgDto.dataType = "TrainingCourseEntity";
                    break;

                case "bdl_training_device_record":
                    sendMsgDto.dataType = "TrainingDeviceRecordEntity";
                    break;

                case "bdl_training_plan":
                    sendMsgDto.dataType = "TrainingPlanEntity";
                    break;

                default:
                    Console.WriteLine("没有这个表");
                    Console.WriteLine(uploadManagement.UM_DataTable);
                    break;
                }

                //sendMsgDto.dataType = "TrainingCourseEntity";


                sendMsgDto.dataExec      = uploadManagement.UM_Exec;
                sendMsgDto.dataId        = uploadManagement.UM_DataId;
                sendMsgDto.belongProduct = "aisport";
                //sendMsgDto.content = JsonTools.Obj2JSONStrNew <TrainingCourseEntity>
                // Console.WriteLine("大数据线程实例化Upload方法-table:" + uploadManagement.UM_DataTable);
                //1.查询
                ServiceResult serviceResult = uploadManagementService.GetServiceResult(uploadManagement);
                sendMsgDto.content = serviceResult.Data;
                int i = 1;
                Console.WriteLine("这里是上传表的每一条内容" + i + "数字" + uploadManagement.Pk_UM_Id + uploadManagement.UM_DataId + uploadManagement.UM_Exec);
                i++;
                if (serviceResult == null)
                {
                    //没有查到返回
                    Console.WriteLine("没有查到信息");
                    return;
                }
                //用于接受云服务器端返回的字符串
                string strWebResult = "";
                //创建一个新的用来接受服务器端返回结果的实体类对象
                WebResult webResult = new WebResult();
                //固定的url
                serviceResult.URL = "msg";


                serviceResult.Data = JsonTools.Obj2JSONStrNew <SendMsgDTO>(sendMsgDto);

                try
                {
                    //2.上传
                    //返回的值
                    strWebResult = HttpSender.POSTByJsonStr(serviceResult.URL, serviceResult.Data);
                }
                catch
                {
                    Console.WriteLine("发送失败");
                }

                if (strWebResult != null && strWebResult != "")
                {
                    //将接受云服务器的字符串装换成实体类对象
                    webResult = JsonTools.DeserializeJsonToObject <WebResult>(strWebResult);
                    //3.根据结果删除,返回信息中是否包括0和1,包括就删除

                    if (webResult.result == "0")
                    {
                        uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                    }
                    else
                    if (webResult.result == "1")
                    {
                        uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                    }
                    else
                    if (webResult.result == "2")
                    {
                        break;//不做处理,五分钟后再发,目的是等待云服务器建表
                    }
                }
                else
                {
                    Console.WriteLine("云端返回为空");
                    //return;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 异步进程与UI更新
        /// </summary>

        #region 绑定通知公告
        private void BindNotice()
        {
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                try
                {
                    //如果用户没有被上传则return,不允许发心跳,否则就按照不合法冻结了
                    if (new UploadManagementDAO().CheckExistAuth() != null)
                    {
                        return;
                    }

                    HeartBeatOffice heartBeatOffice = new HeartBeatOffice();
                    HttpHeartBeat result            = heartBeatOffice.GetHeartBeatByCurrent();
                    //心跳直接上传   !HttpSender.Ping() ||
                    if (result == null)
                    {
                        //如果没有取到值
                        return;
                    }
                    string jsonStr = HttpSender.POSTByJsonStr("communicationController/analysisJson",
                                                              JsonTools.Obj2JSONStrNew <HttpHeartBeat>(result));
                    HttpHeartBeat webResult = JsonTools.DeserializeJsonToObject <HttpHeartBeat>(jsonStr);
                    //本地数据更改
                    if (webResult == null)
                    {
                        return;
                    }
                    heartBeatOffice.SolveHeartbeat(webResult);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (webResult.authStatus == 0)
                        {
                            //正常心跳不处理
                        }
                        else if (webResult.authStatus == 1)
                        {
                            //冻结,弹窗,然后关闭窗口
                            // 程序强制退出
                            authDao.UpdateByUserName(webResult.username, 1);
                            // 停止定时器
                            timerNotice.Stop();

                            MessageBoxX.Warning(LanguageUtils.ConvertLanguage("用户被冻结,即将退出,请联系宝德龙管理员解冻!", "The user is frozen, will exit, please contact the administrator thaw!"));
                            Environment.Exit(0);
                        }
                        else if (webResult.authStatus == 2)
                        {
                            //解冻,只需要更改数据库。界面无反馈,不处理
                            //authDao.UpdateByUserName(webResult.username, 2);
                        }
                        else if (webResult.authStatus == 3)
                        {
                            //永久离线,只需要更改数据库。界面无反馈,不处理
                            //authDao.UpdateByUserName(webResult.username, 3);
                        }
                        else if (webResult.authStatus == 4)
                        {
                            //已删除,按照冻结处理
                            //authDao.UpdateByUserName(webResult.username, 1);

                            timerNotice.Stop();
                            MessageBoxX.Warning(LanguageUtils.ConvertLanguage("用户被删除,即将退出,请联系宝德龙管理员恢复!", "The user is removed, will exit, please contact the administrator to restore!"));
                            Environment.Exit(0);
                        }
                    }));
                }
                catch
                {
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 应用启动的时候生命周期
        /// </summary>
        /// <param name="ex"></param>
        protected override void OnStartup(StartupEventArgs ex)
        {
            //全局异常处理机制,UI异常
            Current.DispatcherUnhandledException += App_OnDispatcherUnhandledException;
            //全局异常处理机制,线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            //加载语言
            LanguageUtils.SetLanguage();

            //启动netty,用于与设备端通信
            Thread th = new Thread(() =>
            {
                try
                {
                    logger.Info("线程启动成功");
                    NettyLuncher.getInstance().Start().Wait();
                }
                catch (AggregateException ee)
                {
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        MessageBoxX.Info(LanguageUtils.GetCurrentLanuageStrByKey("App.PortOccupy"));
                        System.Environment.Exit(0);
                    }));
                }
            });

            th.Start();


            //启动远程更新
            Thread updateTh = new Thread(() =>
            {
                try
                {
                    Thread.Sleep(1000 * 8);
                    Dictionary <string, string> param = new Dictionary <string, string>();

                    param.Add("version", CommUtil.GetCurrentVersion());
                    var result = HttpSender.GET(HttpSender.URL_UPDATE, param);
                    if (string.IsNullOrEmpty(result))
                    {
                        return;
                    }
                    var info = JsonTools.DeserializeJsonToObject <VersionInfo>(result);
                    if (info == null || info.update == false)
                    {
                        return;
                    }

                    info.language = LanguageUtils.IsChainese() ? 1 : 0;
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        Boolean dr = MessageBoxX.Question(LanguageUtils.GetCurrentLanuageStrByKey("App.UpdateInfo"));
                        if (dr == true)
                        {
                            Process.Start("AutoUpdater.exe", info.GetProcessString());
                            Environment.Exit(0);
                        }
                    }));
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.ToString());
                    return;
                }
            });

            updateTh.Start();



            //大数据线程

            Thread bdth = new Thread(() =>
            {
                try
                {
                    SetterDAO setterDao = new SetterDAO();
                    AuthDAO authDAO     = new AuthDAO();
                    while (true)
                    {
                        if (setterDao.ListAll().Count != 1)
                        {
                            //不激活不开启
                            Thread.Sleep(1000 * 15);
                            continue;
                        }
                        if (authDAO.ListAll().Count == 1)
                        {
                            //Console.WriteLine("-----------------boom shakalaka--------------");
                            //只有admin,不创建用户,不开启,睡个15s
                            Thread.Sleep(1000 * 15);
                            continue;
                        }
                        try
                        {
                            BigDataOfficer bigDataOfficer = new BigDataOfficer();
                            bigDataOfficer.Run();
                            //int heartBeatRate = (int)CommUtil.GetBigDataRate();
                            Thread.Sleep(1000 * 60);
                            //Console.WriteLine("-----------------boom");
                        }
                        catch (Exception e)
                        {
                            logger.Error("大数据线程失败:" + e.StackTrace);
                            Console.WriteLine("大数据线程失败:" + e.Message);
                        }
                    }
                }
                catch (Exception exct)
                {
                    Console.WriteLine(exct.ToString());
                }
            });

            bdth.Start();

            //心跳线程
            Thread hbth = new Thread(() =>
            {
                ProtoBufSocket socket = null;
                try
                {
                    socket = new ProtoBufSocket();
                    socket.Connect();
                }
                catch (Exception exception)
                {
                    Console.WriteLine("连接失败:" + exception.StackTrace);
                    TcpHeartBeatUtils.WriteLogFile("连接失败:" + exception.StackTrace);
                }

                while (true)
                {
                    try
                    {
                        BodyStrongMessage bodyStrongMessage = new BodyStrongMessage
                        {
                            MessageType = BodyStrongMessage.Types.MessageType.Heaerbeatreq,
                            //可能为null
                            HeartbeatRequest = TcpHeartBeatUtils.GetHeartBeatByCurrent()
                        };

                        socket.SendMessage(bodyStrongMessage);
                        Console.WriteLine("发送msg!!");
                        //Thread.Sleep(5000);
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine("发送msg失败" + eee.StackTrace);
                        TcpHeartBeatUtils.WriteLogFile("发送msg失败" + eee.StackTrace);
                    }
                    finally
                    {
                        Thread.Sleep(5000);
                    }
                }
            });

            hbth.Start();

            base.OnStartup(ex);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 定时器轮询方法
        /// </summary>
        /// <param name="threadCount"></param>
        ///
        public void Run()
        {
            if (setterDao.ListAll() == null)
            {
                //网路不通 或 未注册 不上传//Console.WriteLine("大数据线程实例化run方法-执行:");

                return;
            }



            //从上传表查询30条数据
            var result = uploadManagementService.ListLimit30();

            if (result == null)
            {
                Console.WriteLine("大数据线程RUN方法-result==null");
            }
            //遍历查询到的数据集合
            foreach (var uploadManagement in result)
            {
                //生成新的SendMsgDTO对象(上传云平台的最终对象)
                SendMsgDTO sendMsgDto = new SendMsgDTO();

                //根据表名,给字段dataType(数据所在实体类)赋值
                switch (uploadManagement.UM_DataTable)
                {
                case "bdl_auth":
                    sendMsgDto.dataType = "Auther";
                    break;

                case "bdl_customdata":
                    sendMsgDto.dataType = "CustomData";
                    break;

                case "bdl_datacode":
                    sendMsgDto.dataType = "DataCode";
                    break;

                case "bdl_deviceprescription":
                    sendMsgDto.dataType = "DevicePrescription";
                    break;

                case "bdl_deviceset":
                    sendMsgDto.dataType = "DeviceSet";
                    break;

                case "bdl_devicesort":
                    sendMsgDto.dataType = "DeviceSort";
                    break;

                case "bdl_onlinedevice":
                    sendMsgDto.dataType = "OnlineDevice";
                    break;

                case "bdl_physicalpower":
                    sendMsgDto.dataType = "PhysicalPower";
                    break;

                case "bdl_prescriptionresult":
                    sendMsgDto.dataType = "PrescriptionResult";
                    break;

                case "bdl_set":
                    sendMsgDto.dataType = "Setter";
                    break;

                case "bdl_symptominfo":
                    sendMsgDto.dataType = "SymptomInfo";
                    break;

                case "bdl_traininfo":
                    sendMsgDto.dataType = "TrainInfo";
                    break;

                case "bdl_user":
                    sendMsgDto.dataType = "User";
                    break;

                case "bdl_error":
                    sendMsgDto.dataType = "Error";
                    break;

                default:
                    Console.WriteLine("没找到对应的表");
                    //Console.WriteLine(uploadManagement.UM_DataTable);
                    break;
                }

                sendMsgDto.dataExec      = uploadManagement.UM_Exec;   //操作方式 0是add(insert) 1是update
                sendMsgDto.dataId        = uploadManagement.UM_DataId; //数据的id
                sendMsgDto.belongProduct = "Recovery";                 //项目名称必须是这个,与云平台相一致
                if (sendMsgDto.dataType == "Error")
                {
                    sendMsgDto.belongProduct = "RecoveryError";
                }


                // Console.WriteLine("大数据线程实例化Upload方法-table:" + uploadManagement.UM_DataTable);
                //1.根据上传表内容查询具体数据(这里的数据是已经转换成json串形式),赋值给字段content
                ServiceResult serviceResult = null;
                try
                {
                    serviceResult = uploadManagementService.GetServiceResult(uploadManagement);
                }
                catch (Exception e)
                {
                    logger.Error("uploadManagement上传云平台失败");
                }

                /*
                 * int i = 1;
                 * Console.WriteLine("这里是上传表的每一条内容" + i + "数字" + uploadManagement.Pk_UM_Id + uploadManagement.UM_DataId + uploadManagement.UM_Exec);
                 * i++;*/
                if (serviceResult == null)
                {
                    //没有查到返回
                    Console.WriteLine("上传表查询失败____________________");
                    logger.Error("上传表查询失败," + DateTime.Now.ToString());
                    continue;
                }
                sendMsgDto.content = serviceResult.Data;
                //用于接受云服务器端返回的字符串
                string strWebResult = "";
                //创建一个新的用来接受服务器端返回结果的对象
                WebResult webResult = new WebResult();

                //这里是url的后缀,每一条数据都是发送到这个地方
                serviceResult.URL = "msg";

                //将发送的实体类SendMsgDTO装成json串
                serviceResult.Data = JsonTools.Obj2JSONStrNew <SendMsgDTO>(sendMsgDto);

                //2.上传和接受云服务器端返回的字符串
                //strWebResult = HttpSender.POSTByJsonStr(serviceResult.URL, serviceResult.Data);
                strWebResult = HTTPClientHelper.HttpPost(serviceResult.Data);

                //将接受到的字符串赋值给webResult对象
                webResult = JsonTools.DeserializeJsonToObject <WebResult>(strWebResult);

                //Console.WriteLine("线程"+ threadCount +"   id: "+webResult.dataId +"type: "+ webResult.dataType + "结果:"+webResult.result);


                //3.根据返回结果删除
                //返回值result为0或1删除上传表所对应的的内容,2则跳出循环,不做处理,隔五分钟再次上传
                if (webResult.result == "0")
                {
                    uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                }
                else
                if (webResult.result == "1")
                {
                    uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                }
                else
                if (webResult.result == "2")
                {
                    Console.WriteLine("线程");
                    break;//不做处理,五分钟后再发,目的是等待云服务器建表
                }
                else
                {
                    logger.Error("失败的内容:" + webResult.result + "," + DateTime.Now.ToString());
                    //Console.WriteLine("失败的内容:" + webResult.result);
                }
                //Console.WriteLine("-----------------------------返回结果 dataid"+webResult.dataId +"type:"+webResult.dataType+"result:"+webResult.result);
            }
        }