本文整理汇总了C#中System.Diagnostics.Tracing.EventSource.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# EventSource.GetType方法的具体用法?C# EventSource.GetType怎么用?C# EventSource.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Tracing.EventSource
的用法示例。
在下文中一共展示了EventSource.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEventSchemas
private ICollection<EventSchema> GetEventSchemas(EventSource eventSource)
{
try
{
string manifest = EventSource.GenerateManifest(eventSource.GetType(), null);
this.CheckForBadFormedManifest(manifest);
return new EventSourceSchemaReader().GetSchema(manifest).Values;
}
catch (EventSourceAnalyzerException)
{
throw;
}
catch (Exception e)
{
throw new EventSourceAnalyzerException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.EventSourceAnalyzerManifestGenerationError, e.Message, EventSource.GenerateManifest(eventSource.GetType(), null)));
}
}
示例2: GetSchema
/// <summary>
/// Gets the schema for the specified event source.
/// </summary>
/// <param name="eventSource">The event source.</param>
/// <returns>The event schema.</returns>
public IDictionary<int, EventSchema> GetSchema(EventSource eventSource)
{
Guard.ArgumentNotNull(eventSource, "eventSource");
return this.GetSchema(EventSource.GenerateManifest(eventSource.GetType(), null));
}
示例3: GetMethodFromSchema
private MethodInfo GetMethodFromSchema(EventSource source, EventSchema schema)
{
return source.GetType().GetMethods(Bindings).SingleOrDefault(m => this.IsEvent(m, schema.Id)) ??
source.GetType().GetMethod(schema.TaskName, Bindings);
}
示例4: EventSourceInfo
/// <summary>
/// ctor.
/// </summary>
/// <param name="source">EventSource object to instantiate from.</param>
public EventSourceInfo(EventSource source)
{
this.Source = source;
// DOM+XPath parsing for now, manifests should be very small and we shouldn't be doing this too frequently
string manifestXML = EventSource.GenerateManifest(source.GetType(), "");
var manifest = new XmlDocument();
manifest.LoadXml(manifestXML);
var namespaceMgr = new XmlNamespaceManager(manifest.NameTable);
XmlElement root = manifest.DocumentElement; // instrumentationManifest
namespaceMgr.AddNamespace("win", root.NamespaceURI);
// keep track of event to template mapping (template name can differ from event name)
var templateMapping = new Dictionary<string, EventInfo>(StringComparer.OrdinalIgnoreCase);
// not verifying but we expect a single provider
XmlNode provider = root.SelectSingleNode("//win:provider", namespaceMgr);
this.Name = provider.Attributes["name"].Value;
foreach (XmlNode ev in provider.SelectNodes("//win:events/win:event", namespaceMgr))
{
// EventSource+TraceEvent provide for the following naming scheme:
// - Events with neither a task nor opcode will have a task generated for them automatically.
// - Events with named tasks and the default opcode have the name of the task. It is possible
// as a result to have many events with the same name. We don't hedge against this today since
// we key on ID.
// - Events with opcodes but not task names do not get generated task names, so we simply use
// the event's ID as its name.
int eventID = int.Parse(ev.Attributes["value"].Value);
var taskName = ev.Attributes.GetNamedItem("task");
var opCodeName = ev.Attributes.GetNamedItem("opcode");
string eventName;
if (taskName != null && opCodeName != null)
{
int opCodeOffset = (opCodeName.Value.StartsWith("win:") ? 4 : 0);
eventName = string.Format("{0}/{1}", taskName.Value, opCodeName.Value.Substring(opCodeOffset));
}
else if (taskName != null)
{
eventName = taskName.Value;
}
else
{
eventName = eventID.ToString(CultureInfo.InvariantCulture);
}
var eventData = new EventInfo {Name = eventName};
this.eventIDs[eventID] = eventData;
if (ev.Attributes.GetNamedItem("template") != null)
{
templateMapping[ev.Attributes["template"].Value] = eventData;
}
}
// Each template has one or more 'data' tags whose attributes are the name of the argument and its
// type. Since we only care about the name we ignore the type. For array arguments EventSource emits
// two entries in the template, first a <foo>.Length entry specifying the length of the array,
// followed by the actual array data itself (<foo>). Since we're constructing this data only
// for handling intra-application EventSource calls we don't need to care about the .Length
// bit that comes in the manifest since it is specific to decoding ETW events.
foreach (XmlNode template in provider.SelectNodes("//win:templates/win:template", namespaceMgr))
{
string name = template.Attributes["tid"].Value;
// we want to throw right away if we somehow got a template for an unnamed event, that's a big
// contract breach.
EventInfo data = templateMapping[name];
XmlNodeList arguments = template.SelectNodes("win:data", namespaceMgr);
int numArgs = 0;
data.Arguments = new string[arguments.Count];
for (int i = 0; i < arguments.Count; ++i)
{
XmlNode node = arguments[i];
string dataName = node.Attributes["name"].Value;
if (!dataName.EndsWith(ArrayLengthArgumentSuffix, StringComparison.OrdinalIgnoreCase))
{
data.Arguments[numArgs] = dataName;
++numArgs;
}
}
}
}