AppDomainInfo.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Administration
  5. {
  6. using System;
  7. using System.Diagnostics;
  8. using System.Runtime;
  9. sealed class AppDomainInfo
  10. {
  11. static object syncRoot = new object();
  12. // Double-checked locking pattern requires volatile for read/write synchronization
  13. static volatile AppDomainInfo singleton;
  14. Guid instanceId;
  15. string friendlyName;
  16. bool isDefaultAppDomain;
  17. string processName;
  18. string machineName;
  19. int processId;
  20. int id;
  21. AppDomainInfo(AppDomain appDomain)
  22. {
  23. // Assumption: Only one AppDomainInfo is created per AppDomain
  24. Fx.Assert(null != appDomain, "");
  25. this.instanceId = Guid.NewGuid();
  26. this.friendlyName = appDomain.FriendlyName;
  27. this.isDefaultAppDomain = appDomain.IsDefaultAppDomain();
  28. Process process = Process.GetCurrentProcess();
  29. this.processName = process.ProcessName;
  30. this.machineName = Environment.MachineName;
  31. this.processId = process.Id;
  32. this.id = appDomain.Id;
  33. }
  34. public int Id
  35. {
  36. get
  37. {
  38. return this.id;
  39. }
  40. }
  41. public Guid InstanceId
  42. {
  43. get
  44. {
  45. return this.instanceId;
  46. }
  47. }
  48. public string MachineName
  49. {
  50. get
  51. {
  52. return this.machineName;
  53. }
  54. }
  55. public string Name
  56. {
  57. get
  58. {
  59. return this.friendlyName;
  60. }
  61. }
  62. public bool IsDefaultAppDomain
  63. {
  64. get
  65. {
  66. return this.isDefaultAppDomain;
  67. }
  68. }
  69. public int ProcessId
  70. {
  71. get
  72. {
  73. return this.processId;
  74. }
  75. }
  76. public string ProcessName
  77. {
  78. get
  79. {
  80. return this.processName;
  81. }
  82. }
  83. internal static AppDomainInfo Current
  84. {
  85. get
  86. {
  87. if (null == singleton)
  88. {
  89. lock (AppDomainInfo.syncRoot)
  90. {
  91. if (null == singleton)
  92. {
  93. singleton = new AppDomainInfo(AppDomain.CurrentDomain);
  94. }
  95. }
  96. }
  97. return singleton;
  98. }
  99. }
  100. }
  101. }