예제 #1
0
        /// <summary>
        /// See <seealso cref="StatePropertyAttribute.Enabled"/>
        /// </summary>
        /// <returns>
        /// true if <see cref="StatePropertyAttribute.Enabled"/> is set to true for this node.
        /// false if <see cref="StatePropertyAttribute.Enabled"/> is set to false (or unspecified) for this node.
        /// </returns>
        public bool IsEnabled()
        {
            StatePropertyAttribute spa = this.GetStatePropertyAttribute();

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

            return(spa.Enabled == true);
        }
예제 #2
0
        public void DisablePresentation()
        {
            // TODO: Write unit test
            // TODO: Create the SPA (with Enabled=false) if one is not defined, instead of throwing an exception
            StatePropertyAttribute spa = GetStatePropertyAttribute();

            // SPA is not defined, therefore do nothing since presentation is already disabled by default
            if (spa is null)
            {
                return;
            }

            spa.Enabled = false;
        }
예제 #3
0
        /// <summary>
        /// <para>Validator of the <see cref="StatePropertyAttribute"/> name value.</para>
        /// <para>Valid if property is overridden and not defined as null/empty/whitespace.</para>
        /// </summary>
        /// <returns>
        /// <para>true if valid</para>
        /// <para>false if invalid</para>
        /// </returns>
        private bool IsValidStatePropertyName(StatePropertyAttribute statePropertyAttribute)
        {
            // Declaring StatePropertyAttribute is optional, so it's a valid name if one is not defined.
            if (statePropertyAttribute is null)
            {
                return(true);
            }

            // If StatePropertyAttribute is declared as a Node attribute, but name is null, then the name is invalid.
            if (statePropertyAttribute.Name is null)
            {
                return(false);
            }

            return(!string.IsNullOrWhiteSpace(statePropertyAttribute.Name));
        }
예제 #4
0
        public void EnablePresentation()
        {
            // TODO: Write unit test
            // TODO: Create the SPA (with Enabled=true) if one is not defined, instead of throwing an exception
            StatePropertyAttribute spa = null;

            try
            {
                spa = GetStatePropertyAttribute(throwExceptionIfNotDefined: true);
            }
            catch (Exception e)
            {
                throw new Exception($"Cannot enable a node with no StatePropertyAttribute defined. {e.Message}");
            }

            if (!this.IsValidStatePropertyName(spa))
            {
                throw new Exception("Cannot enable a node with an invalid/no name StatePropertyAttribute property defined.");
            }

            spa.Enabled = true;
        }