Ejemplo n.º 1
0
        public static TService Cast <TService>(this IRpcProxy rpcService) where TService : class
        {
            var service = rpcService?.TryCastAsync <TService>().Result;

            if (service != null)
            {
                return(service);
            }

            throw new InvalidCastException($"Cannot cast RPC service to {typeof(TService)}.");
        }
Ejemplo n.º 2
0
        public static async Task <TService> CastAsync <TService>(this IRpcProxy rpcService) where TService : class
        {
            var service = rpcService != null ? await rpcService.TryCastAsync <TService>().ConfigureAwait(false) : null;

            if (service != null)
            {
                return(service);
            }

            throw new InvalidCastException($"Cannot cast RPC service to {typeof(TService)}.");
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public static bool TryCast <TService>(this IRpcProxy rpcService, out TService?service) where TService : class
 {
     service = rpcService?.TryCastAsync <TService>()?.AwaiterResult();
     return(service != null);
 }
Ejemplo n.º 5
0
 public static TService?TryCast <TService>(this IRpcProxy rpcService) where TService : class
 {
     return(rpcService?.TryCastAsync <TService>()?.AwaiterResult());
 }