Ejemplo n.º 1
0
        internal int GetInteractionsWaiting(string workgroupName, bool waitForData)
        {
            using (Trace.Cic.scope())
            {
                try
                {
                    var key = new StatisticKey(InteractionsWaitingDefinition.Id,
                                               new ParameterValueKeyedCollection
                    {
                        new ParameterValue(new ParameterTypeId("ININ.People.WorkgroupStats:Workgroup"), workgroupName)
                    });

                    return(GetStatisticInt(key, waitForData));
                }
                catch (NullStatisticValueException ex)
                {
                    Trace.Cic.warning(ex.Message);
                    return(-1);
                }
                catch (StatisticErrorException ex)
                {
                    Trace.Cic.exception(ex);
                    return(-1);
                }
                catch (Exception ex)
                {
                    Trace.Cic.exception(ex);
                    return(-1);
                }
            }
        }
Ejemplo n.º 2
0
        internal TimeSpan GetAverageWaitTime(string workgroupName, IntervalTypes intervalType, bool waitForData)
        {
            using (Trace.Cic.scope())
            {
                try
                {
                    var key = new StatisticKey(AverageWaitTimeDefinition.Id,
                                               new ParameterValueKeyedCollection
                    {
                        new ParameterValue(new ParameterTypeId("ININ.People.WorkgroupStats:Workgroup"), workgroupName),
                        new ParameterValue(new ParameterTypeId("ININ.Queue:Interval"), intervalType.ToString())
                    });

                    return(GetStatisticDuration(key, waitForData));
                }
                catch (NullStatisticValueException ex)
                {
                    Trace.Cic.warning(ex.Message);
                    return(TimeSpan.MinValue);
                }
                catch (StatisticErrorException ex)
                {
                    Trace.Cic.exception(ex);
                    return(TimeSpan.MinValue);
                }
                catch (Exception ex)
                {
                    Trace.Cic.exception(ex);
                    return(TimeSpan.MinValue);
                }
            }
        }
Ejemplo n.º 3
0
        private double GetStatisticPercent(StatisticKey key, bool waitForData)
        {
            var statValue = GetStatistic(key, waitForData ? 0 : RetryAllowance);

            // Return stat value
            if (statValue.Definition.ValueType == StatisticValueType.Percent)
            {
                return(((StatisticPercentValue)statValue).Value);
            }

            // This should never happen
            Trace.Cic.error("Statistic was of unexpected type: {}", statValue.Definition.ValueType);
            return(-1);
        }
Ejemplo n.º 4
0
        private TimeSpan GetStatisticDuration(StatisticKey key, bool waitForData)
        {
            var statValue = GetStatistic(key, waitForData ? 0 : RetryAllowance);

            // Return stat value
            if (statValue.Definition.ValueType == StatisticValueType.Duration)
            {
                return(((StatisticDurationValue)statValue).Value);
            }

            // This should never happen
            Trace.Cic.error("Statistic was of unexpected type: {}", statValue.Definition.ValueType);
            return(TimeSpan.MinValue);
        }
Ejemplo n.º 5
0
        private StatisticValue GetStatistic(StatisticKey key, int retryCount = 0)
        {
            // Watch key
            if (!_statisticListener.IsWatching(key))
            {
                if (_statisticListener.IsWatching())
                {
                    _statisticListener.ChangeWatchedKeys(new[] { key }, new StatisticKey[] { }, false);
                }
                else
                {
                    _statisticListener.StartWatching(new[] { key });
                }
            }

            // Get value
            var statValue = _statisticListener[key];

            // Error checking
            if (statValue.IsError)
            {
                throw new StatisticErrorException(statValue.ErrorReason.ToString());
            }
            if (statValue.IsNull)
            {
                // If this isn't already a retry, try again and return whatever we get back
                if (retryCount >= RetryAllowance)
                {
                    throw new NullStatisticValueException(key.UriString);
                }
                Thread.Sleep(500);
                return(GetStatistic(key, retryCount + 1));
            }

            return(statValue);
        }