~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/SimiasClient/.svn/text-base/IProcEventData.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 | Author: Mike Lasky
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
using System.Text;
27
 
using System.Xml;
28
 
 
29
 
namespace Simias.Client.Event
30
 
{
31
 
        /// <summary>
32
 
        /// Describes the name-value pair contained in an IProcEventData object.
33
 
        /// </summary>
34
 
        public class IProcEventNameValue
35
 
        {
36
 
                #region Class Members
37
 
                /// <summary>
38
 
                /// Name of the value.
39
 
                /// </summary>
40
 
                private string name;
41
 
 
42
 
                /// <summary>
43
 
                /// Value.
44
 
                /// </summary>
45
 
                private string value;
46
 
                #endregion
47
 
 
48
 
                #region Properties
49
 
                /// <summary>
50
 
                /// Gets the name.
51
 
                /// </summary>
52
 
                public string Name
53
 
                {
54
 
                        get { return name; }
55
 
                }
56
 
 
57
 
                /// <summary>
58
 
                /// Gets the value.
59
 
                /// </summary>
60
 
                public string Value
61
 
                {
62
 
                        get { return value; }
63
 
                }
64
 
                #endregion
65
 
 
66
 
                #region Constructor
67
 
                /// <summary>
68
 
                /// Initializes an instance of the object.
69
 
                /// </summary>
70
 
                /// <param name="name">Name of the value.</param>
71
 
                /// <param name="value">String that represents the value.</param>
72
 
                public IProcEventNameValue( string name, string value )
73
 
                {
74
 
                        this.name = name;
75
 
                        this.value = value;
76
 
                }
77
 
                #endregion
78
 
        }
79
 
 
80
 
        /// <summary>
81
 
        /// Implements the parsing of event data to and from is serialized
82
 
        /// representation to an object.
83
 
        /// </summary>
84
 
        public class IProcEventData
85
 
        {
86
 
                #region Class Members
87
 
                /// <summary>
88
 
                /// Xml tags that define the event data.
89
 
                /// </summary>
90
 
                private static string EventTag = "Event";
91
 
                private static string EventTypeTag = "type";
92
 
 
93
 
                /// <summary>
94
 
                /// Xml tags used to describe a NodeEventArgs object.
95
 
                /// </summary>
96
 
                private const string NEA_ActionTag = "Action";
97
 
                private const string NEA_TimeTag = "Time";
98
 
                private const string NEA_SourceTag = "Source";
99
 
                private const string NEA_CollectionTag = "Collection";
100
 
                private const string NEA_ModifierTag = "Modifier";
101
 
                private const string NEA_TypeTag = "Type";
102
 
                private const string NEA_EventIDTag = "EventID";
103
 
                private const string NEA_NodeTag = "Node";
104
 
                private const string NEA_FlagsTag = "Flags";
105
 
                private const string NEA_MasterRevTag = "MasterRev";
106
 
                private const string NEA_SlaveRevTag = "SlaveRev";
107
 
                private const string NEA_FileSizeTag = "FileSize";
108
 
 
109
 
                /// <summary>
110
 
                /// Xml tags used to describe a CollectionSyncEventArgs object.
111
 
                /// </summary>
112
 
                private const string CEA_NameTag = "Name";
113
 
                private const string CEA_IDTag = "ID";
114
 
                private const string CEA_ActionTag = "Action";
115
 
                private const string CEA_ConnectedTag = "Connected";
116
 
                private const string CEA_YieldedTag = "Yielded";
117
 
 
118
 
                /// <summary>
119
 
                /// Xml tags used to describe a FileSyncEventArgs object.
120
 
                /// </summary>
121
 
                private const string FEA_CollectionIDTag = "CollectionID";
122
 
                private const string FEA_ObjectTypeTag = "ObjectType";
123
 
                private const string FEA_DeleteTag = "Delete";
124
 
                private const string FEA_NameTag = "Name";
125
 
                private const string FEA_SizeTag = "Size";
126
 
                private const string FEA_SizeToSyncTag = "SizeToSync";
127
 
                private const string FEA_SizeRemainingTag = "SizeRemaining";
128
 
                private const string FEA_DirectionTag = "Direction";
129
 
                private const string FEA_StatusTag = "Status";
130
 
 
131
 
                /// <summary>
132
 
                /// Xml tags used to describe an NotifyEventArgs object.
133
 
                /// </summary>
134
 
                private const string NMA_MessageTag = "Message";
135
 
                private const string NMA_TimeTag = "Time";
136
 
                private const string NMA_TypeTag = "Type";
137
 
                
138
 
                /// <summary>
139
 
                /// Xml document used to hold event data.
140
 
                /// </summary>
141
 
                private XmlDocument document;
142
 
                #endregion
143
 
 
144
 
                #region Properties
145
 
                /// <summary>
146
 
                /// Returns the type of event this object represents.
147
 
                /// </summary>
148
 
                public string Type
149
 
                {
150
 
                        get { return document.DocumentElement.GetAttribute( EventTypeTag ); }
151
 
                }
152
 
                #endregion
153
 
 
154
 
                #region Constructor
155
 
                /// <summary>
156
 
                /// Initializes an instance of the object.
157
 
                /// </summary>
158
 
                /// <param name="args">Information regarding the collection sync event.</param>
159
 
                public IProcEventData( CollectionSyncEventArgs args )
160
 
                {
161
 
                        document = new XmlDocument();
162
 
                        XmlElement element = document.CreateElement( EventTag );
163
 
                        element.SetAttribute( EventTypeTag, typeof( CollectionSyncEventArgs ).Name );
164
 
                        document.AppendChild( element );
165
 
                        FromCollectionSyncEventArgs( args );
166
 
                }
167
 
 
168
 
                /// <summary>
169
 
                /// Initializes an instance of the object.
170
 
                /// </summary>
171
 
                /// <param name="args">Information regarding the file sync event.</param>
172
 
                public IProcEventData( FileSyncEventArgs args )
173
 
                {
174
 
                        document = new XmlDocument();
175
 
                        XmlElement element = document.CreateElement( EventTag );
176
 
                        element.SetAttribute( EventTypeTag, typeof( FileSyncEventArgs ).Name );
177
 
                        document.AppendChild( element );
178
 
                        FromFileSyncEventArgs( args );
179
 
                }
180
 
 
181
 
                /// <summary>
182
 
                /// Initializes an instance of the object.
183
 
                /// </summary>
184
 
                /// <param name="args">Information regarding the node event.</param>
185
 
                public IProcEventData( NodeEventArgs args )
186
 
                {
187
 
                        document = new XmlDocument();
188
 
                        XmlElement element = document.CreateElement( EventTag );
189
 
                        element.SetAttribute( EventTypeTag, typeof( NodeEventArgs ).Name );
190
 
                        document.AppendChild( element );
191
 
                        FromNodeEventArgs( args );
192
 
                }
193
 
 
194
 
                /// <summary>
195
 
                /// Initalizes an instance of the object.
196
 
                /// </summary>
197
 
                /// <param name="args">Information regarding the notify event.</param>
198
 
                public IProcEventData( NotifyEventArgs args )
199
 
                {
200
 
                        document = new XmlDocument();
201
 
                        XmlElement element = document.CreateElement( EventTag );
202
 
                        element.SetAttribute( EventTypeTag, typeof( NotifyEventArgs ).Name );
203
 
                        document.AppendChild( element );
204
 
                        FromNotifyEventArgs( args );
205
 
                }
206
 
 
207
 
                /// <summary>
208
 
                /// Initializes an instance of the object.
209
 
                /// </summary>
210
 
                /// <param name="document">Xml document that contains an IProcEventData message.</param>
211
 
                public IProcEventData( XmlDocument document )
212
 
                {
213
 
                        this.document = document;
214
 
                }
215
 
                #endregion
216
 
 
217
 
                #region Private Methods
218
 
                /// <summary>
219
 
                /// Translates the information in the NodeEventArgs object into the IProcEventData object.
220
 
                /// </summary>
221
 
                /// <param name="args">NodeEventArgs containing Node event information.</param>
222
 
                private void FromNodeEventArgs( NodeEventArgs args )
223
 
                {
224
 
                        AddData( new IProcEventNameValue( NEA_ActionTag, args.EventData ) );
225
 
                        AddData( new IProcEventNameValue( NEA_TimeTag, args.TimeStamp.Ticks.ToString() ) );
226
 
                        AddData( new IProcEventNameValue( NEA_SourceTag, args.Source ) );
227
 
                        AddData( new IProcEventNameValue( NEA_CollectionTag, args.Collection ) );
228
 
                        AddData( new IProcEventNameValue( NEA_TypeTag, args.Type ) );
229
 
                        AddData( new IProcEventNameValue( NEA_EventIDTag, args.EventId.ToString() ) );
230
 
                        AddData( new IProcEventNameValue( NEA_NodeTag, args.Node ) );
231
 
                        AddData( new IProcEventNameValue( NEA_FlagsTag, args.Flags.ToString() ) );
232
 
                        AddData( new IProcEventNameValue( NEA_MasterRevTag, args.MasterRev.ToString() ) );
233
 
                        AddData( new IProcEventNameValue( NEA_SlaveRevTag, args.SlaveRev.ToString() ) );
234
 
                        AddData( new IProcEventNameValue( NEA_FileSizeTag, args.FileSize.ToString() ) );
235
 
                        AddData( new IProcEventNameValue( NEA_ModifierTag, args.Modifier ) );
236
 
                }
237
 
 
238
 
                /// <summary>
239
 
                /// Translates the information in the CollectionSyncEventArgs object into the IProcEventData object.
240
 
                /// </summary>
241
 
                /// <param name="args">CollectionSyncEventArgs containing Sync event information.</param>
242
 
                private void FromCollectionSyncEventArgs( CollectionSyncEventArgs args )
243
 
                {
244
 
                        AddData( new IProcEventNameValue( CEA_NameTag, args.Name ) );
245
 
                        AddData( new IProcEventNameValue( CEA_IDTag, args.ID ) );
246
 
                        AddData( new IProcEventNameValue( CEA_ActionTag, args.Action.ToString() ) );
247
 
                        AddData( new IProcEventNameValue( CEA_ConnectedTag, args.Connected.ToString() ) );
248
 
                        AddData( new IProcEventNameValue( CEA_YieldedTag, args.Yielded.ToString() ) );
249
 
                }
250
 
 
251
 
                /// <summary>
252
 
                /// Translates the information in the FileSyncEventArgs object into the IProcEventData object.
253
 
                /// </summary>
254
 
                /// <param name="args">FileSyncEventArgs containing Sync event information.</param>
255
 
                private void FromFileSyncEventArgs( FileSyncEventArgs args )
256
 
                {
257
 
                        AddData( new IProcEventNameValue( FEA_CollectionIDTag, args.CollectionID ) );
258
 
                        AddData( new IProcEventNameValue( FEA_ObjectTypeTag, args.ObjectType.ToString() ) );
259
 
                        AddData( new IProcEventNameValue( FEA_DeleteTag, args.Delete.ToString() ) );
260
 
                        AddData( new IProcEventNameValue( FEA_NameTag, args.Name ) );
261
 
                        AddData( new IProcEventNameValue( FEA_SizeTag, args.Size.ToString() ) );
262
 
                        AddData( new IProcEventNameValue( FEA_SizeToSyncTag, args.SizeToSync.ToString() ) );
263
 
                        AddData( new IProcEventNameValue( FEA_SizeRemainingTag, args.SizeRemaining.ToString() ) );
264
 
                        AddData( new IProcEventNameValue( FEA_DirectionTag, args.Direction.ToString() ) );
265
 
                        AddData( new IProcEventNameValue( FEA_StatusTag, args.Status.ToString() ) );
266
 
                }
267
 
 
268
 
                /// <summary>
269
 
                /// Translates the information in the NotifyEventArgs object into the IProcEventData object.
270
 
                /// </summary>
271
 
                /// <param name="args">NotifyEventArgs containing the notify event information.</param>
272
 
                private void FromNotifyEventArgs( NotifyEventArgs args )
273
 
                {
274
 
                        AddData( new IProcEventNameValue( NMA_TypeTag, args.EventData ) );
275
 
                        AddData( new IProcEventNameValue( NMA_TimeTag, args.TimeStamp.Ticks.ToString() ) );
276
 
                        AddData( new IProcEventNameValue( NMA_MessageTag, args.Message ) );
277
 
                }
278
 
                #endregion
279
 
 
280
 
                #region Public Methods
281
 
                /// <summary>
282
 
                /// Adds a name value pair to the event data.
283
 
                /// </summary>
284
 
                /// <param name="data">IProcEventNameValue object that contains the name value pair.</param>
285
 
                public void AddData( IProcEventNameValue data )
286
 
                {
287
 
                        XmlElement element = document.CreateElement( data.Name );
288
 
                        element.InnerText = data.Value;
289
 
                        document.DocumentElement.AppendChild( element );
290
 
                }
291
 
 
292
 
                /// <summary>
293
 
                /// Method used by clients to enumerate the data in the IProcEventData object.
294
 
                /// </summary>
295
 
                /// <returns>An IEnumerator object that can be used to get a list of IProcEventNameValue objects.</returns>
296
 
                public IEnumerator GetEventEnumerator()
297
 
                {
298
 
                        return new DataEnumerator( document ).GetEnumerator();
299
 
                }
300
 
 
301
 
                /// <summary>
302
 
                /// Converts an IProcEventRegistration object to a buffer representation.
303
 
                /// </summary>
304
 
                /// <returns>A byte array that represents the IProcEventRegistration object.</returns>
305
 
                public byte[] ToBuffer()
306
 
                {
307
 
                        string msgString = ToString();
308
 
                        UTF8Encoding utf8 = new UTF8Encoding();
309
 
                        int msgLength = utf8.GetByteCount( msgString );
310
 
                        byte[] msgHeader = BitConverter.GetBytes( msgLength );
311
 
                        byte[] buffer = new byte[ msgHeader.Length + msgLength ];
312
 
 
313
 
                        // Copy the message length and the message into the buffer.
314
 
                        msgHeader.CopyTo( buffer, 0 );
315
 
                        utf8.GetBytes( msgString, 0, msgString.Length, buffer, 4 );
316
 
                        return buffer;
317
 
                }
318
 
 
319
 
                /// <summary>
320
 
                /// Converts the IProcEventData object into a CollectionSyncEventArgs object.
321
 
                /// </summary>
322
 
                /// <returns>A CollectionSyncEventArgs object.</returns>
323
 
                public CollectionSyncEventArgs ToCollectionSyncEventArgs()
324
 
                {
325
 
                        // Preinitialize all of the node event arguments.
326
 
                        string name = string.Empty;
327
 
                        string ID = string.Empty;
328
 
                        Action action = Action.StartSync;
329
 
                        bool successful = true;
330
 
                        bool yielded = false;
331
 
 
332
 
                        // Walk through each named/value pair and convert the xml data back into CollectionSyncEventArgs data.
333
 
                        foreach ( XmlNode xn in document.DocumentElement )
334
 
                        {
335
 
                                switch ( xn.Name )
336
 
                                {
337
 
                                        case CEA_NameTag:
338
 
                                        {
339
 
                                                name = xn.InnerText;
340
 
                                                break;
341
 
                                        }
342
 
 
343
 
                                        case CEA_IDTag:
344
 
                                        {
345
 
                                                ID = xn.InnerText;
346
 
                                                break;
347
 
                                        }
348
 
 
349
 
                                        case CEA_ActionTag:
350
 
                                        {
351
 
                                                action = ( Action )Enum.Parse( typeof( Action ), xn.InnerText, false );
352
 
                                                break;
353
 
                                        }
354
 
 
355
 
                                        case CEA_ConnectedTag:
356
 
                                        {
357
 
                                                successful = Boolean.Parse( xn.InnerText );
358
 
                                                break;
359
 
                                        }
360
 
 
361
 
                                        case CEA_YieldedTag:
362
 
                                        {
363
 
                                                yielded = Boolean.Parse( xn.InnerText );
364
 
                                                break;
365
 
                                        }
366
 
                                }
367
 
                        }
368
 
                        
369
 
                        // Create the object and set the flags.
370
 
                        return new CollectionSyncEventArgs( name, ID, action, successful, yielded );
371
 
                }
372
 
 
373
 
                /// <summary>
374
 
                /// Converts the IProcEventData object into a FileSyncEventArgs object.
375
 
                /// </summary>
376
 
                /// <returns>A FileSyncEventArgs object.</returns>
377
 
                public FileSyncEventArgs ToFileSyncEventArgs()
378
 
                {
379
 
                        // Preinitialize all of the node event arguments.
380
 
                        string collectionID = string.Empty;
381
 
                        ObjectType objectType = ObjectType.File;
382
 
                        bool delete = false;
383
 
                        string name = string.Empty;
384
 
                        long size = 0;
385
 
                        long sizeToSync = 0;
386
 
                        long sizeRemaining = 0;
387
 
                        Direction direction = Direction.Downloading;
388
 
                        SyncStatus status = SyncStatus.Success;
389
 
 
390
 
                        // Walk through each named/value pair and convert the xml data back into FileSyncEventArgs data.
391
 
                        foreach ( XmlNode xn in document.DocumentElement )
392
 
                        {
393
 
                                switch ( xn.Name )
394
 
                                {
395
 
                                        case FEA_CollectionIDTag:
396
 
                                        {
397
 
                                                collectionID = xn.InnerText;
398
 
                                                break;
399
 
                                        }
400
 
                                        case FEA_ObjectTypeTag:
401
 
                                        {
402
 
                                                objectType = ( ObjectType )Enum.Parse( typeof( ObjectType ), xn.InnerText, false );
403
 
                                                break;
404
 
                                        }
405
 
                                        case FEA_DeleteTag:
406
 
                                        {
407
 
                                                delete = Boolean.Parse( xn.InnerText );
408
 
                                                break;
409
 
                                        }
410
 
                                        case FEA_NameTag:
411
 
                                        {
412
 
                                                name = xn.InnerText;
413
 
                                                break;
414
 
                                        }
415
 
 
416
 
                                        case FEA_SizeTag:
417
 
                                        {
418
 
                                                size = Convert.ToInt64( xn.InnerText );
419
 
                                                break;
420
 
                                        }
421
 
 
422
 
                                        case FEA_SizeToSyncTag:
423
 
                                        {
424
 
                                                sizeToSync = Convert.ToInt64( xn.InnerText );
425
 
                                                break;
426
 
                                        }
427
 
 
428
 
                                        case FEA_SizeRemainingTag:
429
 
                                        {
430
 
                                                sizeRemaining = Convert.ToInt64( xn.InnerText );
431
 
                                                break;
432
 
                                        }
433
 
 
434
 
                                        case FEA_DirectionTag:
435
 
                                        {
436
 
                                                direction = ( Direction )Enum.Parse( typeof( Direction ), xn.InnerText, false );
437
 
                                                break;
438
 
                                        }
439
 
 
440
 
                                        case FEA_StatusTag:
441
 
                                        {
442
 
                                                status = (SyncStatus)Enum.Parse( typeof(SyncStatus), xn.InnerText, false);
443
 
                                                break;
444
 
                                        }
445
 
                                }
446
 
                        }
447
 
                        
448
 
                        // Create the object and set the flags.
449
 
                        return new FileSyncEventArgs( collectionID, objectType, delete, name, size, sizeToSync, sizeRemaining, direction, status );
450
 
                }
451
 
 
452
 
                /// <summary>
453
 
                /// Converts the IProcEventData object into a NodeEventArgs object.
454
 
                /// </summary>
455
 
                /// <returns>A NodeEventArgs object.</returns>
456
 
                public NodeEventArgs ToNodeEventArgs()
457
 
                {
458
 
                        // Preinitialize all of the node event arguments.
459
 
                        EventType changeType = EventType.NodeChanged;
460
 
                        DateTime time = DateTime.MinValue;
461
 
                        string source = string.Empty;
462
 
                        string node = string.Empty;
463
 
                        string collection = string.Empty;
464
 
                        string modifier = string.Empty;
465
 
                        string type = string.Empty;
466
 
                        int eventID = 0;
467
 
                        ushort flags = 0;
468
 
                        ulong masterRev = 0;
469
 
                        ulong slaveRev = 0;
470
 
                        long fileSize = 0;
471
 
 
472
 
                        // Walk through each named/value pair and convert the xml data back into NodeEventArgs data.
473
 
                        foreach ( XmlNode xn in document.DocumentElement )
474
 
                        {
475
 
                                switch ( xn.Name )
476
 
                                {
477
 
                                        case NEA_ActionTag:
478
 
                                        {
479
 
                                                changeType = ( EventType )Enum.Parse( typeof( EventType ), xn.InnerText );
480
 
                                                break;
481
 
                                        }
482
 
 
483
 
                                        case NEA_TimeTag:
484
 
                                        {
485
 
                                                time = new DateTime( Convert.ToInt64( xn.InnerText ) );
486
 
                                                break;
487
 
                                        }
488
 
 
489
 
                                        case NEA_SourceTag:
490
 
                                        {
491
 
                                                source = xn.InnerText;
492
 
                                                break;
493
 
                                        }
494
 
 
495
 
                                        case NEA_CollectionTag:
496
 
                                        {
497
 
                                                collection = xn.InnerText;
498
 
                                                break;
499
 
                                        }
500
 
 
501
 
                                        case NEA_ModifierTag:
502
 
                                        {
503
 
                                                modifier = xn.InnerText;
504
 
                                                break;
505
 
                                        }
506
 
 
507
 
                                        case NEA_TypeTag:
508
 
                                        {
509
 
                                                type = xn.InnerText;
510
 
                                                break;
511
 
                                        }
512
 
 
513
 
                                        case NEA_EventIDTag:
514
 
                                        {
515
 
                                                eventID = Convert.ToInt32( xn.InnerText );
516
 
                                                break;
517
 
                                        }
518
 
 
519
 
                                        case NEA_NodeTag:
520
 
                                        {
521
 
                                                node = xn.InnerText;
522
 
                                                break;
523
 
                                        }
524
 
                                                
525
 
                                        case NEA_FlagsTag:
526
 
                                        {
527
 
                                                flags = Convert.ToUInt16( xn.InnerText );
528
 
                                                break;
529
 
                                        }
530
 
                                                
531
 
                                        case NEA_MasterRevTag:
532
 
                                        {
533
 
                                                masterRev = Convert.ToUInt64( xn.InnerText );
534
 
                                                break;
535
 
                                        }
536
 
 
537
 
                                        case NEA_SlaveRevTag:
538
 
                                        {
539
 
                                                slaveRev = Convert.ToUInt64( xn.InnerText );
540
 
                                                break;
541
 
                                        }
542
 
 
543
 
                                        case NEA_FileSizeTag:
544
 
                                        {
545
 
                                                fileSize = Convert.ToInt64( xn.InnerText );
546
 
                                                break;
547
 
                                        }
548
 
                                }
549
 
                        }
550
 
                        
551
 
                        // Create the object and set the flags.
552
 
                        NodeEventArgs args = new NodeEventArgs( source, node, collection, modifier, type, changeType, eventID, time, masterRev, slaveRev, fileSize );
553
 
                        args.Flags = flags;
554
 
                        return args;
555
 
                }
556
 
 
557
 
                /// <summary>
558
 
                /// Converts the IProcEventData object into a NotifyEventArgs object.
559
 
                /// </summary>
560
 
                /// <returns>A NotifyEventArgs object.</returns>
561
 
                public NotifyEventArgs ToNotifyEventArgs()
562
 
                {
563
 
                        // Preinitialize all of the node event arguments.
564
 
                        string type = string.Empty;
565
 
                        string message = string.Empty;
566
 
                        DateTime time = DateTime.MinValue;
567
 
 
568
 
                        // Walk through each named/value pair and convert the xml data back into NotifyEventArgs data.
569
 
                        foreach ( XmlNode xn in document.DocumentElement )
570
 
                        {
571
 
                                switch ( xn.Name )
572
 
                                {
573
 
                                        case NMA_TypeTag:
574
 
                                        {
575
 
                                                type = xn.InnerText;
576
 
                                                break;
577
 
                                        }
578
 
 
579
 
                                        case NMA_MessageTag:
580
 
                                        {
581
 
                                                message = xn.InnerText;
582
 
                                                break;
583
 
                                        }
584
 
 
585
 
                                        case NMA_TimeTag:
586
 
                                        {
587
 
                                                time = new DateTime( Convert.ToInt64( xn.InnerText ) );
588
 
                                                break;
589
 
                                        }
590
 
                                }
591
 
                        }
592
 
                        
593
 
                        // Create the object and set the flags.
594
 
                        return new NotifyEventArgs( type, message, time );
595
 
                }
596
 
 
597
 
                /// <summary>
598
 
                /// Converts an IProcEventData object to a string representation.
599
 
                /// </summary>
600
 
                /// <returns>A string that represents the IProcEventData object.</returns>
601
 
                public override string ToString()
602
 
                {
603
 
                        return document.OuterXml;
604
 
                }
605
 
                #endregion
606
 
 
607
 
                #region IEnumerator Members
608
 
                private class DataEnumerator : IEnumerable, IEnumerator
609
 
                {
610
 
                        #region Class Members
611
 
                        /// <summary>
612
 
                        /// Contains the enumeration for all data elements.
613
 
                        /// </summary>
614
 
                        private IEnumerator dataEnumerator;
615
 
                        #endregion
616
 
 
617
 
                        #region Constructor
618
 
                        /// <summary>
619
 
                        /// Initializes an instance of the object.
620
 
                        /// </summary>
621
 
                        /// <param name="document">Xml document that represents an IProcEventData object.</param>
622
 
                        public DataEnumerator( XmlDocument document )
623
 
                        {
624
 
                                dataEnumerator = document.DocumentElement.GetEnumerator();
625
 
                        }
626
 
                        #endregion
627
 
 
628
 
                        #region IEnumerable Members
629
 
                        /// <summary>
630
 
                        /// Method used by clients to enumerate the data in the IProcEventData object.
631
 
                        /// </summary>
632
 
                        /// <returns>An IEnumerator.</returns>
633
 
                        public IEnumerator GetEnumerator()
634
 
                        {
635
 
                                return this;
636
 
                        }
637
 
                        #endregion
638
 
 
639
 
                        #region IEnumerator Members
640
 
                        /// <summary>
641
 
                        /// Sets the enumerator to its initial position, which is before
642
 
                        /// the first element in the collection.
643
 
                        /// </summary>
644
 
                        public void Reset()
645
 
                        {
646
 
                                dataEnumerator.Reset();
647
 
                        }
648
 
 
649
 
                        /// <summary>
650
 
                        /// Gets the current element in the collection.
651
 
                        /// </summary>
652
 
                        public object Current
653
 
                        {
654
 
                                get 
655
 
                                { 
656
 
                                        XmlElement element = dataEnumerator.Current as XmlElement; 
657
 
                                        return new IProcEventNameValue( element.Name, element.InnerText );
658
 
                                }
659
 
                        }
660
 
 
661
 
                        /// <summary>
662
 
                        /// Advances the enumerator to the next element of the collection.
663
 
                        /// </summary>
664
 
                        /// <returns>
665
 
                        /// true if the enumerator was successfully advanced to the next element; 
666
 
                        /// false if the enumerator has passed the end of the collection.
667
 
                        /// </returns>
668
 
                        public bool MoveNext()
669
 
                        {
670
 
                                return dataEnumerator.MoveNext();
671
 
                        }
672
 
                        #endregion
673
 
                }
674
 
                #endregion
675
 
        }
676
 
}