biz_scanTemplate.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 Newtonsoft.Json;
  8. using Saraff.Twain;
  9. using HXX.Scanner.Socket;
  10. using HXX.Scanner.Common;
  11. namespace HXX.Scanner.Biz.Socket
  12. {
  13. /// <summary>
  14. /// 业务处理 扫描模板(扫描后不存数据库,不上传,只返回图片文件信息)
  15. /// </summary>
  16. public class biz_scanTemplate
  17. {
  18. /// <summary>
  19. /// 主业务
  20. /// </summary>
  21. /// <param name="connId"></param>
  22. /// <param name="data"></param>
  23. public async static void Work(IntPtr connId, cmd_scanTemplate data)
  24. {
  25. var response = new response_startScanTemplate();
  26. if (!config_environment.scan_state)
  27. {
  28. var result = await work_detail(connId, data);
  29. if (result.Status == 1)
  30. {
  31. response.code = 200;
  32. response.msg = "启动扫描成功";
  33. }
  34. else
  35. {
  36. response.code = result.Status;
  37. response.msg = result.Message;
  38. }
  39. }
  40. else
  41. {
  42. response.code = 509;
  43. response.msg = "扫描仪正在使用中";
  44. }
  45. response.data = data;
  46. //SocketServerManager.Send_Family(connId, response.ToJson());
  47. SocketServerManager.Send_Single(connId, response.ToJson());
  48. }
  49. /// <summary>
  50. /// 扫描及构造返回值
  51. /// </summary>
  52. /// <param name="connId"></param>
  53. /// <param name="data"></param>
  54. /// <returns></returns>
  55. private async static Task<ResponseEntity> work_detail(IntPtr connId, cmd_scanTemplate data)
  56. {
  57. var result = new ResponseEntity();
  58. try
  59. {
  60. //获取当前激活的扫描仪
  61. var scanner = scanner_manager.get_current();
  62. if (scanner != null)
  63. {
  64. //设置环境参数
  65. config_environment.scan_type2 = ScanType.ScanTemplate;
  66. config_environment.scan_type = biz_environment.get_scan_type(0);
  67. config_environment.scan_ab = biz_environment.get_ab(data.paperSchema);
  68. config_environment.paper_size = biz_environment.get_paper_size(3);
  69. config_environment.current_invoker = connId;
  70. //config_environment.use_source_ui = false;
  71. config_environment.use_source_ui = data.useDriveUI == 1;
  72. if (data.dpi > 0)
  73. {
  74. scanner.resolution = data.dpi;
  75. }
  76. scanner.setPaperSize(config_environment.paper_size);
  77. //初始化文件信息,文件名及计数器
  78. cmd_startScan2 fake = new cmd_startScan2();
  79. fake.batchNumber = data.batchNumber;
  80. fake.subjectCode = data.subjectCode;
  81. fake.paperSchema = data.paperSchema;
  82. fake.isLocalConfig = "0";
  83. config_environment.web_parameter = fake;//保存参数本身
  84. file_manager.Init(fake);
  85. //发送扫描指令
  86. result = await engine_twain32.Engine.Scan(scanner);
  87. }
  88. else
  89. {
  90. result.Status = 509;
  91. result.Message = "未找到指定的扫描仪";
  92. }
  93. }
  94. catch (TwainException te)
  95. {
  96. config_environment.scan_state = false;
  97. LogManager.WriteLog(te);
  98. result.Message = biz_twainException.get_TwainException_msg(te);
  99. if (te.ConditionCode.Equals(TwCC.OperationError))
  100. {
  101. result.Status = 501;
  102. }
  103. else
  104. {
  105. result.Status = 501;
  106. }
  107. }
  108. catch (Exception ee)
  109. {
  110. LogManager.WriteLog(ee);
  111. result.Status = 509;
  112. result.Message = ee.Message;
  113. }
  114. finally
  115. {
  116. //config_environment.scan_state = false;
  117. }
  118. return result;
  119. }
  120. }
  121. }