コード例 #1
0
        /// <summary> Iterate over all childs and lists from business object root with a recursive function.
        /// </summary>
        /// <param name="businessObject">The business object root.</param>
        /// <param name="action">The standard action delegate.</param>
        public static void ForEachItem(IObjectBM businessObject, Action <IObjectBM> action)
        {
            action.DynamicInvoke(new object[] { businessObject });
            var bList = businessObject as IListBM;

            if (bList != null)
            {
                foreach (IItemBM childObject in bList)
                {
                    var bObj = childObject as ObjectBM;
                    if (bObj != null)
                    {
                        ForEach(bObj, action);
                    }
                    else
                    {
                        throw new NotImplementedException("{3F920045-C968-41BB-A77C-0120EED027A6}");
                    }
                }
            }
            else
            {
                throw new NotImplementedException("{10CACD37-AD48-4818-BCB5-3D0CDE5BA430}");
            }
        }
コード例 #2
0
        /// <summary> Iterate over all childs and lists from business object root with a recursive function.
        /// </summary>
        /// <param name="businessObject">The business object root.</param>
        /// <param name="action">The standard action delegate.</param>
        public static void ForEach(IObjectBM businessObject, Action <IObjectBM> action)
        {
            action.DynamicInvoke(new object[] { businessObject });

            var businessList = businessObject as IListBM;

            if (businessList != null)
            {
                foreach (IItemBM childObject in businessList)
                {
                    ForEach((ObjectBM)childObject, action);              //TODO REVISE suspipious cast
                }
            }
            else if (businessObject != null)
            {
                foreach (ObjectBM childObject in businessObject.Children)
                {
                    ForEach(childObject, action);
                }
            }
            else
            {
                throw new NotImplementedException("{526690D2-0E07-46F4-98BC-2EFC636A919A}");
            }
        }
コード例 #3
0
 /// <summary> Iterate over all childs and lists from business object root with a recursive function.
 /// </summary>
 /// <param name="businessObject">The business object root.</param>
 /// <param name="action">The standard action delegate.</param>
 public static void ForEachChild(IObjectBM businessObject, Action <IObjectBM> action)
 {
     action.DynamicInvoke(new object[] { businessObject });
     foreach (ObjectBM childObject in businessObject.Children)
     {
         ForEachChild(childObject, action);
     }
 }
コード例 #4
0
        public static int GetLevel(IObjectBM businessObject)
        {
            int level        = 0;
            var parentObject = (IObjectBM)businessObject.Parent;

            while (parentObject != null)
            {
                parentObject = (IObjectBM)parentObject.Parent;
                level++;
            }
            return(level);
        }
コード例 #5
0
        public static T GetAncestor <T>(IObjectBM start) where T : IObjectBM
        {
            var parent = (IObjectBM)start.Parent;

            if (parent == null)
            {
                return(default(T));
            }
            IObjectBM p = parent;

            while (p != null)
            {
                if (p is T)
                {
                    return((T)p);
                }
                p = (IObjectBM)p.Parent;
            }
            return(default(T));
        }
コード例 #6
0
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]        //REVISE: too complex
        protected virtual Exception ValidateValueInternal(object value, IValueSettings rules, IObjectBM businessObject, bool throwOnInvalid)
        {
            //		    var result=base.Validate(value, rules, throwOnError);
            //		    if(!throwOnError && !result) return false;

            #region Null Validator

            if (Equals(value, null))
            {
                if (!rules.AllowNull)
                {
                    var ex = new ValueValidationException(value, businessObject, new ArgumentNullException(nameof(value), "Value must be not null!"));
                    if (!throwOnInvalid)
                    {
                        return(ex);
                    }
                    throw ex;
                }
                return(null);            // if null allowed all other test are skipped
            }

            #endregion

            // at this point value is never null

            #region Empty Validator

            if (value is string && Equals(value, string.Empty))
            {
                if (!rules.AllowEmpty)
                {
                    var ex = new ValueValidationException(value, businessObject, new ArgumentOutOfRangeException(nameof(value), value, "Value must not be an empty string!"));
                    if (!throwOnInvalid)
                    {
                        return(ex);
                    }
                    throw ex;
                }
                return(null);            // if empty string allowed all other test are skipped
            }

            #endregion

            // at this point value is never null nor empty string

            if (value is IComparable)
            {
                // this is true for all simple types (Int32, Boolean, etc.) and for String, DateTime, TimeSpan, Guid

                if (rules.MinimumSpecified)
                {
                    if (Comparer.Default.Compare(rules.Minimum, value) > 0)
                    {
                        var ex = new ValueValidationException(value, businessObject, new ArgumentOutOfRangeException(nameof(value), value, "Value must not be less then Minimum!"));
                        if (!throwOnInvalid)
                        {
                            return(ex);
                        }
                        throw ex;
                    }
                }
                if (rules.MaximumSpecified)
                {
                    if (Comparer.Default.Compare(value, rules.Maximum) > 0)
                    {
                        var ex = new ValueValidationException(value, businessObject, new ArgumentOutOfRangeException(nameof(value), value, "Value must not be greater then Maximum!"));
                        if (!throwOnInvalid)
                        {
                            return(ex);
                        }
                        throw ex;
                    }
                }
                if (rules.IncludeValuesSpecified)
                {
                    if (!rules.IncludeValues.Cast <object>().Any(a => Comparer.Default.Compare(a, value) == 0))
                    {
                        var ex = new ValueValidationException(value, businessObject, new ArgumentOutOfRangeException(nameof(value), value, "Value must be in IncludeValues"));
                        if (!throwOnInvalid)
                        {
                            return(ex);
                        }
                        throw ex;
                    }
                }
                if (rules.ExcludeValuesSpecified && rules.ExcludeValues != null)
                {
                    if (rules.ExcludeValues.Cast <object>().Any(a => Comparer.Default.Compare(a, value) == 0))
                    {
                        var ex = new ValueValidationException(value, businessObject, new ArgumentOutOfRangeException(nameof(value), value, "Value must not be in EcludeValues!"));
                        if (!throwOnInvalid)
                        {
                            return(ex);
                        }
                        throw ex;
                    }
                }
            }
            else
            {
                throw new NotImplementedException("Type is not comparable! ValidateValueInternal must be overridden! " + value.GetType().FullName + ", Implementing Type: " + this.GetType().FullName);
            }

            return(null);
        }
コード例 #7
0
 public object InputRequired(IObjectBM sender, string inputField)
 {
     sender.RequestUserFeedback(new MessageFeedbackEventArgs("Input required: " + inputField, "Error", MessageBoxButton.OK, MessageBoxImage.Error));
     return(null);
 }
コード例 #8
0
 public static ICollection <IObjectBM> GetChildren(IObjectBM current)
 {
     /*REVISE:*/
     return(current.Children.Cast <IObjectBM>().ToList().AsReadOnly());
 }
コード例 #9
0
 public static IObjectBM GetParent(IObjectBM current)
 {
     return((IObjectBM)current.Parent);
 }
コード例 #10
0
 /// <summary> Initializes a new instance of the <see cref="ValidationException"/> class.
 /// </summary>
 /// <param name="errorValue">The error value.</param>
 /// <param name="businessObject">The business object.</param>
 /// <param name="innerException">The inner exception.</param>
 protected ValidationException(BusinessModelError errorValue, IObjectBM businessObject, Exception innerException) : base(errorValue, businessObject, innerException)
 {
 }
コード例 #11
0
 /// <summary> Initializes a new instance of the <see cref="ValidationException"/> class.
 /// </summary>
 /// <param name="errorValue">The error value.</param>
 /// <param name="businessObject">The business object.</param>
 protected ValidationException(BusinessModelError errorValue, IObjectBM businessObject) : base(errorValue, businessObject, null)
 {
 }
コード例 #12
0
 /// <summary> Initializes a new instance of the <see cref="ValueErrorEventArgs"/> class.
 /// </summary>
 /// <param name="error">The error.</param>
 /// <param name="businessObject">The business object.</param>
 public ValueErrorEventArgs(BusinessModelError error, IObjectBM businessObject)
 {
     this._exception = new BusinessModelException(error, businessObject);
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessModelException"/> class.
 /// </summary>
 /// <param name="errorNumber">The error number.</param>
 /// <param name="businessObject">The business object.</param>
 /// <param name="innerException">The inner exception.</param>
 public BusinessModelException(BusinessModelError errorNumber, IObjectBM businessObject, Exception innerException) : base(CreateMessage(errorNumber), innerException)
 {
     _errorNumber    = errorNumber;
     _businessObject = businessObject;
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BusinessModelException"/> class.
 /// </summary>
 /// <param name="errorNumber">The error number.</param>
 /// <param name="businessObject">The business object.</param>
 public BusinessModelException(BusinessModelError errorNumber, IObjectBM businessObject) : this(errorNumber, businessObject, null)
 {
 }