protected override bool Execute(T ruleContext) { Assert.ArgumentNotNull(ruleContext, nameof(ruleContext)); // Get passed method and property var deviceItem = Sitecore.Context.Database.GetItem(DeviceId); var methodItem = Sitecore.Context.Database.GetItem(MethodId); var propertyItem = Sitecore.Context.Database.GetItem(PropertyId); Assert.ArgumentNotNull(deviceItem, $"deviceItem.ID='{DeviceId}'"); Assert.ArgumentNotNull(methodItem, $"methodItem.ID='{MethodId}'"); Assert.ArgumentNotNull(propertyItem, $"propertyItem.ID='{PropertyId}'"); var device = _hubRepository.CastToDevice(deviceItem); var method = _hubRepository.CastToMethod(methodItem); var property = _hubRepository.CastToMessageProperty(propertyItem); // Call method and receive results var parsedResults = method.Invoke(device, Payload); var dynamicValue = property.GetValue(parsedResults); var parsedValue = dynamicValue == null ? string.Empty : dynamicValue.ToString(); // Compare values var comparisonResult = Compare(parsedValue, Value); return(comparisonResult); }
protected override bool Execute(T ruleContext) { Assert.ArgumentNotNull(ruleContext, nameof(ruleContext)); // Get passed method and property var deviceItem = Sitecore.Context.Database.GetItem(DeviceId); var methodItem = Sitecore.Context.Database.GetItem(MethodId); var propertyItem = Sitecore.Context.Database.GetItem(PropertyId); Assert.ArgumentNotNull(deviceItem, $"deviceItem.ID='{DeviceId}'"); Assert.ArgumentNotNull(methodItem, $"methodItem.ID='{MethodId}'"); Assert.ArgumentNotNull(propertyItem, $"propertyItem.ID='{PropertyId}'"); var device = _hubRepository.CastToDevice(deviceItem); var method = _hubRepository.CastToMethod(methodItem); var property = _hubRepository.CastToMessageProperty(propertyItem); // Call method and receive results var parsedResults = method.Invoke(device, Payload); var dynamicValue = property.GetValue(parsedResults); var parsedValue = dynamicValue == null ? 0 : (double)dynamicValue; // Compare values var comparisonResult = false; switch (this.GetOperator()) { case ConditionOperator.Equal: comparisonResult = parsedValue == Value; break; case ConditionOperator.GreaterThanOrEqual: comparisonResult = parsedValue >= Value; break; case ConditionOperator.GreaterThan: comparisonResult = parsedValue > Value; break; case ConditionOperator.LessThanOrEqual: comparisonResult = parsedValue <= Value; break; case ConditionOperator.LessThan: comparisonResult = parsedValue < Value; break; case ConditionOperator.NotEqual: comparisonResult = parsedValue != Value; break; default: comparisonResult = false; break; } return(comparisonResult); }