Exemple #1
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="id">ID</param>
 /// <param name="method">函数的信息</param>
 /// <param name="message">消息</param>
 /// <param name="traceKey">调用链键值</param>
 /// <param name="traceOrder">调用链顺序</param>
 /// <param name="error">错误</param>
 public EventInfo(long id, MethodBase method, string message, long traceKey, int traceOrder, Exception error = null)
     : this(id, DateTime.Now,
            method != null ? (method.ReflectedType ?? method.DeclaringType).FullName : null,
            method != null ? method.Name : null,
            message,
            error != null ? error.GetType().FullName : null,
            error != null ? AppRun.GetErrorMessage(error) : null,
            Principal.CurrentIdentity != null ? Principal.CurrentIdentity.UserName : null,
            NetConfig.LocalAddress, traceKey, traceOrder)
 {
 }
        /// <summary>
        /// 打包错误消息
        /// </summary>
        /// <param name="response">HttpResponse</param>
        /// <param name="error">错误消息</param>
        public static async Task PackAsync(this HttpResponse response, Exception error)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (error == null)
            {
                response.StatusCode = (int)HttpStatusCode.OK;  //等效于 HTTP 状态 200 -> 成功
                return;
            }

            response.Headers["Access-Control-Allow-Origin"] = "*";

            switch (error)
            {
            case ArgumentException _:
                response.StatusCode = (int)HttpStatusCode.BadRequest;      //等效于 HTTP 状态 400 -> 表示API的消费者发送到服务器的请求是错误的
                EventLog.Save(response.StatusCode.ToString(), error);
                break;

            case AuthenticationException _:
                response.StatusCode = (int)HttpStatusCode.Unauthorized;      //等效于 HTTP 状态 401 -> 表示用户没有认证,无法进行操作
                break;

            case SecurityException _:
                response.StatusCode = (int)HttpStatusCode.Forbidden;      //等效于 HTTP 状态 403 -> 表示用户验证成功,但是该用户仍然无法访问该资源
                break;

            case System.ComponentModel.DataAnnotations.ValidationException _:
            case InvalidOperationException _:
                response.StatusCode = (int)HttpStatusCode.Conflict;      //等效于 HTTP 状态 409 -> 服务器在完成请求时发生冲突
                await response.WriteAsync(error is Phenix.Mapper.Rule.ValidationException validationException
                                          ?Utilities.JsonSerialize(validationException.ValidationMessage)
                                          : Utilities.JsonSerialize(new Phenix.Mapper.Rule.ValidationMessage(null, -1, error.Message)));

                return;

            case NotSupportedException _:
            case NotImplementedException _:
                response.StatusCode = (int)HttpStatusCode.NotImplemented;      //等效于 HTTP 状态 501 -> 服务器不具备完成请求的功能
                break;

            default:
                response.StatusCode = (int)HttpStatusCode.InternalServerError;      //等效于 HTTP 状态 500 -> 服务器遇到错误,无法完成请求
                EventLog.Save(response.StatusCode.ToString(), error);
                break;
            }

            await response.WriteAsync(AppRun.GetErrorHint(error));
        }
Exemple #3
0
            public static void Main(string[] args)
            {
                // 工程名("GMS2GiMiSi")
                var projectName = Assembly.GetExecutingAssembly().GetName().Name;

                // 单实例监视
                SingleInstanceWatcher = new Semaphore(0, 1, projectName, out _createdNew);
                if (_createdNew)
                {
                    //加载DLL
                    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                    //启动
                    var app = new AppRun();
                    app.Run();
                }
                else
                {
                    MessageBox.Show("请不要重复运行(ノ`Д)ノ");
                    Environment.Exit(-2);
                }
            }
 public static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         // 工程名("饥荒开服工具ByTpxxn")
         var projectName = Assembly.GetExecutingAssembly().GetName().Name;
         // 单实例监视
         SingleInstanceWatcher = new Semaphore(0, 1, projectName, out _createdNew);
         if (_createdNew)
         {
             //启动
             var app = new AppRun();
             app.Run();
         }
         else
         {
             MessageBox.Show("请不要重复运行(ノ`Д)ノ");
             Environment.Exit(-2);
         }
     }
     //else
     //{
     //    if (args[0].ToLower() == "-clear")
     //    {
     //        if (MessageBox.Show("警告:您将会删除所有注册表设置,点“确定”立即清除,点“取消”取消清除!", "Σ(っ°Д°;)っ", MessageBoxButton.OKCancel) ==
     //            MessageBoxResult.OK)
     //        {
     //            RegeditRw.ClearReg();
     //            MessageBox.Show("清除完毕!", "ヾ(๑╹◡╹)ノ");
     //        }
     //        else
     //        {
     //            MessageBox.Show("取消清除!", "(~ ̄▽ ̄)~");
     //        }
     //        Environment.Exit(0);
     //    }
     //}
 }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** 业务类代码生成工具 ****");
            Console.WriteLine();

            string dataSource;
            string databaseName;
            string userId;
            string password;

            if (args.Length == 4)
            {
                dataSource   = args[0];
                databaseName = args[1];
                userId       = args[2];
                password     = args[3];
            }
            else
            {
                while (true)
                {
                    Console.WriteLine("请按照提示,输入需映射到业务对象的数据库的连接串...");
                    Console.Write("dataSource(数据源,示例'192.168.248.52'):");
                    dataSource = Console.ReadLine();
                    Console.Write("databaseName(数据库名称,示例'TEST'):");
                    databaseName = Console.ReadLine();
                    Console.Write("userId(用户ID,示例'SHBPMO'):");
                    userId = Console.ReadLine();
                    Console.Write("password(用户口令,示例'SHBPMO'):");
                    password = Console.ReadLine();
                    Console.Write("以上是否正确(Y/N):");
                    if (String.Compare(Console.ReadKey().KeyChar.ToString(), "Y", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        break;
                    }
                    Console.WriteLine();
                }
            }

            Console.WriteLine();
            Console.WriteLine("如需Class名称取自被整理过后的表名(如果第4位是“_”则剔去其及之前的字符),请设置Phenix.Core.Data.Schema.Table.ClassNameByTrimTableName属性,默认是{0};", Phenix.Core.Data.Schema.Table.ClassNameByTrimTableName);
            Console.WriteLine("如需Class名称取自被整理过后的视图名(如果第4位是“_”则剔去其及之前的字符, 如果倒数第2位是“_”则剔去其及之后的字符),请设置Phenix.Core.Data.Schema.View.ClassNameByTrimViewName属性,默认是{0};", Phenix.Core.Data.Schema.View.ClassNameByTrimViewName);
            Console.WriteLine();
            string baseDirectory = Path.Combine(AppRun.BaseDirectory, DateTime.Now.ToString("yyyyMMddHHmm"));

            Console.WriteLine("生成的业务类文件将存放在目录:{0}", baseDirectory);
            Console.WriteLine("你可以根据开发需要,摘取文件到自己的项目工程目录中。");
            Console.WriteLine();

            try
            {
                Database database = Database.RegisterDefault(dataSource, null, databaseName, userId, password);
                Console.Write("是否遍历{0}数据库的表,生成业务类代码(Y/N):", database.DatabaseName);
                if (String.Compare(Console.ReadKey().KeyChar.ToString(), "Y", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("Building...");
                    foreach (KeyValuePair <string, Table> kvp in database.MetaData.Tables)
                    {
                        Console.WriteLine(BuildClass(kvp.Value, baseDirectory));
                    }
                    Console.WriteLine();
                }

                Console.Write("是否遍历{0}数据库的视图,生成业务类代码(Y/N):", database.DatabaseName);
                if (String.Compare(Console.ReadKey().KeyChar.ToString(), "Y", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("Building...");
                    foreach (KeyValuePair <string, View> kvp in database.MetaData.Views)
                    {
                        Console.WriteLine(BuildClass(kvp.Value, baseDirectory));
                    }
                    Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("发生异常,中断代码生成过程: " + AppRun.GetErrorMessage(ex));
                Console.Write("请按回车键结束程序");
                Console.ReadLine();
                return;
            }

            Console.WriteLine("完成代码生成。");
            System.Diagnostics.Process.Start("Explorer.exe", baseDirectory);
            Console.Write("请按回车键结束程序");
            Console.ReadLine();
            Console.WriteLine();
        }
Exemple #6
0
 /// <summary>
 /// 保存对象日志
 /// </summary>
 /// <param name="method">函数的信息</param>
 /// <param name="message">消息</param>
 /// <param name="error">错误</param>
 public async Task SaveEventLogAsync(MethodBase method, string message, Exception error = null)
 {
     if (!await SaveEventLogAsync(new Phenix.Core.Log.EventInfo(await GetSequenceAsync(), DateTime.Now,
                                                                method != null ? (method.ReflectedType ?? method.DeclaringType).FullName : null,
                                                                method != null ? method.Name : null,
                                                                message,
                                                                error != null ? error.GetType().FullName : null,
                                                                error != null ? AppRun.GetErrorMessage(error) : null,
                                                                Identity.CurrentIdentity != null ? Identity.CurrentIdentity.User.Name : null, NetConfig.LocalAddress)))
     {
         Phenix.Core.Log.EventLog.SaveLocal(method, message, error);
     }
 }
Exemple #7
0
 private static void run([NotNull] CompileProjects lab, AppRun<CompilerUserInteractionModel> message)
 {
     Console.WriteLine("I would be parsing the project file here.");
     lab._mission_control.announce(new AppQuit(AppErrorLevel.Ok));
 }
Exemple #8
0
 /// <summary>
 /// 保存错误日志到本地LocalDirectory目录
 /// </summary>
 /// <param name="message">消息</param>
 /// <param name="error">错误</param>
 /// <param name="extension">后缀</param>
 public static void SaveLocal(string message, Exception error = null, string extension = DefExtension)
 {
     SaveLocal(error != null ? String.Format("{0} : {1}[{2}]", message, AppRun.GetErrorMessage(error), error.StackTrace) : message, extension);
 }