Exemple #1
0
 public AnalyticsSortOptions AddDescending(AnalyticsMetric metric)
 {
     if (metric == null)
     {
         throw new ArgumentNullException("metric");
     }
     return(Add(metric, AnalyticsSortOrder.Descending));
 }
 public AnalyticsMetricSortField(AnalyticsMetric metric, AnalyticsSortOrder order)
 {
     if (metric == null)
     {
         throw new ArgumentNullException("metric");
     }
     Metric = metric;
     Order  = order;
 }
Exemple #3
0
 public AnalyticsSortOptions Add(AnalyticsMetric metric, AnalyticsSortOrder order)
 {
     if (metric == null)
     {
         throw new ArgumentNullException("metric");
     }
     _fields.Add(new AnalyticsMetricSortField(metric, order));
     return(this);
 }
 /// <summary>
 /// Adds the specified metric.
 /// </summary>
 /// <param name="metric">The metric to add.</param>
 public AnalyticsRealtimeDataOptions AddMetric(AnalyticsMetric metric)
 {
     if (Metrics == null)
     {
         Metrics = new AnalyticsMetricCollection();
     }
     Metrics.Add(metric);
     return(this);
 }
Exemple #5
0
        /// <summary>
        /// Converts the string representation of the filter options.
        /// </summary>
        /// <param name="str">A string containing the filter options to convert.</param>
        /// <returns>The converted filter options.</returns>
        public static AnalyticsFilterOptions Parse(string str)
        {
            AnalyticsFilterOptions options = new AnalyticsFilterOptions();

            string[] a = str.Split(';');

            for (int i = 0; i < a.Length; i++)
            {
                string[] b = a[i].Split(',');

                if (i > 0)
                {
                    options._filters.Add(AnalyticsFilterOperator.And);
                }

                for (int j = 0; j < b.Length; j++)
                {
                    if (j > 0)
                    {
                        options._filters.Add(AnalyticsFilterOperator.Or);
                    }

                    Match m = Regex.Match(b[j], "^(ga:[a-zA-Z]+)(.{1,2})(.+?)$");

                    if (!m.Success)
                    {
                        throw new Exception("Unable to parse filter '" + b[j] + "'");
                    }

                    AnalyticsMetric            metric;
                    AnalyticsMetricOperator    metricOperator;
                    AnalyticsDimension         dimension;
                    AnalyticsDimensionOperator dimensionOperator;

                    if (AnalyticsMetric.TryParse(m.Groups[1].Value, out metric) && AnalyticsMetricOperator.TryParse(m.Groups[2].Value, out metricOperator))
                    {
                        options._filters.Add(new AnalyticsMetricFilter(metric, metricOperator, HttpUtility.UrlDecode(m.Groups[3].Value)));
                    }
                    else if (AnalyticsDimension.TryParse(m.Groups[1].Value, out dimension) && AnalyticsDimensionOperator.TryParse(m.Groups[2].Value, out dimensionOperator))
                    {
                        options._filters.Add(new AnalyticsDimensionFilter(dimension, dimensionOperator, HttpUtility.UrlDecode(m.Groups[3].Value)));
                    }
                    else
                    {
                        // Currently the parsing will only work if the specified dimension or
                        // metric name matches a defined constant, so if Google adds a new
                        // dimension or metric, the constants must be updated before the parsing
                        // will work. I'm not sure how often Google adds new dimensions or metric,
                        // so perhaps this isn't a problem
                        throw new Exception("Unable to parse filter '" + b[j] + "'");
                    }
                }
            }

            return(options);
        }
Exemple #6
0
        /// <summary>
        /// Converts the string representation of the sort options.
        /// </summary>
        /// <param name="str">A string containing the sort options to convert.</param>
        /// <returns>The converted sort options.</returns>
        public static AnalyticsSortOptions Parse(string str)
        {
            // If the strign is NULL, we also return NULL
            if (str == null)
            {
                return(null);
            }

            AnalyticsSortOptions options = new AnalyticsSortOptions();

            // The sort fields are separated by commas
            string[] b = str.Split(new [] { "," }, StringSplitOptions.RemoveEmptyEntries);

            for (int j = 0; j < b.Length; j++)
            {
                string piece = b[j];

                AnalyticsSortOrder order = AnalyticsSortOrder.Ascending;
                if (piece.StartsWith("-"))
                {
                    order = AnalyticsSortOrder.Descending;
                    piece = piece.Substring(1);
                }

                // Does the piece have the characteristics of a metric or dimension?
                Match m = Regex.Match(piece, "^(ga:[a-zA-Z]+)$");
                if (!m.Success)
                {
                    throw new Exception("Unable to parse metric or dimension '" + piece + "'");
                }

                AnalyticsMetric    metric;
                AnalyticsDimension dimension;
                if (AnalyticsMetric.TryParse(m.Groups[1].Value, out metric))
                {
                    options.Add(metric, order);
                }
                else if (AnalyticsDimension.TryParse(m.Groups[1].Value, out dimension))
                {
                    options.Add(dimension, order);
                }
                else
                {
                    // Currently the parsing will only work if the specified dimension or
                    // metric name matches a defined constant, so if Google adds a new
                    // dimension or metric, the constants must be updated before the parsing
                    // will work. I'm not sure how often Google adds new dimensions or metric,
                    // so perhaps this isn't a problem
                    throw new Exception("Unable to parse metric or dimension '" + m.Groups[1].Value + "'");
                }
            }

            return(options);
        }
        public AnalyticsMetricFilter(AnalyticsMetric metric, AnalyticsMetricOperator op, object value)
        {
            if (metric == null)
            {
                throw new ArgumentNullException("metric");
            }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            Metric   = metric;
            Operator = op;
            Value    = value;
        }
Exemple #8
0
 /// <summary>
 /// Adds the specified metric to the collection.
 /// </summary>
 /// <param name="metric">The metric to add.</param>
 public void Add(AnalyticsMetric metric)
 {
     _list.Add(metric);
 }
Exemple #9
0
 /// <summary>
 /// Attempts to parse the specified string as a metric. The parsing is done against a list
 /// of known metrics. The method will return TRUE if the parsing succeeds, otherwise FALSE.
 /// </summary>
 /// <param name="str">The string to parse.</param>
 /// <param name="metric">The parsed metric.</param>
 public static bool TryParse(string str, out AnalyticsMetric metric)
 {
     metric = Values.FirstOrDefault(temp => temp.Name == str);
     return(metric != null);
 }
 /// <summary>
 /// Adds a metric filter with the specified information.
 /// </summary>
 /// <param name="metric">The metric.</param>
 /// <param name="op">The operator.</param>
 /// <param name="value">The value.</param>
 public AnalyticsRealtimeDataOptions AddMetricFilter(AnalyticsMetric metric, AnalyticsMetricOperator op, string value)
 {
     _filters.Add(new AnalyticsMetricFilter(metric, op, value));
     return(this);
 }