Exemplo n.º 1
0
        public Calculation(ICalculationRules context)
        {
            _context = context;

            foreach (var attribute in _context.ContributingAttributes)
            {
                var value = GetOrAddPendingValue(attribute);
            }

            var prepared = GetPreparedAttributes();

            while (prepared.Count > 0)
            {
                foreach (var attribute in prepared)
                {
                    // this will remove the attribute from the 'pending' queue
                    var removed = CompletePendingCalculation(attribute);

                    foreach (var contribution in _context.ContributionsBy(attribute))
                    {
                        AddContribution(contribution);
                    }
                }
                prepared = GetPreparedAttributes();
            }

            if (_pendingValues.Count > 0)
            {
                throw new Exception("not enough info to calculate all attributes");
            }

            Result = new CalculationResult {
                AttributeValues = _completedValues.Values
            };
        }
Exemplo n.º 2
0
        public Calculation(ICalculationRules context)
        {
            _context = context;

            foreach (var attribute in _context.ContributingAttributes)
            {
                var value = GetOrAddPendingValue(attribute);
            }

            var prepared = GetPreparedAttributes();
            while (prepared.Count > 0)
            {
                foreach (var attribute in prepared)
                {
                    // this will remove the attribute from the 'pending' queue
                    var removed = CompletePendingCalculation(attribute);

                    foreach (var contribution in _context.ContributionsBy(attribute))
                    {
                        AddContribution(contribution);
                    }
                }
                prepared = GetPreparedAttributes();
            }

            if (_pendingValues.Count > 0)
            {
                throw new Exception("not enough info to calculate all attributes");
            }

            Result = new CalculationResult { AttributeValues = _completedValues.Values };
        }
Exemplo n.º 3
0
        public CalculationResult Calculate(ICalculationRules context)
        {
            var calculation = new Calculation(context);

            return(calculation.Result);
        }
Exemplo n.º 4
0
 public CalculationResult Calculate(ICalculationRules context)
 {
     var calculation = new Calculation(context);
     return calculation.Result;
 }
Exemplo n.º 5
0
 public static IEnumerable <Campaigns.Model.AttributeContribution> ContributionsBy(this ICalculationRules ctx, int sourceId)
 {
     return(ctx.AllContributionsFrom(sourceId)
            .Where(c => ctx.IsAttributeContributing(c.Target)));
 }
Exemplo n.º 6
0
 public static IEnumerable <Campaigns.Model.AttributeContribution> ContributionsTo(this ICalculationRules ctx, int targetId)
 {
     return(ctx.AllContributionsTo(targetId)
            .Where(c => null == c.Source || ctx.IsAttributeContributing(c.Source)));
 }