public OffnetServiceKey(OffnetServiceKeyWeb web) : this(web.ServiceID) { if (web.Attributes != null) { foreach (var ai in web.Attributes) { if (ai.Value != null) { var a = new AttributeValue(ai.Value.Value, ai.Value.DisplayValue, new AttributeType(ai.Type)); AddValue(ai.Name, a); } } } if (web.Date != null) { EffectiveDate = (DateTime)web.Date; } if (web.ParentServiceKey != null) { ParentServiceKey = new OffnetServiceKey(web.ParentServiceKey); } if (web.ChildServices != null || web.ChildServices.Count() > 0) { foreach (var child in web.ChildServices) { Children.Add(child.Name, child.Services.Select(s => new OffnetServiceKey(s)).ToList()); } } }
public static void AddMissingParentAttributes(OffnetServiceKey key) { if (key.ParentServiceKey != null) { key.ParentServiceKey.AddMissingAttributes(); var childConfig = OffnetServiceConfiguration.Get(key.Id, key.EffectiveDate); var parentConfig = OffnetServiceConfiguration.Get(key.ParentServiceKey.Id, key.ParentServiceKey.EffectiveDate); string value; foreach (var attribute in childConfig.Attributes) { if (attribute.Value.Type == AttributeType.Parent) { value = key.ParentServiceKey.GetAttributeValue(attribute.Value.Name, SearchOptions.ALL_TRUE); if (value == null) { value = parentConfig.GetDefaultValue(attribute.Value.Name, key.ParentServiceKey); } if (value != null) { key.AddAttribute(attribute.Value.Name, value); } } } } }
public void SetAttributeValue(OffnetServiceKey key, long id) { var childConfig = OffnetServiceConfiguration.Get(key.Id, key.EffectiveDate); string value; foreach (var attribute in childConfig.Attributes) { if (attribute.Value.Name.Equals("UNI Reference ID")) { value = id.ToString(); key.AddAttribute(attribute.Value.Name, value); } } }
public string GetDefaultValue(string name, OffnetServiceKey sk) { Attributes.TryGetValue(name, out var ad); if (ad != null && !string.IsNullOrEmpty(ad.DefaultValue)) { try { if (ad.Type == AttributeType.Related) { return(sk.GetAttributeValue(ad.DefaultValue, SearchOptions.ALL_TRUE)); } var rule = ValueRuleParser.ParseRule(ad.DefaultValue); if (rule != null && !(rule is RuleValue)) { RuleValue value; string error; var rs = sk.ToValueHolder(); if (rule.TryGetValue(rs, SearchOptions.ALL_TRUE, out value, out error)) { return(value?.ToString()); } } } catch (Exception e) { return("Error getting default"); } if (ad.DefaultValue != null && ad.DefaultValue.StartsWith("'") && ad.DefaultValue.EndsWith("'")) { return(ad.DefaultValue.Substring(1, ad.DefaultValue.Length - 2)); } else if (ad.DefaultValue.Contains(".")) { return(sk.GetAttributeValue(ad.DefaultValue, SearchOptions.ALL_TRUE)); } else { return(ad.DefaultValue); } } return(null); }
public static void AddMissingDefaultAttributes(OffnetServiceKey key) { var childConfig = OffnetServiceConfiguration.Get(key.Id, key.EffectiveDate); string value; foreach (var attribute in childConfig.Attributes) { //if (attribute.Value.Type != AttributeType.List // && key.GetAttributeValue(attribute.Value.Name, SearchOptions.ALL_FALSE) == null // && !childConfig.IsOptional(attribute.Value.Name, key)) //{ value = childConfig.GetDefaultValue(attribute.Value.Name, key); if (value != null) { key.AddAttribute(attribute.Value.Name, value); } //} } }
public OffnetServiceKey Clone(bool downTree) { var key = new OffnetServiceKey(Id); foreach (var pair in Values) { key.AddValue(pair.Key, pair.Value); } key.EffectiveDate = EffectiveDate; key.ParentServiceKey = ((ParentServiceKey != null && !downTree) ? ParentServiceKey.Clone(false) : ParentServiceKey); if (downTree) { foreach (var child in Children) { key.Children.Add(child.Key, child.Value.Select(v => v.Clone(true)).ToList()); } } return(key); }
public static void AddMissingRelatedAttributes(OffnetServiceKey key) { //Relationships if needed }