public void DebugLogger_LoggingTest() { string message = "Error Message"; Exception ex = new Exception(); string messageFormat = "Message Format: message: {0}, exception: {1}"; ILog log = new DebugLogger(GetType()); Assert.IsNotNull(log); log.Debug(message); log.Debug(message, ex); log.DebugFormat(messageFormat, messageFormat, ex.Message); log.Error(message); log.Error(message, ex); log.ErrorFormat(messageFormat, messageFormat, ex.Message); log.Fatal(message); log.Fatal(message, ex); log.FatalFormat(messageFormat, messageFormat, ex.Message); log.Info(message); log.Info(message, ex); log.InfoFormat(messageFormat, messageFormat, ex.Message); log.Warn(message); log.Warn(message, ex); log.WarnFormat(messageFormat, messageFormat, ex.Message); }
private void RpcNotify(byte[] data) { var msg = ProtobufDecoder(data); DebugLogger.Debug(msg.OpCode.ToString()); if (msg.OpCode == OPCODE.NotifyInfo) { var seq = msg.NotifyInfo.Sequence; if (seq > 0) { DebugLogger.Debug(seq.ToString()); GameNodeRpc.NotificationMsg.text = seq.ToString() + "\n"; // clientReceiveSeq = seq; } var rpcFunc = msg.NotifyInfo.RpcFunc; if (rpcFunc == null) { DebugLogger.DebugError("RpcNotify wrong fucntion code"); } else { object retParam = MessagePackDecoder <object>(msg.NotifyInfo.RpcParams); int i = 0; GameNodeRpc.NotificationMsg.text += retParam.ToString(); } } }
public object GetOrCreate(string key, Func <string, object> creator) { object result; int hashKey = key.GetHashCode(); DebugLogger.Debug($"HashKey : [{key}] => [{hashKey}]"); if (pool.TryGetValue(hashKey, out result)) { DebugLogger.Debug($"发现缓存 : {hashKey}"); if (result is ICopy c) { return(c.Copy()); } return(result); } result = creator(key); if (result is ICopy c2) { var copied = c2.Copy(); pool[hashKey] = copied; } else { pool[hashKey] = result; } return(result); }
public static byte[] GenSecretUserToken(string account, byte[] secret) { string sdkId = "OFFICIAL"; string device = Utils.GetDeviceID(); List <string> loginParameters = new List <string>(); loginParameters.Add(account); loginParameters.Add(device); loginParameters.Add("mscode"); string parameters = string.Empty; for (int i = 0; i < loginParameters.Count; i++) { parameters += Convert.ToBase64String(Encoding.UTF8.GetBytes(loginParameters[i])) + ":"; } string sign = "sign"; string token_base64 = "0" + ":" + Convert.ToBase64String(Encoding.UTF8.GetBytes(sdkId)) + ":" + parameters + "#" + Convert.ToBase64String(Encoding.UTF8.GetBytes(sign)) + "#" + Convert.ToBase64String(Encoding.UTF8.GetBytes(device)); DebugLogger.Debug("GenSecretUserToken ---- " + token_base64); byte[] token_base64_bits = Encoding.Default.GetBytes(token_base64); byte[] token_base64_des_bits = Crypt.des_encode(secret, token_base64_bits); byte[] token_base64_des_bits2 = Crypt.des_decode(secret, token_base64_des_bits); byte[] token_base64_des_base64bits = Encoding.Default.GetBytes(Convert.ToBase64String(token_base64_des_bits)); return(token_base64_des_base64bits); }
private void RpcNotify(byte[] data) { var msg = ProtobufDecoder(data); DebugLogger.Debug(msg.OpCode.ToString());//NotifyInfo if (msg.OpCode == OPCODE.NotifyInfo) { var seq = msg.NotifyInfo.Sequence; if (seq > 0) { DebugLogger.Debug(seq.ToString());//1 //GameNodeRpc.NotificationMsg.text = seq.ToString() + "\n"; // clientReceiveSeq = seq; } var rpcFunc = msg.NotifyInfo.RpcFunc; Debug.Log(rpcFunc.ToString());//isMatchSuccess if (severMonitorCallback.ContainsKey(rpcFunc.ToString())) { severMonitorCallback[rpcFunc.ToString()](msg);//执行注册的函数isMatchSuccess } if (rpcFunc == null) { DebugLogger.DebugError("RpcNotify wrong fucntion code"); } else { //object retParam = MessagePackDecoder<object>(msg.NotifyInfo.RpcParams); //int i = 0; //GameNodeRpc.NotificationMsg.text += retParam.ToString(); //Debug.Log(retParam.ToString()); } } }
public void startLoginProcess() { //DebugLogger.Debug("start login process " + LoginInputAccount.text, Color.blue); ucl = NetClient.GetInstance("logic"); /* * if (ucl.Login(ServerIP, ServerPort, LoginInputAccount.text)) * { * switchScene("ServerScene"); * //LoginRequist.ucl.rpcCall("notifytester.rpc_start_notify", "1", null); * } * else * { * DebugLogger.Debug("Login Error"); * } */ if (ucl.Login(ServerIP, ServerPort, GameObject.FindGameObjectWithTag("UserName").GetComponent <InputField>().text)) { //switchScene("ServerScene"); GameManager.Instance.StartMatchmaking(); } else { DebugLogger.Debug("Login Error"); } }
public void Intercept(IInvocation invocation) { string methodName = invocation.Method.Name; Type typeofIDao = typeof(INpiDao <>); Type entityType = invocation.Method.DeclaringType.GetInterface(typeofIDao.FullName).GetGenericArguments()[0]; // todo :对其单例化 ISqlCommandGenerator g = NpiServicesCollection.GetService <ISqlServerCommandGenerator>(); SqlCommandDescription d = g.Generate(invocation.Method, invocation.Arguments); DebugLogger.Debug(d.ToString()); DapperParameters dp = new DapperParameters(); foreach (var p in d.Parameters) { dp[p.Key] = p.Value.Value; } object dbReturnedValue = null; object handledValue = null; DebugLogger.Debug("准备执行 Sql"); switch (d.Type) { case SqlCommandTypes.Insert: case SqlCommandTypes.Update: case SqlCommandTypes.Delete: { var executor = ServicesCollection.GetService <ISqlCommandExecutor>(); dbReturnedValue = executor.Execute(d.SqlCommand, dp, dbConnectionContext); } break; case SqlCommandTypes.Select: { var querier = ServicesCollection.GetService <ISqlCommandQuerier>(); dbReturnedValue = querier.Select(entityType, d.SqlCommand, dp, dbConnectionContext); } break; default: break; } DebugLogger.Debug("Sql 执行完毕,开始处理结果集"); foreach (var handler in dbReturnValueHandlers) { if (!handler.CanHandle(invocation.Method, entityType)) { continue; } handledValue = handler.Handle(invocation.Method, entityType, dbReturnedValue); } invocation.ReturnValue = handledValue; DebugLogger.Debug("结果集处理完毕"); }
private IEnumerator Load(string sceneName) { AsyncOperation op = SceneManager.LoadSceneAsync(sceneName); DebugLogger.Debug(op.ToString()); yield return(new WaitForEndOfFrame()); op.allowSceneActivation = true; }
private byte[] kcpRead() { while (udpClient != null) { var size = mKCP.PeekSize(); if (size > 0) { lock (mKCP) { if (size > mRecvBuffer.Length) { mRecvBuffer = new byte[(size * 3) / 2]; } var n = mKCP.Recv(mRecvBuffer, 0, size); var recvBytes = (((int)mRecvBuffer[0]) << 8) + mRecvBuffer[1]; if (recvBytes <= n - 2) { byte[] data = new byte[recvBytes]; Array.Copy(mRecvBuffer, Const.PackageHeaderLength, data, 0, recvBytes); return(data); } } } var reclen = rawRead(); int inputN = 0; lock (mKCP) { int sidx = 0; while (sidx < reclen) { uint datalen = 0; KCP.ikcp_decode32u(sRecvBuffer, sidx + 20, ref datalen); int kcplen = (int)datalen + 24; if (redlen <= 0 || sRecvBuffer[4 + sidx] != KCP.IKCP_CMD_PUSH) { inputN = mKCP.Input(sRecvBuffer, sidx, kcplen, true, ackNoDelay); } else { int pnum = redRevFmt(sRecvBuffer, sidx, kcplen); for (int i = 0; i < pnum; i++) { uint tDataLen = 0; KCP.ikcp_decode32u(redBuffer[i], 20, ref tDataLen); inputN = mKCP.Input(redBuffer[i], 0, (int)tDataLen + 24, true, ackNoDelay); } } sidx += kcplen; } } if (inputN < 0) { DebugLogger.Debug($"input err resinput {inputN}"); } } return(null); }
private void NotifyAssign(Message msg) { object retParam = MessagePackDecoder <object>(msg.NotifyInfo.RpcParams); Side side = (Side)JsonConvert.DeserializeObject(retParam.ToString(), typeof(Side)); GameManager.Instance.EnterMatch(side.side); //ServerModules.AssignServer.text += retParam.ToString(); DebugLogger.Debug("Side object :" + side.side.ToString()); }
void startLoginProcess() { DebugLogger.Debug("start login process " + LoginInputAccount.text, Color.blue); ucl = NetClient.GetInstance("logic"); if (ucl.Login(ServerIP, ServerPort, LoginInputAccount.text)) { switchScene("GameNode"); } else { DebugLogger.Debug("Login Error"); } }
private void NotifyCheck(Message msg) { object retParam = MessagePackDecoder <object>(msg.NotifyInfo.RpcParams); DebugLogger.Debug(retParam.ToString()); VerifyList verifyList = (VerifyList)JsonConvert.DeserializeObject(retParam.ToString(), typeof(VerifyList)); int[] x = verifyList.intX; int[] y = verifyList.intY; RoundManager.Instance.ValidatePosition(x, y); //LocalList local = (LocalList)JsonConvert.DeserializeObject(retParam.ToString(), typeof(LocalList)); //Debug.Log("Check class: " + local.Ball_1.x.ToString()); //BallMove.ltball.transform.position = new Vector3(asd.x, 0, -5); }
public IStateMachineBuilder <TState, TAction> Create <TState, TAction>(string stateMachineName) where TState : struct where TAction : struct { DebugLogger.Debug($"创建状态机 : {stateMachineName}"); return(this.cache.GetOrCreate <IStateMachineBuilder <TState, TAction> >($"STATE_MACHINE_BUILDER_{stateMachineName}", key => { string name = this.resourceNameProvider.GetStateMachineCsv(stateMachineName); using (var stream = this.resourceProvider.Provide(name)) { return CsvStateMachineBuilder <TState, TAction> .FromStream(stream); } })); }
private void userCreateCallback(byte[] data) { var msg = ProtobufDecoder(data); if (msg.Response.RpcRsp != null) { var createdUserInfo = MessagePackDecoder <object>(msg.Response.RpcRsp); SerializeDB serializedMsg; serializedMsg = JsonConvert.DeserializeAnonymousType <SerializeDB>(createdUserInfo.ToString(), new SerializeDB()); DebugLogger.Debug("Created game agent for player" + serializedMsg.playerName); } }
internal static Exception Connect(NodeInfo node, IProtocol p) { p.Connect(); // 连接后第一步,使用约定的加密密钥传输rid和uid来寻找对应的房间,之后采用加密通信传输数据 // 暂时采用明文传输房间号 todo... byte[] data = System.Text.Encoding.Default.GetBytes(node.token); p.Send(DataPack.PackLength(data)); // 等待服务端确认 data = p.Read(); string uid = System.Text.Encoding.Default.GetString(data); DebugLogger.Debug(string.Format("login to server {0}", uid)); // 战斗不需要额外连接node return(null); }
internal void LoginRpcCallback(byte[] data) { var msg = ProtobufDecoder(data); if (msg.Response.RpcRsp != null) { var needCreate = MessagePackDecoder <long>(msg.Response.RpcRsp); DebugLogger.Debug(needCreate.ToString()); if (needCreate == 1) { RpcCallBackDelegate createPlayerCallback = new RpcCallBackDelegate(userCreateCallback); rpcCall("user.create", "player_" + netProtocol.Node.uid, createPlayerCallback); } } }
internal void SerializeRpcCallback(byte[] data) { var msg = ProtobufDecoder(data); if (msg.Response.RpcRsp != null) { var RspMsg = MessagePackDecoder <object>(msg.Response.RpcRsp); DebugLogger.Debug(RspMsg.ToString()); SerializeDB serializedMsg; serializedMsg = JsonConvert.DeserializeAnonymousType <SerializeDB>(RspMsg.ToString(), new SerializeDB()); GameNodeRpc.SerializedPlayername.text = serializedMsg.playerName; GameNodeRpc.SerializedUid.text = serializedMsg.uid; } }
public async UniTaskVoid LoadAllConfig() { int configCount = (int)EnConfig.Count; UniTask<AsyncOperationHandle<TextAsset>>[] handles = new UniTask<AsyncOperationHandle<TextAsset>>[configCount]; for (int i = 0; i < configCount; i++) { handles[i] = LoadConfig(i); } var configDatas = await UniTask.WhenAll(handles); for (int i = 0; i < configDatas.Length; ++i) { if (configDatas[i].Status == AsyncOperationStatus.Succeeded) { if (i >= CongfigConst.ConfigName.Length) { DebugLogger.Debug("LoadAllConfig: ...... 当前index 超过了ConfigName的长度!!!"); return; } string configDataName = CongfigConst.ConfigName[i]; string dataClassName = "TinyJoy.SSG.Game.Configs." + configDataName; if (null == configDatas[i].Result) { DebugLogger.Debug("LoadAllConfig: ......" + dataClassName + " 数据读出为空!!!"); return; } LoadConfigData(configDatas[i].Result.bytes, dataClassName, i); } } for (int i = 0; i < configDatas.Length; ++i) { if (configDatas[i].IsValid()) { resourceLoader.UnloadAsset(configDatas[i]); } } await furnitureManager.LoadFurnitureDataAsync(); GameDataUtility.InitFilterList(); CollectionService.LoadCollectionData(); playerService.CountItemBagRes(); PlayerAccountDataContainer.LoadAccount(); loadStep.Value = EnGameLoadStep.LoadAtlas; }
public JsonResult Add() { var user = new User() { Id = Guid.NewGuid(), Username = "******", Email = "*****@*****.**", Mobilephone = "18000009999", Active = true, Deleted = false, }; _userService.InsertUser(user); DebugLogger.Debug($"inserted user:id{user.Id}"); return(Json(true)); }
private void other_player_coming(Message msg) { if (msg.OpCode == OPCODE.NotifyInfo) { var seq = msg.NotifyInfo.Sequence; if (seq > 0) { object retParam = MessagePackDecoder <object>(msg.NotifyInfo.RpcParams); DebugLogger.Debug(retParam.ToString()); Debug.Log("server callback"); // clientReceiveSeq = seq; } } }
public async Task <HttpResponseMessage> Add() { var user = new User() { Id = Guid.NewGuid(), Username = "******", Email = "*****@*****.**", Mobilephone = "18000009999", Active = true, Deleted = false, }; _userService.InsertUser(user); DebugLogger.Debug($"inserted user:id{user.Id}"); return(SuccessMessage(Data: true)); }
public static byte[] GenHandShake(string uid, string gameServer, string subid, uint connectionIndex) { int clientReceivedSeq = 0; DebugLogger.Debug("GenHandShake uid:" + uid + " gameServer:" + gameServer + " subid:" + subid); string handshake = string.Format ( "{0}@{1}#{2}:{3}:{4}", Convert.ToBase64String(Encoding.Default.GetBytes(uid)), Convert.ToBase64String(Encoding.Default.GetBytes(gameServer)), Convert.ToBase64String(Encoding.Default.GetBytes(subid)), connectionIndex, clientReceivedSeq ); string hmac_encode64 = handshake + ":" + NetCrypter.CryptData(handshake); byte[] hmac_encode64_bits = Encoding.Default.GetBytes(hmac_encode64); return(hmac_encode64_bits); }
public bool Login(string ip, int port, string secret) { // 连接服务器 if (ChkException(usrLogin(ip, port, secret, out netProtocol))) { OnError("ConnectLogin"); rpcCall("user.get_login_info", null, null); return(false); } else { // 登陆成功 DebugLogger.Debug("Login success"); } RpcCallBackDelegate callback = new RpcCallBackDelegate(LoginRpcCallback); rpcCall("user.get_login_info", null, callback); // 启动发送和接收 StartNetWorkService(); return(true); }
void StartNotify() { if (!matchFlag) { NotificationButtonText.text = "取消(10s返回)"; matchFlag = true; LoginRequist.ucl.rpcCall("combat.start_match", null, (byte[] data) => { var msg = BaseFramework.Network.UserClient.ProtobufDecoder(data); if (msg.Response.RpcRsp != null) { var result = UserClient.MessagePackDecoder <object>(msg.Response.RpcRsp); DebugLogger.Debug("start_match callback: " + result); //NotificationMsg.text = result.ToString(); } }); } else { NotificationButtonText.text = "新的匹配"; matchFlag = false; LoginRequist.ucl.rpcCall("combat.cancel_match", null, (byte[] data) => { var msg = UserClient.ProtobufDecoder(data); if (msg.Response.RpcRsp != null) { object result = UserClient.MessagePackDecoder <object>(msg.Response.RpcRsp); //TODO:UI按钮改回“新的匹配” DebugLogger.Debug("cancel_match callback: " + result); //NotificationMsg.text = result.ToString(); } }); } }
private void Match(Message msg) { if (msg.NotifyInfo.RpcParams != "0") { var seq = msg.NotifyInfo.Sequence; if (seq > 0) { Boolean retParam = MessagePackDecoder <Boolean>(msg.NotifyInfo.RpcParams); if (retParam) { DebugLogger.Debug("匹配成功"); LoginRequist.ucl.rpcCall("combat.getOtherId", null, (byte[] data) => { var massage = BaseFramework.Network.UserClient.ProtobufDecoder(data); if (massage.Response.RpcRsp != null) { var result = UserClient.MessagePackDecoder <object>(massage.Response.RpcRsp); //TODO:显示两个对战玩家信息(uid) GameManager.gm.setEnemyText(result.ToString()); GameManager.gm.setUserText(userText); DebugLogger.Debug("OtherID callback: " + result); } }); SceneManager.LoadScene("TowerScene"); } else { DebugLogger.Debug("匹配失败"); } Debug.Log("server callback:isMatchSuccess"); // clientReceiveSeq = seq; } } }
static DefaultCache() { DebugLogger.Debug("初始化缓存池"); }
public static NodeInfo ProcessLoginData(byte[] data) { if (data.Length < 2) { DebugLogger.Debug("Data Length is Less Than 2 ! Got " + data.Length, NetUtil.ErrorColor); throw new NetworkingException((int)ErrorCode.DataError); } UInt32 code = ((UInt32)data[0] << 8) + (UInt32)data[1]; if (code != (int)ErrorCode.Success) { if (code == (int)ErrorCode.Forbidden || code == (int)ErrorCode.LoginBusy) { byte[] b_message = new byte[data.Length - 2]; Buffer.BlockCopy(data, 2, b_message, 0, data.Length - 2); var base64Str = Encoding.Default.GetString(b_message); string message = Encoding.Default.GetString(Convert.FromBase64String(base64Str));//Convert.ToBase64String(b_message); DebugLogger.DebugError("Forbidden LoginBusy"); throw new NetworkingException((int)code, message); } else { DebugLogger.Debug("Login Code is Not Equal 200 ! Got " + code, NetUtil.ErrorColor); throw new NetworkingException((int)code); } } byte[] auth_return_bytes = new byte[data.Length - 2]; Buffer.BlockCopy(data, 2, auth_return_bytes, 0, data.Length - 2); string auth_return = Encoding.Default.GetString(auth_return_bytes); string[] strs = Regex.Split(auth_return, "@([^#]*)#"); if (strs.Length != 3) { DebugLogger.Debug("Network Strs Length Error, Required 3 Got " + strs.Length, NetUtil.ErrorColor); throw new NetworkingException((int)ErrorCode.DataError); } string uid = Encoding.Default.GetString(Convert.FromBase64String(strs[0])); string server = Encoding.Default.GetString(Convert.FromBase64String(strs[1])); string[] infos = Regex.Split(strs[2], "#"); if (infos.Length != 2) { DebugLogger.Debug("Network Infos Length Error, Required 2 Got " + infos.Length, NetUtil.ErrorColor); throw new NetworkingException((int)ErrorCode.DataError); } string netinfo = Encoding.Default.GetString(Convert.FromBase64String(infos[0])); string loginToken = Encoding.Default.GetString(Convert.FromBase64String(infos[1])); string[] netStrs = Regex.Split(netinfo, ":"); if (netStrs.Length != 2) { DebugLogger.Debug("Network NetStrs Length Error, Required 2 Got " + netStrs.Length, NetUtil.ErrorColor); throw new NetworkingException((int)ErrorCode.DataError); } string[] ids = Regex.Split(uid, ":"); if (ids.Length != 2) { DebugLogger.Debug("Network Ids Length Error, Required 2 Got " + ids.Length, NetUtil.ErrorColor); throw new NetworkingException((int)ErrorCode.DataError); } DebugLogger.Debug("ProcessLoginData2"); //#if UNITY_EDITOR DebugLogger.Debug("login success,UID:" + ids[0] + " subid: " + ids[1] + " gameServer: " + server + " nodeHost:" + netStrs[0] + " nodePort:" + netStrs[1] + " token:" + loginToken); //#endif return(new NodeInfo(ids[0], ids[1], server, netStrs[0], Convert.ToInt32(netStrs[1]), loginToken)); }
internal static Exception Login(string ip, int port, string account, out IProtocol p) { p = new TcpProtocol(ip, port, null); var cfg = new Dictionary <string, ProtocolCfg>() { { "SendBufferSize", new ProtocolCfg { intElement = Const.PackageMaxLength } }, { "ReceiveBufferSize", new ProtocolCfg { intElement = Const.PackageMaxLength } }, { "ReceiveTimeout", new ProtocolCfg { intElement = 3000 } } }; p.SetCfg(cfg); NodeInfo node = null; try { // 第一步建立连接 p.Connect(); //第二步,收到服务端发回的base64(8bytes random challenge)随机串,用于后序的握手验证// byte[] data = p.Read(); //第三步 生成 8bytes 随机串 client key byte[] client_key = Convert.FromBase64String(Encoding.Default.GetString(data, 0, data.Length)); data = LoginPass.GenSecretKey(data, client_key); //第四步,向服务端发送base64(DH-Exchange(client key)) 用于生成 secret 的 key p.Send(DataPack.PackLength(data)); //第五步,收到服务端发送过来的base64(DH-Exchange(server key)) 用于生成 secret 的 key data = p.Read(); //第六步,secret := DH-Secret(client key/server key)服务器和客户端都可以计算出同一个 8 字节的 secret 用来加密数据 byte[] secret = LoginPass.GenVerifySecret(data, client_key); NetCrypter.setSecret(secret); //第七步,base64(HMAC(challenge, secret))回应服务器第一步握手的挑战码,确认握手正常 data = LoginPass.GenFirstChallenge(client_key, secret); p.Send(DataPack.PackLength(data)); //第八步,DES(secret, base64(token))使用 DES 算法,以 secret 做 key 加密传输 token,token 包含帐号信息[user,sdkid] data = LoginPass.GenSecretUserToken(account, secret); p.Send(DataPack.PackLength(data)); //第九步,认证结果信息,前2个字节retcode 200 表示成功,只有成功才解析后续内容(base64(uid:subid)@base64(server)#base64(info)) data = p.Read(); node = LoginPass.ProcessLoginData(data); // 登陆完毕,关闭当前连接,准备连接node p.Close(); } catch (Exception e) { return(e); } DebugLogger.Debug("login node" + node.nodeHost + node.nodePort); // 连接节点 p = new TcpProtocol(node.nodeHost, node.nodePort, new ReConnect(UsrLogin.ConnectNode)); cfg["ReceiveTimeout"] = new ProtocolCfg { intElement = 10000 }; p.SetCfg(cfg); p.Node = node; return(ConnectNode(p.Node, p)); }
public DbConnectionContext(IDbConnection dbConnection) { DbConnection = dbConnection; this.Id = Guid.NewGuid(); DebugLogger.Debug($"{nameof(DbConnectionContext)}.Ctor : Id = {Id}"); }
static void Main(string[] args) { List <ITask> tasks = new List <ITask>(); foreach (var type in typeof(ITask).Assembly.GetTypes()) { if (!typeof(ITask).IsAssignableFrom(type)) { continue; } if (type.IsAbstract) { continue; } if (type.IsInterface) { continue; } tasks.Add((ITask)Activator.CreateInstance(type)); } SQLiteConnectionStringBuilder connectionStringBuilder = new SQLiteConnectionStringBuilder(); connectionStringBuilder.DataSource = ".\\data\\app.db"; using (SQLiteConnection conn = new SQLiteConnection(connectionStringBuilder.ToString())) { conn.Open(); DbConnectionContext ctx = new DbConnectionContext(conn); INPIImplementer implementer = new NPIImplementer(ctx); IUserDao userDao = implementer.Implement <IUserDao>(); Dictionary <string, object> context = new Dictionary <string, object>(); context[Constant.CONTEXT_KEY_DB_CONTEXT] = ctx; userDao.Delete(); foreach (var task in tasks) { Console.Write("{0} : ", task.TaskName); DebugLogger.Debug($"开始任务 : {task.TaskName}"); DateTime d1 = DateTime.Now; try { task.DoTask(userDao, context); DateTime d2 = DateTime.Now; Console.WriteLine("SUCCESS\t{0} ms", (d2 - d1).Milliseconds); } catch (Exception ex) { DateTime d2 = DateTime.Now; Console.WriteLine("Error\t{0} ms", (d2 - d1).Milliseconds); Console.WriteLine(ex.ToString()); break; } } } Console.WriteLine("Finished"); Console.ReadLine(); }