PerformanceCounterPermissionEntryCollection.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // System.Diagnostics.PerformanceCounterPermissionEntryCollection.cs
  3. //
  4. // Authors:
  5. // Jonathan Pryor ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Sebastien Pouliot <[email protected]>
  8. //
  9. // (C) 2002
  10. // (C) 2003 Andreas Nahr
  11. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System.Collections;
  33. using System.Globalization;
  34. using System.Security.Permissions;
  35. namespace System.Diagnostics {
  36. [Serializable]
  37. public class PerformanceCounterPermissionEntryCollection : CollectionBase {
  38. private PerformanceCounterPermission owner;
  39. internal PerformanceCounterPermissionEntryCollection (PerformanceCounterPermission owner)
  40. {
  41. this.owner = owner;
  42. ResourcePermissionBaseEntry[] entries = owner.GetEntries ();
  43. if (entries.Length > 0) {
  44. foreach (ResourcePermissionBaseEntry entry in entries) {
  45. PerformanceCounterPermissionAccess elpa = (PerformanceCounterPermissionAccess) entry.PermissionAccess;
  46. string machine = entry.PermissionAccessPath [0];
  47. string category = entry.PermissionAccessPath [1];
  48. PerformanceCounterPermissionEntry elpe = new PerformanceCounterPermissionEntry (elpa, machine, category);
  49. // we don't want to add them (again) to the base class
  50. InnerList.Add (elpe);
  51. }
  52. }
  53. }
  54. internal PerformanceCounterPermissionEntryCollection (ResourcePermissionBaseEntry[] entries)
  55. {
  56. foreach (ResourcePermissionBaseEntry entry in entries) {
  57. List.Add (new PerformanceCounterPermissionEntry ((PerformanceCounterPermissionAccess) entry.PermissionAccess, entry.PermissionAccessPath[0], entry.PermissionAccessPath[1]));
  58. }
  59. }
  60. public PerformanceCounterPermissionEntry this [int index] {
  61. get { return (PerformanceCounterPermissionEntry) InnerList[index]; }
  62. set { InnerList[index] = value; }
  63. }
  64. public int Add (PerformanceCounterPermissionEntry value)
  65. {
  66. return List.Add (value);
  67. }
  68. public void AddRange (PerformanceCounterPermissionEntry[] value)
  69. {
  70. foreach (PerformanceCounterPermissionEntry e in value)
  71. List.Add (e);
  72. }
  73. public void AddRange (PerformanceCounterPermissionEntryCollection value)
  74. {
  75. foreach (PerformanceCounterPermissionEntry e in value)
  76. List.Add (e);
  77. }
  78. public bool Contains (PerformanceCounterPermissionEntry value)
  79. {
  80. return List.Contains (value);
  81. }
  82. public void CopyTo (PerformanceCounterPermissionEntry[] array, int index)
  83. {
  84. List.CopyTo (array, index);
  85. }
  86. public int IndexOf (PerformanceCounterPermissionEntry value)
  87. {
  88. return List.IndexOf (value);
  89. }
  90. public void Insert (int index, PerformanceCounterPermissionEntry value)
  91. {
  92. List.Insert (index, value);
  93. }
  94. protected override void OnClear ()
  95. {
  96. owner.ClearEntries ();
  97. }
  98. protected override void OnInsert (int index, object value)
  99. {
  100. owner.Add (value);
  101. }
  102. protected override void OnRemove (int index, object value)
  103. {
  104. owner.Remove (value);
  105. }
  106. protected override void OnSet (int index, object oldValue, object newValue)
  107. {
  108. owner.Remove (oldValue);
  109. owner.Add (newValue);
  110. }
  111. public void Remove (PerformanceCounterPermissionEntry value)
  112. {
  113. List.Remove (value);
  114. }
  115. }
  116. }