using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Threading; using System.Collections.Concurrent; using Newtonsoft.Json; using Saraff.Twain; using HXX.Scanner.Socket; using HXX.Scanner.Common; namespace HXX.Scanner.Biz.Socket { /// /// 业务处理 对每个连接发送间歇1秒的已扫描过的batch编号 /// public class biz_scannedBatch { /// /// 本次运行后已扫描的batch的列表 /// public static ConcurrentDictionary dic_scanned_batch_list = new ConcurrentDictionary(); /// /// 添加batch /// /// public static void add_batch(string batch) { if (!dic_scanned_batch_list.ContainsKey(batch)) { dic_scanned_batch_list[batch] = string.Empty; } } /// /// 主业务 从程序运行到退出始终发送 /// public static void Work() { Task.Run(() => { Thread.Sleep(2000); while (true) { Thread.Sleep(1000); //SocketServerManager.Send_All(get_cmd().ToJson()); } }); } /// /// 构造返回值 /// /// private static cmd_scannedBatch get_cmd() { cmd_scannedBatch result = new cmd_scannedBatch(); result.action = "scannedBatch"; result.param = new subcmd_scannedBatch(); result.param.zipId = get_batch(); return result; } /// /// 获取所有batch的字符串 /// /// private static string get_batch() { string result = string.Empty; foreach (var b in dic_scanned_batch_list) { result += "," + b.Key; } if (result.Length > 0) { result = result.Substring(1); } return result; } } }