private void AddEventDescriptor(EventAttribute eventAttribute)
 {
     if ((this.m_eventData == null) || (this.m_eventData.Length <= eventAttribute.EventId))
     {
         EventData[] destinationArray = new EventData[this.m_eventData.Length + 0x10];
         Array.Copy(this.m_eventData, destinationArray, this.m_eventData.Length);
         this.m_eventData = destinationArray;
     }
     this.m_eventData[eventAttribute.EventId].Descriptor = new EventDescriptorInternal(eventAttribute.EventId, eventAttribute.Version, (byte) eventAttribute.Channel, (byte) eventAttribute.Level, (byte) eventAttribute.Opcode, (int) eventAttribute.Task, (long) eventAttribute.Keywords);
     this.m_eventData[eventAttribute.EventId].CaptureStack = eventAttribute.CaptureStack;
     this.m_eventData[eventAttribute.EventId].Message = eventAttribute.Message;
 }
Exemplo n.º 2
0
 private void AddEventDescriptor(EventAttribute eventAttribute)
 {
     if ((this.m_eventData == null) || (this.m_eventData.Length <= eventAttribute.EventId))
     {
         EventData[] destinationArray = new EventData[this.m_eventData.Length + 0x10];
         Array.Copy(this.m_eventData, destinationArray, this.m_eventData.Length);
         this.m_eventData = destinationArray;
     }
     this.m_eventData[eventAttribute.EventId].Descriptor   = new EventDescriptorInternal(eventAttribute.EventId, eventAttribute.Version, (byte)eventAttribute.Channel, (byte)eventAttribute.Level, (byte)eventAttribute.Opcode, (int)eventAttribute.Task, (long)eventAttribute.Keywords);
     this.m_eventData[eventAttribute.EventId].CaptureStack = eventAttribute.CaptureStack;
     this.m_eventData[eventAttribute.EventId].Message      = eventAttribute.Message;
 }
Exemplo n.º 3
0
        private void DebugCheckEvent(MethodInfo method, EventAttribute eventAttribute)
        {
            int helperCallFirstArg = GetHelperCallFirstArg(method);

            if ((helperCallFirstArg >= 0) && (eventAttribute.EventId != helperCallFirstArg))
            {
                throw new ArgumentException(string.Concat(new object[] { "Error: event ", method.Name, " is given event ID ", eventAttribute.EventId, " but ", helperCallFirstArg, " was passed to the helper." }));
            }
            if ((eventAttribute.EventId < this.m_eventData.Length) && (this.m_eventData[eventAttribute.EventId].Descriptor.EventId != 0))
            {
                throw new ArgumentException(string.Concat(new object[] { "Event ", method.Name, " has ID ", eventAttribute.EventId, " which is the same as a previously defined event." }));
            }
            if (this.m_eventsByName == null)
            {
                this.m_eventsByName = new Dictionary <string, string>();
            }
            if (this.m_eventsByName.ContainsKey(method.Name))
            {
                throw new ArgumentException("Event name " + method.Name + " used more than once.  If you wish to overload a method, the overloaded method should have a [Event(-1)] attribute to indicate the method should not have associated meta-data.");
            }
            this.m_eventsByName[method.Name] = method.Name;
        }
 public void StartEvent(string eventName, EventAttribute eventAttribute)
 {
     this.templateName = eventName + "Args";
     this.numParams    = 0;
     this.events.Append("  <event name=\"").Append(eventName).Append("\"").Append(" value=\"").Append(eventAttribute.EventId).Append("\"").Append(" version=\"").Append(eventAttribute.Version).Append("\"").Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append("\"");
     if (eventAttribute.Keywords != EventKeywords.None)
     {
         this.events.Append(" keywords=\"").Append(this.GetKeywords((ulong)eventAttribute.Keywords, eventName)).Append("\"");
     }
     if (eventAttribute.Opcode != EventOpcode.Info)
     {
         this.events.Append(" opcode=\"").Append(this.GetOpcodeName(eventAttribute.Opcode, eventName)).Append("\"");
     }
     if (eventAttribute.Task != EventTask.None)
     {
         this.events.Append(" task=\"").Append(this.GetTaskName(eventAttribute.Task, eventName)).Append("\"");
     }
     if (eventAttribute.Channel != EventChannel.Default)
     {
         this.events.Append(" channel=\"").Append(this.GetChannelName(eventAttribute.Channel, eventName)).Append("\"");
     }
 }
Exemplo n.º 5
0
        private byte[] CreateManifestAndDescriptors(string providerDllName)
        {
            Type type = base.GetType();

            MethodInfo[]   methods   = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            EventAttribute attribute = new EventAttribute(0);
            int            num       = 1;

            this.m_eventData = new EventData[methods.Length];
            ManifestBuilder builder = new ManifestBuilder(this.Name, this.Guid, providerDllName);

            FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
            if (fields.Length > 0)
            {
                foreach (FieldInfo info in fields)
                {
                    Type fieldType = info.FieldType;
                    if (fieldType == typeof(EventOpcode))
                    {
                        builder.AddOpcode(info.Name, (int)info.GetRawConstantValue());
                    }
                    else if (fieldType == typeof(EventTask))
                    {
                        builder.AddTask(info.Name, (int)info.GetRawConstantValue());
                    }
                    else if (fieldType == typeof(EventKeywords))
                    {
                        builder.AddKeyword(info.Name, (ulong)((long)info.GetRawConstantValue()));
                    }
                    else if (fieldType == typeof(EventChannel))
                    {
                        builder.AddChannel(info.Name, (int)info.GetRawConstantValue());
                    }
                }
            }
            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo      element        = methods[i];
                ParameterInfo[] parameters     = element.GetParameters();
                EventAttribute  eventAttribute = (EventAttribute)Attribute.GetCustomAttribute(element, typeof(EventAttribute), false);
                if (element.ReturnType != typeof(void))
                {
                    if ((eventAttribute != null) && this.DoDebugChecks())
                    {
                        throw new ArgumentException("Event attribute placed on method " + element.Name + " which does not return 'void'");
                    }
                }
                else
                {
                    if (!element.IsVirtual && !element.IsStatic)
                    {
                        if (eventAttribute == null)
                        {
                            if (Attribute.GetCustomAttribute(element, typeof(NonEventAttribute), false) != null)
                            {
                                goto Label_0297;
                            }
                            attribute.EventId = num;
                            attribute.Opcode  = EventOpcode.Info;
                            attribute.Task    = EventTask.None;
                            eventAttribute    = attribute;
                        }
                        else if (eventAttribute.EventId <= 0)
                        {
                            throw new ArgumentException("Event IDs <= 0 are illegal.");
                        }
                        num++;
                        if ((eventAttribute.Opcode == EventOpcode.Info) && (eventAttribute.Task == EventTask.None))
                        {
                            eventAttribute.Opcode = (EventOpcode)(10 + eventAttribute.EventId);
                        }
                        builder.StartEvent(element.Name, eventAttribute);
                        for (int j = 0; j < parameters.Length; j++)
                        {
                            builder.AddEventParameter(parameters[j].ParameterType, parameters[j].Name);
                        }
                        builder.EndEvent();
                        if (this.DoDebugChecks())
                        {
                            this.DebugCheckEvent(element, eventAttribute);
                        }
                        this.AddEventDescriptor(eventAttribute);
                    }
                    Label_0297 :;
                }
            }
            this.TrimEventDescriptors();
            this.m_eventsByName = null;
            return(builder.CreateManifest());
        }
Exemplo n.º 6
0
        private void DebugCheckEvent(MethodInfo method, EventAttribute eventAttribute)
        {
            int eventArg = GetHelperCallFirstArg(method); 
            if (eventArg >= 0 && eventAttribute.EventId != eventArg)
            { 
                throw new ArgumentException("Error: event " + method.Name + " is given event ID " + 
                    eventAttribute.EventId + " but " + eventArg + " was passed to the helper.");
            } 

            if (eventAttribute.EventId < m_eventData.Length && m_eventData[eventAttribute.EventId].Descriptor.EventId != 0)
            {
                throw new ArgumentException("Event " + method.Name + " has ID " + eventAttribute.EventId + 
                    " which is the same as a previously defined event.");
            } 
 
            if (m_eventsByName == null)
                m_eventsByName = new Dictionary<string, string>(); 

            if (m_eventsByName.ContainsKey(method.Name))
                throw new ArgumentException("Event name " + method.Name + " used more than once.  " +
                    "If you wish to overload a method, the overloaded method should have a " + 
                    "[Event(-1)] attribute to indicate the method should not have associated meta-data.");
 
            m_eventsByName[method.Name] = method.Name; 
        }
Exemplo n.º 7
0
        private void AddEventDescriptor(EventAttribute eventAttribute)
        { 
            if (m_eventData == null || m_eventData.Length <= eventAttribute.EventId)
            {
                EventData[] newValues = new EventData[m_eventData.Length + 16];
                Array.Copy(m_eventData, newValues, m_eventData.Length); 
                m_eventData = newValues;
            } 
            m_eventData[eventAttribute.EventId].Descriptor = new EventDescriptorInternal( 
                    eventAttribute.EventId,
                    eventAttribute.Version, 
                    (byte)eventAttribute.Channel,
                    (byte)eventAttribute.Level,
                    (byte)eventAttribute.Opcode,
                    (int)eventAttribute.Task, 
                    (long)eventAttribute.Keywords);
 
            m_eventData[eventAttribute.EventId].CaptureStack = eventAttribute.CaptureStack; 
            m_eventData[eventAttribute.EventId].Message = eventAttribute.Message;
        } 
Exemplo n.º 8
0
        private byte[] CreateManifestAndDescriptors(string providerDllName)
        { 
            Type providerType = this.GetType();
            MethodInfo[] methods = providerType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            EventAttribute defaultEventAttribute = new EventAttribute(0);
            int eventId = 1;        // The number given to an event that does not have a explicitly given ID. 
            m_eventData = new EventData[methods.Length];
            ManifestBuilder manifest = new ManifestBuilder(Name, Guid, providerDllName); 
 
            // Collect task, opcode, keyword and channel information
            FieldInfo[] staticFields = providerType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); 
            if (staticFields.Length > 0)
            {
                foreach (FieldInfo staticField in staticFields)
                { 
                    Type staticFieldType = staticField.FieldType;
                    if (staticFieldType == typeof(EventOpcode)) 
                        manifest.AddOpcode(staticField.Name, (int)staticField.GetRawConstantValue()); 
                    else if (staticFieldType == typeof(EventTask))
                        manifest.AddTask(staticField.Name, (int)staticField.GetRawConstantValue()); 
                    else if (staticFieldType == typeof(EventKeywords))
                        manifest.AddKeyword(staticField.Name, (ulong)(long)staticField.GetRawConstantValue());
                    else if (staticFieldType == typeof(EventChannel))
                        manifest.AddChannel(staticField.Name, (int)staticField.GetRawConstantValue()); 
                }
            } 
 
            for (int i = 0; i < methods.Length; i++)
            { 
                MethodInfo method = methods[i];
                ParameterInfo[] args = method.GetParameters();

                // Get the EventDescriptorInternal (from the Custom attributes) 
                EventAttribute eventAttribute = (EventAttribute)Attribute.GetCustomAttribute(method, typeof(EventAttribute), false);
 
                // Methods that don't return void can't be events. 
                if (method.ReturnType != typeof(void))
                { 
                    if (eventAttribute != null && DoDebugChecks())
                        throw new ArgumentException("Event attribute placed on method " + method.Name + " which does not return 'void'");
                    continue;
                } 
                if (method.IsVirtual || method.IsStatic)
                { 
                    continue; 
                }
 
                if (eventAttribute == null)
                {
                    // If we explictly mark the method as not being an event, then honor that.
                    if (Attribute.GetCustomAttribute(method, typeof(NonEventAttribute), false) != null) 
                        continue;
 
                    defaultEventAttribute.EventId = eventId; 
                    defaultEventAttribute.Opcode = EventOpcode.Info;
                    defaultEventAttribute.Task = EventTask.None; 
                    eventAttribute = defaultEventAttribute;
                }
                else if (eventAttribute.EventId <= 0)
                    throw new ArgumentException("Event IDs <= 0 are illegal."); 
                eventId++;
 
                if (eventAttribute.Opcode == EventOpcode.Info && eventAttribute.Task == EventTask.None) 
                    eventAttribute.Opcode = (EventOpcode)(10 + eventAttribute.EventId);
 
                manifest.StartEvent(method.Name, eventAttribute);
                for (int fieldIdx = 0; fieldIdx < args.Length; fieldIdx++)
                    manifest.AddEventParameter(args[fieldIdx].ParameterType, args[fieldIdx].Name);
                manifest.EndEvent(); 

                if (DoDebugChecks()) 
                    DebugCheckEvent(method, eventAttribute); 
                AddEventDescriptor(eventAttribute);
            } 
            TrimEventDescriptors();
            m_eventsByName = null;

            return manifest.CreateManifest(); 
        }
Exemplo n.º 9
0
        public void StartEvent(string eventName, EventAttribute eventAttribute)
        {
            Contract.Assert(numParams == 0); 
            Contract.Assert(templateName == null);
            templateName = eventName + "Args"; 
            numParams = 0; 

            events.Append("  <event name=\"").Append(eventName).Append("\""). 
                // Append(" symbol=\"").Append(eventName).Append("\"").
                // Symbols have to be unique across all items (opcodes, tasks ...)
                //
                 Append(" value=\"").Append(eventAttribute.EventId).Append("\""). 
                 Append(" version=\"").Append(eventAttribute.Version).Append("\"").
                 Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append("\""); 
            if (eventAttribute.Keywords != 0) 
                events.Append(" keywords=\"").Append(GetKeywords((ulong)eventAttribute.Keywords, eventName)).Append("\"");
            if (eventAttribute.Opcode != 0) 
                events.Append(" opcode=\"").Append(GetOpcodeName(eventAttribute.Opcode, eventName)).Append("\"");
            if (eventAttribute.Task != 0)
                events.Append(" task=\"").Append(GetTaskName(eventAttribute.Task, eventName)).Append("\"");
            if (eventAttribute.Channel != 0) 
                events.Append(" channel=\"").Append(GetChannelName(eventAttribute.Channel, eventName)).Append("\"");
        } 
 public void StartEvent(string eventName, EventAttribute eventAttribute)
 {
     this.templateName = eventName + "Args";
     this.numParams = 0;
     this.events.Append("  <event name=\"").Append(eventName).Append("\"").Append(" value=\"").Append(eventAttribute.EventId).Append("\"").Append(" version=\"").Append(eventAttribute.Version).Append("\"").Append(" level=\"").Append(GetLevelName(eventAttribute.Level)).Append("\"");
     if (eventAttribute.Keywords != EventKeywords.None)
     {
         this.events.Append(" keywords=\"").Append(this.GetKeywords((ulong) eventAttribute.Keywords, eventName)).Append("\"");
     }
     if (eventAttribute.Opcode != EventOpcode.Info)
     {
         this.events.Append(" opcode=\"").Append(this.GetOpcodeName(eventAttribute.Opcode, eventName)).Append("\"");
     }
     if (eventAttribute.Task != EventTask.None)
     {
         this.events.Append(" task=\"").Append(this.GetTaskName(eventAttribute.Task, eventName)).Append("\"");
     }
     if (eventAttribute.Channel != EventChannel.Default)
     {
         this.events.Append(" channel=\"").Append(this.GetChannelName(eventAttribute.Channel, eventName)).Append("\"");
     }
 }
 private byte[] CreateManifestAndDescriptors(string providerDllName)
 {
     Type type = base.GetType();
     MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
     EventAttribute attribute = new EventAttribute(0);
     int num = 1;
     this.m_eventData = new EventData[methods.Length];
     ManifestBuilder builder = new ManifestBuilder(this.Name, this.Guid, providerDllName);
     FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
     if (fields.Length > 0)
     {
         foreach (FieldInfo info in fields)
         {
             Type fieldType = info.FieldType;
             if (fieldType == typeof(EventOpcode))
             {
                 builder.AddOpcode(info.Name, (int) info.GetRawConstantValue());
             }
             else if (fieldType == typeof(EventTask))
             {
                 builder.AddTask(info.Name, (int) info.GetRawConstantValue());
             }
             else if (fieldType == typeof(EventKeywords))
             {
                 builder.AddKeyword(info.Name, (ulong) ((long) info.GetRawConstantValue()));
             }
             else if (fieldType == typeof(EventChannel))
             {
                 builder.AddChannel(info.Name, (int) info.GetRawConstantValue());
             }
         }
     }
     for (int i = 0; i < methods.Length; i++)
     {
         MethodInfo element = methods[i];
         ParameterInfo[] parameters = element.GetParameters();
         EventAttribute eventAttribute = (EventAttribute) Attribute.GetCustomAttribute(element, typeof(EventAttribute), false);
         if (element.ReturnType != typeof(void))
         {
             if ((eventAttribute != null) && this.DoDebugChecks())
             {
                 throw new ArgumentException("Event attribute placed on method " + element.Name + " which does not return 'void'");
             }
         }
         else
         {
             if (!element.IsVirtual && !element.IsStatic)
             {
                 if (eventAttribute == null)
                 {
                     if (Attribute.GetCustomAttribute(element, typeof(NonEventAttribute), false) != null)
                     {
                         goto Label_0297;
                     }
                     attribute.EventId = num;
                     attribute.Opcode = EventOpcode.Info;
                     attribute.Task = EventTask.None;
                     eventAttribute = attribute;
                 }
                 else if (eventAttribute.EventId <= 0)
                 {
                     throw new ArgumentException("Event IDs <= 0 are illegal.");
                 }
                 num++;
                 if ((eventAttribute.Opcode == EventOpcode.Info) && (eventAttribute.Task == EventTask.None))
                 {
                     eventAttribute.Opcode = (EventOpcode) (10 + eventAttribute.EventId);
                 }
                 builder.StartEvent(element.Name, eventAttribute);
                 for (int j = 0; j < parameters.Length; j++)
                 {
                     builder.AddEventParameter(parameters[j].ParameterType, parameters[j].Name);
                 }
                 builder.EndEvent();
                 if (this.DoDebugChecks())
                 {
                     this.DebugCheckEvent(element, eventAttribute);
                 }
                 this.AddEventDescriptor(eventAttribute);
             }
         Label_0297:;
         }
     }
     this.TrimEventDescriptors();
     this.m_eventsByName = null;
     return builder.CreateManifest();
 }
 private void DebugCheckEvent(MethodInfo method, EventAttribute eventAttribute)
 {
     int helperCallFirstArg = GetHelperCallFirstArg(method);
     if ((helperCallFirstArg >= 0) && (eventAttribute.EventId != helperCallFirstArg))
     {
         throw new ArgumentException(string.Concat(new object[] { "Error: event ", method.Name, " is given event ID ", eventAttribute.EventId, " but ", helperCallFirstArg, " was passed to the helper." }));
     }
     if ((eventAttribute.EventId < this.m_eventData.Length) && (this.m_eventData[eventAttribute.EventId].Descriptor.EventId != 0))
     {
         throw new ArgumentException(string.Concat(new object[] { "Event ", method.Name, " has ID ", eventAttribute.EventId, " which is the same as a previously defined event." }));
     }
     if (this.m_eventsByName == null)
     {
         this.m_eventsByName = new Dictionary<string, string>();
     }
     if (this.m_eventsByName.ContainsKey(method.Name))
     {
         throw new ArgumentException("Event name " + method.Name + " used more than once.  If you wish to overload a method, the overloaded method should have a [Event(-1)] attribute to indicate the method should not have associated meta-data.");
     }
     this.m_eventsByName[method.Name] = method.Name;
 }