Beispiel #1
0
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Log4.Error("Application_ThreadException:" +
                       e.Exception.Message);
            Log4.Error(e.Exception);

            //throw new NotImplementedException();
        }
Beispiel #2
0
        /// <summary>
        /// 监听接口异常
        /// </summary>
        /// <param name="ctx">连接上下信息</param>
        /// <param name="ex">异常信息</param>
        /// <returns></returns>
        private Response OnErroe(NancyContext ctx, Exception ex)
        {
            try
            {
                Log4.Error(ctx, ex);
            }
            catch (Exception)
            {
            }
            string msg = "提醒您:" + ex.Message;

            return(Response.AsText(msg).WithContentType("application/json").WithStatusCode(HttpStatusCode.OK));
        }
Beispiel #3
0
 protected override void OnStop()
 {
     try
     {
         owinHelper.Shutdown();
         if (pcScheduler != null)
         {
             pcScheduler.Shutdown();
         }
     }
     catch (Exception ex) {
         Log4.Error(ex.Message);
         Log4.Error(ex.StackTrace);
     }
 }
Beispiel #4
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log4.Error("CurrentDomain_UnhandledException");
            Log4.Error("IsTerminating : " + e.IsTerminating.ToString());
            Log4.Error(e.ExceptionObject.ToString());

            while (true)
            {     //循环处理,否则应用程序将会退出
                if (glExitApp)
                { //标志应用程序可以退出,否则程序退出后,进程仍然在运行
                    Log4.Error("ExitApp");
                    return;
                }
                System.Threading.Thread.Sleep(2 * 1000);
            }
            ;
        }
Beispiel #5
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Quartz.Core.IOC.ObjectContainer.ApplicationStart(new Quartz.Core.IOC.AutoFacContainer());
                if (this.pcScheduler == null)
                {
                    pcScheduler = Scheduler.Create();
                }
                pcScheduler.Start();

                owinHelper = OwinHelper.Create(SysConfig <ProjectInstaller> .OwinPort);
                owinHelper.Start();
            }
            catch (Exception ex)
            {
                Log4.Error(ex.Message);
                Log4.Error(ex.StackTrace);
            }
        }
Beispiel #6
0
        private Response cardexitx(dynamic _)
        {
            try
            {
                //加锁防止并发调用
                lock (obj)
                {
                    //打开端口
                    var port = ConfigurationManager.AppSettings["Port"];
                    var baud = ConfigurationManager.AppSettings["Baud"];

                    IntPtr handle = dcrf.dc_init(Convert.ToInt32(port), Convert.ToInt32(baud));
                    if ((int)handle <= 0)
                    {
                    }
                    else
                    {
                        AppCfg.Instance.Handle = (int)handle;
                        AppCfg.Instance.Save();
                    }
                    //弹卡
                    int res1 = dcrf.dc_SelfServiceDeviceCardEject((IntPtr)AppCfg.Instance.Handle, Convert.ToByte(30), System.Convert.ToByte("0x00", 16));
                    //关闭端口
                    var res2 = dcrf.dc_exit((IntPtr)AppCfg.Instance.Handle);


                    Log4.Debug($"打开端口:{(int)handle},弹卡:{res1},关闭端口:{res2}");
                    AppReportManager.Instance.Send(new LogEntity()
                    {
                        Log = $"打开端口:{(int)handle},弹卡:{res1},关闭端口:{res2}"
                    });
                    return(Success(new { log = $"打开端口:{(int)handle},弹卡:{res1},关闭端口:{res2}" }));
                }
            }
            catch (Exception e)
            {
                Log4.Error(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "[程序异常]" + e.ToString());
                return(Fail(e.ToString()));
            }
        }
Beispiel #7
0
        public static bool CancelSelfStarting()
        {
            bool result;

            try
            {
                RegistryKey rk        = Registry.LocalMachine;
                RegistryKey softWare  = rk.OpenSubKey("Software");
                RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
                RegistryKey windows   = microsoft.OpenSubKey("Windows");
                RegistryKey current   = windows.OpenSubKey("CurrentVersion");
                RegistryKey run       = current.OpenSubKey("Run", true);
                run.DeleteValue("HFCentraControl");
                result = true;
            }
            catch (Exception ex)
            {
                Log4.Error(ex.ToString());
                result = false;
            }
            return(result);
        }
Beispiel #8
0
        public static bool SetSelfStarting()
        {
            bool result;

            try
            {
                string      exeDir    = Application.ExecutablePath;
                RegistryKey rk        = Registry.LocalMachine;
                RegistryKey softWare  = rk.OpenSubKey("SOFTWARE");
                RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
                RegistryKey windows   = microsoft.OpenSubKey("Windows");
                RegistryKey current   = windows.OpenSubKey("CurrentVersion");
                RegistryKey run       = current.OpenSubKey("Run", true);
                run.SetValue("HFCentraControl", exeDir);
                result = true;
            }
            catch (Exception ex)
            {
                Log4.Error(ex.ToString());
                result = false;
            }
            return(result);
        }
Beispiel #9
0
        static void Main()
        {
            try
            {
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(("log4net.config")));
                AppCfg.FileName = Application.StartupPath + "\\config.yl";
                Log4.Debug("startup");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                System.Threading.Mutex mutex = new System.Threading.Mutex(true, "c9d85cde-f58e-49fa-a99a-7b79e71a0de6", out bool ret);
                if (ret)
                {
                    //处理未捕获的异常
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    //处理UI线程异常
                    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                    //处理非UI线程异常
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                    Application.Run(new FrmMain());
                    glExitApp = true;//标志应用程序可以退出
                    mutex.ReleaseMutex();
                }
                else
                {
                    //MessageBox.Show(null, "有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //   提示信息,可以删除。
                    Application.Exit();//退出程序
                }
            }
            catch (Exception e)
            {
                Log4.Error(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "[程序崩溃]" + GetExceptionMsg(e, string.Empty));
            }
        }