text.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. using NVRCsharpDemo;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.Xml;
  16. using Common;
  17. using System.Configuration;
  18. using com.hnshituo.core.webapp.vo;
  19. using System.Resources;
  20. using System.Security.Cryptography;
  21. using TrainVideoDataDispose.Properties;
  22. namespace TrainVideoDataDispose
  23. {
  24. public partial class text : Form
  25. {
  26. public int m_lUserID = -1;
  27. public int m_lGetFaceParamCfgHandle = -1;
  28. private CHCNetSDK.REALDATACALLBACK RealData = null;
  29. public CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo;
  30. public CHCNetSDK.NET_DVR_DEVICEINFO_V40 tDeviceInfo;
  31. public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
  32. public CHCNetSDK.NET_DVR_STREAM_MODE m_struStreamMode;
  33. public CHCNetSDK.NET_DVR_IPCHANINFO m_struChanInfo;
  34. public CHCNetSDK.NET_DVR_PU_STREAM_URL m_struStreamURL;
  35. public CHCNetSDK.NET_DVR_IPCHANINFO_V40 m_struChanInfoV40;
  36. public CHCNetSDK.NET_DVR_USER_LOGIN_INFO pLoginInfo;
  37. public CHCNetSDK.LOGINRESULTCALLBACK LoginCallBack;
  38. public CHCNetSDK.RemoteConfigCallback remoteConfigCallback;
  39. //private PlayCtrl.DECCBFUN m_fDisplayFun = null;
  40. public delegate void MyDebugInfo(string str);
  41. private MetetBaseRailwayAiweightService metetBaseRailwayAiweightService = new MetetBaseRailwayAiweightService();
  42. private Label labelLogin;
  43. public text()
  44. {
  45. InitializeComponent();
  46. }
  47. private void button1_Click(object sender, EventArgs e)
  48. {
  49. #region 海康
  50. //bool m_bInitSDK = CHCNetSDK.NET_DVR_Init();
  51. //string DVRIPAddress = '10.111.67.23'; //设备IP地址或者域名 Device IP
  52. //Int16 DVRPortNumber = Int16.Parse('8000');//设备服务端口号 Device Port
  53. //string DVRUserName = 'admin';//设备登录用户名 User name to login
  54. //string DVRPassword = 'Admin12345';//设备登录密码 Password to login
  55. ////设备IP地址或者域名
  56. //byte[] byIP = System.Text.Encoding.Default.GetBytes(DVRIPAddress);
  57. //pLoginInfo.sDeviceAddress = new byte[129];
  58. //byIP.CopyTo(pLoginInfo.sDeviceAddress, 0);
  59. ////设备用户名
  60. //byte[] byUserName = System.Text.Encoding.Default.GetBytes(DVRUserName);
  61. //pLoginInfo.sUserName = new byte[64];
  62. //byUserName.CopyTo(pLoginInfo.sUserName, 0);
  63. ////设备密码
  64. //byte[] byPassword = System.Text.Encoding.Default.GetBytes(DVRPassword);
  65. //pLoginInfo.sPassword = new byte[64];
  66. //byPassword.CopyTo(pLoginInfo.sPassword, 0);
  67. //pLoginInfo.wPort = 8000;
  68. //if (LoginCallBack == null)
  69. //{
  70. // LoginCallBack = new CHCNetSDK.LOGINRESULTCALLBACK(cbLoginCallBack);//注册回调函数
  71. //}
  72. //pLoginInfo.cbLoginResult = LoginCallBack;
  73. //pLoginInfo.bUseAsynLogin = true;
  74. ////登录设备 Login the device
  75. ////m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
  76. //m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref pLoginInfo, ref tDeviceInfo);
  77. //if (m_lUserID < 0)
  78. //{
  79. // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
  80. // string str = 'NET_DVR_Login_V30 failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
  81. // textinfo.Text = str;
  82. // return;
  83. //}
  84. //else
  85. //{
  86. // //登录成功
  87. // //停止远程配置
  88. // if (m_lGetFaceParamCfgHandle != -1)
  89. // {
  90. // CHCNetSDK.NET_DVR_StopRemoteConfig(m_lGetFaceParamCfgHandle);
  91. // }
  92. // //清除表格信息
  93. // //listViewFaceConfig.Items.Clear();
  94. // //LpArr.Clear();
  95. // //定义查询信息对象
  96. // CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND struCond = new CHCNetSDK.NET_DVR_TRAFFIC_DATA_QUERY_COND();
  97. // struCond.dwSize = (uint)Marshal.SizeOf(struCond);
  98. // //保留
  99. // byte[] byRes = System.Text.Encoding.Default.GetBytes('0');
  100. // struCond.byRes = new byte[254];
  101. // byRes.CopyTo(struCond.byRes, 0);
  102. // //struCond.dwQueryCond
  103. // if (remoteConfigCallback == null)
  104. // {
  105. // remoteConfigCallback = new CHCNetSDK.RemoteConfigCallback(cbStateCallback);//注册回调函数
  106. // }
  107. // int dwSize = Marshal.SizeOf(struCond);
  108. // IntPtr ptrStruCond = Marshal.AllocHGlobal(dwSize);
  109. // Marshal.StructureToPtr(struCond, ptrStruCond, true);
  110. // m_lGetFaceParamCfgHandle = CHCNetSDK.NET_DVR_StartRemoteConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TRAFFIC_DATA, ptrStruCond, dwSize, remoteConfigCallback, IntPtr.Zero);
  111. // if (m_lGetFaceParamCfgHandle < 0)
  112. // {
  113. // uint iLastErr = CHCNetSDK.NET_DVR_GetLastError();
  114. // string str = 'NET_DVR_StartRemoteConfig failed, error code= ' + iLastErr; //登录失败,输出错误号 Failed to login and output the error code
  115. // textinfo.Text = str;
  116. // return;
  117. // }
  118. // else
  119. // {
  120. // Marshal.FreeHGlobal(ptrStruCond);
  121. // }
  122. //}
  123. #endregion
  124. try
  125. {
  126. //string strUrl = "http://10.111.67.23/ISAPI/System/deviceInfo";
  127. string strUrl = "http://10.111.67.23/ISAPI/Traffic/ContentMgmt/dataOperation";
  128. WebClient client = new WebClient();
  129. int interval = int.Parse(ConfigurationManager.AppSettings["interval"].ToString());
  130. string startTime = DateTime.Now.ToString("yyyy-MM-dd") + "Y" + DateTime.Now.ToString("HH:mm:ss") + "Z";
  131. string endTime = DateTime.Now.AddMinutes(interval).ToString("yyyy-MM-dd") + "Y" + DateTime.Now.AddMinutes(interval).ToString("HH:mm:ss") + "Z";
  132. string searchID =  System.Guid.NewGuid().ToString();
  133. // 设置用户名和密码
  134. client.Credentials = new NetworkCredential("admin", "Admin12345");
  135. string requestXmls = string.Format(@"<?xml version:'1.0' encoding='utf-8'?>
  136. <DataOperation>
  137. <operationType>search</operationType>
  138. <searchCond>
  139. <searchID>{0}</searchID>
  140. <timeSpanList>
  141. <timeSpan>
  142. <startTime>{1}</startTime>
  143. <endTime>{2}</endTime>
  144. </timeSpan>
  145. </timeSpanList>
  146. <criteria>
  147. <dataType>0</dataType>
  148. <channel/>
  149. <plateType/>
  150. <plateColor/>
  151. <direction/>
  152. <plate/>
  153. <speedMin/>
  154. <speedMax/>
  155. <vehicleType/>
  156. <vehicleColor/>
  157. <laneNo/>
  158. <surveilType>0</surveilType>
  159. <romoteHost/>
  160. <analysised>true</analysised>
  161. <sendFlag/>
  162. </criteria>
  163. <searchResultPosition>0</searchResultPosition>
  164. <maxResults>999</maxResults>
  165. </searchCond>
  166. </DataOperation>", searchID,startTime,endTime);
  167. byte[] sendData = Encoding.UTF8.GetBytes(requestXmls);
  168. byte[] responseData = client.UploadData(strUrl,"POST", sendData);
  169. string strResponseData = Encoding.UTF8.GetString(responseData);
  170. XmlToDataSet(strResponseData);
  171. XmlDocument xmlDoc = new XmlDocument();//初始化一个实例
  172. xmlDoc.LoadXml(strResponseData);//读取文件
  173. List<MetetBaseRailwayAiweight> metetBaseRailwayAiweights = new List<MetetBaseRailwayAiweight>();
  174. XmlNodeList s = xmlDoc.DocumentElement.GetElementsByTagName("matchElement");
  175. foreach (XmlElement node in s)
  176. {
  177. MetetBaseRailwayAiweight metetBaseRailwayAiweight = new MetetBaseRailwayAiweight();
  178. int stratIndex = node.GetElementsByTagName("plate")[0].InnerText.Length - 7;
  179. metetBaseRailwayAiweight.railwayNo = node.GetElementsByTagName("plate")[0].InnerText.Substring(stratIndex, 7);
  180. metetBaseRailwayAiweight.railwayType = node.GetElementsByTagName("plate")[0].InnerText.Substring(0, stratIndex);
  181. metetBaseRailwayAiweight.meterWeight = node.GetElementsByTagName("selfWeight")[0].InnerText;
  182. metetBaseRailwayAiweight.railwaySpeed = node.GetElementsByTagName("speed")[0].InnerText;
  183. metetBaseRailwayAiweights.Add(metetBaseRailwayAiweight);
  184. }
  185. if (metetBaseRailwayAiweights.Count > 0)
  186. {
  187. RESTfulResult<List<MetetBaseRailwayAiweight>> result = metetBaseRailwayAiweightService.add(metetBaseRailwayAiweights);
  188. if (result.Succeed)
  189. {
  190. // 输出接收的消息
  191. this.textinfo.Text = "成功";
  192. }
  193. }
  194. }
  195. catch (Exception ex)
  196. {
  197. this.textinfo.Text = ex.Message;
  198. }
  199. return;
  200. }
  201. #region Xml To DataSet
  202. public static DataSet XmlToDataSet(string xmlString)
  203. {
  204. XmlDocument xmldoc = new XmlDocument();
  205. xmldoc.LoadXml(xmlString);
  206. StringReader stream = null;
  207. XmlTextReader reader = null;
  208. try
  209. {
  210. DataSet xmlDS = new DataSet();
  211. stream = new StringReader(xmldoc.InnerXml);
  212. reader = new XmlTextReader(stream);
  213. xmlDS.ReadXml(reader);
  214. reader.Close();
  215. return xmlDS;
  216. }
  217. catch (System.Exception ex)
  218. {
  219. reader.Close();
  220. throw ex;
  221. }
  222. }
  223. #endregion
  224. }
  225. }