| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using Newtonsoft.Json;
- using Saraff.Twain;
- using HXX.Scanner.Socket;
- using HXX.Scanner.Common;
- namespace HXX.Scanner.Biz.Socket
- {
- /// <summary>
- /// 业务处理 扫描模板(扫描后不存数据库,不上传,只返回图片文件信息)
- /// </summary>
- public class biz_scanTemplate
- {
- /// <summary>
- /// 主业务
- /// </summary>
- /// <param name="connId"></param>
- /// <param name="data"></param>
- public async static void Work(IntPtr connId, cmd_scanTemplate data)
- {
- var response = new response_startScanTemplate();
- if (!config_environment.scan_state)
- {
- var result = await work_detail(connId, data);
- if (result.Status == 1)
- {
- response.code = 200;
- response.msg = "启动扫描成功";
- }
- else
- {
- response.code = result.Status;
- response.msg = result.Message;
- }
- }
- else
- {
- response.code = 509;
- response.msg = "扫描仪正在使用中";
- }
- response.data = data;
- //SocketServerManager.Send_Family(connId, response.ToJson());
- SocketServerManager.Send_Single(connId, response.ToJson());
- }
- /// <summary>
- /// 扫描及构造返回值
- /// </summary>
- /// <param name="connId"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- private async static Task<ResponseEntity> work_detail(IntPtr connId, cmd_scanTemplate data)
- {
- var result = new ResponseEntity();
- try
- {
- //获取当前激活的扫描仪
- var scanner = scanner_manager.get_current();
- if (scanner != null)
- {
- //设置环境参数
- config_environment.scan_type2 = ScanType.ScanTemplate;
- config_environment.scan_type = biz_environment.get_scan_type(0);
- config_environment.scan_ab = biz_environment.get_ab(data.paperSchema);
- config_environment.paper_size = biz_environment.get_paper_size(3);
- config_environment.current_invoker = connId;
- //config_environment.use_source_ui = false;
- config_environment.use_source_ui = data.useDriveUI == 1;
- if (data.dpi > 0)
- {
- scanner.resolution = data.dpi;
- }
- scanner.setPaperSize(config_environment.paper_size);
- //初始化文件信息,文件名及计数器
- cmd_startScan2 fake = new cmd_startScan2();
- fake.batchNumber = data.batchNumber;
- fake.subjectCode = data.subjectCode;
- fake.paperSchema = data.paperSchema;
- fake.isLocalConfig = "0";
- config_environment.web_parameter = fake;//保存参数本身
- file_manager.Init(fake);
- //发送扫描指令
- result = await engine_twain32.Engine.Scan(scanner);
- }
- else
- {
- result.Status = 509;
- result.Message = "未找到指定的扫描仪";
- }
- }
- catch (TwainException te)
- {
- config_environment.scan_state = false;
- LogManager.WriteLog(te);
- result.Message = biz_twainException.get_TwainException_msg(te);
- if (te.ConditionCode.Equals(TwCC.OperationError))
- {
- result.Status = 501;
- }
- else
- {
- result.Status = 501;
- }
- }
- catch (Exception ee)
- {
- LogManager.WriteLog(ee);
- result.Status = 509;
- result.Message = ee.Message;
- }
- finally
- {
- //config_environment.scan_state = false;
- }
- return result;
- }
- }
- }
|