/// <summary> /// 执行查询文本并返回一个 <see cref="IDataReader"/>。 /// </summary> /// <param name="queryCommand">查询命令。</param> /// <param name="segment">数据分段对象。</param> /// <param name="parameters">查询参数集合。</param> /// <returns>一个 <see cref="IDataReader"/> 对象。</returns> public virtual IDataReader ExecuteReader(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null) { Guard.ArgumentNull(queryCommand, "queryCommand"); return(UsingConnection(() => { var command = CreateDbCommand(queryCommand, parameters); try { var cmdBehavior = CommandBehavior.Default; IDataReader reader = null; var context = new CommandContext(this, command, segment, parameters); OnCommandExecuted(command, segment, parameters, TimeWatcher.Watch(() => ProcessSegmentCommand(context, () => reader = command.ExecuteReader(cmdBehavior)))); command.SyncParameters(parameters); command.ClearParameters(); return reader; } catch (DbException exp) { TrackFailedLog(command, exp); throw new CommandException(command, exp); } })); }
public void TestCache2() { using (var db = new DbContext()) { var a1 = new DataPager(10, 2); var a2 = new DataPager(10, 2); Console.WriteLine(TimeWatcher.Watch(() => { var list1 = db.Orders .Segment(a1) .CacheParsing(true, TimeSpan.FromDays(1)) .CacheExecution(true, TimeSpan.FromDays(1)) .AsNoTracking() .ToList(); })); Console.WriteLine(TimeWatcher.Watch(() => { var list2 = db.Orders .Segment(a2) .CacheParsing(true, TimeSpan.FromDays(1)) .CacheExecution(true, TimeSpan.FromDays(1)) .AsNoTracking() .ToList(); })); } }
/// <summary> /// 执行查询文本,返回受影响的记录数。 /// </summary> /// <param name="queryCommand">查询命令。</param> /// <param name="parameters">查询参数集合。</param> /// <returns>所影响的记录数。</returns> public virtual int ExecuteNonQuery(IQueryCommand queryCommand, ParameterCollection parameters = null) { Guard.ArgumentNull(queryCommand, "queryCommand"); return(UsingConnection(() => { using (var command = CreateDbCommand(queryCommand, parameters)) { try { var result = 0; OnCommandExecuted(command, null, parameters, TimeWatcher.Watch(() => result = command.ExecuteNonQuery())); command.SyncParameters(parameters); command.ClearParameters(); return result; } catch (DbException exp) { TrackFailedLog(command, exp); throw new CommandException(command, exp); } } })); }
public void Test() { var t1 = TimeWatcher.Watch(() => { for (var i = 0; i < 10000; i++) { Console.WriteLine($"{2222}fadfasdfasf{4454545}ffdafdf{33}ffdfad{44}"); } }); Console.WriteLine(t1); var t2 = TimeWatcher.Watch(() => { for (var i = 0; i < 10000; i++) { Console.WriteLine(string.Concat(2222, "fadfasdfasf", 4454545, "ffdafdf", 33, "ffdfad", 44)); } }); Console.WriteLine(t2); var t3 = TimeWatcher.Watch(() => { var sb = new StringBuilder(); for (var i = 0; i < 10000; i++) { Console.WriteLine(string.Format("{0}fadfasdfasf{1}ffdafdf{2}ffdfad{3}", 2222, 4454545, 33, 44)); } }); Console.WriteLine(t3); }
/// <summary> /// 异步执行查询文本,并返回第一行的第一列。 /// </summary> /// <param name="queryCommand">查询命令。</param> /// <param name="parameters">查询参数集合。</param> /// <returns>第一行的第一列数据。</returns> public async virtual Task <object> ExecuteScalarAsync(IQueryCommand queryCommand, ParameterCollection parameters = null) { Guard.ArgumentNull(queryCommand, "queryCommand"); return(await UsingConnection(() => { using (var command = CreateDbCommand(queryCommand, parameters)) { try { Task <object> result = null; OnCommandExecuted(command, null, parameters, TimeWatcher.Watch(() => result = command.ExecuteScalarAsync())); command.SyncParameters(parameters); command.ClearParameters(); return result; } catch (DbException exp) { if (ConnectionString.IsTracking && Track != null) { Track.Fail(command, exp); } throw new CommandException(command, exp); } } })); }
public void TestNew1() { var t1 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { var tt = Activator.CreateInstance(typeof(TestClass), "aa"); } }); var t2 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { var tt = typeof(TestClass).New(null, 11); } }); var t3 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { var tt = new TestClass("aa"); } }); Console.WriteLine("反射:" + t1); Console.WriteLine("缓存:" + t2); Console.WriteLine("直接:" + t3); }
/// <summary> /// 在后台启动一个任务,并显示一个进度提示框。 /// </summary> /// <param name="owner">进度提示框的所有者。</param> /// <param name="taskAct">要启动的任务。</param> /// <param name="cancelAct">取消后进行的动作。</param> /// <returns></returns> public static TimeSpan Run(IWin32Window owner, Action taskAct, Action cancelAct = null) { return(TimeWatcher.Watch(() => { new frmProcessor(taskAct, cancelAct).ShowDialog(owner); })); }
public void TestInvoke() { var n = typeof(TestClass).GetMethod("Call"); var ins = new TestClass("bb"); var t1 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { n.Invoke(ins, new[] { "aaaaaa" }); } }); var t2 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { n.FastInvoke(ins, "aaaaaa"); } }); var t3 = TimeWatcher.Watch(() => { for (var i = 0; i < 100000; i++) { ins.Call("aaaaaa"); } }); Console.WriteLine("反射:" + t1); Console.WriteLine("缓存:" + t2); Console.WriteLine("直接:" + t3); }
public void Test() { var dic1 = new Dictionary <string, string>(); var dic2 = new Dictionary <Type, string>(); foreach (var assn in typeof(EntityTest).Assembly.GetReferencedAssemblies().Distinct()) { var ass = Assembly.Load(assn); foreach (var type in ass.GetTypes()) { dic1.Add(type.AssemblyQualifiedName, type.FullName); dic2.Add(type, type.FullName); } } var k = dic2.Last().Key; var t = TimeWatcher.Watch(() => { dic1[k.AssemblyQualifiedName] = "dd"; }); Console.WriteLine(t); t = TimeWatcher.Watch(() => { dic2[k] = "dd"; }); Console.WriteLine(t); }
protected override void Draw(GameTime time) { GraphicsDevice.Clear(new Color(51, 51, 51)); render = new Rectangle(200, 0, GraphicsDevice.Viewport.Width - 200, GraphicsDevice.Viewport.Height - 80); if (!ConsoleCommands.FreezeGame) { GraphicsDevice.SetRenderTarget(gameContent); GraphicsDevice.Clear(Color.Black); phaseManager.Draw(renderer, time); GraphicsDevice.SetRenderTarget(null); render = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); recorder.AddRecordEntry(new RecordEntry(gameContent, time)); } renderer.Begin(); renderer.Draw(gameContent, render, Color.White); if (ConsoleCommands.FreezeGame && ConsoleCommands.PlayLoop) { recorder.Draw(renderer, time); } consoleControl.Draw(renderer); batch.End(); TimeWatcher.ClearCurrent(); base.Draw(time); }
/// <summary> /// 异步执行查询文本并返回一个 <see cref="IDataReader"/>。 /// </summary> /// <param name="queryCommand">查询命令。</param> /// <param name="segment">数据分段对象。</param> /// <param name="parameters">查询参数集合。</param> /// <returns>一个 <see cref="IDataReader"/> 对象。</returns> public async virtual Task <IDataReader> ExecuteReaderAsync(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null) { Guard.ArgumentNull(queryCommand, "queryCommand"); return(await UsingConnection(() => { using (var command = CreateDbCommand(queryCommand, parameters)) { try { Task <DbDataReader> reader = null; var context = new CommandContext(this, command, segment, parameters); OnCommandExecuted(command, segment, parameters, TimeWatcher.Watch(() => ProcessSegmentCommand(context, () => reader = command.ExecuteReaderAsync()))); command.SyncParameters(parameters); command.ClearParameters(); return reader; } catch (DbException exp) { TrackFailedLog(command, exp); throw new CommandException(command, exp); } } })); }
private void TimeWatcher_Tick(object sender, EventArgs e) { if (Tmins == 0 && Tsecs == 0) { TimeWatcher.Stop(); EnemiesMover.Stop(); BulletChecker.Stop(); IntersectionsDetecter.Stop(); this.KeyDown -= new KeyEventHandler(Level1_KeyDown); StartStop.Text = "Start"; Tsecs = 2; Tmins = 0; ClearCurrentWindow(); if (IScore >= 3000) { GameResult("Winner"); } else { GameResult("Loser"); } return; } else if (Tmins >= 1 && Tsecs == 0) { Tmins--; Tsecs = 59; } else if (Tsecs > 0) { Tsecs--; } UpdateTime(); }
private void OnCloseToNode(Event_ e) { var npcId = (NpcTypeID)e.param1; var watcher = TimeWatcher.Watch("show star window"); _starWindow.Initialize(npcId); watcher.See("Initialize"); watcher.Stop(); watcher.UnWatch(); }
void GameResult(string result) { IntersectionsDetecter.Stop(); TimeWatcher.Stop(); EnemiesMover.Stop(); RandomEnemyBullets.Stop(); Form2 f = new Form2(result); f.Show(); }
/// <summary> /// 通知应用程序,一个 <see cref="DbCommand"/> 已经执行。 /// </summary> /// <param name="command">所执行的 <see cref="IDbCommand"/> 对象。</param> /// <param name="func">执行的方法。</param> protected virtual T HandleCommandExecute <T>(IDbCommand command, Func <T> func) { var result = default(T); var period = TimeWatcher.Watch(() => result = func()); Debug.WriteLine("Execute: " + command.Output() + "\nDissipation times: " + period); HandleLog(command, period); return(result); }
public void WatchTest() { var time = TimeWatcher.Watch( () => { Thread.Sleep(1000); }); Assert.IsNotNull(time); Console.WriteLine(time); }
public void TestQueryFireasyAll() { using (var db = new FireasyDbContext()) { var t = TimeWatcher.Watch(() => { var list1 = db.Users.Where(s => s.UserID != 0).AsNoTracking().ToList(); }); Console.WriteLine(t); } }
/// <summary> /// 异步的,通知应用程序,一个 <see cref="DbCommand"/> 已经执行。 /// </summary> /// <param name="command">所执行的 <see cref="DbCommand"/> 对象。</param> /// <param name="parameters"></param> /// <param name="func">执行的方法。</param> private async Task <T> AfterCommandExecutedAsync <T>(DbCommand command, ParameterCollection parameters, Func <Task <T> > func) { var result = default(T); var period = await TimeWatcher.WatchAsync(async() => result = await func()); await HandleLogAsync(command, period); command.SyncParameters(parameters); command.ClearParameters(); return(result); }
/// <summary> /// 通知应用程序,一个 <see cref="DbCommand"/> 已经执行。 /// </summary> /// <param name="command">所执行的 <see cref="DbCommand"/> 对象。</param> /// <param name="func">执行的方法。</param> private T AfterCommandExecuted <T>(DbCommand command, ParameterCollection parameters, Func <T> func) { var result = default(T); var period = TimeWatcher.Watch(() => result = func()); HandleLogAsync(command, period); command.SyncParameters(parameters); command.ClearParameters(); return(result); }
private void OnFarAwayNode(Event_ e) { var npcId = (NpcTypeID)e.param1; var watcher = TimeWatcher.Watch("show detail window"); _detailWindow.Initialize(npcId); watcher.See("Initialize"); watcher.Stop(); watcher.UnWatch(); moduleGlobal.ShowGlobalLayerDefault(1, false); _root.SafeSetActive(true); }
/// <summary> /// 解压缩数据 /// </summary> /// <param name="buffer">要解压的数据</param> /// <returns>若解压成功 返回解压后的数据 否则返回 null</returns> public static byte[] DecompressData(byte[] buffer, int off = 0) { var watcher = TimeWatcher.Watch("Util.DecompressData"); var inStream = new MemoryStream(buffer, off, buffer.Length - 1); var decoder = new Decoder(); var properties = new byte[5]; if (inStream.Read(properties, 0, 5) != 5) { Logger.LogError("Util::DecompressData: Invalid compress data."); inStream.Dispose(); watcher.UnWatch(false); return(null); } decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { var v = inStream.ReadByte(); if (v < 0) { inStream.Dispose(); watcher.UnWatch(false); return(null); } outSize |= ((long)(byte)v) << (8 * i); } var outStream = new MemoryStream(); var compressedSize = inStream.Length - inStream.Position; decoder.Code(inStream, outStream, compressedSize, outSize, null); outStream.Position = 0; var data = new byte[outStream.Length]; outStream.Read(data, 0, data.Length); inStream.Dispose(); outStream.Dispose(); watcher.UnWatch(); return(data); }
public void TestQueryEFAll() { using (var db = new EfDbContext()) { var t = TimeWatcher.Watch(() => { var list1 = db.Users.Where(s => s.UserID != 0).ToList(); list1[0].Name = "aa"; }); db.SaveChanges(); Console.WriteLine(t); } }
private void OnNodeGetFocus(Event_ e) { var npcId = (NpcTypeID)e.param1; var watcher = TimeWatcher.Watch("show detail window2"); _detailWindow.Initialize(npcId); watcher.See("Initialize"); watcher.Stop(); watcher.UnWatch(); if (_npcDict.ContainsKey(npcId)) { _npcDict[npcId].isOn = true; } }
public void TestQuerySqlSugarAll() { var db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = connstr, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); var t = TimeWatcher.Watch(() => { var list1 = db.Queryable <SysUser>().ToList(); }); Console.WriteLine(t); }
private void button5_Click(object sender, EventArgs e) { var time = TimeWatcher.Watch(() => { treeList1.Items.Clear(); for (var i = 0; i < 5000; i++) { var item = new TreeListItem(); treeList1.Items.Add(item); item.Cells[0].Value = "祖国要举行建国" + (i + 1) + "周年纪念活动"; item.Cells[1].Value = DateTime.Today; item.Cells[2].Value = (i + 1); } }); MessageBox.Show("5000条数据需要" + time.TotalMilliseconds.ToString() + "毫秒"); }
/// <summary> /// 当摄像机靠近时触发 /// </summary> public void OnCameraCloseTo() { var watcher = TimeWatcher.Watch("OnCameraCloseTo"); watcher.See("lineGray"); RefreshStarState(); watcher.See("RefreshStarState"); starRoot?.SafeSetActive(true); AddListener(); Module_Awake.instance?.DispatchEvent(Module_Awake.Event_CloseToNode, Event_.Pop(npcId)); watcher.See("Event_CloseToNode"); watcher.Stop(); watcher.UnWatch(); animEffect.SafeSetActive(true); }
public void WatchAroundTest() { var times = TimeWatcher.WatchAround( () => { Thread.Sleep(1000); }, () => { Thread.Sleep(1000); }); Assert.IsNotNull(times); foreach (var time in times) { Console.WriteLine(time); } }
private int UpdateSimple(DataTable dataTable, ParameterCollection parameters, SqlCommand sqlCommand) { const string COLUMN_RESULT = "_Result"; if (dataTable.Columns[COLUMN_RESULT] == null) { dataTable.Columns.Add(COLUMN_RESULT, typeof(int)); } var result = 0; UsingConnection(connection => { BeginTransaction(); using (var command = CreateDbCommand(connection, sqlCommand, parameters)) { try { foreach (DataRow row in dataTable.Rows) { UpdateParameters(command.Parameters, row); var time = TimeWatcher.Watch(() => row[COLUMN_RESULT] = command.ExecuteScalar() ?? 0); HandleLog(command, time); result++; } CommitTransaction(); } catch (DbException exp) { HandleFailedLog(command, exp); RollbackTransaction(); throw new CommandException(command, exp); } } }, mode: DistributedMode.Master); return(result); }
private void button6_Click(object sender, EventArgs e) { var time = TimeWatcher.Watch(() => { treeList1.BeginUpdate(); treeList1.Items.Clear(); for (var i = 0; i < 5000; i++) { treeList1.Items.AddCells(new object[] { "祖国要举行建国" + (i + 1) + "周年纪念活动", DateTime.Today, (i + 1) }); } treeList1.EndUpdate(); }); MessageBox.Show("5000条数据需要" + time.TotalMilliseconds.ToString() + "毫秒"); treeList1.Items[treeList1.Items.Count - 1].Selected = true; treeList1.Items[treeList1.Items.Count - 1].EnsureVisible(); }
public override void Draw(Renderer2D renderer, GameTime time) { renderer.Begin(cam.Transform); TimeWatcher.Start("Map.Draw"); w.map.Draw(renderer, cam.Transform); TimeWatcher.End(); renderer.End(); if (debug) { renderer.Begin(cam.Transform); DebugRenderer.DrawWorld(renderer, time); renderer.End(); renderer.Begin(); DebugRenderer.DrawScreen(renderer, time); renderer.End(); } }