示例#1
0
        /// <summary>
        /// 使用目录内所有扫描器扫描目录
        /// </summary>
        private void ScanCatalog(string directoryPath)
        {
            LogUtils.Info("使用所有扫描器扫描目录...");

            //遍历符合条件的链接库
            foreach (var assembly in this.TargetAssemblyFactory.CreateAssemblys(
                         directoryPath,
                         path => path.ToUpper().EndsWith("SADE.DLL")))
            {
                if (assembly == null)
                {
                    continue;
                }

                //遍历程序集内的扫描器
                foreach (var scanner in this.TargetSADEFactory.CreateScanners(assembly))
                {
                    if (scanner == null)
                    {
                        continue;
                    }
                    LogUtils.Info($"发现扫描器:{scanner.SADESource} in {assembly.FullName}");

                    TabPage tabPage = this.CreateCatalogContainer(scanner.SADESource);

                    try
                    {
                        //Scanner 将在代理工厂内扫描完毕后释放
                        ArticleProxyFactory articleProxyFactory = new ArticleProxyFactory(
                            tabPage,
                            tabPage.Tag as FlowLayoutPanel,
                            assembly,
                            scanner
                            );
                    }
                    catch (Exception ex)
                    {
                        LogUtils.Error($"创建 ArticleProxyFactory 遇到异常:{ex.Message}");
                        using (MessageBoxForm messageBox = new MessageBoxForm("Scanner.Process() 遇到异常:", ex.Message, MessageBoxForm.MessageType.Error))
                            messageBox.ShowDialog();
                    }

                    try
                    {
                        scanner.Process();
                    }
                    catch (Exception ex)
                    {
                        LogUtils.Error($"调用扫描器失败:{ex.Message}");
                        using (MessageBoxForm messageBox = new MessageBoxForm("Scanner.Process() 遇到异常:", ex.Message, MessageBoxForm.MessageType.Error))
                            messageBox.ShowDialog();
                    }
                }
            }
        }
示例#2
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //需要强制退出时,显示调用堆栈
            Trace.Assert(e.IsTerminating);

            Exception UnhandledException   = e.ExceptionObject as Exception;
            string    ExceptionDescription = string.Format(
                "应用域内发现未被捕获的异常:\r\n" +
                "   异常类型 : {0}\r\n" +
                "   异常地址 : {1}\r\n" +
                "   出错方法 : {2}\r\n" +
                "   所在文件 : {3}\r\n" +
                "   异常信息 : {4}\r\n" +
                "   调用堆栈 : \r\n{5}\r\n" +
                "   即将终止 : {6}\r\n" +
                "   ——————————\r\n" +
                "   日志文件:{7}\r\n",
                //"   出错方法MSIL : {8}",
                UnhandledException.GetType().ToString(),
                UnhandledException.Source,
                UnhandledException.TargetSite.Name,
                UnhandledException.TargetSite.Module.FullyQualifiedName,
                UnhandledException.Message,
                UnhandledException.StackTrace,
                e.IsTerminating,
                LogUtils.LogFilePath
                //string.Join("", UnhandledException.TargetSite.GetMethodBody().GetILAsByteArray())
                );

            LogUtils.Fatal(ExceptionDescription);

            using (MessageBoxForm messageBox = new MessageBoxForm("发生未捕获异常,点击确定打开日志", ExceptionDescription, MessageBoxForm.MessageType.Error))
            {
                if (messageBox.ShowDialog() == DialogResult.OK)
                {
                    Process.Start(LogUtils.LogFilePath);
                }
            }
        }
示例#3
0
 /// <summary>
 /// 弹出消息框
 /// </summary>
 /// <param name="caption">标题</param>
 /// <param name="message">消息</param>
 /// <param name="type">类型</param>
 public static DialogResult ShowDialog(string caption, string message, MessageType type, Form owner = null)
 {
     using (MessageBoxForm messageBox = new MessageBoxForm(caption, message, type))
         return(messageBox.ShowDialog(owner));
 }