Exemple #1
0
 protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
 {
     result = new Inputs.Text();
     input.SetInputProperty(result);
     result.Init(input.PropertyContent, input.Name, input.Value, null);
     return(true);
 }
Exemple #2
0
        protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
        {
            if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(byte)))
            {
                result = new Inputs.Integer();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(short)))
            {
                result = new Inputs.Integer();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(uint)))
            {
                result = new Inputs.Integer();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(ulong)))
            {
                result = new Inputs.Integer();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(int)))
            {
                result = new Inputs.Integer();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(long)))
            {
                result = new Inputs.Integer();
            }
            if (result == null)
            {
                return(false);
            }

            input.SetInputProperty(result);
            result.Init(input.PropertyContent, input.Name, input.Value, null);
            return(true);
        }
Exemple #3
0
        internal async Task <object> HandleGet(HandlerParameter handler, string deviceId)
        {
            if (DeviceIsInvalid(handler, deviceId))
            {
                _logger.LogDebug($"RequestHandler | handlerget failed for {deviceId}");
                throw new NEEOException("INVALID_GET_PARAMETER");
            }
            _logger.LogDebug($"RequestHandler | process get request for {deviceId}");

            object result = null;

            switch (handler.ComponentType)
            {
            case ComponentType.TYPE_BUTTON:
            case ComponentType.TYPE_TEXTLABEL:
            case ComponentType.TYPE_IMAGEURL:
            case ComponentType.TYPE_SENSOR:
            case ComponentType.TYPE_SLIDER:
            case ComponentType.TYPE_SWITCH:
                NEEOGetFunc handlerFunction = handler.Controller.Getter;
                if (handlerFunction != null)
                {
                    result = await handlerFunction(deviceId);
                }
                break;

            default:
                _logger.LogWarning($"RequestHandler | INVALID_GET_COMPONENT { handler.ComponentType }");
                break;
            }
            _logger.LogDebug($"RequestHandler | process get request for {deviceId} : {result}");
            return(result);
        }
Exemple #4
0
        protected override bool Request(HandlerParameter input, ref IFormInput result)
        {
            var content = input.PropertyContent;
            var type    = content.Property.PropertyType;

            if (type.IsGenericType && type.GetInterfaces().Contains(typeof(IEnumerable)))
            {
                var itemType = type.GetGenericArguments()[0];
                if (itemType.IsEnum)
                {
                    result = new Inputs.CheckBoxList();
                    input.SetInputProperty(result);
                    result.Init(content, input.Name, input.Value, Util.EnumProvider.Instance.GetDataItems(itemType, input.Source.GetCanNull(input.Name)));
                    return(true);
                }
                else if (ItemHandlers.TryGetValue(itemType, out Func <HandlerParameter, ModelPropertyContent, IFormInput> deal))
                {
                    result = deal(input, content);
                    return(true);
                }
                else if (!itemType.IsClass)
                {
                    result = new Inputs.CheckBoxList();
                    input.SetInputProperty(result);
                    result.Init(content, input.Name, input.Value, input.Source.Get(input.Name));
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        private static IFormInput DealString(HandlerParameter input, ModelPropertyContent content)
        {
            var result = new Inputs.MultiSelect();

            input.SetInputProperty(result);
            result.Init(content, input.Name, input.Value, input.Source.Get(input.Name));
            return(result);
        }
Exemple #6
0
        private static IFormInput DealFile(HandlerParameter input, ModelPropertyContent content)
        {
            var result = new FormInputCreator.Inputs.MultiFile();

            input.SetInputProperty(result);
            result.Init(content, input.Name, input.Value, null);
            return(result);
        }
Exemple #7
0
        internal async Task <NEEODiscoveredDevice[]> Discover(HandlerParameter handler)
        {
            if (handler == null || handler.Controller == null || handler.Controller.Discover == null)
            {
                throw new NEEOException("INVALID_DISCOVER_PARAMETER");
            }
            var devices = await handler.Controller.Discover();

            return(devices);
        }
Exemple #8
0
 protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
 {
     if (input.PropertyContent.DataType == System.ComponentModel.DataAnnotations.DataType.Time)
     {
         result = new Inputs.Time();
         input.SetInputProperty(result);
         result.Init(input.PropertyContent, input.Name, input.Value, null);
         return(true);
     }
     return(false);
 }
 protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
 {
     if (input.Source.Contains(input.Name))
     {
         result = new Inputs.Select();
         input.SetInputProperty(result);
         result.Init(input.PropertyContent, input.Name, input.Value, input.Source.Get(input.Name));
         return(true);
     }
     return(false);
 }
Exemple #10
0
 protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
 {
     if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(bool)))
     {
         result = new Inputs.Bool();
         input.SetInputProperty(result);
         result.Init(input.PropertyContent, input.Name, input.Value, null);
         return(true);
     }
     return(false);
 }
Exemple #11
0
        protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
        {
            var type = typeof(System.Web.HttpPostedFileBase);

            if (input.PropertyContent.Property.PropertyType == type ||
                input.PropertyContent.Property.PropertyType.IsSubclassOf(type))
            {
                result = new Inputs.File();
                input.SetInputProperty(result);
                result.Init(input.PropertyContent, input.Name, input.Value, null);
                return(true);
            }
            return(false);
        }
Exemple #12
0
        internal async Task <bool> HandleSet(HandlerParameter handler, string deviceId, string value)
        {
            if (DeviceIsInvalid(handler, deviceId))
            {
                _logger.LogError($"RequestHandler | handlerset failed for {deviceId}");
                throw new NEEOException("INVALID_GET_PARAMETER");
            }
            NEEOSetFunc handlerFunction;

            _logger.LogDebug($"RequestHandler | process set request for {deviceId}");

            bool result = false;

            switch (handler.ComponentType)
            {
            case ComponentType.TYPE_SLIDER:
                handlerFunction = handler.Controller.Setter;
                if (handlerFunction != null)
                {
                    result = true;
                    double dval;
                    if (value.GetType() == typeof(string) && value.ToString().IndexOf(',') >= 0)
                    {
                        dval = Convert.ToDouble(value);
                    }
                    else
                    {
                        dval = Convert.ToDouble(value, CultureInfo.InvariantCulture);
                    }
                    await handlerFunction(deviceId, dval);
                }
                break;

            case ComponentType.TYPE_SWITCH:
                handlerFunction = handler.Controller.Setter;
                if (handlerFunction != null)
                {
                    result = true;
                    await handlerFunction(deviceId, Convert.ToBoolean(value));
                }
                break;

            default:
                _logger.LogWarning($"RequestHandler | INVALID_SET_COMPONENT { handler.ComponentType }");
                break;
            }
            return(result);
        }
        protected override bool Request(HandlerParameter input, ref IFormInput result)
        {
            var customInput = input.PropertyContent.Attributes.Get <Annotations.CustomInputAttribute>();

            if (customInput == null)
            {
                return(false);
            }

            var customer = Activator.CreateInstance(customInput.InputType) as ICustomInput;

            customer.Set(customInput.Parameter);

            result = customer;
            input.SetInputProperty(result);
            var options = Util.EnumProvider.Instance.GetDataItems(input.PropertyContent.Property.PropertyType, input.Source.GetCanNull(input.Name));

            result.Init(input.PropertyContent, input.Name, input.Value, options);
            return(true);
        }
Exemple #14
0
        protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
        {
            var content = input.PropertyContent;
            var type    = content.Property.PropertyType;

            if (type.IsEnum)
            {
                result = new Inputs.RadioList();
                input.SetInputProperty(result);
                result.Init(content, input.Name, input.Value, input.Source.Contains(input.Name) ? input.Source.Get(input.Name) : Util.EnumProvider.Instance.GetDataItems(type));
                return(true);
            }
            else if (Util.EnumProvider.IsNullableEnum(type))
            {
                result = new Inputs.RadioList();
                input.SetInputProperty(result);
                result.Init(content, input.Name, input.Value, input.Source.Contains(input.Name) ? input.Source.Get(input.Name) : Util.EnumProvider.Instance.GetDataItems(type.GenericTypeArguments[0]));
                return(true);
            }
            return(false);
        }
            public static HandlerMethod Create(MethodInfo method)
            {
                var methodParameters = method.GetParameters();
                var parameters       = new HandlerParameter[methodParameters.Length];

                for (var i = 0; i < methodParameters.Length; i++)
                {
                    parameters[i] = new HandlerParameter()
                    {
                        DefaultValue = methodParameters[i].HasDefaultValue ? methodParameters[i].DefaultValue : null,
                        Name         = methodParameters[i].Name,
                        Type         = methodParameters[i].ParameterType,
                    };
                }

                if (method.ReturnType == typeof(Task))
                {
                    return(new NonGenericTaskHandlerMethod(parameters, method));
                }
                else if (method.ReturnType == typeof(void))
                {
                    return(new VoidHandlerMethod(parameters, method));
                }
                else if (
                    method.ReturnType.IsConstructedGenericType &&
                    method.ReturnType.GetTypeInfo().GetGenericTypeDefinition() == typeof(Task <>) &&
                    typeof(IActionResult).IsAssignableFrom(method.ReturnType.GetTypeInfo().GetGenericArguments()[0]))
                {
                    return(new GenericTaskHandlerMethod(parameters, method));
                }
                else if (typeof(IActionResult).IsAssignableFrom(method.ReturnType))
                {
                    return(new ActionResultHandlerMethod(parameters, method));
                }
                else
                {
                    throw new InvalidOperationException("unsupported handler method return type");
                }
            }
Exemple #16
0
        protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
        {
            if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(float)))
            {
                result = new Inputs.Numeric();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(double)))
            {
                result = new Inputs.Numeric();
            }
            else if (ModelPropertyContent.IsType(input.PropertyContent.Property.PropertyType, typeof(decimal)))
            {
                result = new Inputs.Numeric();
            }
            if (result == null)
            {
                return(false);
            }

            input.SetInputProperty(result);
            result.Init(input.PropertyContent, input.Name, input.Value, null);
            return(true);
        }
Exemple #17
0
 protected override bool Request(HandlerParameter input, ref Input.IFormInput result)
 {
     return(false);
 }
 public async Task <object> DeviceGetValue(HandlerParameter handler, string deviceId)
 {
     return(await _requestHandler.HandleGet(handler, deviceId));
 }
Exemple #19
0
 private bool DeviceIsInvalid(HandlerParameter handler, string deviceId)
 {
     return(deviceId == null || handler == null || handler.ComponentType == ComponentType.TYPE_UNKNOWN || handler.Controller == null);
 }