Exemple #1
0
        /// <summary>
        /// Конструктор UseOnlyExistedWinMultiInstanceCategory
        /// </summary>
        /// <param name="name">Имя категории</param>
        /// <param name="description">Описание категории</param>
        /// <param name="rootName">Корневое имя</param>
        /// <param name="info">Информация о функционировании</param>
        internal UseOnlyExistedWinMultiInstanceCategory(string name, string description, string rootName, WinCountersWorkingInfo info)
            : base(name, description, rootName, info)
        {
            if (info.InstantiationMode != WinCountersInstantiationMode.UseOnlyExisted)
            {
                throw new InvalidOperationException("Category UseOnlyExistedWinSingleInstanceCategory can't be used with instantiation mode: " + info.InstantiationMode.ToString());
            }

            if (!HasWinCategory())
            {
                throw new CategoryCreationException(string.Format("Can't create category ({0}) cause it is not registerd in Windows (UseOnlyExisted mode)", this.ToString()));
            }

            _instances = new ConcurrentDictionary <string, WinInstanceInMultiInstanceCategory>();
            _counters  = new ConcurrentDictionary <string, WinCounterDescriptor>();

            _winCategory = GetExistedWinCategory();
            var existedCntr = _winCategory.GetCounters("");

            foreach (var cnt in existedCntr)
            {
                var newCounter = CounterHelper.CreateDescriptorByExistedCounter(cnt, Info);
                if (newCounter != null)
                {
                    _counters.TryAdd(newCounter.Name, newCounter);
                }

                cnt.Dispose();
            }

            this.Init();
        }