AiControl.cs 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.IO;
  9. using System.Configuration;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Linq;
  12. using System.Net;
  13. using System.Net.Sockets;
  14. //using GenerateReport;
  15. namespace AiControlRequest
  16. {
  17. /// <summary>
  18. /// Ai控制过程结果
  19. /// </summary>
  20. public class AiControl
  21. {
  22. #region 检测项目枚举参数
  23. /// <summary>
  24. /// 检测分类参数
  25. /// </summary>
  26. public enum catagoryParam //钢种
  27. {
  28. /// <summary>
  29. /// 灰铸铁
  30. /// </summary>
  31. GrayCastIron = 14, //灰铸铁
  32. /// <summary>
  33. /// 球墨铸铁
  34. /// </summary>
  35. NodularCastIron = 15, //球墨铸铁
  36. /// <summary>
  37. /// 轴承钢
  38. /// </summary>
  39. BearingSteel = 16, //轴承钢
  40. /// <summary>
  41. /// 亚共析带状
  42. /// </summary>
  43. HypoeutectoidStrip = 17, //亚共析带状
  44. /// <summary>
  45. /// 组织识别
  46. /// </summary>
  47. OrganizationIdentification = 0, //组织识别
  48. /// <summary>
  49. /// 魏氏
  50. /// </summary>
  51. Westergren = 18, //魏氏
  52. /// <summary>
  53. /// 夹杂物
  54. /// </summary>
  55. Inclusion = 18, //夹杂物
  56. /// <summary>
  57. /// 晶粒度
  58. /// </summary>
  59. GrainSize = 18, //晶粒度
  60. }
  61. /// <summary>
  62. /// 检测项目参数
  63. /// </summary>
  64. public enum itemParam //项目
  65. {
  66. /// <summary>
  67. /// 石墨形状
  68. /// </summary>
  69. GraphiteShape = 1,
  70. /// <summary>
  71. /// 石墨长度
  72. /// </summary>
  73. GraphiteLength = 2,
  74. /// <summary>
  75. /// 珠光体数量
  76. /// </summary>
  77. PearliteNumber = 3,
  78. /// <summary>
  79. /// 磷共晶数量
  80. /// </summary>
  81. SteaditeNumber = 5,
  82. /// <summary>
  83. /// 共晶团分类检测
  84. /// </summary>
  85. EutecticClusterItemize = 10,
  86. /// <summary>
  87. /// 球化率
  88. /// </summary>
  89. Nodularity = 1,
  90. /// <summary>
  91. /// 球墨大小
  92. /// </summary>
  93. SpheroidalGraphiteSize = 2,
  94. /// <summary>
  95. /// 铁素体数量
  96. /// </summary>
  97. FerriteNumber = 4,
  98. /// <summary>
  99. /// 球化退火
  100. /// </summary>
  101. Spheroidizing = 1,
  102. /// <summary>
  103. /// 碳化物网状
  104. /// </summary>
  105. CarbideNetwork = 2,
  106. /// <summary>
  107. /// 碳化物带状
  108. /// </summary>
  109. CarbideBanding = 4,
  110. /// <summary>
  111. /// 亚共析钢带状-A
  112. /// </summary>
  113. HypoeutectoidStripA = 11,
  114. /// <summary>
  115. /// 亚共析钢带状-B
  116. /// </summary>
  117. HypoeutectoidStripB = 12,
  118. /// <summary>
  119. /// 亚共析钢带状-C
  120. /// </summary>
  121. HypoeutectoidStripC = 13,
  122. /// <summary>
  123. /// 亚共析钢带状-D
  124. /// </summary>
  125. HypoeutectoidStripD = 14,
  126. /// <summary>
  127. /// 亚共析钢带状-E
  128. /// </summary>
  129. HypoeutectoidStripE = 15,
  130. /// <summary>
  131. /// 魏氏-A
  132. /// </summary>
  133. WestergrenA = 3,
  134. /// <summary>
  135. /// 魏氏-B
  136. /// </summary>
  137. WestergrenB = 3,
  138. /// <summary>
  139. /// 夹杂物
  140. /// </summary>
  141. Inclusion = 1,
  142. /// <summary>
  143. /// 晶粒度-定级
  144. /// </summary>
  145. GrainSizeGrading = 2,
  146. /// <summary>
  147. /// 晶粒度-分类检测
  148. /// </summary>
  149. GrainSizeItemize = 10,
  150. /// <summary>
  151. /// 组织识别
  152. /// </summary>
  153. OrganizationIdentification = 0
  154. }
  155. /// <summary>
  156. /// 评级参数
  157. /// </summary>
  158. public enum jsonParam //评级json参数
  159. {
  160. /// <summary>
  161. /// 无参数
  162. /// </summary>
  163. Null = 0,
  164. /// <summary>
  165. /// 魏氏-A
  166. /// </summary>
  167. WestergrenA = 1,
  168. /// <summary>
  169. /// 魏氏-B
  170. /// </summary>
  171. WestergrenB = 2,
  172. /// <summary>
  173. /// 夹杂物ABC
  174. /// </summary>
  175. InclusionABC = 3,
  176. /// <summary>
  177. /// 夹杂物DDS
  178. /// </summary>
  179. InclusionDDS = 4,
  180. /// <summary>
  181. /// 夹杂物ALL
  182. /// </summary>
  183. InclusionALL = 5,
  184. /// <summary>
  185. /// 轴承钢-碳化物带状垂直
  186. /// </summary>
  187. CarbideBandingVertical = 6,
  188. /// <summary>
  189. /// 组织识别-碳素钢珠光体定量
  190. /// </summary>
  191. CarbonSteelPearliteNumber = 7,
  192. /// <summary>
  193. /// 组织识别-α铁素体含量
  194. /// </summary>
  195. AlphafFerriteContent = 8,
  196. /// <summary>
  197. /// 组织识别-δ铁素体含量
  198. /// </summary>
  199. DeltafFerriteContent = 9,
  200. /// <summary>
  201. /// 组织识别-A+F双相含量
  202. /// </summary>
  203. AFBiphasicContent = 10
  204. }
  205. /// <summary>
  206. /// 评级参数对应的字符串
  207. /// </summary>
  208. private List<String> jsonList = new List<string>()
  209. {
  210. @"",
  211. @"{'YBG-W': {'w_cls':'wa'}}",
  212. @"{'YBG-W': {'w_cls':'wb'}}",
  213. @"{'YGB-JZW': {'output_cls_names': ['a','b','c']}}",
  214. @"{'YGB-JZW': {'output_cls_names': ['d','ds']}}",
  215. @"{'YGB-JZW': {'output_cls_names': ['a','b','c','d','ds']}}",
  216. @"{'ZCG_GTG-DZ': {'direction':'v'}}",
  217. @"{'draw_color_zz':['p']}",
  218. @"{'draw_color_zz':['alphaf']}",
  219. @"{'draw_color_zz':['deltaf']}",
  220. @"{'draw_color_zz':['a'],'zzsb_names':['a','f']}"
  221. };
  222. #endregion
  223. #region 参数定义
  224. //读取程序所在目录
  225. private string path = System.AppDomain.CurrentDomain.BaseDirectory;
  226. //配置文件参数
  227. private ExeConfigurationFileMap map = new ExeConfigurationFileMap();
  228. private Configuration cfg;
  229. //定义一个文件夹路径
  230. private String _gradePath;
  231. /// <summary>
  232. /// 必须在评级结束时才可以更改目录
  233. /// </summary>
  234. public String GradePaht
  235. {
  236. get { return _gradePath; }
  237. set
  238. {
  239. if (_isStart == false)
  240. {
  241. _gradePath = value;
  242. }
  243. }
  244. }
  245. //定义一个列表,存放一些列表的集合
  246. private List<List<String>> _nameList = new List<List<string>>();
  247. //定义一个批次返回处理完成的文件列表
  248. private List<String> _batchList = new List<string>();
  249. //定义一个存储文件全路径的集合
  250. private List<String> _tempList = new List<string>();
  251. //定义一个锁,判断请求是否有返回
  252. private Boolean _postLock = false;
  253. //操作之间的互斥锁
  254. private Boolean _mutexLock = false;
  255. //定义一个发送请求的最小数
  256. private int _countList = 100;
  257. //定义执行该操作的开始标志
  258. private Boolean _isStart;
  259. private Boolean _isEnd;
  260. private Boolean _isFirst;
  261. //定义本机评级开关
  262. private Boolean _localLock = false;
  263. //定义是远程还是本机
  264. private Boolean _isLocalHost;
  265. //请求的URL
  266. private String _url = "";
  267. private const String Post = "Post";
  268. private const String Content_Type = "Content-Type:application/json";
  269. //本地评级参数
  270. PythonExecutor pythonExecutor = null;
  271. private SynchronizationContext synchronizationContext = null;
  272. Label lblret = new Label();
  273. private int test_index = 0;//当前完成评级的图片数量
  274. private int test_count = 0;//当前评级的总张数
  275. //评级检测参数-分类、项目、参数
  276. private String _catagory;
  277. private String _item;
  278. private String _param;
  279. //报告参数
  280. //WordReport wordReport = null;
  281. //评级结果文件名
  282. String resultName = "";
  283. //是否单机测试
  284. Boolean _isDebug = false;
  285. //放大倍数
  286. private int _zoom_key = 1;
  287. //分辨率
  288. private double _um_per_pix = 0;
  289. //批次序号
  290. int batch_index = 0;
  291. #endregion
  292. #region 事件
  293. //委托事件-批次结束
  294. public delegate void CompleteBatch(List<String> batchfilenames);
  295. public event CompleteBatch CompleteBatchEvent;
  296. //委托事件-全部结束
  297. public delegate void CompleteAll(String resultfilename);
  298. public event CompleteAll CompleteAllEvent;
  299. #endregion
  300. #region 初始化参数
  301. /// <summary>
  302. /// 构造函数
  303. /// </summary>
  304. /// <param name="gradepath">评级图片的路径</param>
  305. public AiControl(String gradepath)
  306. {
  307. LogHelper.info("初始化20210520");
  308. //识别图片目录
  309. _gradePath = gradepath;
  310. LogHelper.info("获取路径");
  311. if (!System.IO.Directory.Exists(_gradePath))
  312. {
  313. LogHelper.info("目录不存在");
  314. throw (new Exception("目录文件不存在!"));
  315. }
  316. LogHelper.info("初始化评级参数");
  317. //初始化评级参数
  318. Init();
  319. }
  320. /// <summary>
  321. /// 初始化参数
  322. /// </summary>
  323. private void Init()
  324. {
  325. _postLock = false; //远程锁
  326. _mutexLock = false; //互斥锁
  327. _isStart = false; //未开始评级
  328. _isEnd = true; //评级没有结束
  329. _isFirst = false;
  330. //线程间同步上下文
  331. lblret.Text = "";
  332. //this.synchronizationContext = SynchronizationContext.Current;
  333. //pythonExecutor = new PythonExecutor(SynchronizationContext.Current);
  334. //pythonExecutor.ReceivedControlData += ReceivedControlData;
  335. LogHelper.info("读取配置文件");
  336. ReadAISetting();
  337. }
  338. /// <summary>
  339. /// 读配置文件参数
  340. /// </summary>
  341. private void ReadAISetting()
  342. {
  343. try
  344. {
  345. //读取配置文件参数
  346. map.ExeConfigFilename = Path.Combine(path, "AISetting.config");
  347. cfg = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
  348. //服务器URL
  349. _url = cfg.AppSettings.Settings["ServerURL"].Value;
  350. //远程或本地
  351. _isLocalHost = Convert.ToBoolean(cfg.AppSettings.Settings["IsLocalHost"].Value);
  352. //评级文件最小数
  353. _countList = Convert.ToInt32(cfg.AppSettings.Settings["CountList"].Value);
  354. //读结果文件名
  355. resultName = cfg.AppSettings.Settings["ResultName"].Value;
  356. //调试状态
  357. _isDebug = Convert.ToBoolean(cfg.AppSettings.Settings["Debug"].Value);
  358. }
  359. catch
  360. {
  361. throw (new Exception("读取配置文件出错!"));
  362. }
  363. }
  364. #endregion
  365. #region 检测远程端口是否打开
  366. public Boolean Test_Port()
  367. {
  368. int s1 = this._url.IndexOf("//") + 2;
  369. int s2 = this._url.IndexOf(":");
  370. s2 = this._url.IndexOf(":", s2 + 1);
  371. int s3 = this._url.IndexOf("/", s2 + 1);
  372. string ipd = this._url.Substring(s1, s2 - s1);
  373. string port = this._url.Substring(s2 + 1, s3 - s2 - 1);
  374. IPAddress ip = IPAddress.Parse(ipd);
  375. IPEndPoint point = new IPEndPoint(ip, int.Parse(port));
  376. try
  377. {
  378. TcpClient tcp = new TcpClient();
  379. tcp.Connect(point);
  380. tcp.Close();
  381. tcp = null;
  382. }
  383. catch
  384. {
  385. return false;
  386. }
  387. return true;
  388. }
  389. #endregion
  390. #region 参数设置
  391. /// <summary>
  392. /// 服务器URL设置(包括IP:端口和服务地址)
  393. /// </summary>
  394. /// <param name="url">服务器URL设置(包括IP:端口和服务地址)</param>
  395. public void SetServerURL(String url)
  396. {
  397. if (_isStart == false)
  398. {
  399. this._url = url;
  400. cfg.AppSettings.Settings["ServerURL"].Value = url;
  401. cfg.Save();
  402. LogHelper.info(url);
  403. }
  404. }
  405. /// <summary>
  406. /// 评级文件的最小总数
  407. /// </summary>
  408. /// <param name="countList">评级文件的最小总数</param>
  409. public void SetCountList(int countList)
  410. {
  411. if (_isStart == false)
  412. {
  413. if (countList < 0)
  414. {
  415. return;
  416. }
  417. this._countList = countList;
  418. cfg.AppSettings.Settings["CountList"].Value = countList.ToString();
  419. cfg.Save();
  420. LogHelper.info("文件最小总数设置=" + countList.ToString());
  421. }
  422. }
  423. /// <summary>
  424. /// 远程或本地评级
  425. /// </summary>
  426. /// <param name="isLocalhost">True:本地;False:远程</param>
  427. private void SetIsLocalHost(Boolean isLocalhost)
  428. {
  429. this._isLocalHost = isLocalhost;
  430. cfg.AppSettings.Settings["IsLocalHost"].Value = this._isLocalHost.ToString();
  431. cfg.Save();
  432. }
  433. #endregion
  434. #region 评级开始和结束处理函数
  435. /// <summary>
  436. /// 开始评级且设置评级参数
  437. /// </summary>
  438. /// <param name="catagory">分类</param>
  439. /// <param name="item">项目</param>
  440. /// <param name="param">评级参数</param>
  441. /// <returns>评级开始设置是否成功</returns>
  442. public Boolean StartAndSetGradeParam(catagoryParam catagory, itemParam item, jsonParam param, int zoom_key, double um_per_pix)
  443. {
  444. if (_isEnd == false || this._postLock == true)
  445. {
  446. return false;
  447. }
  448. try
  449. {
  450. this._zoom_key = zoom_key;
  451. this._um_per_pix = um_per_pix;
  452. this._catagory = ((int)catagory).ToString();
  453. String ctgy = catagoryParam.GetName(typeof(catagoryParam), catagory);
  454. //根据分类查找模板文件
  455. //try
  456. //{
  457. // switch (ctgy)
  458. // {
  459. // case "GrayCastIron":
  460. // wordReport = new WordReport(path + "\\Template\\灰铸铁.docx");
  461. // break;
  462. // case "NodularCastIron":
  463. // wordReport = new WordReport(path + "\\Template\\球墨铸铁.docx");
  464. // break;
  465. // case "BearingSteel":
  466. // wordReport = new WordReport(path + "\\Template\\轴承钢.docx");
  467. // break;
  468. // case "HypoeutectoidStrip":
  469. // wordReport = new WordReport(path + "\\Template\\亚共析带状.docx");
  470. // break;
  471. // case "Westergren":
  472. // wordReport = new WordReport(path + "\\Template\\魏氏.docx");
  473. // break;
  474. // case "Inclusion":
  475. // wordReport = new WordReport(path + "\\Template\\夹杂物.docx");
  476. // break;
  477. // case "GrainSize":
  478. // wordReport = new WordReport(path + "\\Template\\晶粒度.docx");
  479. // break;
  480. // default:
  481. // wordReport = new WordReport(path + "\\Template\\灰铸铁.docx");
  482. // break;
  483. // }
  484. //}
  485. //catch(Exception e)
  486. //{
  487. // throw (new Exception(e.ToString()));
  488. //}
  489. LogHelper.info("zoom_key=" + zoom_key.ToString());
  490. LogHelper.info("um_per_pix=" + um_per_pix.ToString());
  491. LogHelper.info("Server URL=" + this._url);
  492. LogHelper.info("CountList =" + this._countList.ToString());
  493. LogHelper.info("开始评级");
  494. batch_index = 0;
  495. this._item = ((int)item).ToString();
  496. //wordReport = new WordReport(path + "\\Template\\夹杂物.docx");
  497. this._param = jsonList[(int)param];
  498. _isStart = true;
  499. _isEnd = false;
  500. _isFirst = true;
  501. return true;
  502. }
  503. catch
  504. {
  505. return false;
  506. }
  507. }
  508. public Boolean StartAndSetGradeParam(int zoom_key, double um_per_pix)
  509. {
  510. if (_isEnd == false || this._postLock == true)
  511. {
  512. return false;
  513. }
  514. try
  515. {
  516. LogHelper.info("zoom_key=" + zoom_key.ToString());
  517. LogHelper.info("um_per_pix=" + um_per_pix.ToString());
  518. LogHelper.info("开始评级");
  519. batch_index = 0;
  520. this._zoom_key = zoom_key;
  521. this._um_per_pix = um_per_pix;
  522. this._catagory = "18";
  523. this._item = "1";
  524. this._param = jsonList[5];
  525. _isStart = true;
  526. _isEnd = false;
  527. _isFirst = true;
  528. return true;
  529. }
  530. catch
  531. {
  532. return false;
  533. }
  534. }
  535. /// <summary>
  536. /// 结束本次评级
  537. /// </summary>
  538. public void EndGrade()
  539. {
  540. if (!this._isStart)
  541. {
  542. return;
  543. }
  544. this._isEnd = true;
  545. LogHelper.info("执行结束本次评级");
  546. //判断是否还有文件,如果还有则进行评级
  547. if (_nameList.Count == 1 && _nameList[0].Count > 0 && _postLock == false)
  548. {
  549. //互斥锁检测
  550. while (_mutexLock) { }
  551. //上锁
  552. _mutexLock = true;
  553. //发送请求
  554. Thread th = new Thread(SendPost);
  555. th.Start();
  556. }
  557. else if (_postLock == false)
  558. {
  559. //如果结束时所有文件都评完级,则发一个空的图片数据和结束参数
  560. JObject json = new JObject();
  561. JObject json1 = new JObject();
  562. JObject json2 = new JObject();
  563. json1.Add("end", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  564. json1.Add("catagory", this._catagory);
  565. json1.Add("items", this._item);
  566. json1.Add("path", this._gradePath.Replace("\\", "/"));
  567. if (this._catagory == "0")
  568. {
  569. json1.Add("func", "zzsb");
  570. }
  571. else
  572. {
  573. json1.Add("func", "bzpj");
  574. }
  575. json1.Add("images", "");
  576. json.Add("json1", json1);
  577. if (this._param != "")
  578. {
  579. json2 = JObject.Parse(this._param);
  580. }
  581. json2.Add("zoom_key", this._zoom_key);
  582. json2.Add("um_per_pix", this._um_per_pix);
  583. json.Add("json2", json2);
  584. String param = json.ToString();
  585. LogHelper.info(param);
  586. if (!this._isDebug)
  587. {
  588. //发送请求
  589. String res = RequestString(param);
  590. }
  591. //完成后且记录条数为0则发送完成事件
  592. try
  593. {
  594. this._isStart = false;
  595. CompleteAllEvent(AnalysisAIFile());
  596. LogHelper.info("评级全部结束");
  597. }
  598. catch (Exception e)
  599. {
  600. CompleteAllEvent("");
  601. LogHelper.info("ERR:" + e.ToString());
  602. }
  603. }
  604. }
  605. #endregion
  606. #region 返回图像检测结果
  607. /// <summary>
  608. /// 获取图像检测结果
  609. /// </summary>
  610. /// <param name="filename">检测图像的全路径和文件名</param>
  611. /// <returns>检测结果</returns>
  612. public String GetImageTestResult(String filename)
  613. {
  614. string ret = "";
  615. if (this._isDebug)
  616. {
  617. return "{\"fun\":\"test\",\"return\":\"test_result\"}";
  618. }
  619. if (File.Exists(filename))
  620. {
  621. String aifilename = Path.Combine(Path.GetDirectoryName(filename), "AI", Path.GetFileNameWithoutExtension(filename) + ".ai");
  622. if (File.Exists(aifilename))
  623. {
  624. using (System.IO.StreamReader _file = System.IO.File.OpenText(aifilename))
  625. {
  626. using (JsonTextReader reader = new JsonTextReader(_file))
  627. {
  628. try
  629. {
  630. JObject o = (JObject)JToken.ReadFrom(reader);
  631. JObject content = JObject.Parse(o["content"].ToString());
  632. ret = content["title"].ToString();
  633. }
  634. catch (Exception e)
  635. {
  636. throw (new Exception("AI文件错误!"));
  637. }
  638. reader.Close();
  639. _file.Close();
  640. _file.Dispose();
  641. }
  642. }
  643. }
  644. }
  645. LogHelper.info("返回" + filename + "的结果:" + ret);
  646. return ret;
  647. }
  648. #endregion
  649. #region 返回检测过程图像
  650. /// <summary>
  651. /// 返回检测过程图像
  652. /// </summary>
  653. /// <param name="filename">检测图像的全路径和文件名</param>
  654. /// <returns>过程图像的路径和文件名</returns>
  655. public String GetImageProcess(String filename)
  656. {
  657. string ret = "";
  658. if (this._isDebug)
  659. {
  660. return "{\"fun\":\"test\",\"return\":\"fullfilename\"}";
  661. }
  662. if (File.Exists(filename))
  663. {
  664. String aifilename = Path.Combine(Path.GetDirectoryName(filename), "AI", Path.GetFileName(filename));
  665. if (File.Exists(aifilename))
  666. {
  667. ret = aifilename;
  668. }
  669. }
  670. LogHelper.info("返回" + filename + "的过程图像:" + ret);
  671. return ret;
  672. }
  673. #endregion
  674. #region 插入单个文件
  675. /// <summary>
  676. /// 插入单个文件路径
  677. /// </summary>
  678. /// <param name="filename">文件路径字符串</param>
  679. /// <returns>0:满足条件发送请求;1:记录不够;2:请求正在执行;3:本地请求正在执行;255:没有开始工作</returns>
  680. public int PostFileName(String filename)
  681. {
  682. //如果没有开始过程则不与理会
  683. if (!this._isStart)
  684. {
  685. return 255;
  686. }
  687. //如果文件路径为空
  688. if (filename == "")
  689. {
  690. return 254;
  691. }
  692. //向最后的文件列表添加数据
  693. if (_nameList.Count == 0 || _nameList[_nameList.Count - 1].Count == this._countList)
  694. {
  695. List<String> fileList = new List<string>();
  696. _nameList.Add(fileList);
  697. }
  698. _nameList[_nameList.Count - 1].Add(filename);
  699. LogHelper.info("插入单个文件" + filename);
  700. //请求锁
  701. if (_postLock)
  702. {
  703. return 2;
  704. }
  705. //文件数量不满足
  706. else if (_nameList[0].Count < _countList)
  707. {
  708. return 1;
  709. }
  710. //如果请求锁打开且文件列表第一个集合满足记录条数则发送请求
  711. else
  712. {
  713. //请求锁应该在这里上
  714. _postLock = true;
  715. //互斥锁检测
  716. while (_mutexLock) { }
  717. //上锁
  718. _mutexLock = true;
  719. //发送请求
  720. Thread th = new Thread(SendPost);
  721. th.Start();
  722. }
  723. return 0;
  724. }
  725. #endregion
  726. #region 发送Post线程
  727. /// <summary>
  728. /// 线程-发送请求
  729. /// </summary>
  730. private void SendPost()
  731. {
  732. //发送请求锁
  733. _postLock = true;
  734. //解锁
  735. _mutexLock = false;
  736. //清空数据
  737. _batchList.Clear();
  738. //取发送请求参数
  739. string images = "";
  740. for (int i = 0; i < _nameList[0].Count; i++)
  741. {
  742. images += _nameList[0][i] + ";";
  743. _batchList.Add(_nameList[0][i]);
  744. }
  745. images = images.Substring(0, images.Length - 1);
  746. JObject json = new JObject();
  747. JObject json1 = new JObject();
  748. JObject json2 = new JObject();
  749. if (_isFirst)
  750. {
  751. json1.Add("start", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  752. _isFirst = false;
  753. }
  754. if (_isEnd == true && _nameList.Count == 1)
  755. {
  756. json1.Add("end", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  757. }
  758. json1.Add("catagory", this._catagory);
  759. json1.Add("items", this._item);
  760. json1.Add("path", this._gradePath.Replace("\\", "/"));
  761. if (this._catagory == "0")
  762. {
  763. json1.Add("func", "zzsb");
  764. }
  765. else
  766. {
  767. json1.Add("func", "bzpj");
  768. }
  769. json1.Add("images", images);
  770. json.Add("json1", json1);
  771. if (this._param != "")
  772. {
  773. json2 = JObject.Parse(this._param);
  774. }
  775. json2.Add("zoom_key", this._zoom_key);
  776. json2.Add("um_per_pix", this._um_per_pix);
  777. json.Add("json2", json2);
  778. String param = json.ToString();
  779. //发送完请求后删除文件
  780. _nameList.RemoveAt(0);
  781. LogHelper.info(param);
  782. if (!this._isDebug)
  783. {
  784. //发送请求
  785. String res = RequestString(param);
  786. }
  787. //批次完成事件
  788. try
  789. {
  790. CompleteBatchEvent(_batchList);
  791. batch_index++;
  792. LogHelper.info("batchListCount=" + _batchList.Count.ToString());
  793. LogHelper.info("批次结束,序号-" + batch_index.ToString());
  794. }
  795. catch (Exception e)
  796. {
  797. LogHelper.info("ERR:" + e.ToString());
  798. }
  799. //再判断是否满足条件
  800. if (_nameList.Count > 0 && _nameList[0].Count == _countList)
  801. {
  802. //上锁
  803. _mutexLock = true;
  804. //请求锁
  805. _postLock = true;
  806. //发送请求
  807. Thread th = new Thread(SendPost);
  808. th.Start();
  809. }
  810. else if (_nameList.Count == 1 && _nameList[0].Count > 0 && _isEnd)
  811. {
  812. //上锁
  813. _mutexLock = true;
  814. //请求锁
  815. _postLock = true;
  816. //发送请求
  817. Thread th = new Thread(SendPost);
  818. th.Start();
  819. }
  820. else if (_isEnd == true && _nameList.Count == 0)
  821. {
  822. //完成后且记录条数为0则发送完成事件
  823. try
  824. {
  825. this._isStart = false;
  826. CompleteAllEvent(AnalysisAIFile());
  827. LogHelper.info("全部评级结束");
  828. }
  829. catch (Exception e)
  830. {
  831. CompleteAllEvent("");
  832. LogHelper.info("ERR:" + e.ToString());
  833. }
  834. }
  835. //请求返回后解锁
  836. _postLock = false;
  837. }
  838. #endregion
  839. #region Post返回结果处理
  840. /// <summary>
  841. /// 向WebServer请求数据及返回结果
  842. /// </summary>
  843. /// <param name="postString">请求数据的JSON</param>
  844. /// <returns>返回结果的JSON</returns>
  845. private String RequestString(String postString)
  846. {
  847. try
  848. {
  849. String res = HttpRequestHelper.DoRequest(this._url, Post, Content_Type, postString);
  850. return res;
  851. }
  852. catch
  853. {
  854. return "Error";
  855. }
  856. }
  857. #endregion
  858. #region 生成报告
  859. /// <summary>
  860. /// 生成报告
  861. /// </summary>
  862. /// <param name="wordPath">生成报告的文件</param>
  863. /// <param name="project_json">从界面传的json参数</param>
  864. /// <returns></returns>
  865. private Boolean GetWordReport(String wordPath, String project_json)
  866. {
  867. return true;
  868. //JObject jo = new JObject();
  869. //if (_isDebug)
  870. //{
  871. // jo.Add("Project", "这是一个测试报告");
  872. // return wordReport.GenerateWordReport(wordPath, jo.ToString());
  873. //}
  874. //else
  875. //{
  876. // try
  877. // {
  878. // jo = JObject.Parse(project_json);
  879. // jo.Add("REPORT_NO", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
  880. // jo.Add("REPORT_DATE", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  881. // //查找result文件
  882. // String aiFile = @"D:/aitest".Replace('/', '\\') + "\\AI\\result.ai";
  883. // if (File.Exists(aiFile))
  884. // {
  885. // using (System.IO.StreamReader _file = System.IO.File.OpenText(aiFile))
  886. // {
  887. // using (JsonTextReader reader = new JsonTextReader(_file))
  888. // {
  889. // JObject o = (JObject)JToken.ReadFrom(reader);
  890. // jo.Add("REPORT_RESULT", o["result"].ToString());
  891. // string[] results = o["result"].ToString().Split(';');
  892. // jo.Add("REPORT_IMAGE", results.Length.ToString());
  893. // JArray jarr = new JArray();
  894. // for (int i = 0; i < results.Length; i++)
  895. // {
  896. // jo.Add("REPORT_RESULT" + i.ToString(), results[i]);
  897. // jarr = JArray.Parse(o[results[i]].ToString());
  898. // for (int j = 0; j < jarr.Count; j++)
  899. // {
  900. // jarr[j] = o["path"].ToString().Replace('/', '\\') + "\\" + jarr[j];
  901. // }
  902. // jo.Add("REPORT_PIC" + i.ToString(), jarr);
  903. // }
  904. // }
  905. // }
  906. // }
  907. // return wordReport.GenerateWordReport(wordPath, jo.ToString());
  908. // }
  909. // catch
  910. // {
  911. // throw (new Exception("参数不是标准的JSON数据!"));
  912. // }
  913. //}
  914. }
  915. #endregion
  916. #region 结束评级后处理文件
  917. /// <summary>
  918. /// 结束评级后处理文件
  919. /// </summary>
  920. /// <param name="aiFile">AI结果文件</param>
  921. /// <returns>结果文件内容</returns>
  922. private String AnalysisAIFile()
  923. {
  924. String ret = "";
  925. try
  926. {
  927. String aiFile = Path.Combine(this._gradePath, "AI") + "\\" + resultName;
  928. if (File.Exists(aiFile))
  929. {
  930. using (System.IO.StreamReader _file = System.IO.File.OpenText(aiFile))
  931. {
  932. using (JsonTextReader reader = new JsonTextReader(_file))
  933. {
  934. try
  935. {
  936. Dictionary<String, List<String>> gradeA = new Dictionary<string, List<string>>();
  937. Dictionary<String, List<String>> gradeAe = new Dictionary<string, List<string>>();
  938. Dictionary<String, List<String>> gradeAs = new Dictionary<string, List<string>>();
  939. Dictionary<String, List<String>> gradeB = new Dictionary<string, List<string>>();
  940. Dictionary<String, List<String>> gradeBe = new Dictionary<string, List<string>>();
  941. Dictionary<String, List<String>> gradeBs = new Dictionary<string, List<string>>();
  942. Dictionary<String, List<String>> gradeC = new Dictionary<string, List<string>>();
  943. Dictionary<String, List<String>> gradeCe = new Dictionary<string, List<string>>();
  944. Dictionary<String, List<String>> gradeCs = new Dictionary<string, List<string>>();
  945. Dictionary<String, List<String>> gradeD = new Dictionary<string, List<string>>();
  946. Dictionary<String, List<String>> gradeDe = new Dictionary<string, List<string>>();
  947. Dictionary<String, List<String>> gradeDs = new Dictionary<string, List<string>>();
  948. JObject o = (JObject)JToken.ReadFrom(reader);
  949. JObject arrList = JObject.Parse(o["file_results"].ToString());
  950. foreach (var item in arrList)
  951. {
  952. string temp = item.Value.ToString();
  953. string[] v = temp.Split('+');
  954. for (int j = 0; j < v.Length; j++)
  955. {
  956. //包含A的
  957. if (v[j].IndexOf("A") > -1)
  958. {
  959. if (v[j].IndexOf("e") < 0 && v[j].IndexOf("s") < 0)
  960. {
  961. if (gradeA.ContainsKey(v[j]))
  962. {
  963. gradeA[v[j]].Add(item.Key);
  964. }
  965. else
  966. {
  967. gradeA.Add(v[j], new List<string>());
  968. gradeA[v[j]].Add(item.Key);
  969. }
  970. }
  971. else if (v[j].IndexOf("e") > -1 && v[j].IndexOf("s") < 0)
  972. {
  973. if (gradeAe.ContainsKey(v[j]))
  974. {
  975. gradeAe[v[j]].Add(item.Key);
  976. }
  977. else
  978. {
  979. gradeAe.Add(v[j], new List<string>());
  980. gradeAe[v[j]].Add(item.Key);
  981. }
  982. }
  983. else if (v[j].IndexOf("s") > -1)
  984. {
  985. if (gradeAs.ContainsKey(v[j]))
  986. {
  987. gradeAs[v[j]].Add(item.Key);
  988. }
  989. else
  990. {
  991. gradeAs.Add(v[j], new List<string>());
  992. gradeAs[v[j]].Add(item.Key);
  993. }
  994. }
  995. }
  996. //包含B的
  997. if (v[j].IndexOf("B") > -1)
  998. {
  999. if (v[j].IndexOf("e") < 0 && v[j].IndexOf("s") < 0)
  1000. {
  1001. if (gradeB.ContainsKey(v[j]))
  1002. {
  1003. gradeB[v[j]].Add(item.Key);
  1004. }
  1005. else
  1006. {
  1007. gradeB.Add(v[j], new List<string>());
  1008. gradeB[v[j]].Add(item.Key);
  1009. }
  1010. }
  1011. else if (v[j].IndexOf("e") > -1 && v[j].IndexOf("s") < 0)
  1012. {
  1013. if (gradeBe.ContainsKey(v[j]))
  1014. {
  1015. gradeBe[v[j]].Add(item.Key);
  1016. }
  1017. else
  1018. {
  1019. gradeBe.Add(v[j], new List<string>());
  1020. gradeBe[v[j]].Add(item.Key);
  1021. }
  1022. }
  1023. else if (v[j].IndexOf("s") > -1)
  1024. {
  1025. if (gradeBs.ContainsKey(v[j]))
  1026. {
  1027. gradeBs[v[j]].Add(item.Key);
  1028. }
  1029. else
  1030. {
  1031. gradeBs.Add(v[j], new List<string>());
  1032. gradeBs[v[j]].Add(item.Key);
  1033. }
  1034. }
  1035. }
  1036. //包含C的
  1037. if (v[j].IndexOf("C") > -1)
  1038. {
  1039. if (v[j].IndexOf("e") < 0 && v[j].IndexOf("s") < 0)
  1040. {
  1041. if (gradeC.ContainsKey(v[j]))
  1042. {
  1043. gradeC[v[j]].Add(item.Key);
  1044. }
  1045. else
  1046. {
  1047. gradeC.Add(v[j], new List<string>());
  1048. gradeC[v[j]].Add(item.Key);
  1049. }
  1050. }
  1051. else if (v[j].IndexOf("e") > -1 && v[j].IndexOf("s") < 0)
  1052. {
  1053. if (gradeCe.ContainsKey(v[j]))
  1054. {
  1055. gradeCe[v[j]].Add(item.Key);
  1056. }
  1057. else
  1058. {
  1059. gradeCe.Add(v[j], new List<string>());
  1060. gradeCe[v[j]].Add(item.Key);
  1061. }
  1062. }
  1063. else if (v[j].IndexOf("s") > -1)
  1064. {
  1065. if (gradeCs.ContainsKey(v[j]))
  1066. {
  1067. gradeCs[v[j]].Add(item.Key);
  1068. }
  1069. else
  1070. {
  1071. gradeCs.Add(v[j], new List<string>());
  1072. gradeCs[v[j]].Add(item.Key);
  1073. }
  1074. }
  1075. }
  1076. //包含D的
  1077. if (v[j].IndexOf("D") > -1)
  1078. {
  1079. if (v[j].IndexOf("e") < 0 && v[j].IndexOf("S") < 0)
  1080. {
  1081. if (gradeD.ContainsKey(v[j]))
  1082. {
  1083. gradeD[v[j]].Add(item.Key);
  1084. }
  1085. else
  1086. {
  1087. gradeD.Add(v[j], new List<string>());
  1088. gradeD[v[j]].Add(item.Key);
  1089. }
  1090. }
  1091. else if (v[j].IndexOf("e") > -1 && v[j].IndexOf("S") < 0)
  1092. {
  1093. if (gradeDe.ContainsKey(v[j]))
  1094. {
  1095. gradeDe[v[j]].Add(item.Key);
  1096. }
  1097. else
  1098. {
  1099. gradeDe.Add(v[j], new List<string>());
  1100. gradeDe[v[j]].Add(item.Key);
  1101. }
  1102. }
  1103. else if (v[j].IndexOf("S") > -1)
  1104. {
  1105. if (gradeDs.ContainsKey(v[j]))
  1106. {
  1107. gradeDs[v[j]].Add(item.Key);
  1108. }
  1109. else
  1110. {
  1111. gradeDs.Add(v[j], new List<string>());
  1112. gradeDs[v[j]].Add(item.Key);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. //结果JSON
  1119. JObject res = new JObject();
  1120. res.Add("path", o["path"]);
  1121. //结果显示
  1122. String result = "";
  1123. //排序,S的都输出,所以无需排序(DS除外)
  1124. if (gradeA.Count > 0)
  1125. {
  1126. string maxStr = "";
  1127. foreach (string key in gradeA.Keys)
  1128. {
  1129. if (maxStr == "")
  1130. {
  1131. maxStr = key;
  1132. }
  1133. else
  1134. {
  1135. if (string.Compare(maxStr, key, true) < 0)
  1136. {
  1137. maxStr = key;
  1138. }
  1139. }
  1140. }
  1141. JArray jarr = new JArray();
  1142. for (int i = 0; i < gradeA[maxStr].Count; i++)
  1143. {
  1144. jarr.Add(gradeA[maxStr][i]);
  1145. }
  1146. if (res.ContainsKey(maxStr))
  1147. {
  1148. }
  1149. else
  1150. {
  1151. result += maxStr + ";";
  1152. res.Add(maxStr, jarr);
  1153. }
  1154. }
  1155. if (gradeAe.Count > 0)
  1156. {
  1157. string maxStr = "";
  1158. foreach (string key in gradeAe.Keys)
  1159. {
  1160. if (maxStr == "")
  1161. {
  1162. maxStr = key;
  1163. }
  1164. else
  1165. {
  1166. if (string.Compare(maxStr, key, true) < 0)
  1167. {
  1168. maxStr = key;
  1169. }
  1170. }
  1171. }
  1172. JArray jarr = new JArray();
  1173. for (int i = 0; i < gradeAe[maxStr].Count; i++)
  1174. {
  1175. jarr.Add(gradeAe[maxStr][i]);
  1176. }
  1177. if (res.ContainsKey(maxStr))
  1178. {
  1179. }
  1180. else
  1181. {
  1182. result += maxStr + ";";
  1183. res.Add(maxStr, jarr);
  1184. }
  1185. }
  1186. if (gradeB.Count > 0)
  1187. {
  1188. string maxStr = "";
  1189. foreach (string key in gradeB.Keys)
  1190. {
  1191. if (maxStr == "")
  1192. {
  1193. maxStr = key;
  1194. }
  1195. else
  1196. {
  1197. if (string.Compare(maxStr, key, true) < 0)
  1198. {
  1199. maxStr = key;
  1200. }
  1201. }
  1202. }
  1203. JArray jarr = new JArray();
  1204. for (int i = 0; i < gradeB[maxStr].Count; i++)
  1205. {
  1206. jarr.Add(gradeB[maxStr][i]);
  1207. }
  1208. if (res.ContainsKey(maxStr))
  1209. {
  1210. }
  1211. else
  1212. {
  1213. result += maxStr + ";";
  1214. res.Add(maxStr, jarr);
  1215. }
  1216. }
  1217. if (gradeBe.Count > 0)
  1218. {
  1219. string maxStr = "";
  1220. foreach (string key in gradeBe.Keys)
  1221. {
  1222. if (maxStr == "")
  1223. {
  1224. maxStr = key;
  1225. }
  1226. else
  1227. {
  1228. if (string.Compare(maxStr, key, true) < 0)
  1229. {
  1230. maxStr = key;
  1231. }
  1232. }
  1233. }
  1234. JArray jarr = new JArray();
  1235. for (int i = 0; i < gradeBe[maxStr].Count; i++)
  1236. {
  1237. jarr.Add(gradeBe[maxStr][i]);
  1238. }
  1239. if (res.ContainsKey(maxStr))
  1240. {
  1241. }
  1242. else
  1243. {
  1244. result += maxStr + ";";
  1245. res.Add(maxStr, jarr);
  1246. }
  1247. }
  1248. if (gradeC.Count > 0)
  1249. {
  1250. string maxStr = "";
  1251. foreach (string key in gradeC.Keys)
  1252. {
  1253. if (maxStr == "")
  1254. {
  1255. maxStr = key;
  1256. }
  1257. else
  1258. {
  1259. if (string.Compare(maxStr, key, true) < 0)
  1260. {
  1261. maxStr = key;
  1262. }
  1263. }
  1264. }
  1265. JArray jarr = new JArray();
  1266. for (int i = 0; i < gradeC[maxStr].Count; i++)
  1267. {
  1268. jarr.Add(gradeC[maxStr][i]);
  1269. }
  1270. if (res.ContainsKey(maxStr))
  1271. {
  1272. }
  1273. else
  1274. {
  1275. result += maxStr + ";";
  1276. res.Add(maxStr, jarr);
  1277. }
  1278. }
  1279. if (gradeCe.Count > 0)
  1280. {
  1281. string maxStr = "";
  1282. foreach (string key in gradeCe.Keys)
  1283. {
  1284. if (maxStr == "")
  1285. {
  1286. maxStr = key;
  1287. }
  1288. else
  1289. {
  1290. if (string.Compare(maxStr, key, true) < 0)
  1291. {
  1292. maxStr = key;
  1293. }
  1294. }
  1295. }
  1296. JArray jarr = new JArray();
  1297. for (int i = 0; i < gradeCe[maxStr].Count; i++)
  1298. {
  1299. jarr.Add(gradeCe[maxStr][i]);
  1300. }
  1301. if (res.ContainsKey(maxStr))
  1302. {
  1303. }
  1304. else
  1305. {
  1306. result += maxStr + ";";
  1307. res.Add(maxStr, jarr);
  1308. }
  1309. }
  1310. if (gradeD.Count > 0)
  1311. {
  1312. string maxStr = "";
  1313. foreach (string key in gradeD.Keys)
  1314. {
  1315. if (maxStr == "")
  1316. {
  1317. maxStr = key;
  1318. }
  1319. else
  1320. {
  1321. if (string.Compare(maxStr, key, true) < 0)
  1322. {
  1323. maxStr = key;
  1324. }
  1325. }
  1326. }
  1327. JArray jarr = new JArray();
  1328. for (int i = 0; i < gradeD[maxStr].Count; i++)
  1329. {
  1330. jarr.Add(gradeD[maxStr][i]);
  1331. }
  1332. if (res.ContainsKey(maxStr))
  1333. {
  1334. }
  1335. else
  1336. {
  1337. result += maxStr + ";";
  1338. res.Add(maxStr, jarr);
  1339. }
  1340. }
  1341. if (gradeDe.Count > 0)
  1342. {
  1343. string maxStr = "";
  1344. foreach (string key in gradeDe.Keys)
  1345. {
  1346. if (maxStr == "")
  1347. {
  1348. maxStr = key;
  1349. }
  1350. else
  1351. {
  1352. if (string.Compare(maxStr, key, true) < 0)
  1353. {
  1354. maxStr = key;
  1355. }
  1356. }
  1357. }
  1358. JArray jarr = new JArray();
  1359. for (int i = 0; i < gradeDe[maxStr].Count; i++)
  1360. {
  1361. jarr.Add(gradeDe[maxStr][i]);
  1362. }
  1363. if (res.ContainsKey(maxStr))
  1364. {
  1365. }
  1366. else
  1367. {
  1368. result += maxStr + ";";
  1369. res.Add(maxStr, jarr);
  1370. }
  1371. }
  1372. if (gradeDs.Count > 0)
  1373. {
  1374. string maxStr = "";
  1375. foreach (string key in gradeDs.Keys)
  1376. {
  1377. if (maxStr == "")
  1378. {
  1379. maxStr = key;
  1380. }
  1381. else
  1382. {
  1383. if (string.Compare(maxStr, key, true) < 0)
  1384. {
  1385. maxStr = key;
  1386. }
  1387. }
  1388. }
  1389. JArray jarr = new JArray();
  1390. for (int i = 0; i < gradeDs[maxStr].Count; i++)
  1391. {
  1392. jarr.Add(gradeDs[maxStr][i]);
  1393. }
  1394. if (res.ContainsKey(maxStr))
  1395. {
  1396. }
  1397. else
  1398. {
  1399. result += maxStr + ";";
  1400. res.Add(maxStr, jarr);
  1401. }
  1402. }
  1403. if (gradeAs.Count > 0)
  1404. {
  1405. foreach (string key in gradeAs.Keys)
  1406. {
  1407. result += key + ";";
  1408. JArray jarr = new JArray();
  1409. for (int i = 0; i < gradeAs[key].Count; i++)
  1410. {
  1411. jarr.Add(gradeAs[key][i]);
  1412. }
  1413. if (res.ContainsKey(key))
  1414. {
  1415. continue;
  1416. }
  1417. else
  1418. {
  1419. res.Add(key, jarr);
  1420. }
  1421. }
  1422. }
  1423. if (gradeBs.Count > 0)
  1424. {
  1425. foreach (string key in gradeBs.Keys)
  1426. {
  1427. result += key + ";";
  1428. JArray jarr = new JArray();
  1429. for (int i = 0; i < gradeBs[key].Count; i++)
  1430. {
  1431. jarr.Add(gradeBs[key][i]);
  1432. }
  1433. if (res.ContainsKey(key))
  1434. {
  1435. continue;
  1436. }
  1437. else
  1438. {
  1439. res.Add(key, jarr);
  1440. }
  1441. }
  1442. }
  1443. if (gradeCs.Count > 0)
  1444. {
  1445. foreach (string key in gradeCs.Keys)
  1446. {
  1447. result += key + ";";
  1448. JArray jarr = new JArray();
  1449. for (int i = 0; i < gradeCs[key].Count; i++)
  1450. {
  1451. jarr.Add(gradeCs[key][i]);
  1452. }
  1453. if (res.ContainsKey(key))
  1454. {
  1455. continue;
  1456. }
  1457. else
  1458. {
  1459. res.Add(key, jarr);
  1460. }
  1461. }
  1462. }
  1463. if (result.Length == 0)
  1464. {
  1465. ret = "not result!";
  1466. return ret;
  1467. }
  1468. res.Add("result", result.Substring(0, result.Length - 1));
  1469. ret = res.ToString();
  1470. using (System.IO.StreamWriter file = new System.IO.StreamWriter(Path.Combine(this._gradePath, "AI") + "\\result.ai", false, Encoding.Default))
  1471. {
  1472. file.WriteLine(ret);// 直接追加文件末尾,换行
  1473. file.Close();
  1474. }
  1475. }
  1476. catch (Exception e)
  1477. {
  1478. throw (new Exception("AI文件错误!"));
  1479. }
  1480. reader.Close();
  1481. _file.Close();
  1482. _file.Dispose();
  1483. }
  1484. }
  1485. }
  1486. }
  1487. catch { }
  1488. return ret;
  1489. }
  1490. #endregion
  1491. }
  1492. }