Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Core / System / Diagnostics / Eventing / Reader / EventMetadata.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 /*============================================================
7 **
8 ** Class: EventMetadata
9 **
10 ** Purpose: 
11 ** This public class describes the metadata for a specific event 
12 ** raised by Provider. An instance of this class is obtained from 
13 ** ProviderMetadata class.
14 ** 
15 ============================================================*/
16
17 using System.Globalization;
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Text;
21 using System.Diagnostics.CodeAnalysis;
22
23 namespace System.Diagnostics.Eventing.Reader {
24     /// <summary>
25     /// Event Metadata
26     /// </summary>
27     [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
28     public sealed class EventMetadata {
29         private long id;
30         private byte version;
31         private byte channelId;
32         private byte level;
33         private short opcode;
34         private int task;
35         private long keywords;
36         private string template;
37         private string description;
38
39         ProviderMetadata pmReference;
40
41         internal EventMetadata(uint id, byte version, byte channelId,
42                  byte level, byte opcode, short task, long keywords,
43                  string template, string description, ProviderMetadata pmReference) {
44             this.id = id;
45             this.version = version;
46             this.channelId = channelId;
47             this.level = level;
48             this.opcode = opcode;
49             this.task = task;
50             this.keywords = keywords;
51             this.template = template;
52             this.description = description;
53             this.pmReference = pmReference;
54         }
55
56         //
57         // Max value will be UINT32.MaxValue - it is a long because this property
58         // is really a UINT32.  The legacy API allows event message ids to be declared 
59         // as UINT32 and these event/messages may be migrated into a Provider's 
60         // manifest as UINT32.  Note that EventRecord ids are 
61         // still declared as int, because those ids max value is UINT16.MaxValue
62         // and rest of the bits of the legacy event id would be stored in 
63         // Qualifiers property.
64         // 
65         public long Id {
66             get {
67                 return this.id;
68             }
69         }
70
71         public byte Version {
72             get {
73                 return this.version;
74             }
75         }
76
77         public EventLogLink LogLink {
78             get {
79                 return new EventLogLink((uint)this.channelId, this.pmReference);
80             }
81         }
82
83         public EventLevel Level {
84             get {
85                 return new EventLevel(this.level, this.pmReference);
86             }
87         }
88
89         [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "Opcode", Justification = "[....]: Shipped public in 3.5, breaking change to fix now.")]
90         public EventOpcode Opcode {
91             get {
92                 return new EventOpcode(this.opcode, this.pmReference);
93             }
94         }
95
96         public EventTask Task {
97             get {
98                 return new EventTask(this.task, this.pmReference);
99             }
100         }
101
102
103         public IEnumerable<EventKeyword> Keywords {
104             get {
105                 List<EventKeyword> list = new List<EventKeyword>();
106
107                 ulong theKeywords = (ulong)this.keywords;
108                 ulong mask = 0x8000000000000000;
109
110                 //for every bit
111                 //for (int i = 0; i < 64 && theKeywords != 0; i++)
112                 for (int i = 0; i < 64; i++) {
113                     //if this bit is set
114                     if ((theKeywords & mask) > 0) {
115                         //the mask is the keyword we will be searching for.
116                         list.Add(new EventKeyword((long)mask, this.pmReference));
117                         //theKeywords = theKeywords - mask;
118                     }
119                     //modify the mask to check next bit.
120                     mask = mask >> 1;
121                 }
122
123                 return list;
124             }
125         }
126
127         public string Template {
128             get {
129                 return this.template;
130             }
131         }
132
133         public string Description {
134             get {
135                 return this.description;
136             }
137         }
138     }
139 }