Esempio n. 1
0
        public PageFactory WithInput(string id, string name, string value, EInputType type = EInputType.Text)
        {
            var iv = new InputView(id, name, value, type);

            Page.AddView(iv);
            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Add a view change to the page
        /// <para>
        /// Used to log value changes for views on settings pages.  All names are left blank
        /// </para>
        /// </summary>
        /// <param name="id">The id of the view</param>
        /// <param name="type">The EViewType of the view</param>
        /// <param name="value">The new value for the view</param>
        /// <exception cref="ArgumentNullException">A valid ID was not specified</exception>
        /// <exception cref="ArgumentOutOfRangeException">The type or integer value is invalid</exception>
        /// <exception cref="ArgumentException">The value type doesn't match the view type</exception>
        public void AddViewDelta(string id, int type, object value)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id), "ID cannot be blank");
            }

            if (type < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            AbstractView view = null;

            switch (value)
            {
            case string valueString:
                if (type == (int)EViewType.SelectList)
                {
                    try {
                        var intValue = int.Parse(valueString);
                        if (intValue < 0)
                        {
                            throw new ArgumentOutOfRangeException(nameof(value), "Selection index must be greater than or equal to 0.");
                        }
                        var selectListOptions = new List <string>();
                        for (var i = 0; i <= intValue; i++)
                        {
                            selectListOptions.Add(i.ToString());
                        }
                        view = new SelectListView(id, id, selectListOptions, ESelectListType.DropDown, intValue);
                        break;
                    }
                    catch (Exception exception) {
                        throw new ArgumentException("Value type does not match the view type", exception);
                    }
                }

                if (type != (int)EViewType.Input)
                {
                    if (!bool.TryParse(valueString, out var boolValue))
                    {
                        throw new ArgumentException("The view type does not match the value type");
                    }

                    if (type != (int)EViewType.Toggle)
                    {
                        throw new ArgumentException("The view type does not match the value type");
                    }

                    view = new ToggleView(id, id, boolValue);
                    break;
                }

                view = new InputView(id, id, valueString);
                break;

            case int valueInt:

                if (type != (int)EViewType.SelectList)
                {
                    throw new ArgumentException("The view type does not match the value type");
                }

                if (valueInt < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), "Selection index must be greater than or equal to 0.");
                }

                var options = new List <string>();
                for (var i = 0; i <= valueInt; i++)
                {
                    options.Add(i.ToString());
                }

                view = new SelectListView(id, id, options, ESelectListType.DropDown, valueInt);
                break;

            case bool valueBool:
                if (type != (int)EViewType.Toggle)
                {
                    throw new ArgumentException("The view type does not match the value type");
                }

                view = new ToggleView(id, id, valueBool);
                break;
            }

            if (view == null)
            {
                throw new ArgumentException("Unable to build a view from the data provided");
            }

            AddView(view);
        }