AGVManager.cs 3.2 KB
using BLL.BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace BLL
{
    public class AGVManager
    {

        //public static string Add_emptyMsg = "http://10.85.199.1/BenQMIR/Webservice/AGVService.asmx/CreateEmptyRecycleTask";//"http://localhost:11111/BenQMIR/Webservice/AGVService.asmx/CreateEmptyRecycleTask";//
        public static string CreateEmptyTask(string Add_emptyMsg, string line)
        {
            try
            {
                //Dictionary<string, string> paramMap = new Dictionary<string, string>();
                //paramMap.Add("emptyStation", "D1");
                string path = Add_emptyMsg;
                //foreach (string paramName in paramMap.Keys)
                //{
                //    string par = System.Web.HttpUtility.UrlEncode(paramMap[paramName], System.Text.Encoding.UTF8);
                //    path += paramName + "=" + par + "&";
                //}
                //path = path.Substring(0, path.Length - 1);

                string resultStr = HttpUtil.Post(path, "emptyStation=" + line);//HttpHelper.Post(path, "");
                //Common.log.Debug("【" + path + "】【" + resultStr + "】");

                //Result data = JsonHelper.DeserializeJsonToObject<Result>(resultStr);
                return resultStr;
                //if (data == null)
                //{
                //    return " updateDeviceAlarmMsg 没有收到服务器反馈";
                //}
                //else
                //{
                //    return data.Succeed;
                //}
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }



        public static Result GetWebservice(string Add_emptyMsg,string id)
        {
            Result rb = new Result();
            try
            {
                //http://10.85.36.156/BenQMIR/Webservice/AGVService.asmx
                string strURL = Add_emptyMsg + "?emptyStation=" + id;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
                //request.Method="get";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream s = response.GetResponseStream();
                XmlTextReader Reader = new XmlTextReader(s);
                Reader.MoveToContent();
                string strValue = Reader.ReadInnerXml();
                strValue = strValue.Replace("&lt;", "<");
                strValue = strValue.Replace("&gt;", ">");
                //{"Succeed":false,"ResultData":null,"ErrorMessage":"无法通过[Feederaaaa]lineCode找到小车停靠点"}
                rb = JsonConvert.DeserializeObject<Result>(strValue);
                Reader.Close();
            }
            catch (Exception e)
            {
               System.Windows.Forms.MessageBox.Show(e.Message);
            }
            return rb;
        }

    }
    public class Result
    {
        public string Succeed { get; set; }

        public string ResultData { get; set; }

        public string ErrorMessage { get; set; }

    }
}