/// <summary>
 /// Static initialization.
 /// </summary>
 static BindingSetup()
 {
     ActionExecutionModelBinderProvider = new ActionExecutionModelBinderProvider();
     EntityModelBinderProvider          = new EntityModelBinderProvider();
     DomosValidatorProvider             = new DomosValidatorProvider();
     CustomValidatorProvider            = new CustomValidatorProvider();
     DomosMetadataProvider = new DomosMetadataProvider();
 }
Beispiel #2
0
        public ActionExecutionMetadata(DomosMetadataProvider provider,
                                       CachedDataAnnotationsModelMetadata prototype,
                                       Func <object> modelAccessor)
            : base(prototype, modelAccessor)
        {
            if (prototype == null)
            {
                throw new ArgumentNullException(nameof(prototype));
            }
            if (modelAccessor == null)
            {
                throw new ArgumentNullException(
                          nameof(modelAccessor),
                          "Metadata can only be extracted if a concrete model exists with ActionCodeName set. " +
                          "Use [Try]UpdateModelXXX methods on already created instances.");
            }

            var model = (Models.ActionExecutionModel)modelAccessor();

            var parameterSpecifications = model.GetParameterSpecifications();

            properties = new List <ModelMetadata>(parameterSpecifications.Count + prototype.Properties.Count());

            // Add all the original properties except "Parameters".
            properties.AddRange(prototype.Properties.Where(p => p.PropertyName != nameof(Models.ActionExecutionModel.Parameters)));

            foreach (var parameterSpecification in parameterSpecifications.Values)
            {
                object parameterValue = GetParameterValue(model, parameterSpecification);

                var property = new CachedDataAnnotationsModelMetadata(
                    provider,
                    typeof(Models.ActionExecutionModel),
                    parameterSpecification.Type,
                    parameterSpecification.Key,
                    parameterSpecification.ValidationAttributes)
                {
                    IsReadOnly  = false,
                    IsRequired  = parameterSpecification.IsRequired,
                    Container   = model,
                    Model       = parameterValue,
                    DisplayName = parameterSpecification.Caption,
                    Description = parameterSpecification.Description,
                };

                properties.Add(property);

                this.AdditionalValues[parameterSpecification.Key] = parameterValue;
            }
        }