Example #1
0
 private string GetChannelName(EventChannel channel, string eventName)
 {
     ManifestBuilder.ChannelInfo channelInfo = null;
     if (this.channelTab == null || !this.channelTab.TryGetValue(channel, out channelInfo))
     {
         throw new ArgumentException(EventSourceSR.EventSource_UndefinedChannel(channel, eventName));
     }
     return(channelInfo.Name);
 }
Example #2
0
        public void AddChannel(string name, int channelId, ChannelAttribute channelAttribute)
        {
            this.AddChannelKeyword((EventChannel)((byte)channelId));
            if (this.channelTab == null)
            {
                this.channelTab = new Dictionary <int, ManifestBuilder.ChannelInfo>();
            }
            Dictionary <int, ManifestBuilder.ChannelInfo> nums = this.channelTab;

            ManifestBuilder.ChannelInfo channelInfo = new ManifestBuilder.ChannelInfo()
            {
                Name    = name,
                Attribs = channelAttribute
            };
            nums[channelId] = channelInfo;
        }
Example #3
0
        private string CreateManifestString()
        {
            if (this.channelTab != null)
            {
                this.sb.Append(" <channels>").AppendLine();
                List <int> nums = new List <int>(this.channelTab.Keys);
                nums.Sort();
                foreach (int num in nums)
                {
                    ManifestBuilder.ChannelInfo item = this.channelTab[num];
                    string type          = null;
                    string str           = "channel";
                    bool   enabled       = false;
                    string isolation     = null;
                    string importChannel = null;
                    if (item.Attribs != null)
                    {
                        ChannelAttribute attribs = item.Attribs;
                        type = attribs.Type;
                        if (attribs.ImportChannel != null)
                        {
                            importChannel = attribs.ImportChannel;
                            str           = "importChannel";
                        }
                        enabled   = attribs.Enabled;
                        isolation = attribs.Isolation;
                    }
                    if (importChannel == null)
                    {
                        importChannel = string.Concat(this.providerName, "/", type);
                    }
                    string str1 = item.Name.Replace('-', '\u005F');
                    this.sb.Append("  <").Append(str);
                    this.sb.Append(" name=\"").Append(importChannel).Append("\"");
                    this.sb.Append(" chid=\"").Append(item.Name).Append("\"");
                    this.sb.Append(" symbol=\"").Append(str1).Append("\"");
                    this.WriteMessageAttrib(this.sb, str, str1, type);
                    this.sb.Append(" value=\"").Append(num).Append("\"");
                    if (str == "channel")
                    {
                        if (type != null)
                        {
                            this.sb.Append(" type=\"").Append(type).Append("\"");
                        }
                        this.sb.Append(" enabled=\"").Append(enabled.ToString().ToLowerInvariant()).Append("\"");
                        if (isolation != null)
                        {
                            this.sb.Append(" isolation=\"").Append(isolation).Append("\"");
                        }
                    }
                    if (item.Attribs == null || item.Attribs.BufferSize <= 0)
                    {
                        this.sb.Append("/>").AppendLine();
                    }
                    else
                    {
                        StringBuilder stringBuilder    = this.sb.AppendLine(">").Append("    <publishing>");
                        CultureInfo   invariantCulture = CultureInfo.InvariantCulture;
                        object[]      bufferSize       = new object[] { item.Attribs.BufferSize };
                        StringBuilder stringBuilder1   = stringBuilder.AppendFormat(invariantCulture, "      <bufferSize>{0}</bufferSize>", bufferSize).Append("    </publishing>").AppendLine();
                        CultureInfo   cultureInfo      = CultureInfo.InvariantCulture;
                        object[]      objArray         = new object[] { str };
                        stringBuilder1.AppendFormat(cultureInfo, "  </{0}>", objArray).AppendLine();
                    }
                }
                this.sb.Append(" </channels>").AppendLine();
            }
            if (this.taskTab != null)
            {
                this.sb.Append(" <tasks>").AppendLine();
                List <int> nums1 = new List <int>(this.taskTab.Keys);
                nums1.Sort();
                foreach (int num1 in nums1)
                {
                    this.sb.Append("  <task name=\"").Append(this.taskTab[num1]).Append("\" value=\"").Append(num1).Append("\"/>").AppendLine();
                }
                this.sb.Append(" </tasks>").AppendLine();
            }
            if (this.mapsTab != null)
            {
                this.sb.Append(" <maps>").AppendLine();
                foreach (Type value in this.mapsTab.Values)
                {
                    string str2 = (Attribute.GetCustomAttribute(value, typeof(FlagsAttribute), false) != null ? "bitMap" : "valueMap");
                    this.sb.Append("  <").Append(str2).Append(" name=\"").Append(value.Name).Append("\">").AppendLine();
                    FieldInfo[] fields = value.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
                    for (int i = 0; i < (int)fields.Length; i++)
                    {
                        FieldInfo fieldInfo        = fields[i];
                        object    rawConstantValue = fieldInfo.GetRawConstantValue();
                        if (rawConstantValue != null)
                        {
                            string str3 = null;
                            if (rawConstantValue is int)
                            {
                                str3 = ((int)rawConstantValue).ToString("x", CultureInfo.InvariantCulture);
                            }
                            else if (rawConstantValue is long)
                            {
                                str3 = ((long)rawConstantValue).ToString("x", CultureInfo.InvariantCulture);
                            }
                            this.sb.Append("   <map value=\"0x").Append(str3).Append("\"");
                            this.WriteMessageAttrib(this.sb, "map", string.Concat(value.Name, ".", fieldInfo.Name), fieldInfo.Name);
                            this.sb.Append("/>").AppendLine();
                        }
                    }
                    this.sb.Append("  </").Append(str2).Append(">").AppendLine();
                }
                this.sb.Append(" </maps>").AppendLine();
            }
            this.sb.Append(" <opcodes>").AppendLine();
            List <int> nums2 = new List <int>(this.opcodeTab.Keys);

            nums2.Sort();
            foreach (int num2 in nums2)
            {
                this.sb.Append("  <opcode");
                this.WriteNameAndMessageAttribs(this.sb, "opcode", this.opcodeTab[num2]);
                this.sb.Append(" value=\"").Append(num2).Append("\"/>").AppendLine();
            }
            this.sb.Append(" </opcodes>").AppendLine();
            if (this.keywordTab != null)
            {
                this.sb.Append(" <keywords>").AppendLine();
                List <ulong> nums3 = new List <ulong>(this.keywordTab.Keys);
                nums3.Sort();
                foreach (ulong num3 in nums3)
                {
                    this.sb.Append("  <keyword");
                    this.WriteNameAndMessageAttribs(this.sb, "keyword", this.keywordTab[num3]);
                    this.sb.Append(" mask=\"0x").Append(num3.ToString("x", CultureInfo.InvariantCulture)).Append("\"/>").AppendLine();
                }
                this.sb.Append(" </keywords>").AppendLine();
            }
            this.sb.Append(" <events>").AppendLine();
            this.sb.Append(this.events);
            this.sb.Append(" </events>").AppendLine();
            if (this.templates.Length > 0)
            {
                this.sb.Append(" <templates>").AppendLine();
                this.sb.Append(this.templates);
                this.sb.Append(" </templates>").AppendLine();
            }
            this.sb.Append("</provider>").AppendLine();
            this.sb.Append("</events>").AppendLine();
            this.sb.Append("</instrumentation>").AppendLine();
            this.sb.Append("<localization>").AppendLine();
            this.sb.Append(" <resources culture=\"").Append("en-US").Append("\">").AppendLine();
            this.sb.Append("  <stringTable>").AppendLine();
            List <string> strs = new List <string>(this.stringTab.Keys);

            strs.Sort();
            foreach (string str4 in strs)
            {
                this.sb.Append("   <string id=\"").Append(str4).Append("\" value=\"").Append(this.stringTab[str4]).Append("\"/>").AppendLine();
            }
            this.sb.Append("  </stringTable>").AppendLine();
            this.sb.Append(" </resources>").AppendLine();
            this.sb.Append("</localization>").AppendLine();
            this.sb.AppendLine("</instrumentationManifest>");
            return(this.sb.ToString());
        }