private static TriggerParameters BindParameters(TriggerParameters triggerParameters, TriggerParameter[] parameters) { var properties = triggerParameters.GetType().GetTypeCache().Properties; foreach (var parameter in parameters) { var name = parameter.Property.ToString(); var propertyCache = properties.FirstOrDefault(p => p.Property.Name == name); if (propertyCache == null) { throw new InvalidOperationException($"Property '{name}' is not a valid property for a trigger of type '{triggerParameters.Type}'."); } var v = parameter.Value; v = TryInvokeTypeParser(parameter.Property, v, triggerParameters); var parser = new Helpers.DynamicPropertyTypeParser(parameter.Property, propertyCache, v); var value = parser.DeserializeValue(); propertyCache.SetValue(triggerParameters, value); } return(triggerParameters); }
void AddValue(DynamicPropertyTypeParser parser) { var parameter = parser.GetParameter(nameResolver); container.AddParameter(parameter); var secondaryPropertyAttrib = parser.Property.GetEnumAttribute <SecondaryPropertyAttribute>(); if (secondaryPropertyAttrib != null) { var secondaryPropertyName = $"{secondaryPropertyAttrib.Property.ToString().ToLower()}_"; switch (secondaryPropertyAttrib.Strategy) { case SecondaryPropertyStrategy.MultipleSerializable: if (parser.Value is IMultipleSerializable) { var val2 = ((IMultipleSerializable)parser.Value).GetSerializedFormats().Last(); container.AddParameter(new CustomParameter(secondaryPropertyName, val2)); } break; case SecondaryPropertyStrategy.SameValue: container.AddParameter(new CustomParameter(secondaryPropertyName, parameter.Value)); break; default: throw new NotImplementedException($"Don't know how to handle {nameof(SecondaryPropertyStrategy)} '{secondaryPropertyAttrib.Strategy}'."); } } }
internal void ParseValueAndDependents <T>(Enum property, object value, bool disableDependentsOnNotReqiuiredValue) { var cache = cacheResolver.GetPropertyCache(property); var parser = new DynamicPropertyTypeParser(property, cache, value); AddValue(parser); AddDependents <T>(parser, disableDependentsOnNotReqiuiredValue); }
internal void AddDependentProperty(object val, Enum parent) { var cache = cacheResolver.GetPropertyCache(parent); var dependencyParser = new DynamicPropertyTypeParser(parent, cache, val); var parameter = dependencyParser.GetParameter(nameResolver); container.AddParameter(parameter); }
internal void AddDependentProperty(object val, Enum parent) { var cache = cacheResolver.GetPropertyCache(parent); var dependencyParser = new DynamicPropertyTypeParser(parent, cache, val); var parameter = dependencyParser.GetParameter(nameResolver); //If there is already an existing value (i.e. from the parameter being specified explicitly) don't set the dependency if (!ParameterExists(parameter)) { container.AddParameter(parameter); } }
void AddDependents <T>(DynamicPropertyTypeParser parser, bool disableDependentsOnNotReqiuiredValue) { var childrenOfParent = parser.Property.GetDependentProperties(); bool isParent = childrenOfParent.Any(); AddDependentPropertyRecursiveUp <T>(parser.Property); if (isParent) { TryDisableDependentProperties(parser, disableDependentsOnNotReqiuiredValue, childrenOfParent); } }
private void TryDisableDependentProperties(DynamicPropertyTypeParser parser, bool disableDependentsOnNotReqiuiredValue, Enum[] childrenOfParent) { //If we reach this method, we know that our property is a parent if (parser != null) { TryDisableDependentPropertiesWithTypeCheck(parser, disableDependentsOnNotReqiuiredValue, childrenOfParent); } else { TryDisableDependentPropertiesWithoutTypeCheck(childrenOfParent); } }
void AddValue(DynamicPropertyTypeParser parser) { var parameter = parser.GetParameter(nameResolver); container.AddParameter(parameter); var secondaryPropertyAttrib = parser.Property.GetEnumAttribute <SecondaryPropertyAttribute>(); if (secondaryPropertyAttrib != null) { if (parser.Value is IMultipleSerializable) { var val2 = ((IMultipleSerializable)parser.Value).GetSerializedFormats().Last(); container.AddParameter(new CustomParameter($"{secondaryPropertyAttrib.Property}_", val2)); } } }
private void TryDisableDependentPropertiesWithTypeCheck(DynamicPropertyTypeParser parser, bool disableDependentsOnNotReqiuiredValue, Enum[] childrenOfParent) { var parentValueAsTypeRequiredByProperty = parser.ToPrimitivePropertyType(); foreach (var child in childrenOfParent) { var attrib = child.GetEnumAttribute <DependentPropertyAttribute>(); //By virtue of the fact we're a child, we can guarantee we have a DependentPropertyAttribute var propertyRequiredValue = attrib.RequiredValue; if (propertyRequiredValue != null && propertyRequiredValue.GetType() != parentValueAsTypeRequiredByProperty.GetType()) { throw new InvalidTypeException($"Dependencies of property '{parser.Property}' should be of type {parser.PropertyType}, however property '{child}' is dependent on type '{propertyRequiredValue.GetType()}'."); } if (parentValueAsTypeRequiredByProperty.Equals(propertyRequiredValue)) // == does not work since we are potentially comparing value types wrapped as type object { //If a child has a reverse dependency (e.g. VerticalAxisMin must be included when VerticalAxisScaling == Manual) //Then we should include those children, where they will be set to empty causing PRTG to throw an exception if (attrib.ReverseDependency) { AddParameterIfNotSet(child, cacheResolver.GetPropertyCache(child), string.Empty); var newChildren = child.GetDependentProperties(); TryDisableDependentProperties(null, disableDependentsOnNotReqiuiredValue, newChildren); } } else { //If we wish to disable dependents when their parent value does not match their required value, add and assign them an empty value if (disableDependentsOnNotReqiuiredValue) { AddParameterIfNotSet(child, cacheResolver.GetPropertyCache(child), string.Empty); var newChildren = child.GetDependentProperties(); TryDisableDependentProperties(null, disableDependentsOnNotReqiuiredValue, newChildren); } } } }
public TypeConversionStateMachine(DynamicPropertyTypeParser parser, SerializationMode mode) { this.parser = parser; this.Mode = mode; }