Beispiel #1
0
        private T InvokeAction <T>(IObjectFacade nakedObject, IActionFacade action, FormCollection parameters, out bool valid)
        {
            ArgumentsContextFacade    ac;
            IOidTranslation           oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
            ActionResultContextFacade contextFacade;

            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1)
            {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through
                ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };
                contextFacade = Facade.ExecuteObjectAction(oid, action.Id, ac);
            }
            else
            {
                ac = GetParameterValues(action, new ObjectAndControlData {
                    Form = parameters
                });
                contextFacade = Facade.ExecuteObjectAction(oid, action.Id, ac);
            }

            valid = contextFacade.HasResult;

            if (valid)
            {
                return(GetResult <T>(contextFacade));
            }

            return(default(T));
        }
Beispiel #2
0
        internal ArgumentsContextFacade Convert(FormCollection form, bool validateOnly = false)
        {
            var ac = new ArgumentsContextFacade {
                ValidateOnly = validateOnly,
                Values       = form.AllKeys.ToDictionary(k => k, k => form.GetValue(k).RawValue)
            };

            return(ac);
        }
Beispiel #3
0
        internal ArgumentsContextFacade ConvertForSave(IObjectFacade nakedObject, ObjectAndControlData controlData, bool validateOnly = false)
        {
            List <IAssociationFacade> usableAndVisibleFields;
            List <Tuple <IAssociationFacade, object> > fieldsAndMatchingValues;

            GetUsableAndVisibleFields(nakedObject, controlData, null, out usableAndVisibleFields, out fieldsAndMatchingValues);

            var ac = new ArgumentsContextFacade {
                ValidateOnly = validateOnly,
                Values       = fieldsAndMatchingValues.ToDictionary(t => t.Item1.Id, f => GetObjectValue(f.Item1, nakedObject, f.Item2))
            };

            return(ac);
        }
        private ActionResult ExecuteAction(ObjectAndControlData controlData, IObjectFacade nakedObject, IActionFacade action)
        {
            if (ActionExecutingAsContributed(action, nakedObject) && action.ParameterCount == 1)
            {
                // contributed action being invoked with a single parm that is the current target
                // no dialog - go straight through

                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };

                if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable)
                {
                    var oids = nakedObject.ToEnumerable().Select(no => Facade.OidTranslator.GetOidTranslation(no)).ToArray();
                    var spec = nakedObject.ElementSpecification;

                    var ar = Facade.ExecuteListAction(oids, spec, action.Id, ac);
                    return(AppropriateView(controlData, GetResult(ar), action));
                }
                else
                {
                    var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);
                    var ar  = Facade.ExecuteObjectAction(oid, action.Id, ac);

                    return(AppropriateView(controlData, GetResult(ar), action));
                }
            }

            if (!action.Parameters.Any())
            {
                var ac = new ArgumentsContextFacade {
                    Values = new Dictionary <string, object>(), ValidateOnly = false
                };
                var oid    = Facade.OidTranslator.GetOidTranslation(nakedObject);
                var result = Facade.ExecuteObjectAction(oid, action.Id, ac);

                return(AppropriateView(controlData, GetResult(result), action));
            }

            SetDefaults(nakedObject, action);
            // do after any parameters set by contributed action so this takes priority
            SetSelectedParameters(action);
            SetPagingValues(controlData, nakedObject);
            var property = DisplaySingleProperty(controlData, controlData.DataDict);

            return(View(property == null ? "ActionDialog" : "PropertyEdit", new FindViewModel {
                ContextObject = nakedObject.GetDomainObject(), ContextAction = action, PropertyName = property
            }));
        }
        private ObjectContextFacade CreateObject(string typeName, ArgumentsContextFacade arguments)
        {
            if (string.IsNullOrWhiteSpace(typeName))
            {
                throw new BadRequestNOSException();
            }

            NakedObject nakedObject;

            try {
                NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);
                nakedObject = [email protected]().createTransientInstance(spec);
            }
            catch (Exception) {
                throw new TypeResourceNotFoundNOSException(typeName);
            }
            return(SetObject(nakedObject, arguments));
        }
        private ActionResultContextFacade ExecuteAction(ActionContext actionContext, ArgumentsContextFacade arguments)
        {
            ValidateConcurrency(actionContext.Target, arguments.Digest);

            var actionResultContext = new ActionResultContext {
                Target = actionContext.Target, ActionContext = actionContext
            };

            if (ConsentHandler(actionContext.Action.isAvailable(actionContext.Target), actionResultContext, Cause.Disabled))
            {
                if (ValidateParameters(actionContext, arguments.Values) && !arguments.ValidateOnly)
                {
                    Naked result = actionContext.Action.execute(actionContext.Target, actionContext.VisibleParameters.Select(p => p.ProposedNakedObject).ToArray());
                    actionResultContext.Result = GetObjectContext(result);
                }
            }
            return(actionResultContext.ToActionResultContextFacade(this));
        }
        private ObjectContextFacade SetObject(NakedObject nakedObject, ArgumentsContextFacade arguments)
        {
            if (nakedObject.getSpecification().getFields().Where(f => !f.isCollection()).Any(p => !arguments.Values.Keys.Select(s => s.ToLower()).Contains(p.getId())))
            {
                throw new BadRequestNOSException("Malformed arguments");
            }

            PropertyContext[] pc = arguments.Values.Select(kvp => CanSetProperty(nakedObject, kvp.Key, arguments.ValidateOnly, kvp.Value)).ToArray();
            var objectContext    = new ObjectContext(pc.First().Target)
            {
                VisibleProperties = pc
            };

            // if we fail we need to display all - if OK only those that are visible
            PropertyContext[] propertiesToDisplay = objectContext.VisibleProperties;

            if (pc.All(c => string.IsNullOrEmpty(c.Reason)))
            {
                if (nakedObject.getResolveState().isTransient())
                {
                    if (nakedObject.getSpecification().persistable() == Persistable.USER_PERSISTABLE)
                    {
                        [email protected]().makePersistent(nakedObject);
                    }
                    else
                    {
                        [email protected]().objectChanged(nakedObject);
                    }
                }

                propertiesToDisplay = nakedObject.getSpecification().getFields().
                                      Where(p => !p.isHidden() && p.isVisible(nakedObject).isAllowed()).
                                      Select(p => new PropertyContext {
                    Target = nakedObject, Property = p
                }).ToArray();
            }

            ObjectContext oc = GetObjectContext(objectContext.Target);

            oc.Mutated           = false;
            oc.Reason            = objectContext.Reason;
            oc.VisibleProperties = propertiesToDisplay;
            return(oc.ToObjectContextFacade(this));
        }
        private ObjectContextFacade ChangeObject(NakedObject nakedObject, ArgumentsContextFacade arguments)
        {
            ValidateConcurrency(nakedObject, arguments.Digest);

            PropertyContext[] pc;
            try {
                pc = arguments.Values.Select(kvp => CanChangeProperty(nakedObject, kvp.Key, arguments.ValidateOnly, kvp.Value)).ToArray();
            }
            catch (PropertyResourceNotFoundNOSException e) {
                // no matching property for argument - consider this a syntax error
                throw new BadRequestNOSException(e.Message);
            }

            var objectContext = new ObjectContext(pc.First().Target)
            {
                VisibleProperties = pc
            };

            // if we fail we need to display passed in properties - if OK all visible
            PropertyContext[] propertiesToDisplay = objectContext.VisibleProperties;

            if (pc.All(c => string.IsNullOrEmpty(c.Reason)))
            {
                propertiesToDisplay = nakedObject.getSpecification().getFields().
                                      Where(p => !p.isHidden() && p.isVisible(nakedObject).isAllowed()).
                                      Select(p => new PropertyContext {
                    Target = nakedObject, Property = p
                }).ToArray();
            }

            ObjectContext oc = GetObjectContext(objectContext.Target);

            oc.Mutated           = true;
            oc.Reason            = objectContext.Reason;
            oc.VisibleProperties = propertiesToDisplay;
            return(oc.ToObjectContextFacade(this));
        }
        public static PropertyContextFacade GetPropertyByName(this IFrameworkFacade frameworkFacade, string domainType, string instanceId, string propertyName, ArgumentsContextFacade argsContext)
        {
            var link = frameworkFacade.OidTranslator.GetOidTranslation(domainType, instanceId);
            var obj  = frameworkFacade.GetObject(link);

            return(frameworkFacade.GetPropertyWithCompletions(obj.Target, propertyName, argsContext));
        }
        public static ActionResultContextFacade ExecuteServiceActionAndValidate(this IFrameworkFacade frameworkFacade, string serviceName, string actionName, ArgumentsContextFacade argsContext)
        {
            var link    = frameworkFacade.OidTranslator.GetOidTranslation(serviceName);
            var context = frameworkFacade.ExecuteServiceAction(link, actionName, argsContext);

            return(ValidateActionResult(context));
        }
        public static ActionResultContextFacade ExecuteMenuActionAndValidate(this IFrameworkFacade frameworkFacade, string menuName, string actionName, ArgumentsContextFacade argsContext)
        {
            var context = frameworkFacade.ExecuteMenuAction(menuName, actionName, argsContext);

            return(ValidateActionResult(context));
        }
        public static ObjectContextFacade PersistObjectAndValidate(this IFrameworkFacade frameworkFacade, string domainType, ArgumentsContextFacade argsContext, RestControlFlags flags)
        {
            var context = frameworkFacade.Persist(domainType, argsContext);

            return(ValidatePersistObjectContext(context, flags));
        }
        public static ActionResultContextFacade ExecuteActionAndValidate(this IFrameworkFacade frameworkFacade, string domainType, string instanceId, string actionName, ArgumentsContextFacade argsContext)
        {
            var link    = frameworkFacade.OidTranslator.GetOidTranslation(domainType, instanceId);
            var context = frameworkFacade.ExecuteObjectAction(link, actionName, argsContext);

            return(ValidateActionResult(context));
        }
 public ObjectContextFacade Persist(string typeName, ArgumentsContextFacade arguments)
 {
     return(MapErrors(() => CreateObject(typeName, arguments)));
 }
        public static ObjectContextFacade PutObjectAndValidate(this IFrameworkFacade frameworkFacade, string domainType, string instanceId, ArgumentsContextFacade argsContext)
        {
            var link    = frameworkFacade.OidTranslator.GetOidTranslation(domainType, instanceId);
            var context = frameworkFacade.PutObject(link, argsContext);

            return(ValidateObjectContext(context));
        }
 public ObjectContextFacade PutObject(IOidTranslation oid, ArgumentsContextFacade arguments)
 {
     return(MapErrors(() => ChangeObject(GetObjectAsNakedObject(oid), arguments)));
 }
 public ObjectContextFacade RefreshObject(IObjectFacade objectFacade, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }
 public ListContextFacade GetPropertyCompletions(IOidTranslation objectId, string propertyName, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }
 public ObjectContextFacade PersistObject(IObjectFacade transient, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }
 public ListContextFacade GetServiceParameterCompletions(IOidTranslation objectId, string actionName, string parmName, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }
 public ActionResultContextFacade ExecuteServiceAction(IOidTranslation serviceName, string actionName, ArgumentsContextFacade arguments)
 {
     return(MapErrors(() => {
         ActionContext actionContext = GetInvokeActionOnService(serviceName, actionName);
         return ExecuteAction(actionContext, arguments);
     }));
 }
 public ActionResultContextFacade ExecuteObjectAction(IOidTranslation objectId, string actionName, ArgumentsContextFacade arguments)
 {
     return(MapErrors(() => {
         ActionContext actionContext = GetInvokeActionOnObject(objectId, actionName);
         return ExecuteAction(actionContext, arguments);
     }));
 }
        public static PropertyContextFacade GetTransientPropertyByName(this IFrameworkFacade frameworkFacade, string domainType, string propertyName, ArgumentsContextFacade persistArgs, ArgumentsContextFacade promptArgs)
        {
            var obj = frameworkFacade.GetTransient(domainType, persistArgs);

            return(frameworkFacade.GetPropertyWithCompletions(obj.Target, propertyName, promptArgs));
        }
        public static ParameterContextFacade GetServiceParameterByName(this IFrameworkFacade frameworkFacade, string serviceName, string actionName, string parmName, ArgumentsContextFacade argsContext)
        {
            var link   = frameworkFacade.OidTranslator.GetOidTranslation(serviceName);
            var action = frameworkFacade.GetServiceActionWithCompletions(link, actionName, parmName, argsContext);

            return(frameworkFacade.GetParameterByName(action, parmName));
        }
        public static ParameterContextFacade GetObjectParameterByName(this IFrameworkFacade frameworkFacade, string domainType, string instanceId, string actionName, string parmName, ArgumentsContextFacade argsContext)
        {
            var link   = frameworkFacade.OidTranslator.GetOidTranslation(domainType, instanceId);
            var action = frameworkFacade.GetObjectActionWithCompletions(link, actionName, parmName, argsContext);

            return(frameworkFacade.GetParameterByName(action, parmName));
        }
 public ActionResultContextFacade ExecuteListAction(IOidTranslation[] objectId, ITypeFacade elementSpec, string actionName, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }
        private bool ApplyEdit(IObjectFacade nakedObject, ObjectAndControlData controlData, IAssociationFacade parent = null)
        {
            var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);

            var usableAndVisibleFields  = nakedObject.Specification.Properties.Where(p => p.IsVisible(nakedObject) && p.IsUsable(nakedObject).IsAllowed);
            var fieldsAndMatchingValues = GetFieldsAndMatchingValues(nakedObject, parent, usableAndVisibleFields, controlData, GetFieldInputId).ToList();

            CheckConcurrency(nakedObject, null, controlData, GetConcurrencyFieldInputId);

            fieldsAndMatchingValues.ForEach(pair => AddAttemptedValue(GetFieldInputId(parent, nakedObject, pair.Item1), pair.Item2));

            var ac = new ArgumentsContextFacade {
                Values       = fieldsAndMatchingValues.ToDictionary(f => f.Item1.Id, f => GetObjectValue(f.Item1, nakedObject, f.Item2)),
                ValidateOnly = false
            };

            // check mandatory fields first to emulate WPF UI behaviour where no validation takes place until
            // all mandatory fields are set.
            foreach (var pair in fieldsAndMatchingValues)
            {
                var result       = pair.Item2;
                var stringResult = result as string;

                if (pair.Item1.IsMandatory && (result == null || (result is string && string.IsNullOrEmpty(stringResult))))
                {
                    AddErrorAndAttemptedValue(nakedObject, stringResult, pair.Item1, MvcUi.Mandatory);
                }
            }

            if (!ModelState.IsValid)
            {
                return(false);
            }

            ApplyInlineEdit(nakedObject, controlData, usableAndVisibleFields);

            if (!ModelState.IsValid)
            {
                return(false);
            }

            var res = Facade.PutObject(oid, ac);

            if (HasError(res))
            {
                foreach (var parm in res.VisibleProperties)
                {
                    if (!string.IsNullOrEmpty(parm.Reason))
                    {
                        ModelState.AddModelError(GetFieldInputId(parent, nakedObject, parm.Property), parm.Reason);
                    }
                }

                if (!(string.IsNullOrEmpty(res.Reason)))
                {
                    ModelState.AddModelError("", res.Reason);
                }

                return(false);
            }

            return(true);
        }
 public ObjectContextFacade GetTransient(string typeName, ArgumentsContextFacade arguments)
 {
     throw new NotImplementedException();
 }