示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_Res"></param>
        public static void ModAuthLog(this string _ResJson, int _RowId, List <ImageInfo> _Images, string _AuthId)
        {
            var _Res = _ResJson.ToEntity <XAIResBase>();

            using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
            {
                try
                {
                    var dbAuthLog = dbContext.Set <Db_AuthLog>().Where(w => w.Id == _RowId).ToList().FirstOrDefault();
                    if (dbAuthLog == null)
                    {
                        throw new Exception("The authlog that needs to be modified does not exist! id=" + _RowId);
                    }
                    dbAuthLog.PaperworkImageId  = _Images.Where(w => w.Kind == "IDCARD").FirstOrDefault()?.ImageId;
                    dbAuthLog.PageworkImageType = "BASE64";
                    dbAuthLog.FaceImageId       = _Images.Where(w => w.Kind == "LIVE").FirstOrDefault()?.ImageId;
                    dbAuthLog.FaceImageType     = "BASE64";
                    dbAuthLog.MessageOut        = _Res.ToJson();
                    dbAuthLog.ReturnCode        = _Res.Code.ToInt();
                    dbAuthLog.ReturnDesc        = _Res.Desc;
                    dbAuthLog.OutTime           = DateTime.Now;
                    dbAuthLog.ModDate           = DateTime.Now;
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
                }
            }
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="res"></param>
 public static void ModSingleRow(this UPPResBase res, UPPReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.UPPDb)._DataAccess)
     {
         try
         {
             var dbRow = dbContext.Set <Db_AppLog>().Where(w => w.Id == req.RowId).ToList().FirstOrDefault();
             if (dbRow == null)
             {
                 throw new Exception("The line that needs to be modified does not exist!");
             }
             dbRow.Code      = res.ResCode;
             dbRow.Msg       = res.ResMsg;
             dbRow.ResTime   = Convert.ToDateTime(res.ResTime);
             dbRow.ResArgs   = res.Args;
             dbRow.ResRandom = res.Random;
             dbRow.ResSign   = res.Sign;
             dbRow.ModDate   = DateTime.Now;
             dbContext.SaveChanges();
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
         }
     }
 }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 public static void AddSingleRow(this UPPReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.UPPDb)._DataAccess)
     {
         try
         {
             var dbReq = new Db_AppLog
             {
                 AppId     = req.AppId,
                 Channel   = req.Channel,
                 Class     = req.Class,
                 Kind      = req.Kind,
                 Mode      = req.Mode,
                 OperCode  = req.OperCode,
                 ReqTime   = Convert.ToDateTime(req.ReqTime),
                 TermCode  = req.TermCode,
                 ReqArgs   = req.Args,
                 ReqRandom = req.Random,
                 ReqSign   = req.Sign,
                 AddDate   = DateTime.Now
             };
             dbContext.Entry(dbReq).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbReq.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
示例#4
0
        public virtual CheckMode GetCheckMode(string deptCode)
        {
            try
            {
                if (deptCode.IsNullOrEmptyOfVar())
                {
                    throw new Exception("TCPCommon.参数deptCode为空");
                }

                using (var cDbContext = new DbContextContainer(DbKind.MySql, DbName.HCDb)._DataAccess)
                {
                    var deptInfo = cDbContext.Set <Db_Dept>().Where(w => w.DeptCode == deptCode).FirstOrDefault();
                    if (deptInfo == null)
                    {
                        throw new Exception("TCPCommon.未找到科室信息");
                    }

                    return((CheckMode)Enum.ToObject(typeof(CheckMode), deptInfo.CheckMode));
                }
            }
            catch (Exception e)
            {
                LogModule.Error("TCPCommon.GetCheckMode()异常,异常信息:" + e.Message);
                throw e;
            }
        }
示例#5
0
 /// <summary>
 ///
 /// </summary>
 public static void AddAuthLog(this XAIReqBase req)
 {
     //TODO AUTH和Find记入参日志
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
     {
         try
         {
             var args      = req.Args.ToEntity <XAIReqAuth>();
             var dbAuthLog = new Db_AuthLog
             {
                 AuthID        = "".CreateKey(),
                 AppCode       = req.AppCode,
                 PaperworkType = "IDCARD",
                 PaperworkNo   = args.UserInfo.PaperWorkNo,
                 PhoneNo       = args.UserInfo.PhoneNo,
                 MessageIn     = req.ToJson(),
                 InTime        = Convert.ToDateTime(req.ReqTime),
                 AddDate       = DateTime.Now,
                 IsDelete      = 0
             };
             dbContext.Entry(dbAuthLog).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbAuthLog.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="res"></param>
        public static void ModFindLog(this string _ResJson, int _RowId, Db_Image _Image)
        {
            var _Res = _ResJson.ToEntity <XAIResBase>();

            using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
            {
                try
                {
                    var dbIdentLog = dbContext.Set <Db_IdentLog>().Where(w => w.Id == _RowId).ToList().FirstOrDefault();
                    if (dbIdentLog == null)
                    {
                        throw new Exception("The identlog that needs to be modified does not exist! id=" + _RowId);
                    }
                    dbIdentLog.ImageId    = _Image.ImageId;
                    dbIdentLog.ImageType  = "BASE64";
                    dbIdentLog.UserId     = _Res.UserId;
                    dbIdentLog.ReturnCode = _Res.Code.ToInt();
                    dbIdentLog.ReturnDesc = _Res.Desc;
                    dbIdentLog.TimeOut    = DateTime.Now;
                    dbIdentLog.ModDate    = DateTime.Now;
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message));
                }
            }
        }
示例#7
0
        /// <summary>
        /// request Get
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string Get(this string url, int timeout = 100)
        {
            GC.Collect();
            string          result = "";
            HttpWebRequest  req    = null;
            HttpWebResponse res    = null;

            try
            {
                ServicePointManager.DefaultConnectionLimit = 200;
                if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                }
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                req         = (HttpWebRequest)WebRequest.Create(url);
                req.Method  = "GET";
                req.Timeout = timeout * 1000;
                res         = (HttpWebResponse)req.GetResponse();
                using (var sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8))
                {
                    result = sr.ReadToEnd().Trim();
                }
            }
            catch (ThreadAbortException ex)
            {
                LogModule.Error(ex);
                Thread.ResetAbort();
                throw new Exception(ex.Message);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    LogModule.Error(ex);
                }
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                LogModule.Error(ex);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (res != null)
                {
                    res.Close();
                }
                if (req != null)
                {
                    req.Abort();
                }
            }
            return(result);
        }
 public bool Start(HostControl hostControl)
 {
     try
     {
         HostNancy(_host);
     }
     catch (Exception ex)
     {
         LogModule.Error(ex);
         return(false);
     }
     return(true);
 }
示例#9
0
 /// <summary>
 /// 初始化
 /// </summary>
 protected static void Init()
 {
     try
     {
         if (_AppCache == null || _AppCache.Count == 0)
         {
             _AppCache.DbAppConfig();
         }
     }
     catch (Exception ex)
     {
         LogModule.Error(ex);
     }
 }
示例#10
0
 public static string OnAck(this string _Code, string _Msgs, Exception ex = null)
 {
     if (ex != null)
     {
         LogModule.Error(ex);
     }
     return(new ExternalResBase()
     {
         ResRet = new ResRet()
         {
             ResRetCode = _Code,
             ResRetMsg = _Msgs
         }
     }.ToJson());
 }
示例#11
0
 public TCPCommonFactory(string hospitalCode = null)
 {
     try
     {
         var builder = new ContainerBuilder();
         builder.RegisterType(Type.GetType("BCL.ToolLibWithApp.TCP.TCPProvider.TCPCommonH" + (hospitalCode ?? "HospitalId".ConfigValue())))
         .As <ITCPCommon>();
         TCPCommon = builder.Build()
                     .Resolve <ITCPCommon>();
     }
     catch (Exception e)
     {
         LogModule.Error(e);
         throw new Exception("创建TCPProvider对象失败:" + e.Message);
     }
 }
 public void HostNancy(NancyHost _host)
 {
     try
     {
         var url = new Url(String.Format("http://localhost:{0}/xai/v1/", "Port".ConfigValue("990")));
         var hc  = new HostConfiguration
         {
             UrlReservations = new UrlReservations {
                 CreateAutomatically = true
             },
             UnhandledExceptionCallback = o =>
             {
                 LogModule.Error("框架层异常:" + o);
             }
         };
         _host = new NancyHost(hc, url);
         Console.WriteLine("Listener address:" + url);
         _host.Start();
         //used for linux
         if (Type.GetType("Mono.Runtime") != null)
         {
             UnixSignal.WaitAny(new[]
             {
                 new UnixSignal(Signum.SIGINT),
                 new UnixSignal(Signum.SIGTERM),
                 new UnixSignal(Signum.SIGQUIT),
                 new UnixSignal(Signum.SIGHUP)
             });
         }
         else
         {
             //System.Diagnostics.Process.Start(url);
         }
     }
     catch (Exception ex)
     {
         LogModule.Error("RESTApiService->HostNancy:" + ex);
     }
 }
示例#13
0
 public static void Main(string[] args)
 {
     try
     {
         HostFactory.Run(o =>
         {
             o.Service <RESTfulAPIService>();
             o.UseLinuxIfAvailable();
             o.RunAsLocalSystem();
             o.EnablePauseAndContinue();
             o.StartAutomatically();
             o.SetDescription("统一人脸平台服务");
             o.SetDisplayName(string.Format("XAI.ProcessAPI_{0}.exe", "Port".ConfigValue("990")));
             o.SetServiceName(string.Format("XAIServiceAPI_{0}", "Port".ConfigValue("990")));
         });
     }
     catch (Exception ex)
     {
         LogModule.Error(ex);
         throw ex;
     }
 }
示例#14
0
 /// <summary>
 ///
 /// </summary>
 public static void AddFindLog(this XAIReqBase req)
 {
     using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.FACEDb)._DataAccess)
     {
         try
         {
             var args       = req.Args.ToEntity <XAIReqFind>();
             var dbIdentLog = new Db_IdentLog
             {
                 TimeIn   = Convert.ToDateTime(req.ReqTime),
                 AddDate  = DateTime.Now,
                 IsDelete = 0
             };
             dbContext.Entry(dbIdentLog).State = EntityState.Added;
             dbContext.SaveChanges();
             req.RowId = dbIdentLog.Id;
         }
         catch (Exception ex)
         {
             LogModule.Error("Db Fail:" + ex.Message + (ex.InnerException == null ? "" : ex.InnerException.Message) + "\r\n参数:" + req.EntityToKeyValue(false));
         }
     }
 }
示例#15
0
 public WebServiceAgent(string url)
 {
     try
     {
         XmlTextReader              reader = new XmlTextReader(url);
         ServiceDescription         sd     = ServiceDescription.Read(reader);
         ServiceDescriptionImporter sdi    = new ServiceDescriptionImporter();
         sdi.AddServiceDescription(sd, null, null);
         CodeNamespace   cn  = new CodeNamespace(CODE_NAMESPACE);
         CodeCompileUnit ccu = new CodeCompileUnit();
         ccu.Namespaces.Add(cn);
         sdi.Import(cn, ccu);
         CSharpCodeProvider ccp = new CSharpCodeProvider();
         CompilerParameters cp  = new CompilerParameters();
         CompilerResults    cr  = ccp.CompileAssemblyFromDom(cp, ccu);
         wsAgentType = cr.CompiledAssembly.GetTypes()[0];
         wsAgent     = Activator.CreateInstance(wsAgentType);
     }
     catch (Exception e)
     {
         GC.Collect();
         LogModule.Error(e);
     }
 }
示例#16
0
        /// <summary>
        /// 18-05-28 add gpw
        /// 返回具体错误信息。
        /// </summary>
        /// <returns></returns>
        public override int SaveChanges()
        {
            try
            {
                return(base.SaveChanges());
            }
            catch (DbEntityValidationException exception)
            {
                var errorMessages =
                    exception.EntityValidationErrors
                    .SelectMany(validationResult => validationResult.ValidationErrors)
                    .Select(m => m.ErrorMessage);

                var fullErrorMessage = string.Join(", ", errorMessages);
                var exceptionMessage = string.Concat(exception.Message, " 验证异常消息是:", fullErrorMessage);
                //记录日志
                LogModule.Error(exceptionMessage);
                throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException());
            }
        }
示例#17
0
        public static Db_Param GetParamByName(this string paramName, string hopitalId)
        {
            Db_Param dbParam = new Db_Param();

            try
            {
                if (!String.IsNullOrEmpty(paramName))
                {
                    using (var dbContext = new DbContextContainer(DbKind.MySql, DbName.HCDb)._DataAccess)
                    {
                        if (!String.IsNullOrEmpty(hopitalId))
                        {
                            dbParam = dbContext.Set <Db_Param>().AsNoTracking()
                                      .Where(p => p.PARAM_NAME == paramName && p.HOSPITAL_ID == hopitalId).FirstOrDefault();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogModule.Error("ESBToolBox->GetParamByName():" + ex.Message);
            }
            return(dbParam);
        }
示例#18
0
        /// <summary>
        /// 获取病人列表
        /// </summary>
        /// <param name="deptCode"></param>
        /// <param name="whereQueueStateStr">类似" queuestate in(0,1,2)"</param>
        /// <param name="isFrontCount">是否统计当前报到模式前面排队人数</param>
        /// <param name="roomId"></param>
        /// <param name="patientId"></param>
        /// <param name="docCode"></param>
        /// <returns></returns>
        public virtual List <Db_RegPatientList> GetPatientList(string deptCode, string docCode, string typeCode)
        {
            try
            {
                docCode.IsNullOrEmptyOfVar("docCode");
                deptCode.IsNullOrEmptyOfVar("deptCode");
                typeCode.IsNullOrEmptyOfVar("typeCode");
                using (var dbContext = new DbContextContainer(DbName.HPDb)._DataAccess)
                {
                    var docLoginInfo = dbContext.Set <Db_DoctorLoginInfo>().Where(w => w.DoctorCode == docCode && w.LoginState == "1" && w.DeptCode == deptCode && w.TypeCode == typeCode).FirstOrDefault();
                    if (docLoginInfo == null)
                    {
                        throw new Exception("未查询到医生登录信息");
                    }
                    CheckMode cm  = GetCheckMode(docLoginInfo.DeptCode);
                    var       sql = "";
                    if (cm == CheckMode.首诊报到到医生)
                    {
                        return(dbContext.Set <Db_RegPatientList>().Where(w => w.RoomId == docLoginInfo.RoomId && w.CheckDoctorCode == docLoginInfo.DoctorCode && w.IsCancel == 0).AsNoTracking().ToList());
                    }
                    if (cm == CheckMode.首诊不报到直接呼叫)
                    {
                        if (docLoginInfo.TypeCode == "1")
                        {
                            sql = string.Format(@"select * from at_regpatientlist 
                                          where RegDeptCode='{0}' and CheckDoctorCode is null and RegTypeCode='1' 
                                          AND IsCancel='0'
                                          UNION ALL
                                          SELECT * from at_regpatientlist where
                                          checkdoctorcode='{1}' and roomid='{2}' and IsCancel=0 ", docLoginInfo, deptCode, docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                        else
                        {
                            sql = string.Format(@"SELECT * from at_regpatientlist 
                                          WHERE checkdoctorcode='{0}'
                                          AND roomid='{1}'
                                          and iscancel=0", docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                    }

                    if (cm == CheckMode.首诊报到到科室)
                    {
                        if (docLoginInfo.TypeCode == "1")
                        {
                            sql = string.Format(@" select * from at_regpatientlist
                                                 WHERE CheckDeptCode='{0}'
                                                 and (CheckDoctorCode is null or CheckDoctorCode ='')
                                                 and RegTypeCode = '1'
                                                 and IsCancel = 0
                                                 UNION ALL
                                                 select * from at_regpatientlist
                                                 WHERE CheckDoctorCode='{1}'
                                                 AND RoomId='{2}'
                                                 AND IsCancel=0", docLoginInfo.DeptCode, docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                        else
                        {
                            sql = string.Format(@"select * from at_regpatientlist 
                                                        where CheckDoctorCode='{0}'
                                                        AND roomid='{1}'
                                                        and IsCancel=0", docLoginInfo.DoctorCode, docLoginInfo.RoomId);
                        }
                    }

                    return(dbContext.Database.SqlQuery <Db_RegPatientList>(sql).ToList());
                }
            }
            catch (Exception e)
            {
                LogModule.Error("TCPCommon.GetPatientList()异常,异常信息:" + e.Message);
                throw e;
            }
        }
示例#19
0
        /// <summary>
        /// request Post
        /// </summary>
        /// <param name="val"></param>
        /// <param name="url"></param>
        /// <param name="isUseCert"></param>
        /// <returns></returns>
        public static string Post(this string url, string val, bool isUseCert = false, string contentType = "application/x-www-form-urlencoded;charset=UTF-8;", string sslPath = null, int timeout = 5, string encode = "UTF-8", string securityProtocolType = null)
        {
            GC.Collect();
            string          result = "";
            HttpWebRequest  req    = null;
            HttpWebResponse res    = null;

            try
            {
                ServicePointManager.DefaultConnectionLimit = 200;
                if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                }
                if (!securityProtocolType.IsNullOrEmptyOfVar())
                {
                    ServicePointManager.SecurityProtocol = (SecurityProtocolType)securityProtocolType.EnumNameToValue <SecurityProtocolType>();
                }
                req                  = (HttpWebRequest)WebRequest.Create(url);
                req.Method           = "POST";
                req.Timeout          = timeout * 1000;
                req.ReadWriteTimeout = 5 * 1000;
                req.ContentType      = contentType;
                req.ServicePoint.Expect100Continue = false;
                req.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                if (isUseCert)
                {
                    X509Certificate2 cert = new X509Certificate2(Directory.GetCurrentDirectory() + "\\" + sslPath, sslPath.Split('\\')[1]);
                    req.ClientCertificates.Add(cert);
                }
                var v = Encoding.GetEncoding(encode).GetBytes(val);
                req.ContentLength = v.Length;

                var s = req.GetRequestStream();
                s.Write(v, 0, v.Length);
                s.Close();
                res = (HttpWebResponse)req.GetResponse();
                using (var sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding(encode)))
                {
                    result = sr.ReadToEnd().Trim();
                }
            }
            catch (ThreadAbortException ex)
            {
                LogModule.Error(ex);
                Thread.ResetAbort();
                throw new Exception(ex.Message);
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    LogModule.Error(ex);
                }
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                LogModule.Error(ex);
                throw new Exception(ex.Message);
            }
            finally
            {
                //关闭连接和流
                if (res != null)
                {
                    res.Close();
                }
                if (req != null)
                {
                    req.Abort();
                }
            }
            return(result);
        }