// returns a set of datetime-value tuples in a JSON string
        // param0: MetricGroupName - MetricGroup->Name
        // param1: MetricName - MetricGroup->Metrics->Name
        // param2: TargetId - Targets->Id
        // param3: StartDateTime - YYYYMMDDHHMM
        // param4: EndDateTime - YYYYMMDDHHMM
        // param5: Interval - M in minutes
        // test string ok http://localhost:3128/ws/fastsingle/Range/SQL%20Server%20Activity/CPU%20mils/0/201305201800/201305201900/5
        // test string not ok http://localhost:3128/ws/fastsingle/Range/SQL%20Server%20Activity/CPU%20mils/0/201305201800/201305M900/5
        private WebServiceResult Range(string[] parameters)
        {
            if (parameters.Count() < 6)
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): not enough parameters. Format is MetricGroupName/MetricName/TargetId/StartDateTime/EndDateTime/IntervalInMinutes"));
            }

            Regex r = new Regex("^[0-9]*$");

            // check that supplied target id is valid
            if (!r.IsMatch(parameters[2]) || !Configuration.targets.ContainsId(Convert.ToInt32(parameters[2])))
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): TargetId is either not numeric or doesn't exist"));
            }

            if (!r.IsMatch(parameters[3]) || !r.IsMatch(parameters[4]) || !r.IsMatch(parameters[5]))
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): at least one of the parameters is not numeric. Format is TargetId/StartDateTime/EndDateTime/IntervalInMinutes"));
            }

            if (parameters[3].Length != 12 || parameters[4].Length != 12)
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): StartDateTime and EndDateTime must be in YYYYMMDDHHMM format"));
            }

            // look up metric group by name
            int metricGroupId = Configuration.metricGroups[parameters[0]].id;

            // look up metric by name
            string columnName = parameters[1].Replace(' ', '_');

            // prepare parameters
            SqlParameters sqlParameters = new SqlParameters
            {
                { "@tablename", SqlServerProbe.DataTableName(Convert.ToInt32(parameters[2]), Configuration.metricGroups[metricGroupId]) },
                { "@columnname", columnName },
                { "@start_dt", SqlServerProbe.FormatDate(parameters[3]) },
                { "@end_dt", SqlServerProbe.FormatDate(parameters[4]) },
                { "@interval", parameters[5] }
            };

            // execute procedure and return results
            return(GetData(System.Data.CommandType.StoredProcedure, "dbo.GetRangeSingleRowFastCumulative", sqlParameters));
        }
        // returns a set of datetime-value tuples in a JSON string
        // param0: MetricGroupName - MetricGroup->Name
        // param1: TargetId - Targets->Id
        // param2: StartDateTime - YYYYMMDDHHMM
        // param3: EndDateTime - YYYYMMDDHHMM
        // param4: Interval - M in minutes
        // param5: MetricName - MetricGroup->metrics->name
        // param6: NumOfRowsToReturn - Number of records to return (TOP X)
        // param7: DictionaryKeyName - MetricGroup->multiRowKeys->name
        // param8: Optional. Dictionary keys to exclude
        // test string ok     http://localhost:3128/ws/fastmulti/Range/SQL%20Server%20Wait%20Stats/0/201305201800/201305201900/5/Wait%20Time%20ms/5/Wait%20Type/
        // test string not ok http://localhost:3128/ws/fastmulti/Range/SQL%20Server%20Wait%20Stats/0/201305201800/201305M900/5/Wait%20Time%20ms/10/Wait%20Type/
        private WebServiceResult Range(string[] parameters)
        {
            if (parameters.Count() < 8)
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): too few parameters. Format is MetricGroupName/TargetId/StartDateTime/EndDateTime/IntervalInMinutes/MetricName/DictionaryKeyName/[DictionaryKeysToExclude]"));
            }

            if (parameters.Count() > 9)
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): too many parameters. Format is MetricGroupName/TargetId/StartDateTime/EndDateTime/IntervalInMinutes/MetricName/numOfRowsToReturn/DictionaryKeyName/[DictionaryKeysToExclude]"));
            }

            Regex r = new Regex("^[0-9]*$");

            // check that supplied target id is valid
            if (!r.IsMatch(parameters[1]) || !Configuration.targets.ContainsId(Convert.ToInt32(parameters[1])))
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): TargetId is either not numeric or target with specified id doesn't exist"));
            }

            if (!r.IsMatch(parameters[2]) || !r.IsMatch(parameters[3]) || !r.IsMatch(parameters[4]))
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): TargetId or StartDateTime or EndDateTime or Interval is not numeric. Format is MetricGroupName/TargetId/StartDateTime/EndDateTime/IntervalInMinutes/MetricName/DictionaryKeyName/[DictionaryKeysToExclude]"));
            }

            if (parameters[2].Length != 12 || parameters[3].Length != 12)
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): StartDateTime and EndDateTime must be in YYYYMMDDHHMM format"));
            }

            if (!r.IsMatch(parameters[6]))
            {
                return(WebServiceResult.ReturnError(GetType().Name + ".Range(): NumOfRowsToReturn is not numeric"));
            }

            // look up metric group by name
            var metricGroup = Configuration.metricGroups[parameters[0]];

            string metricColumn      = parameters[5].Replace(' ', '_');
            string numOfRowsToReturn = parameters[6];
            string exclusionColumn   = parameters[7].Replace(' ', '_');
            string excludedValues    = string.Empty;

            if (parameters.Count() == 9)
            {
                excludedValues = parameters[8];
            }

            // prepare parameters
            SqlParameters sqlParameters = new SqlParameters
            {
                { "@dataTable", SqlServerProbe.DataTableName(Convert.ToInt32(parameters[1]), metricGroup) },
                { "@dictionary", SqlServerProbe.DictTableName(Convert.ToInt32(parameters[1]), metricGroup) },
                { "@start_dt", SqlServerProbe.FormatDate(parameters[2]) },
                { "@end_dt", SqlServerProbe.FormatDate(parameters[3]) },
                { "@interval", parameters[4] },
                { "@metricColumn", metricColumn },
                { "@numOfRowsToReturn", numOfRowsToReturn },
                { "@exclusionColumn", exclusionColumn },
                { "@excludedValues", excludedValues }
            };

            // execute procedure and return results
            if (metricGroup.isCumulative)
            {
                return(GetData(System.Data.CommandType.StoredProcedure, "dbo.GetRangeMultiRowFastCumulative", sqlParameters));
            }

            return(GetData(System.Data.CommandType.StoredProcedure, "dbo.GetRangeMultiRowFastNonCumulative", sqlParameters));
        }