Ejemplo n.º 1
0
        public object Bind(Type type, IBindingContext context)
        {
            var entityType = type.GetConstructors().Single(x => x.GetParameters().Count() == 1).GetParameters().Single().ParameterType;

            // This is our convention.
            var prefix          = entityType.Name;
            var prefixedContext = context.PrefixWith(prefix);

            DomainEntity entity = tryFindExistingEntity(context, prefixedContext, entityType) ?? createNewEntity(entityType, prefixedContext);

            var model = (EditEntityModel)Activator.CreateInstance(type, entity);


            // Get the binding errors from conversion of the Entity
            prefixedContext.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            _innerBinder.Bind(type, model, context);

            // Get the binding errors from conversion of the EditEntityModel
            context.Problems.Each(x =>
            {
                model.Notification.RegisterMessage(x.Properties.Last(), FastPackKeys.PARSE_VALUE);
            });

            return(model);
        }
        protected virtual object GetPropertyValue(BindingContext context,
                                                  PropertyDescriptor property)
        {
            IModelBinder binder = GetPropertyBinder(property);

            return(binder.Bind(context));
        }
Ejemplo n.º 3
0
        private void readTargetFromLine(FlatFileRequest <T> request, FlatFileRequestData data, string line, BindingContext context)
        {
            data.ReadLine(line);

            var target = request.Finder(data);

            _binder.Bind(typeof(T), target, context);

            request.Callback(target);
        }
Ejemplo n.º 4
0
        public object Bind(Type type, IBindingContext context)
        {
            var    path     = FindPath(context.Service <AggregateDictionary>());
            object instance = Activator.CreateInstance(type, path);

            // Setting additional properties

            _binder.Bind(type, instance, context);

            return(instance);
        }
        public void Build <T>(RowProcessingRequest <T> input)
        {
            IDataReader reader  = input.Reader;
            var         request = new DataReaderRequestData(reader, _aliases);
            var         context = new BindingContext(request, _services, new NulloBindingLogger());

            while (reader.Read())
            {
                T target = input.Finder(reader);
                _binder.Bind(typeof(T), target, context);

                input.Callback(target);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handle the given result (<paramref name="a_result"/>).
        /// </summary>
        /// <param name="a_mvc">Mvc engine.</param>
        /// <param name="a_controllerName">Controller name.</param>
        /// <param name="a_result">Result to handle.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_result"/> is null.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_controllerName"/> is null.</exception>
        public override void Handle(MvcEngine a_mvc, string a_controllerName, ViewResult a_result)
        {
            #region Argument Validation

            if (a_mvc == null)
            {
                throw new ArgumentNullException(nameof(a_mvc));
            }

            if (a_result == null)
            {
                throw new ArgumentNullException(nameof(a_result));
            }

            if (a_controllerName == null)
            {
                throw new ArgumentNullException(nameof(a_controllerName));
            }

            #endregion

            // Get view object from view catalog.
            var view = _viewCatalog.Resolve(a_result.ViewName);

            if (view == null)
            {
                throw new TypeNotFoundException(a_result.ViewName);
            }

            // Connect MVC view model.
            var mvcViewModel = (a_result.Model as IMvcViewModel);
            if (mvcViewModel != null)
            {
                mvcViewModel.Navigator      = a_mvc.Navigator;
                mvcViewModel.ControllerName = a_controllerName;
            }

            // Apply model to the view.
            _modelBinder?.Bind(view, a_result.Model);

            // Send view object to view targets.
            foreach (var viewTarget in _viewTargets)
            {
                var currentView = viewTarget.GetView();
                var viewModel   = _modelBinder?.GetModel(currentView) as IMvcViewModel;
                viewModel?.Cleanup();

                viewTarget.SetView(view);
            }
        }
Ejemplo n.º 7
0
 private static BindResult executeModelBinder(Type type, IModelBinder binder, IBindingContext context)
 {
     try
     {
         return(new BindResult {
             Value = binder.Bind(type, context),
             Problems = context.Problems
         });
     }
     catch (Exception e)
     {
         throw new FubuException(2201, e, "Fatal error while binding model of type {0}.  See inner exception",
                                 type.AssemblyQualifiedName);
     }
 }
Ejemplo n.º 8
0
 private static BindResult executeModelBinder(Type type, IModelBinder binder, IBindingContext context)
 {
     try
     {
         return new BindResult{
             Value = binder.Bind(type, context),
             Problems = context.Problems
         };
     }
     catch (Exception e)
     {
         throw new FubuException(2201, e, "Fatal error while binding model of type {0}.  See inner exception",
                                 type.AssemblyQualifiedName);
     }
 }
Ejemplo n.º 9
0
        protected virtual object GetParameterValue(ControllerContext context,
                                                   ParameterDescriptor parameter)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(parameter, () => Error.ArgumentNull("parameter"));

            IModelBinder   binder = GetBinder(parameter);
            BindingContext bc     = new BindingContext(context, parameter.Type,
                                                       parameter.Binding.Name, GetValueProvider(context, parameter.Binding.Source),
                                                       GetController().ModelState);

            bc.FallbackToEmptyPrefix = (String.Equals(parameter.Binding.Name, parameter.Name));

            return(binder.Bind(bc) ?? parameter.Binding.DefaultValue);
        }
Ejemplo n.º 10
0
 public void BindWith(IModelBinder binder)
 {
     _actions.Add(context => binder.Bind(typeof(T), Model, context));
 }