private Util.PerformanceCategory GetPerformanceCategory(string categoryName)
        {
            Console.WriteLine($"Getting counters for CategoryName: {categoryName}");
            try
            {
                var category = PerformanceCounterCategory.GetCategories()
                               .Single(c => string.Equals(categoryName, c.CategoryName, StringComparison.OrdinalIgnoreCase));
                var isMultiInstance = category.CategoryType == PerformanceCounterCategoryType.MultiInstance;
                Trace.WriteLine($"Found category={categoryName}, MultiInstance={isMultiInstance}");

                // If it's multi-instance, check if there are any instances and get counters from there; else we get
                // the counters straight up. For multi-instance, GetCounters() fails if there are any instances. If there
                // are no instances, then GetCounters(instance) can't be called since there is no instance. Instances
                // will exist for each counter even if only one of the counters was "intialized."
                var hasInstances = category.GetInstanceNames().Length > 0;
                var counters     = hasInstances
                    ? category.GetCounters(category.GetInstanceNames().First())
                    : category.GetCounters();

                Trace.WriteLine($"Found {counters.Length} counters");

                var result = new Util.PerformanceCategory
                {
                    Id            = CompilerCore.GetIdentifierFromName(category.CategoryName),
                    Name          = category.CategoryName,
                    Help          = category.CategoryHelp,
                    MultiInstance = isMultiInstance ? Util.YesNoType.yes : Util.YesNoType.no
                };

                foreach (var counter in counters)
                {
                    Console.WriteLine($"Counter={counter.CounterName}, Type={counter.CounterType}");
                    result.AddChild(new Util.PerformanceCounter
                    {
                        Name = counter.CounterName,
                        Type = CounterTypeToWix(counter.CounterType),
                        Help = counter.CounterHelp,
                    });
                }

                return(result);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                throw new WixException(UtilErrors.PerformanceCategoryNotFound(categoryName));
            }
        }
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="category">The name of the performance category.</param>
        /// <returns>A harvested file.</returns>
        public Util.PerformanceCategory HarvestPerformanceCategory(string category)
        {
            if (null == category)
            {
                throw new ArgumentNullException("category");
            }

            if (PerformanceCounterCategory.Exists(category))
            {
                Util.PerformanceCategory perfCategory = new Util.PerformanceCategory();

                // Get the performance counter category and set the appropriate WiX attributes
                PerformanceCounterCategory pcc = new PerformanceCounterCategory(category);
                perfCategory.Id = CompilerCore.GetIdentifierFromName(pcc.CategoryName);
                perfCategory.Name = pcc.CategoryName;
                perfCategory.Help = pcc.CategoryHelp;
                if (PerformanceCounterCategoryType.MultiInstance == pcc.CategoryType)
                {
                    perfCategory.MultiInstance = Util.YesNoType.yes;
                }
                
                foreach (InstanceDataCollection counter in pcc.ReadCategory().Values)
                {
                    Util.PerformanceCounter perfCounter = new Util.PerformanceCounter();

                    // Get the performance counter and set the appropriate WiX attributes
                    PerformanceCounter pc = new PerformanceCounter(pcc.CategoryName, counter.CounterName);
                    perfCounter.Name = pc.CounterName;
                    perfCounter.Type = CounterTypeToWix(pc.CounterType);
                    perfCounter.Help = pc.CounterHelp;

                    perfCategory.AddChild(perfCounter);
                }

                return perfCategory;
            }
            else
            {
                throw new WixException(UtilErrors.PerformanceCategoryNotFound(category));
            }
        }
Пример #3
0
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="category">The name of the performance category.</param>
        /// <returns>A harvested file.</returns>
        public Util.PerformanceCategory HarvestPerformanceCategory(string category)
        {
            if (null == category)
            {
                throw new ArgumentNullException("category");
            }

            if (PerformanceCounterCategory.Exists(category))
            {
                Util.PerformanceCategory perfCategory = new Util.PerformanceCategory();

                // Get the performance counter category and set the appropriate WiX attributes
                PerformanceCounterCategory pcc = new PerformanceCounterCategory(category);
                perfCategory.Id   = CompilerCore.GetIdentifierFromName(pcc.CategoryName);
                perfCategory.Name = pcc.CategoryName;
                perfCategory.Help = pcc.CategoryHelp;
                if (PerformanceCounterCategoryType.MultiInstance == pcc.CategoryType)
                {
                    perfCategory.MultiInstance = Util.YesNoType.yes;
                }

                foreach (InstanceDataCollection counter in pcc.ReadCategory().Values)
                {
                    Util.PerformanceCounter perfCounter = new Util.PerformanceCounter();

                    // Get the performance counter and set the appropriate WiX attributes
                    PerformanceCounter pc = new PerformanceCounter(pcc.CategoryName, counter.CounterName);
                    perfCounter.Name = pc.CounterName;
                    perfCounter.Type = CounterTypeToWix(pc.CounterType);
                    perfCounter.Help = pc.CounterHelp;

                    perfCategory.AddChild(perfCounter);
                }

                return(perfCategory);
            }
            else
            {
                throw new WixException(UtilErrors.PerformanceCategoryNotFound(category));
            }
        }
Пример #4
0
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="argument">The name of the performance category.</param>
        /// <returns>A harvested performance category.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Util.PerformanceCategory perf = this.HarvestPerformanceCategory(argument);

            Wix.Component component = new Wix.Component();
            component.Id      = CompilerCore.GetIdentifierFromName(argument);
            component.KeyPath = Wix.YesNoType.yes;
            component.AddChild(perf);

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";
            //directory.Name = directory.Id;
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(new Wix.Fragment[] { fragment });
        }