Esempio n. 1
0
        public DataAcquisitionResult SaveRunningState([FromBody] RunningStateAPIParameterA param)
        {
            DataAcquisitionResult result = new DataAcquisitionResult();

            result.code = "1000";
            result.msg  = "success";
            if (param == null)
            {
                param = new RunningStateAPIParameterA();
                this.Request.GetQueryNameValuePairs();

                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context
                HttpRequestBase request = context.Request;                                       //定义传统request对象
                param.operator_name = request.Form["operator_name"];
                param.operator_time = request.Form["operator_time"];
                param.sign          = request.Form["sign"];
                param.strdata       = request.Form["strdata"];

                LogHelper.Info("WebApi-SaveRunningState param from forms");
            }
            //else LogHelper.Info(string.Format("WebApi-SaveDataAcquisition param from body{0}", Serialize(param)));
            if (!VerifyMiddleSign(param.operator_name, param.operator_time, param.sign))
            {
                LogHelper.Info(string.Format("operator_name{0},operation_time{1},sign{2}", param.operator_name, param.operator_time, param.sign));
                result.msg  = "签名错误";
                result.code = "1040";
                return(result);
            }
            RunningStateDTOA dto = new RunningStateDTOA();

            try
            {
                dto = Deserialize <RunningStateDTOA>(param.strdata);
                bool fla = InsertRunningState(dto);
                if (!fla)
                {
                    LogHelper.Error(string.Format("新增失败-SaveRunningState:{0}", Serialize(dto)));
                    //result.msg = "数据插入失败";
                    //result.code = "1050";
                    //return result;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                result.msg  = ex.Message;
                result.code = "1060";
                return(result);
            }
            return(result);
        }
Esempio n. 2
0
        private void button6_Click(object sender, EventArgs e)
        {
            DataAcquisitionResult result = new DataAcquisitionResult();
            RunningStateDTOA      dto    = new RunningStateDTOA();

            dto.Describe1      = "CNC1发那科<br>运行中";
            dto.DescribeColor1 = "#23ab33";
            dto.Describe2      = "CNC2发那科<br>运行中";
            dto.DescribeColor2 = "#23ab33";
            dto.Describe3      = "CNC3发那科<br>待机";
            dto.DescribeColor3 = "yellow";
            dto.Describe4      = "CMM2海克斯康<br>离线";
            dto.DescribeColor4 = "#c8c8c8";
            dto.Describe5      = "Robot<br>未就绪";
            dto.DescribeColor5 = "#0fcdfd";
            dto.Describe6      = "清洗机<br>待机";
            dto.DescribeColor6 = "#0865e3";

            string server = "http://localhost:15988/api/AutomationLine/SaveRunningState";
            RunningStateAPIParameterA param = new RunningStateAPIParameterA();

            param.operator_name = "WebApi";
            param.operator_time = GenerateTimeStamp(DateTime.Now);
            param.sign          = GenSign(param.operator_name, param.operator_time);
            param.data          = dto;
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("operator_name", param.operator_name);
            dic.Add("operator_time", param.operator_time);
            dic.Add("sign", param.sign);
            dic.Add("strdata", Serialize(param.data));

            try
            {
                HttpWebResponse        response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null);
                System.IO.StreamReader sr       = new System.IO.StreamReader(response.GetResponseStream());
                string responseContent          = sr.ReadToEnd();
                sr.Close();

                DataAcquisitionResult rtn = Deserialize <DataAcquisitionResult>(responseContent);
                if (rtn.code != "1000")
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }