PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/BTSControl/Microsoft.BizTalk.ApplicationDeployment.CommandLine/MethodTracer.cs

#
C# | 73 lines | 52 code | 9 blank | 12 comment | 1 complexity | 8ae16ddf5adebac86550341a100f6b5f MD5 | raw file
  1. namespace Microsoft.BizTalk.ApplicationDeployment.CommandLine
  2. {
  3. using Microsoft.BizTalk.ApplicationDeployment;
  4. using System;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.Reflection;
  8. internal class MethodTracer : IDisposable
  9. {
  10. private MethodBase currentMethod;
  11. private DateTime endTime;
  12. private string separator = new string('-', 60);
  13. private DateTime startTime;
  14. public MethodTracer(MethodBase currentMethod)
  15. {
  16. this.currentMethod = currentMethod;
  17. this.startTime = DateTime.Now;
  18. this.Enter();
  19. }
  20. public void Dispose()
  21. {
  22. this.Dispose(true);
  23. GC.SuppressFinalize(this);
  24. }
  25. protected virtual void Dispose(bool disposing)
  26. {
  27. if (disposing)
  28. {
  29. this.endTime = DateTime.Now;
  30. this.Exit();
  31. }
  32. }
  33. private void Enter()
  34. {
  35. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(this.separator, new object[0]);
  36. string str = this.startTime.ToString("T", CultureInfo.InvariantCulture);
  37. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, ">>> Entering {0}.{1} @ {2}", new object[] { this.currentMethod.DeclaringType.Name, this.currentMethod.Name, str }), new object[0]);
  38. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Empty, new object[0]);
  39. }
  40. private void Exit()
  41. {
  42. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Empty, new object[0]);
  43. string str = this.endTime.ToString("T", CultureInfo.InvariantCulture);
  44. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "<<< Exiting {0}.{1} @ {2}", new object[] { this.currentMethod.DeclaringType.Name, this.currentMethod.Name, str }), new object[0]);
  45. TimeSpan span = this.endTime.Subtract(this.startTime);
  46. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "(Elapsed time: {0} seconds)", new object[] { span.TotalSeconds }), new object[0]);
  47. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(this.separator, new object[0]);
  48. }
  49. ~MethodTracer()
  50. {
  51. this.Dispose(false);
  52. }
  53. public static void TraceAssembly()
  54. {
  55. Assembly executingAssembly = Assembly.GetExecutingAssembly();
  56. FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(executingAssembly.Location);
  57. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Assembly: {0}", new object[] { executingAssembly.FullName }), new object[0]);
  58. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Location: {0}", new object[] { executingAssembly.Location }), new object[0]);
  59. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Product: {0} {1}", new object[] { versionInfo.ProductName, versionInfo.ProductVersion }), new object[0]);
  60. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "File: {0} {1}", new object[] { versionInfo.OriginalFilename, versionInfo.FileVersion }), new object[0]);
  61. //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Empty, new object[0]);
  62. }
  63. }
  64. }