Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
 public List <IoTDeviceMethod> GetMethods()
 {
     return(InnerItem.Children.Where(p => p.TemplateID == IoTDeviceMethod.TemplateID)
            .Select(p => _ioTHubRepository.CastToMethod(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(IoTMessageProperty.TemplateID.ToString());

            // Get Method Item
            var methodId = element.Attribute("MethodId")?.Value;

            if (string.IsNullOrEmpty(methodId))
            {
                SheerResponse.Alert("Please select a valid IoT Method");
                return;
            }
            var methodItem = Context.ContentDatabase.GetItem(methodId);

            if (methodItem == null)
            {
                SheerResponse.Alert("Please select a valid IoT Method");
                return;
            }
            var method = _ioTHubRepository.CastToMethod(methodItem);

            // Get Return Type item
            var returnTypeField = method.ReturnType;

            if (returnTypeField?.TargetItem == null)
            {
                SheerResponse.Alert($"The IoT Method item {methodItem.ID} has an invalid value in the 'Return Type' field");
                return;
            }
            var returnType = _ioTHubRepository.CastToMessageType(returnTypeField.TargetItem);

            // Selected Item
            Item propertyItem = null;

            if (!string.IsNullOrEmpty(value))
            {
                propertyItem = Context.ContentDatabase.GetItem(value);
            }

            // Setup component state
            selectItemOptions.Root         = returnType.InnerItem;
            selectItemOptions.SelectedItem = propertyItem;
            selectItemOptions.Title        = "Select Property";
            selectItemOptions.Text         = "Select the property 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);
        }