public void AddRules(PartnerKeyWeb key) { var rules = OffnetServiceRuleParser.GetRules(OffnetBiz.GetPartnerServiceConfig(key).ServiceRule, Utility.ConvertToMountain(key.EffectiveDate)); if (rules != null) { foreach (var r in rules) { AddRule(r, key, this); } } }
public PartnerServicePackage ApplyRules(PartnerServicePackage package) { //Validate partner var key = package.Partner; if (key == null) { throw new ApplicationException("Missing Partner!"); } if ((key.PartnerOrderId == 0 || String.IsNullOrEmpty(key.PartnerOrderName)) || string.IsNullOrEmpty(OffnetBiz.GetPartnerServiceConfig(key).ServiceRule)) { return(package); //If there are no rules, there is nothing to do. } AddRules(key); // For all the existing services, move them into the rule set so they can be used by the rules... if (package.Services != null) { foreach (var pair in package.Services) { _existingServices.Add(pair.Key, pair.Value); } } //Run through the rules... _serviceRules = _serviceRules.ToList(); foreach (var rule in _serviceRules) { try { rule.Apply(package, this); } catch (Exception e) { throw new Exception(e.Message + ", Partner " + package?.Partner?.PartnerOrderName + ", Rule: " + rule, e); } } //Any left over services need to be removed from package. foreach (var pair in _existingServices) { var sKey = pair.Value; package.AddService(pair.Key, sKey); } return(package); }