Ejemplo 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
            };
        }
Ejemplo 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 };
        }