EventLogPermission.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // System.Diagnostics.EventLogPermission.cs
  3. //
  4. // Authors:
  5. // Jonathan Pryor ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Sebastien Pouliot <[email protected]>
  8. //
  9. // (C) 2002 Jonathan Pryor
  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.Security.Permissions;
  33. namespace System.Diagnostics {
  34. [Serializable]
  35. public sealed class EventLogPermission : ResourcePermissionBase {
  36. EventLogPermissionEntryCollection innerCollection;
  37. public EventLogPermission ()
  38. {
  39. SetUp ();
  40. }
  41. public EventLogPermission (EventLogPermissionEntry[] permissionAccessEntries)
  42. {
  43. if (permissionAccessEntries == null)
  44. throw new ArgumentNullException ("permissionAccessEntries");
  45. SetUp ();
  46. innerCollection = new EventLogPermissionEntryCollection (this);
  47. innerCollection.AddRange (permissionAccessEntries);
  48. }
  49. public EventLogPermission (PermissionState state)
  50. : base (state)
  51. {
  52. SetUp ();
  53. }
  54. public EventLogPermission (EventLogPermissionAccess permissionAccess, string machineName)
  55. {
  56. SetUp ();
  57. innerCollection = new EventLogPermissionEntryCollection (this);
  58. innerCollection.Add (new EventLogPermissionEntry (permissionAccess, machineName));
  59. }
  60. public EventLogPermissionEntryCollection PermissionEntries {
  61. get {
  62. if (innerCollection == null) {
  63. // must be here to work with XML deserialization
  64. innerCollection = new EventLogPermissionEntryCollection (this);
  65. }
  66. return innerCollection;
  67. }
  68. }
  69. // private stuff
  70. private void SetUp ()
  71. {
  72. TagNames = new string [1] { "Machine" };
  73. PermissionAccessType = typeof (EventLogPermissionAccess);
  74. }
  75. internal ResourcePermissionBaseEntry[] GetEntries ()
  76. {
  77. return base.GetPermissionEntries ();
  78. }
  79. internal void ClearEntries ()
  80. {
  81. base.Clear ();
  82. }
  83. internal void Add (object obj)
  84. {
  85. EventLogPermissionEntry elpe = (obj as EventLogPermissionEntry);
  86. base.AddPermissionAccess (elpe.CreateResourcePermissionBaseEntry ());
  87. }
  88. internal void Remove (object obj)
  89. {
  90. EventLogPermissionEntry elpe = (obj as EventLogPermissionEntry);
  91. base.RemovePermissionAccess (elpe.CreateResourcePermissionBaseEntry ());
  92. }
  93. }
  94. }