public ICollection <AttributeContribution> ContributionsTo(Campaigns.Model.Attribute target) { if (null == target) { throw new ArgumentNullException("target"); } return(_contributionsForAttributeId[target.Id]); }
public ICollection <AttributeContribution> ContributionsFrom(Campaigns.Model.Attribute source) { if (null == source) { throw new ArgumentNullException("source"); } return(_contributionsByAttributeId[source.Id]); }
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); }
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); }
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); }
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)); }
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); }
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); }
public static IQueryable <Campaigns.Model.AttributeContribution> ContributionsFrom(this IEntityStore <AttributeContribution> db, Campaigns.Model.Attribute source) { return(db.AsQueryable.Where(c => c.SourceId == source.Id)); }
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))); }
public bool IsAttributeContributing(Campaigns.Model.Attribute source) { return(_contributingAttributes.Contains(source)); }
public void SetInitialValue(Campaigns.Model.Attribute attribute, int value) { _contributionsDb.Add(attribute.ConstantContributionFrom(null, value)); _contributingAttributes.Add(attribute); }
public IEnumerable <AttributeContribution> AllContributionsFrom(Campaigns.Model.Attribute source) { return(_memDb.ContributionsFrom(source).Concat(_contributionsDb.ContributionsFrom(source))); }
public bool IsAttributeContributing(Campaigns.Model.Attribute source) { return(_memDb.Attributes.Any(a => a.Id == source.Id)); }
public IEnumerable <AttributeContribution> AllContributionsTo(Campaigns.Model.Attribute target) { return(_memDb.ContributionsTo(target).Concat(_contributionsDb.ContributionsTo(target))); }
public static IQueryable <Campaigns.Model.AttributeContribution> ContributionsTo(this IEntityStore <AttributeContribution> db, Campaigns.Model.Attribute target) { return(db.AsQueryable.Where(c => c.TargetId == target.Id)); }
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; }