예제 #1
0
        static void BeginWork(IDownload down, DownloadConfig config, IRpcProxy proxy)
        {
            try
            {
                //调用sp 获取imimKy batchNo imimPath
                var callDataBase = Containers.Resolve <ICallDataBase>(config.CallDataBaseServiceName);
                var data         = callDataBase.FindData(config);
                //var data = Enumerable.Range(1, 16).Select(x => new ImageInfo { ImimKy = x.ToJson(), BatchNo = "5", ImimPath = $@"C:\Users\sh179\Desktop\testx\{x}.jpg" }).ToList();

                var batchNos = data.Select(x => x.BatchNo).Distinct().ToList();
                Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} 批次 down star,count:{batchNos.Count}");
                foreach (var item in batchNos)
                {
                    var directoryName = $"{config.SourceServerIp}{item}";
                    var path          = $@"{config.TargetServerPath}\{directoryName}";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    var list = data.Where(x => x.BatchNo == item).DefaultIfEmpty().ToList();

                    Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} image down star,count:{list.Count}\tBatchNo:{item}");
                    Parallel.ForEach(list, new ParallelOptions {
                        MaxDegreeOfParallelism = int.Parse(config.MaxDegreeOfParallelism)
                    }, f => f.IsSuccess = down.Download(f.ImimPath, $@"{path}\{config.SourceServerIp}{f.ImimKy}{(Path.GetExtension(f.ImimPath)?.ToLower() == "" ? ".jpg" : Path.GetExtension(f.ImimPath)?.ToLower())}"));
                    Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} image down end,count:{list.Count(x => x.IsSuccess)}");

                    string result = "未接收到";
                    try
                    {
                        callDataBase.SendJson(list.Where(x => x.IsSuccess).ToList(), config);
                        result = proxy.SendMessage(config.CallDataBaseServiceName, $"{directoryName}");
                        //todo:批次全部发送成功,跟新数据库
                        if (result.ToLower() == "ok")
                        {
                            callDataBase.SendImage(list.Where(x => x.IsSuccess).ToList(), config);
                        }
                        Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} Ocr.Send:{item} Ocr.Result:{result}");
                    }
                    catch (Exception ex)
                    {
                        Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} Ocr.Send:{item} Ocr.Result:{result}.Catch:{ex.Message}");
                    }
                    Thread.Sleep(1000);
                }
                if (batchNos.Count > 0)
                {
                    Nlog.Info(down.NLogName, $"{config.SourceServerIp}{down.NLogName} 批次 down end!\r\n\r\n");
                }
            }
            catch (Exception ex) { Nlog.Info($"{config.NLogName}", $"beginwork catch:{config.SourceServerIp}.{ex.Message}"); }
            Thread.Sleep(config.SendMillisecondsTimeout);
        }
예제 #2
0
 public void Download()
 {
     TasksList.Add(Protocol.Download());
 }