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); }
/// <summary> /// Get all devices at the current Hub /// </summary> /// <returns></returns> public List <IoTDevice> GetDevices() { return(InnerItem.Children.Where(p => p.TemplateID == IoTDevice.TemplateID) .Select(p => _ioTHubRepository.CastToDevice(p)).ToList()); }
public void Execute(XElement element, string name, UrlString parameters, string value) { // Param validations Condition.Requires(element, nameof(element)).IsNotNull(); Condition.Requires(name, nameof(name)).IsNotNull(); Condition.Requires(parameters, nameof(parameters)).IsNotNull(); Condition.Requires(value, nameof(value)).IsNotNull(); var selectItemOptions = new SelectItemOptions(); // Rule Condition item var path = XElement.Parse(element.ToString()).FirstAttribute.Value; if (!string.IsNullOrEmpty(path)) { var ruleConditionItem = Context.ContentDatabase.GetItem(path); if (ruleConditionItem != null) { selectItemOptions.FilterItem = ruleConditionItem; } } // Filter templates selectItemOptions.ShowRoot = false; selectItemOptions.IncludeTemplatesForSelection = SelectItemOptions.GetTemplateList(IoTDeviceMethod.TemplateID.ToString()); // Get Device Item var deviceId = element.Attribute("DeviceId")?.Value; if (string.IsNullOrEmpty(deviceId)) { SheerResponse.Alert("Please select a valid IoT Device"); return; } var deviceItem = Context.ContentDatabase.GetItem(deviceId); if (deviceItem == null) { SheerResponse.Alert("Please select a valid IoT Device"); return; } var device = _ioTHubRepository.CastToDevice(deviceItem); // Get Device Type item var deviceTypeField = device.DeviceType; if (deviceTypeField?.TargetItem == null) { SheerResponse.Alert($"The IoT Device item {deviceItem.ID} has an invalid value in the 'Device Type' field"); return; } var deviceType = _ioTHubRepository.CastToDeviceType(deviceTypeField.TargetItem); // Selected Item Item methodItem = null; if (!string.IsNullOrEmpty(value)) { methodItem = Context.ContentDatabase.GetItem(value); } // Setup component state selectItemOptions.Root = deviceType.InnerItem; selectItemOptions.SelectedItem = methodItem; selectItemOptions.Title = "Select IoT Method"; selectItemOptions.Text = "Select the IoT Method to use in this rule."; selectItemOptions.Icon = "/~/icon/office/32x32/password_field.png"; var parameter = parameters["resulttype"]; if (!string.IsNullOrEmpty(parameter)) { selectItemOptions.ResultType = (SelectItemOptions.DialogResultType)Enum.Parse(typeof(SelectItemOptions.DialogResultType), parameter); } SheerResponse.ShowModalDialog(selectItemOptions.ToUrlString().ToString(), "1200px", "700px", string.Empty, true); }