예제 #1
0
        // ReSharper disable once CodeAnnotationAnalyzer
        public static T GetOrAdd <T>([NotNull] string categoryName, [CanBeNull] string categoryHelp = null)
            where T : PerfCategory
        {
            // NOTE: Cant have Requires here as contract re-writing might change the method name and we need the name to be kept
            Debug.Assert(!string.IsNullOrWhiteSpace(categoryName));
            // ReSharper disable once AssignNullToNotNullAttribute
            PerfCategoryType pct = _counterTypes.GetOrAdd(typeof(T), t => new PerfCategoryType(t));

            Debug.Assert(pct != null);
            if (pct.Exception != null)
            {
                throw pct.Exception;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            return((T)_categories.GetOrAdd(categoryName, n => pct.Creator(n)));
        }
예제 #2
0
        public static bool Exists([NotNull] Type perfCategoryType, [NotNull] string categoryName)
        {
            if (perfCategoryType == null)
            {
                throw new ArgumentNullException("perfCategoryType");
            }
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            PerfCategoryType pct = _counterTypes.GetOrAdd(perfCategoryType, t => new PerfCategoryType(t));

            Debug.Assert(pct != null);
            if (pct.Exception != null)
            {
                throw pct.Exception;
            }

            return(PerformanceCounterCategory.Exists(categoryName) &&
                   // ReSharper disable once PossibleNullReferenceException,  AssignNullToNotNullAttribute
                   pct.CreationData.All(c => PerformanceCounterCategory.CounterExists(c.CounterName, categoryName)));
        }