FdcServerTcpHandler_GenericDisplayCommandV1Wrapper_Test.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. using GenericDisplayCommand;
  2. using GenericDisplayCommand.Controls;
  3. using GenericDisplayCommand.Controls.V1;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Xml.Serialization;
  12. using Wayne.FDCPOSInterface;
  13. using Wayne.FDCPOSLibrary;
  14. namespace FdcServerTest
  15. {
  16. [TestClass]
  17. public class FdcServerTcpHandler_GenericDisplayCommandV1Wrapper_Test
  18. {
  19. public static bool ValueEquals(IEnumerable<byte> array1, IEnumerable<byte> array2)
  20. {
  21. if (array1 == null && array2 == null)
  22. {
  23. return true;
  24. }
  25. if ((array1 == null) || (array2 == null))
  26. {
  27. return false;
  28. }
  29. if (array1.Count() != array2.Count())
  30. {
  31. return false;
  32. }
  33. if (array1.Equals(array2))
  34. {
  35. return true;
  36. }
  37. else
  38. {
  39. for (int Index = 0; Index < array1.Count(); Index++)
  40. {
  41. if (!Equals(array1.ElementAt(Index), array2.ElementAt(Index)))
  42. {
  43. return false;
  44. }
  45. }
  46. }
  47. return true;
  48. }
  49. public class Message
  50. {
  51. public string Content { get; set; }
  52. }
  53. [TestMethod]
  54. public void UTF8_content_xml_Serialize_Test0()
  55. {
  56. string msgStr = "hell";
  57. var msg_ASCII = new Message() { Content = msgStr };
  58. var xmlMsgBodyMemStream = new MemoryStream();
  59. XmlSerializer serializer = new XmlSerializer(typeof(Message));
  60. //StreamWriter default use UTF-8 encoding
  61. serializer.Serialize(xmlMsgBodyMemStream, msg_ASCII);
  62. byte[] xmlMsgBodyBytes_ascII = null;
  63. xmlMsgBodyMemStream.Position = 0;
  64. using (StreamReader _ = new StreamReader(xmlMsgBodyMemStream, Encoding.UTF8))
  65. xmlMsgBodyBytes_ascII = Encoding.UTF8.GetBytes(_.ReadToEnd());
  66. //==================
  67. msgStr = "你好你好";
  68. xmlMsgBodyMemStream = new MemoryStream();
  69. var msg_UTF8 = new Message() { Content = msgStr };
  70. serializer.Serialize(xmlMsgBodyMemStream, msg_UTF8);
  71. byte[] xmlMsgBodyBytes_utf8 = null;
  72. xmlMsgBodyMemStream.Position = 0;
  73. using (StreamReader _ = new StreamReader(xmlMsgBodyMemStream, Encoding.UTF8))
  74. xmlMsgBodyBytes_utf8 = Encoding.UTF8.GetBytes(_.ReadToEnd());
  75. var byteLengthDiff = Encoding.UTF8.GetBytes(msg_UTF8.Content).Length - Encoding.UTF8.GetBytes(msg_ASCII.Content).Length;
  76. Assert.AreEqual(true, xmlMsgBodyBytes_utf8.Length > xmlMsgBodyBytes_ascII.Length);
  77. Assert.AreEqual(true, (xmlMsgBodyBytes_utf8.Length - byteLengthDiff) == xmlMsgBodyBytes_ascII.Length);
  78. }
  79. [TestMethod]
  80. public void SerializeFdcMessageToNetworkBytes_Test0()
  81. {
  82. string workStationId = "abcdef";
  83. string appSendId = "i'm doing a test";
  84. var innerMsg = this.PrepareGenericDisplayCommandWithChineseCharacterIn();
  85. MemoryStream ms = new MemoryStream();
  86. XmlSerializer xmlSerializer = new XmlSerializer(typeof(GenericDisplayCommandWrapper));
  87. xmlSerializer.Serialize(ms, innerMsg);
  88. ms.Position = 0;
  89. var innerMsgStr = new StreamReader(ms).ReadToEnd();
  90. var outerMsg = new FDCMessageGenericTypelessMessage()
  91. {
  92. WorkstationID = workStationId,
  93. ApplicationSender = appSendId,
  94. MessageID = "9999",
  95. FDCdata = new FDCMessageFDCdataGenericTypelessMessage[] {
  96. new FDCMessageFDCdataGenericTypelessMessage()
  97. {
  98. FDCTimeStamp=FDCConvert.ToString(DateTime.Now),
  99. Message = innerMsgStr
  100. }
  101. }
  102. };
  103. var raw = FdcServerTcpHandler.SerializeFdcMessageToNetworkBytes(outerMsg, true);
  104. // skip 4 bytes len, 16 bytes hash, then get the xml content bytes.
  105. var actual = raw.Item1.Skip(4 + 16).ToArray();
  106. ms = new MemoryStream();
  107. xmlSerializer = new XmlSerializer(typeof(FDCMessageGenericTypelessMessage));
  108. xmlSerializer.Serialize(ms, outerMsg);
  109. ms.Position = 0;
  110. var expect = Encoding.UTF8.GetBytes(new StreamReader(ms).ReadToEnd());
  111. Assert.AreEqual(true, raw.Item2.Length != raw.Item1.Length, "Chinese character contained string should have its (char length) > its (bytes length)");
  112. Assert.AreEqual(true, ValueEquals(actual, expect));
  113. }
  114. [TestMethod]
  115. public void SerializeFdcMessageToNetworkBytes_Test1()
  116. {
  117. string workStationId = "abcdef";
  118. string appSendId = "i'm doing a test";
  119. var innerMsg = this.PrepareGenericDisplayCommandWithOnlyAscIICharacterIn_Simple();
  120. MemoryStream ms = new MemoryStream();
  121. XmlSerializer xmlSerializer = new XmlSerializer(typeof(GenericDisplayCommandWrapper));
  122. xmlSerializer.Serialize(ms, innerMsg);
  123. ms.Position = 0;
  124. var innerMsgStr = new StreamReader(ms).ReadToEnd();
  125. var outerMsg = new FDCMessageGenericTypelessMessage()
  126. {
  127. WorkstationID = workStationId,
  128. ApplicationSender = appSendId,
  129. MessageID = "9999",
  130. FDCdata = new FDCMessageFDCdataGenericTypelessMessage[] {
  131. new FDCMessageFDCdataGenericTypelessMessage()
  132. {
  133. FDCTimeStamp=FDCConvert.ToString(DateTime.Now),
  134. Message = innerMsgStr
  135. }
  136. }
  137. };
  138. var raw = FdcServerTcpHandler.SerializeFdcMessageToNetworkBytes(outerMsg, true);
  139. // skip 4 bytes len, 16 bytes hash, then get the xml content bytes.
  140. var actual = raw.Item1.Skip(4 + 16).ToArray();
  141. ms = new MemoryStream();
  142. xmlSerializer = new XmlSerializer(typeof(FDCMessageGenericTypelessMessage));
  143. xmlSerializer.Serialize(ms, outerMsg);
  144. ms.Position = 0;
  145. var expect = Encoding.UTF8.GetBytes(new StreamReader(ms).ReadToEnd());
  146. Assert.AreEqual(true, (raw.Item2.Length + 4 + 16) == raw.Item1.Length, "Full AscII character contained string should have its (char length) == its (bytes length)");
  147. Assert.AreEqual(true, ValueEquals(actual, expect));
  148. }
  149. [TestMethod]
  150. public void SerializeFdcMessageToNetworkBytes_Test2()
  151. {
  152. string workStationId = "abcdef";
  153. string appSendId = "i'm doing a test";
  154. var innerMsg = this.PrepareGenericDisplayCommandWithOnlyAscIICharacterIn();
  155. MemoryStream ms = new MemoryStream();
  156. XmlSerializer xmlSerializer = new XmlSerializer(typeof(GenericDisplayCommandWrapper));
  157. xmlSerializer.Serialize(ms, innerMsg);
  158. ms.Position = 0;
  159. var innerMsgStr = new StreamReader(ms).ReadToEnd();
  160. var outerMsg = new FDCMessageGenericTypelessMessage()
  161. {
  162. WorkstationID = workStationId,
  163. ApplicationSender = appSendId,
  164. MessageID = "9999",
  165. FDCdata = new FDCMessageFDCdataGenericTypelessMessage[] {
  166. new FDCMessageFDCdataGenericTypelessMessage()
  167. {
  168. FDCTimeStamp=FDCConvert.ToString(DateTime.Now),
  169. Message = innerMsgStr
  170. }
  171. }
  172. };
  173. var raw = FdcServerTcpHandler.SerializeFdcMessageToNetworkBytes(outerMsg, true);
  174. // skip 4 bytes len, 16 bytes hash, then get the xml content bytes.
  175. var actual = raw.Item1.Skip(4 + 16).ToArray();
  176. ms = new MemoryStream();
  177. xmlSerializer = new XmlSerializer(typeof(FDCMessageGenericTypelessMessage));
  178. xmlSerializer.Serialize(ms, outerMsg);
  179. ms.Position = 0;
  180. var expect = Encoding.UTF8.GetBytes(new StreamReader(ms).ReadToEnd());
  181. Assert.AreEqual(true, (raw.Item2.Length + 4 + 16) == raw.Item1.Length, "Full AscII character contained string should have its (char length) == its (bytes length)");
  182. Assert.AreEqual(true, ValueEquals(actual, expect));
  183. }
  184. private GenericDisplayCommandWrapper PrepareGenericDisplayCommandWithOnlyAscIICharacterIn_Simple()
  185. {
  186. LinearLayout root = new LinearLayout();
  187. root.Orientation = "vertical";
  188. root.Height = "match_parent";
  189. root.Width = "match_parent";
  190. root.WeightSum = 10.ToString(CultureInfo.InvariantCulture);
  191. var genericDisplayCommand = new GenericDisplayCommandV1Wrapper() { Version = 1, Control = root };
  192. return genericDisplayCommand;
  193. }
  194. private GenericDisplayCommandWrapper PrepareGenericDisplayCommandWithOnlyAscIICharacterIn()
  195. {
  196. LinearLayout advLinearLayout = new LinearLayout();
  197. advLinearLayout.Views.Add(new VideoView() { Src = "mp4.avi" });
  198. advLinearLayout.Orientation = "vertical";
  199. advLinearLayout.Height = "0dp";
  200. advLinearLayout.WeightSum = 4.ToString(CultureInfo.InvariantCulture);
  201. advLinearLayout.Width = "match_parent";
  202. LinearLayout middleLinearLayout = new LinearLayout()
  203. {
  204. Orientation = "horizontal",
  205. Height = "0dp",
  206. Weight = 3.ToString(CultureInfo.InvariantCulture),
  207. Width = "match_parent",
  208. };
  209. #region middle_left
  210. LinearLayout middle_left_LinearLayout = new LinearLayout()
  211. {
  212. Height = "match_parent",
  213. Width = "0dp",
  214. Weight = 7.5f.ToString(CultureInfo.InvariantCulture),
  215. };
  216. var carPlatesGridView = new GridView() { NumColumns = 3 };
  217. List<Tuple<string, string>> carPlateLabels = new List<Tuple<string, string>>();
  218. carPlateLabels.Add(new Tuple<string, string>("ACD343", "11"));
  219. carPlateLabels.Add(new Tuple<string, string>("BCDFSADF", "22"));
  220. carPlateLabels.Add(new Tuple<string, string>("CDF23423DF", "33"));
  221. carPlateLabels.Add(new Tuple<string, string>("D232f23DF", "44"));
  222. carPlateLabels.Add(new Tuple<string, string>("Eadfvvhjk3DF", "55"));
  223. for (int i = 0; i < carPlateLabels.Count; i++)
  224. {
  225. carPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(carPlateLabels[i].Item1,
  226. carPlateLabels[i].Item2, "Yellow"));
  227. }
  228. middle_left_LinearLayout.Views.Add(carPlatesGridView);
  229. #endregion
  230. #region middle right
  231. LinearLayout middle_right_LinearLayout = new LinearLayout()
  232. {
  233. Height = "match_parent",
  234. Width = "0dp",
  235. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  236. };
  237. var errorCarPlatesGridView = new GridView() { NumColumns = 1 };
  238. List<Tuple<string, string>> errorCarPlateLabels = new List<Tuple<string, string>>();
  239. errorCarPlateLabels.Add(new Tuple<string, string>("QCD343", "66"));
  240. errorCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "77"));
  241. errorCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "88"));
  242. errorCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "99"));
  243. errorCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "00"));
  244. for (int i = 0; i < errorCarPlateLabels.Count; i++)
  245. {
  246. errorCarPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(errorCarPlateLabels[i].Item1,
  247. errorCarPlateLabels[i].Item2, "Red"));
  248. }
  249. middle_right_LinearLayout.Views.Add(errorCarPlatesGridView);
  250. #endregion
  251. LinearLayout bottomLinearLayout = new LinearLayout()
  252. {
  253. Orientation = "horizontal",
  254. Height = "0dp",
  255. Weight = 3.ToString(CultureInfo.InvariantCulture),
  256. WeightSum = 10.ToString(CultureInfo.InvariantCulture),
  257. Width = "match_parent",
  258. };
  259. #region firstNozzleLinearLayout
  260. LinearLayout firstNozzleLinearLayout = new LinearLayout()
  261. {
  262. Orientation = "vertical",
  263. Height = "match_parent",
  264. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  265. Width = "0dp",
  266. };
  267. List<Tuple<string, string>> firstNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  268. firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "11"));
  269. for (int i = 0; i < firstNozzleBoundCarPlateLabels.Count; i++)
  270. {
  271. firstNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(firstNozzleBoundCarPlateLabels[i].Item1,
  272. firstNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  273. }
  274. firstNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 1 });
  275. #endregion
  276. bottomLinearLayout.Views.Add(firstNozzleLinearLayout);
  277. #region second NozzleLinearLayout
  278. LinearLayout secondNozzleLinearLayout = new LinearLayout()
  279. {
  280. Orientation = "vertical",
  281. Height = "match_parent",
  282. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  283. Width = "0dp",
  284. };
  285. List<Tuple<string, string>> secondNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  286. secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "aa"));
  287. for (int i = 0; i < secondNozzleBoundCarPlateLabels.Count; i++)
  288. {
  289. secondNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(secondNozzleBoundCarPlateLabels[i].Item1,
  290. secondNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  291. }
  292. secondNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 2 });
  293. #endregion
  294. bottomLinearLayout.Views.Add(secondNozzleLinearLayout);
  295. #region third NozzleLinearLayout
  296. LinearLayout thirdNozzleLinearLayout = new LinearLayout()
  297. {
  298. Orientation = "vertical",
  299. Height = "match_parent",
  300. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  301. Width = "0dp",
  302. };
  303. List<Tuple<string, string>> thirdNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  304. thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "cc"));
  305. for (int i = 0; i < thirdNozzleBoundCarPlateLabels.Count; i++)
  306. {
  307. thirdNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(thirdNozzleBoundCarPlateLabels[i].Item1,
  308. thirdNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  309. }
  310. thirdNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 3 });
  311. #endregion
  312. bottomLinearLayout.Views.Add(thirdNozzleLinearLayout);
  313. #region fourth NozzleLinearLayout
  314. LinearLayout fourthNozzleLinearLayout = new LinearLayout()
  315. {
  316. Orientation = "vertical",
  317. Height = "match_parent",
  318. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  319. Width = "0dp",
  320. };
  321. List<Tuple<string, string>> fourthNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  322. fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "1111"));
  323. for (int i = 0; i < fourthNozzleBoundCarPlateLabels.Count; i++)
  324. {
  325. fourthNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(fourthNozzleBoundCarPlateLabels[i].Item1,
  326. fourthNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  327. }
  328. fourthNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 4 });
  329. #endregion
  330. bottomLinearLayout.Views.Add(fourthNozzleLinearLayout);
  331. LinearLayout root = new LinearLayout();
  332. root.Orientation = "vertical";
  333. root.Height = "match_parent";
  334. root.Width = "match_parent";
  335. root.WeightSum = 10.ToString(CultureInfo.InvariantCulture);
  336. root.Views.Add(advLinearLayout);
  337. root.Views.Add(middleLinearLayout);
  338. root.Views.Add(bottomLinearLayout);
  339. var genericDisplayCommand = new GenericDisplayCommandV1Wrapper() { Version = 1, Control = root };
  340. return genericDisplayCommand;
  341. }
  342. private GenericDisplayCommandWrapper PrepareGenericDisplayCommandWithChineseCharacterIn()
  343. {
  344. LinearLayout advLinearLayout = new LinearLayout();
  345. advLinearLayout.Views.Add(new VideoView() { Src = "mp4.avi" });
  346. advLinearLayout.Orientation = "vertical";
  347. advLinearLayout.Height = "0dp";
  348. advLinearLayout.WeightSum = 4.ToString(CultureInfo.InvariantCulture);
  349. advLinearLayout.Width = "match_parent";
  350. LinearLayout middleLinearLayout = new LinearLayout()
  351. {
  352. Orientation = "horizontal",
  353. Height = "0dp",
  354. Weight = 3.ToString(CultureInfo.InvariantCulture),
  355. Width = "match_parent",
  356. };
  357. #region middle_left
  358. LinearLayout middle_left_LinearLayout = new LinearLayout()
  359. {
  360. Height = "match_parent",
  361. Width = "0dp",
  362. Weight = 7.5f.ToString(CultureInfo.InvariantCulture),
  363. };
  364. var carPlatesGridView = new GridView() { NumColumns = 3 };
  365. List<Tuple<string, string>> carPlateLabels = new List<Tuple<string, string>>();
  366. carPlateLabels.Add(new Tuple<string, string>("ACD343", "你好世界你好世界你好世界你好世界"));
  367. for (int i = 0; i < carPlateLabels.Count; i++)
  368. {
  369. carPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(carPlateLabels[i].Item1,
  370. carPlateLabels[i].Item2, "Yellow"));
  371. }
  372. middle_left_LinearLayout.Views.Add(carPlatesGridView);
  373. #endregion
  374. #region middle right
  375. LinearLayout middle_right_LinearLayout = new LinearLayout()
  376. {
  377. Height = "match_parent",
  378. Width = "0dp",
  379. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  380. };
  381. var errorCarPlatesGridView = new GridView() { NumColumns = 1 };
  382. List<Tuple<string, string>> errorCarPlateLabels = new List<Tuple<string, string>>();
  383. errorCarPlateLabels.Add(new Tuple<string, string>("QCD343", "66"));
  384. errorCarPlateLabels.Add(new Tuple<string, string>("TCDFSADF", "77"));
  385. errorCarPlateLabels.Add(new Tuple<string, string>("XDF23423DF", "88"));
  386. errorCarPlateLabels.Add(new Tuple<string, string>("Y232f23DF", "99"));
  387. errorCarPlateLabels.Add(new Tuple<string, string>("Zadfvvhjk3DF", "00"));
  388. for (int i = 0; i < errorCarPlateLabels.Count; i++)
  389. {
  390. errorCarPlatesGridView.Views.Add(this.ConstuctCarPlateLabel(errorCarPlateLabels[i].Item1,
  391. errorCarPlateLabels[i].Item2, "Red"));
  392. }
  393. middle_right_LinearLayout.Views.Add(errorCarPlatesGridView);
  394. #endregion
  395. LinearLayout bottomLinearLayout = new LinearLayout()
  396. {
  397. Orientation = "horizontal",
  398. Height = "0dp",
  399. Weight = 3.ToString(CultureInfo.InvariantCulture),
  400. WeightSum = 10.ToString(CultureInfo.InvariantCulture),
  401. Width = "match_parent",
  402. };
  403. #region firstNozzleLinearLayout
  404. LinearLayout firstNozzleLinearLayout = new LinearLayout()
  405. {
  406. Orientation = "vertical",
  407. Height = "match_parent",
  408. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  409. Width = "0dp",
  410. };
  411. List<Tuple<string, string>> firstNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  412. firstNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "11"));
  413. for (int i = 0; i < firstNozzleBoundCarPlateLabels.Count; i++)
  414. {
  415. firstNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(firstNozzleBoundCarPlateLabels[i].Item1,
  416. firstNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  417. }
  418. firstNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 1 });
  419. #endregion
  420. bottomLinearLayout.Views.Add(firstNozzleLinearLayout);
  421. #region second NozzleLinearLayout
  422. LinearLayout secondNozzleLinearLayout = new LinearLayout()
  423. {
  424. Orientation = "vertical",
  425. Height = "match_parent",
  426. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  427. Width = "0dp",
  428. };
  429. List<Tuple<string, string>> secondNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  430. secondNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "aa"));
  431. for (int i = 0; i < secondNozzleBoundCarPlateLabels.Count; i++)
  432. {
  433. secondNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(secondNozzleBoundCarPlateLabels[i].Item1,
  434. secondNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  435. }
  436. secondNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 2 });
  437. #endregion
  438. bottomLinearLayout.Views.Add(secondNozzleLinearLayout);
  439. #region third NozzleLinearLayout
  440. LinearLayout thirdNozzleLinearLayout = new LinearLayout()
  441. {
  442. Orientation = "vertical",
  443. Height = "match_parent",
  444. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  445. Width = "0dp",
  446. };
  447. List<Tuple<string, string>> thirdNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  448. thirdNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "cc"));
  449. for (int i = 0; i < thirdNozzleBoundCarPlateLabels.Count; i++)
  450. {
  451. thirdNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(thirdNozzleBoundCarPlateLabels[i].Item1,
  452. thirdNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  453. }
  454. thirdNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 3 });
  455. #endregion
  456. bottomLinearLayout.Views.Add(thirdNozzleLinearLayout);
  457. #region fourth NozzleLinearLayout
  458. LinearLayout fourthNozzleLinearLayout = new LinearLayout()
  459. {
  460. Orientation = "vertical",
  461. Height = "match_parent",
  462. Weight = 2.5f.ToString(CultureInfo.InvariantCulture),
  463. Width = "0dp",
  464. };
  465. List<Tuple<string, string>> fourthNozzleBoundCarPlateLabels = new List<Tuple<string, string>>();
  466. fourthNozzleBoundCarPlateLabels.Add(new Tuple<string, string>("QCD343", "1111"));
  467. for (int i = 0; i < fourthNozzleBoundCarPlateLabels.Count; i++)
  468. {
  469. fourthNozzleLinearLayout.Views.Add(this.ConstuctCarPlateLabel(fourthNozzleBoundCarPlateLabels[i].Item1,
  470. fourthNozzleBoundCarPlateLabels[i].Item2, "Blue"));
  471. }
  472. fourthNozzleLinearLayout.Views.Add(new NozzleView() { PumpId = 3, NozzleId = 4 });
  473. #endregion
  474. bottomLinearLayout.Views.Add(fourthNozzleLinearLayout);
  475. LinearLayout root = new LinearLayout();
  476. root.Orientation = "vertical";
  477. root.Height = "match_parent";
  478. root.Width = "match_parent";
  479. root.WeightSum = 10.ToString(CultureInfo.InvariantCulture);
  480. root.Views.Add(advLinearLayout);
  481. root.Views.Add(middleLinearLayout);
  482. root.Views.Add(bottomLinearLayout);
  483. var genericDisplayCommand = new GenericDisplayCommandV1Wrapper() { Version = 1, Control = root };
  484. return genericDisplayCommand;
  485. }
  486. private LinearLayout ConstuctCarPlateLabel(string carPlate, string hint, string hintColor)
  487. {
  488. var label = new LinearLayout()
  489. {
  490. Id = carPlate,
  491. Height = "match_parent",
  492. Width = "match_parent",
  493. Orientation = "horizontal",
  494. AllowActions = new List<AllowAction>() { AllowAction.Select, AllowAction.Drag, AllowAction.Drop },
  495. };
  496. label.Views.Add(new TextView()
  497. {
  498. Text = carPlate,
  499. Background = "White",
  500. AllowActions = new List<AllowAction>() { AllowAction.Select, AllowAction.Drag }
  501. });
  502. label.Views.Add(new TextView() { Text = hint, Background = hintColor, PaddingLeft = "2dp" });
  503. return label;
  504. }
  505. }
  506. }