示例#1
0
文件: FrmMain.cs 项目: littleking/DJK
        private string getRemoteDevice()
        {
            string     rtn            = "";
            string     controlAddress = ConfigurationManager.AppSettings["ControlAddress"].ToString();
            string     ip             = ReadAppSetting("OperatorIP");
            string     port           = ReadAppSetting("OperatorPort");
            string     localIP        = ReadAppSetting("LocalIP");
            string     localPort      = ReadAppSetting("LocalPort");
            RemoteJson rj             = new RemoteJson();

            using (var httpClient = new HttpClient())
            {
                //get
                string uri  = controlAddress + "?ip=" + ip + "&port=" + port + "&localIp=" + localIP + "&localPort=" + localPort;
                string data = "";
                try
                {
                    var url = new Uri(uri);
                    // response
                    var response = httpClient.GetAsync(url).Result;
                    data = response.Content.ReadAsStringAsync().Result.ToString();
                }catch (Exception ex)
                {
                    rtn = "调度服务出错";
                    return(rtn);
                }
                if (data == "{}")
                {
                    rtn = "";
                }
                else
                {
                    // JObject jo = (JObject)JsonConvert.DeserializeObject(data);
                    //string decodeRtn = jo["json"].ToString();
                    //rtn = jo["json"].ToString(); //HttpUtility.UrlDecode(decodeRtn, System.Text.Encoding.GetEncoding("utf-8"));
                    rtn = data;
                }
                return(rtn);
            }
        }
示例#2
0
文件: FrmMain.cs 项目: littleking/DJK
        private void msgTick()
        {
            try
            {
                if (operatorStatus == 1)
                {
                    jsonMsg = getRemoteDevice();
                    if (jsonMsg == "调度服务出错")
                    {
                        this.BeginInvoke(updateTxt, "调度服务出错。。。。");
                    }
                    else
                    {
                        if (jsonMsg != "")
                        {
                            RemoteJson rj = JsonConvert.DeserializeObject <RemoteJson>(jsonMsg);
                            waitedSN             = rj.deviceSN;
                            Patient.w_birth_day  = rj.patientDOB;
                            Patient.w_code       = rj.verifyCode;
                            Patient.w_location   = FromBase64(rj.patientLocation);
                            Patient.w_name       = FromBase64(rj.patientName);
                            Patient.w_sex        = rj.patientSex;
                            Patient.w_username   = rj.userName;
                            Patient.w_deviceSN   = rj.deviceSN;
                            Patient.w_deviceCode = FromBase64(rj.deviceName);

                            operatorStatus = 2;
                            this.BeginInvoke(updateTxt, "远程设备信息已接收,等待远程设备" + waitedSN + "接入。。。。");
                            deviceTimer.Enabled = true;
                            msgTimer.Enabled    = false;
                            dtTimeOut           = DateTime.Now.AddMinutes(3);


                            string result = "";
                            string cmd    = @"usbrcd.exe -list";
                            CmdHelper.RunCmd(cmd, out result);
                            List <string> msglist = GetResult(result);
                            if (msglist.Count == 8)
                            {
                                if (msglist[2].Contains("callback connection") && msglist[7].Contains("available for connection"))
                                {
                                    usbPort     = getUsbPort(msglist);
                                    connectedSN = getDeviceSN(msglist);
                                    if (waitedSN != "" && waitedSN == connectedSN)
                                    {
                                        this.btnConnect.Enabled = true;
                                        this.BeginInvoke(updateTxt, "远程设备已接入,可以连接。。。");
                                        connectRemoteDevice();
                                    }
                                }
                            }
                        }
                        else
                        {
                            this.BeginInvoke(updateTxt, "已上线,等待远程设备信息。。。。");
                        }
                    }
                }
            }catch (Exception ex)
            {
                LogHelper.WriteLog(ex.ToString());
            }
        }