Esempio n. 1
0
        /// <summary>
        /// Fluent entry point to configure the viewmodel's property specified through the param: <paramref name="propertyName"/> (e.g. RegisterProperty(nameof(Property)))
        /// </summary>
        /// <typeparam name="TResult">Type of the property</typeparam>
        /// <param name="propertyName">Property name</param>
        /// <returns>A <see cref="ViewModelPropertyDescriptor{TOwner, TResult}"/> describing the property specified through <paramref name="exp"/></returns>
        protected internal static ViewModelPropertyDescriptor <TInheritor, TResult> RegisterProperty <TResult>(string propertyName)
        {
            ViewModelPropertyDescriptor <TInheritor, TResult> result;

            if (PropertyDescriptors.TryGetValue(propertyName, out var desc))
            {
                result = desc as ViewModelPropertyDescriptor <TInheritor, TResult>;
            }
            else
            {
                PropertyDescriptors.Add(propertyName, result = new ViewModelPropertyDescriptor <TInheritor, TResult>(propertyName));
            }
            return(result);
        }
Esempio n. 2
0
        //readonly ILoggerFacade logger = ServiceLocator.Current.GetInstance<ILoggerFacade>(LogNames.Session);
        private void BuildClassResults(object entity, IList <ValidationError> errors)
        {
            if (ClassValidators == null || !ClassValidators.Any())
            {
                return;
            }
            //var timer = new Stopwatch();
#if DEBUG
            var timer2 = new Stopwatch();
#endif
            // timer.Start();

            var ctxt = new ValidationContext(entity);
            foreach (var attr in ClassValidators)
            {
#if DEBUG
                timer2.Start();
#endif

                var result = attr.GetValidationResult(entity, ctxt);

#if DEBUG
                timer2.Stop();
                var message = string.Format("IP/ED dataset imports - Time of Execution of class validation {2}: {0}:{1}",
                                            timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds, attr.GetType().Name);

                Trace.WriteLine(message);
                timer2.Reset();
#endif
                if (result != null && !string.IsNullOrEmpty(result.ErrorMessage))
                {
#if DEBUG
                    timer2.Start();
#endif
                    ValidationErrorState errorState = (attr.GetType() == typeof(RejectIfAnyPropertyHasValueAttribute))
                                                                        ? ValidationErrorState.ExcludedByCrosswalk
                                                                        : ValidationErrorState.ValidationError;

                    if (result.MemberNames != null && result.MemberNames.Any())
                    {
                        foreach (var memberName in result.MemberNames.ToList())
                        {
                            PropertyDescriptor propDesc;
                            if (PropertyDescriptors.TryGetValue(memberName, out propDesc))
                            {
                                errors.Add(new ValidationError(result.ErrorMessage, PropertyDescriptors[memberName].Property, errorState));
                            }
                            else
                            {
                                errors.Add(new ValidationError(result.ErrorMessage, null, errorState));
                            }
                        }
                    }
                    else
                    {
                        errors.Add(new ValidationError(result.ErrorMessage, null, errorState));
                    }

#if DEBUG
                    timer2.Stop();
                    var message2 = string.Format("IP/ED dataset imports - Time of Execution of message processing: {0}:{1}",
                                                 timer2.Elapsed.Seconds, timer2.Elapsed.Milliseconds);
                    Trace.WriteLine(message2);
#endif
                }
            }
            // timer.Stop();
            // var message3 = string.Format("IP/ED dataset imports - Overall Time of Execution of all class validations: {0}:{1}",
            // timer.Elapsed.Seconds, timer.Elapsed.Milliseconds);

            // Trace.WriteLine(message3);

            //if(logger != null)
            //    logger.Write(message, Category.Debug, Priority.High);
        }