Пример #1
0
        /// <summary>
        /// Ouverture d'une nouvelle instance de base de données.
        /// </summary>
        /// <param name="dataBaseName">Nom de la base de données.</param>
        /// <param name="description">Description du manager associé.</param>
        public void OpenDataBase(string dataBaseName, IManagerDescription description)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (dataBaseName == null)
            {
                throw new ArgumentNullException("dataBaseName");
            }

            CounterDataBase db = new CounterDataBase(dataBaseName);

            lock (this) {
                if (_map.ContainsKey(dataBaseName))
                {
                    return;
                }

                _map.Add(dataBaseName, db);

                if (description != null)
                {
                    _mapDescription.Add(dataBaseName, description);

                    foreach (IMonitoringStore store in _monitoringStore)
                    {
                        ExceptionSafeCreateDatabase(store, dataBaseName, description);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// On termine l'enristrement du process et on l'ajoute à la base de données.
        /// </summary>
        /// <param name="dataBaseName">Nom de la base de données.</param>
        /// <returns>Retourne la durée du processus.</returns>
        public long StopProcess(string dataBaseName)
        {
            if (string.IsNullOrEmpty(dataBaseName))
            {
                throw new ArgumentNullException("dataBaseName");
            }

            if (!IsEnabled && !IsSummaryEnabled)
            {
                return(0);
            }

            CounterProcess counterProcess;
            HttpContext    context = HttpContext.Current;

            if (context == null)
            {
                counterProcess = _counterProcess;
            }
            else
            {
                counterProcess = context.Items[ItemProcessCounter] as CounterProcess;
            }

            // On agrège tous les compteurs
            if (counterProcess == null)
            {
                return(0);
            }

            long duration;

            if (IsSummaryEnabled)
            {
                counterProcess.Close();
                duration = counterProcess.Duration;

                lock (_summaryMap) {
                    Tuple <int, long> data;
                    if (_summaryMap.TryGetValue(counterProcess.Name, out data))
                    {
                        _summaryMap[counterProcess.Name] = new Tuple <int, long>(data.Item1 + 1, data.Item2 + duration);
                    }
                    else
                    {
                        _summaryMap[counterProcess.Name] = new Tuple <int, long>(1, duration);
                    }
                }
            }
            else
            {
                CounterDataBase counterDataBase = GetDataBase(dataBaseName);
                duration = counterDataBase.AddProcess(counterProcess);
            }

            // On ferme les compteurs
            if (context == null)
            {
                _counterProcess = counterProcess.Parent;
            }
            else
            {
                context.Items[ItemProcessCounter] = counterProcess.Parent;
            }

            return(duration);
        }