Example #1
0
        /// <summary>
        /// Builds the aggregate expression.
        /// </summary>
        /// <param name="aggregateExpression">The aggregate expression.</param>
        /// <param name="context">The context.</param>
        /// <returns>AggregateExpression.</returns>
        private static AggregateExpression BuildAggregateExpression(Model.AggregateExpression aggregateExpression, FromEntityContext context)
        {
            string[] aggregateExpressionParts = aggregateExpression.AggregateMethod.Alias.Split(':');
            string   method = aggregateExpressionParts.Length == 2 ? aggregateExpressionParts[1].Substring(3) : aggregateExpressionParts[0].Substring(3);
//            string method = aggregateExpression.AggregateMethod.Alias.Substring(3);
            AggregateMethod     aggregateMethod = (AggregateMethod)Enum.Parse(typeof(AggregateMethod), method, true);
            AggregateExpression expression      = new AggregateExpression
            {
                AggregateMethod = aggregateMethod,
                Expression      = aggregateExpression.AggregatedExpression != null?BuildExpression(aggregateExpression.AggregatedExpression, context) : null
            };

            // Validate expression
            if (expression.AggregateMethod != AggregateMethod.Count && expression.Expression == null)
            {
                EventLog.Application.WriteWarning(context.DebugInfo + "the aggregate id: {0} has invalid grouped expression.", aggregateExpression.Id.ToString());
                return(null);    // TODO: Log a warning
            }

            Guid key = Guid.NewGuid();

            context.ReportExpressionMap[key] = aggregateExpression.SourceNode.Id;
            expression.ExpressionId          = key;
            expression.EntityId = aggregateExpression.Id;
            return(expression);
        }
        public static int computeAggregateValue(int[] values, AggregateMethod method)
        {
            int currentValue = values[0];

            for (int i = 1; i < values.Length; i++)
            {
                currentValue = method(currentValue, values[i]);
            }
            return(currentValue);
        }
            private AggregateCollection Aggregate(AggregateMethod method, string name, string alias = null)
            {
                if (string.IsNullOrEmpty(name) && method != AggregateMethod.Count)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                _members.Add(new Aggregate(method, name, alias));

                return(this);
            }
Example #4
0
        public void Update(AggregateMethod method, IValue value)
        {
            if (value.IsNull)
            {
                return;
            }
            switch (method)
            {
            case AggregateMethod.Last:
                if (typeof(T) == typeof(string))
                {
                    (this as ValueWrapper <string>).Value = value.ToString();
                }
                else
                {
                    this.Assign(value);
                }
                break;

            case AggregateMethod.Join:
                if (typeof(T) == typeof(string))
                {
                    var stringValue = value.ToString();
                    if (this.Value == null || (this.Value as string)?.Contains(stringValue) == false)
                    {
                        (this as ValueWrapper <string>).Value =
                            string.Concat((this.Value as string) ?? "", ",", stringValue);
                    }
                }
                break;

            case AggregateMethod.FullJoin:
                if (typeof(T) == typeof(string))
                {
                    var stringValue = value.ToString();
                    (this as ValueWrapper <string>).Value =
                        string.Concat((this.Value as string) ?? "", ",", stringValue);
                }
                break;

            case AggregateMethod.Sum:
                if (typeof(T) == typeof(long))
                {
                    (this as ValueWrapper <long>).Value += (value as IValue <long>)?.GetValue() ?? 0;
                }
                if (typeof(T) == typeof(decimal))
                {
                    (this as ValueWrapper <decimal>).Value += (value as IValue <decimal>)?.GetValue() ?? 0;
                }
                break;
            }
        }
Example #5
0
        private static void AggregateExample()
        {
            Console.WriteLine("=====Example 4 (Aggregate example)=====");

            Console.WriteLine();
            var sumClassic = AggregateMethod.GetSumClassic(numbersList);

            Console.Write($"Sum classic: {sumClassic}");

            Console.WriteLine();
            var sumLinq = AggregateMethod.GetSumLinq(numbersList);

            Console.Write($"Sum Linq: {sumLinq}");

            //TODO 4: Implement AggregateMethod.GetSumOfEvenNumbers
            Console.WriteLine();
            var sumOfEven = AggregateMethod.GetSumOfEvenNumbers(numbersList);

            Console.Write($"Sum of even: {sumOfEven}");

            Console.WriteLine();
        }
Example #6
0
 public void Update(AggregateMethod method, IValue value)
 {
     throw new NotImplementedException();
 }
 public Aggregate(AggregateMethod method, string name, string alias)
 {
     this.Method = method;
     this.Name   = name;
     this.Alias  = alias;
 }