PerformanceCounterPermissionAttribute.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // System.Diagnostics.PerformanceCounterPermissionAttribute.cs
  3. //
  4. // Authors:
  5. // Jonathan Pryor ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) 2002
  9. // (C) 2003 Andreas Nahr
  10. //
  11. using System;
  12. using System.Diagnostics;
  13. using System.Security;
  14. using System.Security.Permissions;
  15. namespace System.Diagnostics
  16. {
  17. [AttributeUsage(
  18. AttributeTargets.Assembly |
  19. AttributeTargets.Class |
  20. AttributeTargets.Struct |
  21. AttributeTargets.Constructor |
  22. AttributeTargets.Method |
  23. AttributeTargets.Event )]
  24. [Serializable]
  25. public class PerformanceCounterPermissionAttribute : CodeAccessSecurityAttribute
  26. {
  27. private string categoryName;
  28. private string machineName;
  29. private PerformanceCounterPermissionAccess permissionAccess;
  30. public PerformanceCounterPermissionAttribute (SecurityAction action)
  31. : base (action)
  32. {
  33. categoryName = "*";
  34. machineName = ".";
  35. permissionAccess = PerformanceCounterPermissionAccess.Browse;
  36. }
  37. public string CategoryName {
  38. get {return categoryName;}
  39. set {categoryName = value;}
  40. }
  41. // May throw ArgumentException if computer name is invalid
  42. public string MachineName {
  43. get {return machineName;}
  44. set {
  45. // TODO check machine name
  46. machineName = value;
  47. }
  48. }
  49. public PerformanceCounterPermissionAccess PermissionAccess {
  50. get {return permissionAccess;}
  51. set {permissionAccess = value;}
  52. }
  53. public override IPermission CreatePermission ()
  54. {
  55. if (base.Unrestricted) {
  56. return new PerformanceCounterPermission (PermissionState.Unrestricted);
  57. }
  58. return new PerformanceCounterPermission (PermissionAccess, MachineName, categoryName);
  59. }
  60. }
  61. }