Ejemplo n.º 1
0
 public ICollection <AttributeContribution> ContributionsTo(Campaigns.Model.Attribute target)
 {
     if (null == target)
     {
         throw new ArgumentNullException("target");
     }
     return(_contributionsForAttributeId[target.Id]);
 }
Ejemplo n.º 2
0
 public ICollection <AttributeContribution> ContributionsFrom(Campaigns.Model.Attribute source)
 {
     if (null == source)
     {
         throw new ArgumentNullException("source");
     }
     return(_contributionsByAttributeId[source.Id]);
 }
Ejemplo n.º 3
0
        private Campaigns.Model.Attribute CreateAttribute(string name, string category, bool isStandard)
        {
            var result = new Campaigns.Model.Attribute {
                Name = name, Category = category, IsStandard = isStandard
            };

            _attributesDb.Add(result);
            return(result);
        }
Ejemplo n.º 4
0
 private IEnumerable <AttributeContribution> GetPendingContributionsTo(Campaigns.Model.Attribute target)
 {
     return(from contrib in _context.AllContributionsTo(target)
            let dependency = contrib.Source
                             where null != dependency &&
                             _context.IsAttributeContributing(dependency) &&
                             !_completedValues.ContainsKey(dependency.Id)
                             select contrib);
 }
Ejemplo n.º 5
0
 public void AddAttribute(Campaigns.Model.Attribute attrib)
 {
     if (_attributes.Values.Any(a => a.Id == attrib.Id))
     {
         throw new Exception(
                   String.Format("Attribute calculation assertion failure: attribute already exists with ID {0} ({1})", attrib.Id, attrib.Name));
     }
     // var attrib = new Attribute { Id = AllocId(), Name = name, Category = category };
     _attributes.Add(AttributeKey(attrib.Name, attrib.Category), attrib);
     GetContributionsByAttribute(attrib);
     GetContributionsForAttribute(attrib);
 }
Ejemplo n.º 6
0
        private int CompletePendingCalculation(Campaigns.Model.Attribute target)
        {
            var value            = GetOrAddPendingValue(target);
            var contribsToTarget = GetRelevantContributionsTo(target).ToList();

            foreach (var contribution in contribsToTarget)
            {
                var source      = contribution.Source;
                var sourceValue = null == source ? 0 : _completedValues[source.Id].Value;
                value.Value += contribution.Formula(sourceValue);
            }
            return(SetCompleted(value));
        }
Ejemplo n.º 7
0
        private AttributeValue GetOrAddPendingValue(Campaigns.Model.Attribute target)
        {
            AttributeValue result;

            if (!_pendingValues.TryGetValue(target.Id, out result))
            {
                result = new AttributeValue
                {
                    Attribute = target,
                    Value     = 0,
                };
                AddValueAsPending(result);
            }
            return(result);
        }
Ejemplo n.º 8
0
        private IList <AttributeContribution> GetContributionsByAttribute(Campaigns.Model.Attribute attrib)
        {
            if (null == attrib)
            {
                throw new ArgumentNullException("attrib");
            }
            IList <AttributeContribution> contribs;

            if (!_contributionsByAttributeId.TryGetValue(attrib.Id, out contribs))
            {
                contribs = new List <AttributeContribution>();
                _contributionsByAttributeId.Add(attrib.Id, contribs);
            }
            return(contribs);
        }
Ejemplo n.º 9
0
 public static IQueryable <Campaigns.Model.AttributeContribution> ContributionsFrom(this IEntityStore <AttributeContribution> db, Campaigns.Model.Attribute source)
 {
     return(db.AsQueryable.Where(c => c.SourceId == source.Id));
 }
Ejemplo n.º 10
0
 private IEnumerable <AttributeContribution> GetRelevantContributionsTo(Campaigns.Model.Attribute target)
 {
     // direct contributions and contributions that are relevant to this calculation
     return(_context.AllContributionsTo(target)
            .Where(contrib => null == contrib.Source || _context.IsAttributeContributing(contrib.Source)));
 }
Ejemplo n.º 11
0
 public bool IsAttributeContributing(Campaigns.Model.Attribute source)
 {
     return(_contributingAttributes.Contains(source));
 }
Ejemplo n.º 12
0
 public void SetInitialValue(Campaigns.Model.Attribute attribute, int value)
 {
     _contributionsDb.Add(attribute.ConstantContributionFrom(null, value));
     _contributingAttributes.Add(attribute);
 }
Ejemplo n.º 13
0
 public IEnumerable <AttributeContribution> AllContributionsFrom(Campaigns.Model.Attribute source)
 {
     return(_memDb.ContributionsFrom(source).Concat(_contributionsDb.ContributionsFrom(source)));
 }
Ejemplo n.º 14
0
 public bool IsAttributeContributing(Campaigns.Model.Attribute source)
 {
     return(_memDb.Attributes.Any(a => a.Id == source.Id));
 }
Ejemplo n.º 15
0
 public IEnumerable <AttributeContribution> AllContributionsTo(Campaigns.Model.Attribute target)
 {
     return(_memDb.ContributionsTo(target).Concat(_contributionsDb.ContributionsTo(target)));
 }
Ejemplo n.º 16
0
 public static IQueryable <Campaigns.Model.AttributeContribution> ContributionsTo(this IEntityStore <AttributeContribution> db, Campaigns.Model.Attribute target)
 {
     return(db.AsQueryable.Where(c => c.TargetId == target.Id));
 }
Ejemplo n.º 17
0
 private Campaigns.Model.Attribute CreateAttribute(string name, string category, bool isStandard)
 {
     var result = new Campaigns.Model.Attribute { Name = name, Category = category, IsStandard = isStandard };
     _attributesDb.Add(result);
     return result;
 }