示例#1
0
        private ITestNaked DoInvoke(params object[] parameters)
        {
            ResetLastMessage();
            AssertIsValidWithParms(parameters);
            var parameterObjectsAdapter = parameters.AsTestNakedArray(manager).Select(x => x.NakedObject).ToArray();
            INakedObjectAdapter result  = null;

            try {
                result = actionSpec.Execute(owningObject.NakedObject, parameterObjectsAdapter);
            }
            catch (ArgumentException) {
                Assert.Fail("Invalid Argument(s)");
            }
            catch (InvalidCastException) {
                Assert.Fail("Invalid Argument(s)");
            }

            if (result == null)
            {
                return(null);
            }

            if (result.Spec.IsCollection && !result.Spec.IsParseable)
            {
                return(factory.CreateTestCollection(result));
            }

            return(factory.CreateTestObject(result));
        }
示例#2
0
        private INakedObject Execute(IActionSpec action, INakedObject target, INakedObject[] parameterSet)
        {
            var result = action.Execute(target, parameterSet);

            if (result != null && result.Oid == null)
            {
                result.SetATransientOid(new CollectionMemento(NakedObjectsContext.LifecycleManager, NakedObjectsContext.NakedObjectManager, NakedObjectsContext.MetamodelManager, target, action, parameterSet));
            }
            return(result);
        }
示例#3
0
        private ActionResult InvokeActionAsFind(ObjectAndControlData controlData)
        {
            string targetActionId  = controlData.DataDict["targetActionId"];
            string targetObjectId  = controlData.DataDict["targetObjectId"];
            string contextObjectId = controlData.DataDict["contextObjectId"];
            string propertyName    = controlData.DataDict["propertyName"];
            string contextActionId = controlData.DataDict["contextActionId"];

            INakedObject targetNakedObject  = NakedObjectsContext.GetNakedObjectFromId(targetObjectId);
            INakedObject contextNakedObject = FilterCollection(NakedObjectsContext.GetNakedObjectFromId(contextObjectId), controlData);
            IActionSpec  targetAction       = NakedObjectsContext.GetActions(targetNakedObject).Single(a => a.Id == targetActionId);
            IActionSpec  contextAction      = string.IsNullOrEmpty(contextActionId) ? null : NakedObjectsContext.GetActionFromId(contextActionId);

            SetContextObjectAsParameterValue(targetAction, contextNakedObject);

            if (ValidateParameters(targetNakedObject, targetAction, controlData))
            {
                IEnumerable <INakedObject> parms = GetParameterValues(targetAction, controlData);
                INakedObject result = targetAction.Execute(targetNakedObject, parms.ToArray());

                if (result != null)
                {
                    IEnumerable resultAsEnumerable = !result.Spec.IsCollection ? new List <object> {
                        result.Object
                    } : (IEnumerable)result.Object;

                    if (resultAsEnumerable.Cast <object>().Count() == 1)
                    {
                        var selectedItem = new Dictionary <string, string> {
                            { propertyName, NakedObjectsContext.GetObjectId(resultAsEnumerable.Cast <object>().Single()) }
                        };
                        return(SelectSingleItem(contextNakedObject, contextAction, controlData, selectedItem));
                    }
                    string view = Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithSelections";
                    return(View(view, new FindViewModel {
                        ActionResult = resultAsEnumerable,
                        TargetObject = targetNakedObject.Object,
                        ContextObject = contextNakedObject.Object,
                        TargetAction = targetAction,
                        ContextAction = contextAction,
                        PropertyName = propertyName
                    }));
                }
            }
            return(View(Request.IsAjaxRequest() ? "PropertyEdit" : "FormWithFinderDialog", new FindViewModel {
                TargetObject = targetNakedObject.Object,
                ContextObject = contextNakedObject.Object,
                TargetAction = targetAction,
                ContextAction = contextAction,
                PropertyName = propertyName
            }));
        }
        private T InvokeAction <T>(INakedObject nakedObject, IActionSpec action, FormCollection parameters, out bool valid)
        {
            if (ActionExecutingAsContributed(action, nakedObject))
            {
                if (action.ParameterCount == 1)
                {
                    // contributed action being invoked with a single parm that is the current target
                    // no dialog - go straight through
                    INakedObject result = action.Execute(nakedObject, new[] { nakedObject });
                    valid = true;
                    return(result.GetDomainObject <T>());
                }
                if (action.ParameterCount > 1)
                {
                    // contributed action being invoked with multiple parms - populate first that match the target
                    IActionParameterSpec parmToPopulate = action.Parameters.FirstOrDefault(p => nakedObject.Spec.IsOfType(p.Spec));
                    if (parmToPopulate != null)
                    {
                        ViewData[IdHelper.GetParameterInputId(action, parmToPopulate)] = NakedObjectsContext.GetObjectId(nakedObject.Object);
                    }
                }
            }

            if (ValidateParameters(nakedObject, action, new ObjectAndControlData {
                Form = parameters
            }))
            {
                IEnumerable <INakedObject> parms = GetParameterValues(action, new ObjectAndControlData {
                    Form = parameters
                });
                INakedObject result = action.Execute(nakedObject, parms.ToArray());
                valid = true;
                return(result.GetDomainObject <T>());
            }

            valid = false;
            return(default(T));
        }