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