New test.
[mono.git] / mcs / class / System / System.Diagnostics / EventLogEntry.cs
1 //
2 // System.Diagnostics.EventLogEntry.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 //
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
33 using System.ComponentModel;
34 #if NET_2_0
35 using System.Runtime.InteropServices;
36 #endif
37 using System.Runtime.Serialization;
38 using System.Security.Permissions;
39
40 namespace System.Diagnostics
41 {
42
43         [Serializable]
44         [ToolboxItem (false), DesignTimeVisible (false)]
45         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
46         public sealed class EventLogEntry : Component, ISerializable
47         {
48
49                 private string category;
50                 private short categoryNumber;
51                 private byte[] data;
52                 private EventLogEntryType entryType;
53                 private int eventID;
54                 private int index;
55                 private string machineName;
56                 private string message;
57                 private string[] replacementStrings;
58                 private string source;
59                 private DateTime timeGenerated;
60                 private DateTime timeWritten;
61                 private string userName;
62 #if NET_2_0
63                 private long instanceId;
64 #endif
65
66                 internal EventLogEntry (string category, short categoryNumber, int index, 
67                                         int eventID, string source, string message, string userName, 
68                                         string machineName, EventLogEntryType entryType, 
69                                         DateTime timeGenerated, DateTime timeWritten, byte[] data, 
70                                         string[] replacementStrings, long instanceId)
71                 {
72                         this.category = category;
73                         this.categoryNumber = categoryNumber;
74                         this.data = data;
75                         this.entryType = entryType;
76                         this.eventID = eventID;
77                         this.index = index;
78                         this.machineName = machineName;
79                         this.message = message;
80                         this.replacementStrings = replacementStrings;
81                         this.source = source;
82                         this.timeGenerated = timeGenerated;
83                         this.timeWritten = timeWritten;
84                         this.userName = userName;
85 #if NET_2_0
86                         this.instanceId = instanceId;
87 #endif
88                 }
89
90                 [MonoTODO]
91                 private EventLogEntry (SerializationInfo info, StreamingContext context)
92                 {
93                 }
94
95                 [MonitoringDescription ("The category of this event entry.")]
96                 public string Category {
97                         get { return category; }
98                 }
99
100                 [MonitoringDescription ("An ID for the category of this event entry.")]
101                 public short CategoryNumber {
102                         get { return categoryNumber; }
103                 }
104
105                 [MonitoringDescription ("Binary data associated with this event entry.")]
106                 public byte[] Data {
107                         get { return data; }
108                 }
109
110                 [MonitoringDescription ("The type of this event entry.")]
111                 public EventLogEntryType EntryType {
112                         get { return entryType; }
113                 }
114
115 #if NET_2_0
116                 [Obsolete ("Use InstanceId")]
117 #endif
118                 [MonitoringDescription ("An ID number for this event entry.")]
119                 public int EventID {
120                         get { return eventID; }
121                 }
122
123                 [MonitoringDescription ("Sequence numer of this event entry.")]
124                 public int Index {
125                         get { return index; }
126                 }
127
128 #if NET_2_0
129                 [ComVisible (false)]
130                 public long InstanceId {
131                         get { return instanceId; }
132                 }
133 #endif
134
135                 [MonitoringDescription ("The Computer on which this event entry occured.")]
136                 public string MachineName {
137                         get { return machineName; }
138                 }
139
140                 [Editor ("System.ComponentModel.Design.BinaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
141                 [MonitoringDescription ("The message of this event entry.")]
142                 public string Message {
143                         get { return message; }
144                 }
145
146                 [MonitoringDescription ("Application strings for this event entry.")]
147                 public string[] ReplacementStrings {
148                         get { return replacementStrings; }
149                 }
150
151                 [MonitoringDescription ("The source application of this event entry.")]
152                 public string Source {
153                         get { return source; }
154                 }
155
156                 [MonitoringDescription ("Generation time of this event entry.")]
157                 public DateTime TimeGenerated {
158                         get { return timeGenerated; }
159                 }
160
161                 [MonitoringDescription ("The time at which this event entry was written to the logfile.")]
162                 public DateTime TimeWritten {
163                         get { return timeWritten; }
164                 }
165
166                 [MonitoringDescription ("The name of a user associated with this event entry.")]
167                 public string UserName {
168                         get { return userName; }
169                 }
170
171                 public bool Equals (EventLogEntry otherEntry)
172                 {
173                         if (otherEntry == this)
174                                 return true;
175
176                         return (
177                                 (otherEntry.Category == category) &&
178                                 (otherEntry.CategoryNumber == categoryNumber) &&
179                                 (otherEntry.Data.Equals (data)) &&
180                                 (otherEntry.EntryType == entryType) &&
181                                 (otherEntry.EventID == eventID) &&
182                                 (otherEntry.Index == index) &&
183                                 (otherEntry.MachineName == machineName) &&
184                                 (otherEntry.Message == message) &&
185                                 (otherEntry.ReplacementStrings.Equals (replacementStrings)) &&
186                                 (otherEntry.Source == source) &&
187                                 (otherEntry.TimeGenerated.Equals (timeGenerated)) &&
188                                 (otherEntry.TimeWritten.Equals (timeWritten)) &&
189                                 (otherEntry.UserName == userName)
190                                 );
191                 }
192
193                 [MonoTODO ("Needs serialization support")]
194                 void ISerializable.GetObjectData (SerializationInfo info, 
195                         StreamingContext context)
196                 {
197                         throw new NotImplementedException ();
198                 }
199         }
200 }
201