public static bool TryParse(string str, out AnalyticsDimensionOperator op) {
     foreach (AnalyticsDimensionOperator temp in Values) {
         if (temp.Value != str) continue;
         op = temp;
         return true;
     }
     op = null;
     return false;
 }
        public AnalyticsDimensionFilter(AnalyticsDimension dimension, AnalyticsDimensionOperator op, object value) {

            if (dimension == null) throw new ArgumentNullException("dimension");
            if (op == null) throw new ArgumentNullException("op");

            Dimension = dimension;
            Operator = op;
            Value = value;

        }
 public static bool TryParse(string str, out AnalyticsDimensionOperator op)
 {
     foreach (AnalyticsDimensionOperator temp in Values)
     {
         if (temp.Value != str)
         {
             continue;
         }
         op = temp;
         return(true);
     }
     op = null;
     return(false);
 }
        public AnalyticsDimensionFilter(AnalyticsDimension dimension, AnalyticsDimensionOperator op, object value)
        {
            if (dimension == null)
            {
                throw new ArgumentNullException("dimension");
            }
            if (op == null)
            {
                throw new ArgumentNullException("op");
            }

            Dimension = dimension;
            Operator  = op;
            Value     = value;
        }
예제 #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);
        }
 /// <summary>
 /// Adds a dimension filter with the specified information.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="op">The operator.</param>
 /// <param name="value">The value.</param>
 public AnalyticsRealtimeDataOptions AddDimensionFilter(AnalyticsDimension dimension, AnalyticsDimensionOperator op, string value) {
     _filters.Add(new AnalyticsDimensionFilter(dimension, op, value));
     return this;
 }
 /// <summary>
 /// Adds a dimension filter with the specified information.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="op">The operator.</param>
 /// <param name="value">The value.</param>
 public AnalyticsDataOptions AddDimensionFilter(AnalyticsDimension dimension, AnalyticsDimensionOperator op, string value)
 {
     _filters.Add(new AnalyticsDimensionFilter(dimension, op, value));
     return(this);
 }