コード例 #1
0
		/// <inheritdoc cref="AbstractView.Update"/>
		/// <summary>
		/// Update the view to the new state.  This will change the enabled state
		/// </summary>
		/// <exception cref="ViewTypeMismatchException">Thrown when the new view's class doesn't match the calling view</exception>
		public override void Update(AbstractView newViewState) {
			base.Update(newViewState);
			
			if (!(newViewState is ToggleView updatedToggleView)) {
				throw new ViewTypeMismatchException("The original view type does not match the type in the update");
			}

			IsEnabled = updatedToggleView.IsEnabled;
		}
コード例 #2
0
        /// <inheritdoc cref="AbstractView.Update"/>
        /// <summary>
        /// Update the view to the new state.  This will change the selected option
        /// </summary>
        /// <exception cref="ViewTypeMismatchException">Thrown when the new view's class doesn't match the calling view</exception>
        public override void Update(AbstractView newViewState)
        {
            base.Update(newViewState);

            if (!(newViewState is SelectListView updatedSelectListView))
            {
                throw new ViewTypeMismatchException("The original view type does not match the type in the update");
            }

            Selection = updatedSelectListView.Selection;
        }
コード例 #3
0
        /// <summary>
        /// Add a view to a collection
        /// </summary>
        /// <param name="view">The view to add to the collection</param>
        /// <param name="viewList">A reference to the current list of views</param>
        /// <param name="viewIds">A reference to the map of view IDs and list indexes</param>
        /// <param name="toGroup">If the collection the view is being added it is a ViewGroup. DEFAULT: false for a Page</param>
        /// <exception cref="ArgumentNullException">The view or its ID is null</exception>
        /// <exception cref="ArgumentException">There is already a view with the same ID present in the collection</exception>
        /// <exception cref="InvalidOperationException">Thrown when trying to add a ViewGroup to another ViewGroup</exception>
        /// <exception cref="ViewTypeMismatchException">Thrown when a view group's type does not match its class</exception>
        internal static void AddView(AbstractView view,
                                     ref List <AbstractView> viewList,
                                     ref Dictionary <string, int> viewIds,
                                     bool toGroup = false)
        {
            if (viewList == null)
            {
                viewList = new List <AbstractView>();
                viewIds  = new Dictionary <string, int>();
            }

            if (view?.Id == null)
            {
                throw new ArgumentNullException(nameof(view), "The view or its ID is null");
            }

            if (viewIds.ContainsKey(view.Id))
            {
                throw new ArgumentException("A view with that ID already exists in the collection");
            }

            var viewIndex = viewList.Count;

            if (view.Type == EViewType.Group)
            {
                if (toGroup)
                {
                    throw new InvalidOperationException("View groups cannot be nested");
                }

                if (!(view is ViewGroup viewGroup))
                {
                    throw new ViewTypeMismatchException();
                }

                //Add all of the view group's view IDs to the map of view IDs pointing to the view group
                // so any update or get calls are funneled through the group
                foreach (var viewGroupView in viewGroup.Views)
                {
                    viewIds.Add(viewGroupView.Id, viewIndex);
                }
            }

            viewList.Add(view);
            viewIds.Add(view.Id, viewIndex);
        }
コード例 #4
0
        /// <summary>
        /// Update the the user editable properties from a new version of the same view
        /// </summary>
        /// <param name="newViewState">
        /// The new state of the view being updated.
        /// This view's ID and Type must match the calling view exactly
        /// </param>
        /// <exception cref="ArgumentNullException">Thrown when the new state of the view is null</exception>
        /// <exception cref="InvalidOperationException">Thrown when the new view's ID or Type don't match the calling view</exception>
        public virtual void Update(AbstractView newViewState)
        {
            if (newViewState == null)
            {
                throw new ArgumentNullException(nameof(newViewState));
            }

            if (newViewState.Id != Id)
            {
                throw new InvalidOperationException("The ID of the update does not match the ID of the original view");
            }

            if (newViewState.Type != Type)
            {
                throw new InvalidOperationException("The original view type does not match the type in the update");
            }
        }
コード例 #5
0
        /// <summary>
        /// Perform a soft update to a view in a collection with a particular ID
        /// </summary>
        /// <param name="view">The new state of the view to update</param>
        /// <param name="viewList">A reference to the current list of views</param>
        /// <param name="viewIds">A reference to the map of view IDs and list indexes</param>
        /// <exception cref="ArgumentNullException">The viewId to look for is NULL</exception>
        /// <exception cref="IndexOutOfRangeException">The ID was found, but the view is not in the collection</exception>
        /// <exception cref="ArgumentException">There are no views in the collection</exception>
        /// <exception cref="ViewNotFoundException">No views with that ID were found in the collection</exception>
        internal static void UpdateViewById(AbstractView view,
                                            ref List <AbstractView> viewList,
                                            ref Dictionary <string, int> viewIds)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            if (viewList == null || viewList.Count == 0)
            {
                throw new ArgumentException("There are no views in this collection");
            }

            try {
                var viewIndex = viewIds[view.Id];
                if (viewIndex >= viewList.Count)
                {
                    throw new IndexOutOfRangeException("That ID points to a view that does not exist in the collection.");
                }

                var foundView = viewList[viewIndex];
                if (foundView.Id == view.Id)
                {
                    foundView.Update(view);
                    return;
                }

                if (foundView.Type == EViewType.Group)
                {
                    if (!(foundView is ViewGroup viewGroup))
                    {
                        throw new ViewTypeMismatchException();
                    }

                    viewGroup.UpdateViewById(view);
                    return;
                }
            }
            catch (KeyNotFoundException exception) {
                throw new ViewNotFoundException("There are no views with that ID in the collection", exception);
            }

            throw new ViewNotFoundException("There are no views with that ID in the collection");
        }
コード例 #6
0
ファイル: InputView.cs プロジェクト: sjhill01/Plugin-SDK
        /// <inheritdoc cref="AbstractView.Update"/>
        /// <summary>
        /// Update the view to the new state.  This will change the inputted value
        /// </summary>
        /// <exception cref="ViewTypeMismatchException">Thrown when the new view's class doesn't match the calling view</exception>
        /// <exception cref="InvalidValueForTypeException">Thrown when the value is invalid for the input type</exception>
        public override void Update(AbstractView newViewState)
        {
            base.Update(newViewState);

            if (!(newViewState is InputView updatedInputView))
            {
                throw new ViewTypeMismatchException("The original view type does not match the type in the update");
            }

            // Removing until we figure out how to handle input types in view changes from HTML -JLW

            /*if (updatedInputView.InputType != InputType) {
             *      throw new InvalidOperationException("The original view type does not match the type in the update");
             * }*/

            if (!IsValueValidForType(updatedInputView.Value))
            {
                throw new InvalidValueForTypeException("The new value is invalid for the input type");
            }

            Value = updatedInputView.Value;
        }
コード例 #7
0
ファイル: Page.cs プロジェクト: sjhill01/Plugin-SDK
        /// <summary>
        /// Get a string representation of this page converted into HTML
        /// </summary>
        /// <returns>An HTML representation of the page as a string</returns>
        public string ToHtml(int indent = 0)
        {
            var sb = new StringBuilder();

            //Open the containing div
            sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            sb.Append($"<div class=\"container jui-page\" pageid=\"{Id}\">");
            sb.Append(Environment.NewLine);
            indent++;
            //sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            //sb.Append($"<input type=\"hidden\" class=\"jui-page\" pageid=\"{Id}\" >");
            //Add all of the child views
            foreach (var view in _views)
            {
                sb.Append(view.ToHtml(indent));
            }
            sb.Append(Environment.NewLine);
            indent--;
            sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            sb.Append("</div>");
            sb.Append(Environment.NewLine);

            return(sb.ToString());
        }
コード例 #8
0
 public PageFactory WithView(AbstractView view)
 {
     Page.AddView(view);
     return(this);
 }
コード例 #9
0
ファイル: Page.cs プロジェクト: sjhill01/Plugin-SDK
            public static string PageListToHtml(List <string> jsonPages, int selectedPage = 0)
            {
                if (jsonPages == null)
                {
                    throw new ArgumentNullException(nameof(jsonPages));
                }

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (jsonPages.Count)
                {
                case 0:
                    throw new ArgumentException("There are no pages to convert to HTML");

                case 1: {
                    var page = FromJsonString(jsonPages[0]);
                    return(page.ToHtml());
                }
                }

                var pages = jsonPages.Select(FromJsonString).ToList();

                var sb     = new StringBuilder();
                var indent = 0;

                //Open the tablist
                sb.Append("<ul class=\"nav nav-tabs hs-tabs\" role=\"tablist\">");
                sb.Append(Environment.NewLine);
                indent++;
                //Add tabs
                var pageIndex = -1;

                foreach (var page in pages)
                {
                    pageIndex++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open nav item
                    sb.Append("<li class=\"nav-item\">");
                    sb.Append(Environment.NewLine);
                    indent++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open anchor
                    sb.Append("<a class=\"nav-link waves-light\" id=\"");
                    sb.Append(page.Id);
                    sb.Append(".tab\" data-toggle=\"tab\" href=\"#");
                    sb.Append(page.Id);
                    sb.Append("\" role=\"tab\" aria-controls=\"");
                    sb.Append(page.Id);
                    sb.Append("\" aria-selected=\"");
                    sb.Append(pageIndex == selectedPage ? "true" : "false");
                    sb.Append("\">");
                    sb.Append(page.Name);
                    //Close anchor
                    sb.Append("</a>");
                    sb.Append(Environment.NewLine);
                    indent--;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Close nav item
                    sb.Append("</li>");
                    sb.Append(Environment.NewLine);
                }

                //Close the tablist
                sb.Append("</ul>");
                sb.Append(Environment.NewLine);
                //Open the content div
                sb.Append("<div class=\"tab-content container\">");
                sb.Append(Environment.NewLine);
                pageIndex = -1;
                //Add the tab content divs
                foreach (var page in pages)
                {
                    pageIndex++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open the tab pane div
                    sb.Append("<div class=\"tab-pane fade");
                    if (pageIndex == 0)
                    {
                        sb.Append(" active show");
                    }
                    sb.Append("\" role=\"tabpanel\" aria-labelledby=\"");
                    sb.Append(page.Id);
                    sb.Append(".tab\" id=\"");
                    sb.Append(page.Id);
                    sb.Append("\">");
                    sb.Append(Environment.NewLine);
                    indent++;
                    //Add the page content
                    sb.Append(page.ToHtml(indent));
                    indent--;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Close the tab content div
                    sb.Append("</div>");
                    sb.Append(Environment.NewLine);
                }
                //Close the content div
                sb.Append("</div>");

                return(sb.ToString());
            }
コード例 #10
0
ファイル: Page.cs プロジェクト: sjhill01/Plugin-SDK
 /// <inheritdoc cref="ViewCollectionHelper.UpdateViewById"/>
 public void UpdateViewById(AbstractView view)
 {
     ViewCollectionHelper.UpdateViewById(view, ref _views, ref _viewIds);
 }
コード例 #11
0
ファイル: Page.cs プロジェクト: sjhill01/Plugin-SDK
        /// <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);
        }
コード例 #12
0
ファイル: Page.cs プロジェクト: sjhill01/Plugin-SDK
 /// <inheritdoc cref="ViewCollectionHelper.AddView"/>
 /// <summary>
 /// Add a view to the page
 /// </summary>
 public void AddView(AbstractView view)
 {
     ViewCollectionHelper.AddView(view, ref _views, ref _viewIds);
 }
コード例 #13
0
 /// <inheritdoc cref="AbstractView.Update"/>
 /// <summary>
 /// Not used by ViewGroups
 /// </summary>
 public override void Update(AbstractView newViewState)
 {
     throw new NotImplementedException("Do not call Update on a ViewGroup; call UpdateViewById(AbstractView) instead.");
 }