public static AttributeValueWrapInt Create(IAttributeContainer container) { if (container == null) { return(null); } var attributeValueWrapInt = new AttributeValueWrapInt(); var containerType = container.GetType(); if (containerType == typeof(Task)) { attributeValueWrapInt.TaskId = container.Id; } if (containerType == typeof(WorkOrder)) { attributeValueWrapInt.WorkOrderId = container.Id; } if (containerType == typeof(ServiceOrder)) { attributeValueWrapInt.ServiceOrderId = container.Id; } return(attributeValueWrapInt); }
/// <summary> /// Gets the attribute value. /// </summary> /// <param name="instance">The instance.</param> /// <param name="propertyName">Name of the property.</param> /// <returns> /// The string value. Null if key does not exist /// </returns> public static string GetAttributeValue(this IAttributeContainer instance, [CallerMemberName] string propertyName = null) { var attributeName = instance.GetAttributeNameFor(propertyName); if (instance.ContainsAttributeFor(propertyName) == false) { return(null); } return(instance.Attributes[attributeName]); }
private bool ValidateResultCode(IAttributeContainer container) { if (ResultCodes == null || !ResultCodes.Any()) { throw new NotSupportedException("Attribute rule is of type that validates a resultcode, but the rule does not define any resultcodes"); } if (string.IsNullOrEmpty(container.FixCode)) { return(false); } return(ResultCodes.Contains(container.FixCode)); }
private AttributeValueWrapBool FindValueWrap(string code, IAttributeContainer container, AttributeGroup rootGroup) { //First try to locate the ValueWrap in the container var valueWrap = container.Attributes.FirstOrDefault(a => a.Code == code) as AttributeValueWrapBool; if (valueWrap == null) { //Otherwise check the spec's assigend ValueWrap (through Initialize) var spec = rootGroup.FindAttributeSpec(code) as AttributeSpecBool; if (spec == null || spec.ValueWrap == null) { throw new NotSupportedException(string.Format("Attribute rule contains operand {0} but has no Attribute with this code defined.", code)); } valueWrap = spec.ValueWrap as AttributeValueWrapBool; } return(valueWrap); }
/// <summary> /// Sets the attribute value. /// </summary> /// <param name="instance">The instance.</param> /// <param name="value">The value.</param> /// <param name="propertyName">Name of the property.</param> /// <returns> /// Sets the string value for the given property /// </returns> public static bool SetAttributeValue(this IAttributeContainer instance, string value, [CallerMemberName] string propertyName = null) { var attributeName = instance.GetAttributeNameFor(propertyName); var currentValue = instance.GetAttributeValue(propertyName); if (currentValue != null && value == null) { instance.Attributes.Remove(attributeName); instance.NotifyAttributeChangedFor(propertyName); return(true); } if (Equals(currentValue, value)) { return(false); } instance.Attributes[attributeName] = value; instance.NotifyAttributeChangedFor(propertyName); return(true); }
/// <summary> /// Adding common attributes /// </summary> /// <param name="container"></param> protected virtual void SetCustomAttributes(IAttributeContainer container) { }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="attributeContainer"></param> /// <param name="attributeName"></param> /// <returns></returns> public static T GetAttribute <T>(this IAttributeContainer attributeContainer, string attributeName) where T : Attribute { return(attributeContainer.GetAttributes <T>(attributeName).FirstOrDefault()); }
public void ApplyRule(IAttributeContainer container, AttributeGroup rootGroup) { if (Target == null) { throw new NotSupportedException("Attribute rule has no Target defined."); } if (ShowAt == null) { throw new NotSupportedException("Attribute rule has no ShowAt defined."); } Target.IsVisible = true; switch (RuleType) { case AttributeRuleType.ShowOnAllTrueWithResultCodes: Target.IsVisible = ValidateResultCode(container); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnAllTrue; } break; case AttributeRuleType.ShowOnAllTrueWithoutResultCodes: Target.IsVisible = string.IsNullOrEmpty(container.FixCode); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnAllTrue; } break; case AttributeRuleType.ShowOnAllTrue: foreach (var operand in Operands) { var attribute = FindValueWrap(operand, container, rootGroup); if ((!attribute.Value.HasValue) || attribute.Value == false) { Target.IsVisible = false; break; } } break; case AttributeRuleType.ShowOnAllFalseWithResultCodes: Target.IsVisible = string.IsNullOrEmpty(container.FixCode); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnAllFalse; } break; case AttributeRuleType.ShowOnAllFalseWithoutResultCodes: Target.IsVisible = ValidateResultCode(container); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnAllFalse; } break; case AttributeRuleType.ShowOnAllFalse: foreach (var operand in Operands) { var attribute = FindValueWrap(operand, container, rootGroup); if (attribute.Value.HasValue && attribute.Value == true) { Target.IsVisible = false; break; } } break; case AttributeRuleType.ShowOnOneTrueWithResultCodes: Target.IsVisible = ValidateResultCode(container); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnOneTrue; } break; case AttributeRuleType.ShowOnOneTrueWithoutResultCodes: Target.IsVisible = string.IsNullOrEmpty(container.FixCode); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnOneTrue; } break; case AttributeRuleType.ShowOnOneTrue: foreach (var operand in Operands) { var attribute = FindValueWrap(operand, container, rootGroup); if (attribute.Value.HasValue && attribute.Value == true) { break; } } Target.IsVisible = false; break; case AttributeRuleType.ShowOnOneFalseWithResultCodes: Target.IsVisible = ValidateResultCode(container); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnOneFalse; } break; case AttributeRuleType.ShowOnOneFalseWithoutResultCodes: Target.IsVisible = string.IsNullOrEmpty(container.FixCode); if (Target.IsVisible) { goto case AttributeRuleType.ShowOnOneFalse; } break; case AttributeRuleType.ShowOnOneFalse: foreach (var operand in Operands) { var attribute = FindValueWrap(operand, container, rootGroup); if (!attribute.Value.HasValue || attribute.Value == false) { break; } } Target.IsVisible = false; break; case AttributeRuleType.Expression: Target.IsVisible = true; //TODO: implement Expression break; } ShowAt.Refresh(); }
/// <summary> /// Gets the attribute name for the given property. /// </summary> /// <param name="instance">The instance.</param> /// <param name="propertyName">Name of the property.</param> /// <returns> /// The matching attribute name /// </returns> public static string GetAttributeNameFor(this IAttributeContainer instance, [CallerMemberName] string propertyName = null) { return(PropertyMaps[instance.GetType()][propertyName]); }
/// <summary> /// Determines whether [contains attribute for] [the specified property name]. /// </summary> /// <param name="instance">The instance.</param> /// <param name="propertyName">Name of the property.</param> /// <returns> /// <c>true</c> if [contains attribute for] [the specified property name]; otherwise, <c>false</c>. /// </returns> public static bool ContainsAttributeFor(this IAttributeContainer instance, [CallerMemberName] string propertyName = null) { var attributeName = instance.GetAttributeNameFor(propertyName); return(instance.Attributes.ContainsKey(attributeName)); }
/// <summary> /// Setting up common attributes to node /// </summary> /// <param name="container"></param> private void SetCommonAttributes(IAttributeContainer container) { SetCustomAttributes(container); }