biz_scannedBatch.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Collections.Concurrent;
  9. using Newtonsoft.Json;
  10. using Saraff.Twain;
  11. using HXX.Scanner.Socket;
  12. using HXX.Scanner.Common;
  13. namespace HXX.Scanner.Biz.Socket
  14. {
  15. /// <summary>
  16. /// 业务处理 对每个连接发送间歇1秒的已扫描过的batch编号
  17. /// </summary>
  18. public class biz_scannedBatch
  19. {
  20. /// <summary>
  21. /// 本次运行后已扫描的batch的列表
  22. /// </summary>
  23. public static ConcurrentDictionary<string, string> dic_scanned_batch_list = new ConcurrentDictionary<string, string>();
  24. /// <summary>
  25. /// 添加batch
  26. /// </summary>
  27. /// <param name="batch"></param>
  28. public static void add_batch(string batch)
  29. {
  30. if (!dic_scanned_batch_list.ContainsKey(batch))
  31. {
  32. dic_scanned_batch_list[batch] = string.Empty;
  33. }
  34. }
  35. /// <summary>
  36. /// 主业务 从程序运行到退出始终发送
  37. /// </summary>
  38. public static void Work()
  39. {
  40. Task.Run(() =>
  41. {
  42. Thread.Sleep(2000);
  43. while (true)
  44. {
  45. Thread.Sleep(1000);
  46. //SocketServerManager.Send_All(get_cmd().ToJson());
  47. }
  48. });
  49. }
  50. /// <summary>
  51. /// 构造返回值
  52. /// </summary>
  53. /// <returns></returns>
  54. private static cmd_scannedBatch get_cmd()
  55. {
  56. cmd_scannedBatch result = new cmd_scannedBatch();
  57. result.action = "scannedBatch";
  58. result.param = new subcmd_scannedBatch();
  59. result.param.zipId = get_batch();
  60. return result;
  61. }
  62. /// <summary>
  63. /// 获取所有batch的字符串
  64. /// </summary>
  65. /// <returns></returns>
  66. private static string get_batch()
  67. {
  68. string result = string.Empty;
  69. foreach (var b in dic_scanned_batch_list)
  70. {
  71. result += "," + b.Key;
  72. }
  73. if (result.Length > 0)
  74. {
  75. result = result.Substring(1);
  76. }
  77. return result;
  78. }
  79. }
  80. }