Ejemplo n.º 1
0
        private static Tuple<INakedObjectAction, string>[] GetOverloadedActionsAndUIds(INakedObjectAction[] actions) {
            INakedObjectAction[] overloadedActions = actions.Where(a => actions.Count(ac => ac.Id == a.Id) > 1).ToArray();

            if (overloadedActions.Any()) {
                return overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, GetUniqueSuffix(a, actions))).ToArray();
            }
            return new Tuple<INakedObjectAction, string>[] { };
        }
        public CollectionMemento(INakedObject target, INakedObjectAction action, INakedObject[] parameters) {
            Target = target;
            Action = action;
            Parameters = parameters;

            if (Target.Specification.IsViewModel) {
                PersistorUtils.PopulateViewModelKeys(Target);
            }
        }
Ejemplo n.º 3
0
        internal ActionResult AppropriateView(ObjectAndControlData controlData, INakedObject nakedObject, INakedObjectAction action = null, string propertyName = null) {
            if (nakedObject == null) {
                // no object to go to 
                // if action on object go to that object. 
                // if action on collection go to collection 
                // if action on service go to last object 

                nakedObject = controlData.GetNakedObject();

                if (nakedObject.Specification.IsService) {
                    object lastObject = Session.LastObject(ObjectCache.ObjectFlag.BreadCrumb);
                    if (lastObject == null) {
                        TempData[IdHelper.NofMessages] = NakedObjectsContext.MessageBroker.Messages;
                        TempData[IdHelper.NofWarnings] = NakedObjectsContext.MessageBroker.Warnings;
                        return RedirectToAction(IdHelper.IndexAction, IdHelper.HomeName);
                    }

                    nakedObject = FrameworkHelper.GetNakedObject(lastObject);
                }
            }

            if (nakedObject.Specification.IsCollection && !nakedObject.Specification.IsParseable) {
                var collection = nakedObject.GetAsQueryable();
                int collectionSize = collection.Count();
                if (collectionSize == 1) {
                    // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering 
                    ViewData.Remove(IdHelper.PagingData);
                    return View("ObjectView", collection.First());
                }

                nakedObject = Page(nakedObject, collectionSize, controlData, nakedObject.IsNotQueryable());
                action = action ?? ((CollectionMemento)nakedObject.Oid).Action;
                int page, pageSize;
                CurrentlyPaging(controlData, collectionSize, out page, out pageSize);
                var format = ViewData["NofCollectionFormat"] as string;
                return View("StandaloneTable", ActionResultModel.Create(action, nakedObject, page, pageSize, format));
            }
            // remove any paging data - to catch case where custom page has embedded standalone collection as paging data will confuse rendering   
            ViewData.Remove(IdHelper.PagingData);

            if (controlData.DataDict.Values.Contains("max")) {
                // maximizing an inline object - do not update history
                ViewData.Add("updateHistory", false);
            }

            return propertyName == null ? View(nakedObject.IsNotPersistent() ? "ObjectView" : "ViewNameSetAfterTransaction", nakedObject.Object) :
                                          View(nakedObject.IsNotPersistent() ? "PropertyView" : "ViewNameSetAfterTransaction", new PropertyViewModel(nakedObject.Object, propertyName));
        }
Ejemplo n.º 4
0
        private static string GetUniqueSuffix(INakedObjectAction action, INakedObjectAction[] actions) {
            INakedObjectAction[] overloadedActions = actions.Where(a => a.Id == action.Id && actions.Count(ac => ac.Id == a.Id) > 1).ToArray();

            if (overloadedActions.Any()) {
                var actionAndParms = overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, ((Func<INakedObjectAction, string>)(act => act.Parameters.Aggregate("", (acc, p) => a + p.Id + p.Specification.FullName)))(a)));

                int index = 0;
                var orderedActions = actionAndParms.OrderBy(ap => ap.Item2).Select(ap => ap.Item1).ToDictionary(a => a, a => index++);

                var suffix = orderedActions[action].ToString();

                while (actions.Select(a => a.Id).Contains(action.Id + suffix)) {
                    suffix = "0" + suffix;
                }

                return suffix;
            }
            return "";
        }
Ejemplo n.º 5
0
        internal void SetDefaults(INakedObject nakedObject, INakedObjectAction action) {
            foreach (INakedObjectActionParameter parm in action.Parameters) {
                INakedObject value = parm.GetDefault(nakedObject);
                TypeOfDefaultValue typeOfValue = parm.GetDefaultType(nakedObject);

                bool ignore = value == null || (value.Object is DateTime && ((DateTime) value.Object).Ticks == 0) || typeOfValue == TypeOfDefaultValue.Implicit;
                if (!ignore) {
                    // deliberately not an attempted value so it only gets populated after masking 
                    ViewData[IdHelper.GetParameterInputId(action, parm)] = parm.Specification.IsParseable ? value.Object : value;
                }
            }
        }
Ejemplo n.º 6
0
 internal IEnumerable<INakedObject> GetParameterValues(INakedObjectAction action, ObjectAndControlData controlData) {
     return action.Parameters.Select(parm => GetParameterValue(parm, IdHelper.GetParameterInputId(action, parm), controlData));
 }
Ejemplo n.º 7
0
 internal void SetContextObjectAsParameterValue(INakedObjectAction targetAction, INakedObject contextNakedObject) {
     if (targetAction.Parameters.Any(p => p.Specification.IsOfType(contextNakedObject.Specification))) {
         foreach (INakedObjectActionParameter parm in targetAction.Parameters) {
             if (parm.Specification.IsOfType(contextNakedObject.Specification)) {
                 string name = IdHelper.GetParameterInputId(targetAction, parm);
                 AddAttemptedValue(name, contextNakedObject);
             }
         }
     }
 }
Ejemplo n.º 8
0
 public static string GetParameterAutoCompleteId(INakedObjectAction action, INakedObjectActionParameter parameter) {
     var id = GetParameterInputId(action, parameter);
     return parameter.Specification.IsParseable ? id : id + sep + autoCompleteName;
 }
Ejemplo n.º 9
0
 public void ValidateParameter(INakedObjectAction action, INakedObjectActionParameter parm, INakedObject targetNakedObject, INakedObject valueNakedObject) {
     IConsent consent = parm.IsValid(targetNakedObject, valueNakedObject);
     if (!consent.IsAllowed) {
         ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), consent.Reason);
     }
 }
 public NakedObjectActionParameterParseable(int index, INakedObjectAction action, INakedObjectActionParamPeer peer)
     : base(index, action, peer) {}
Ejemplo n.º 11
0
 public void SetupAction(INakedObjectAction action) {
     this.action = action;
 }
Ejemplo n.º 12
0
 internal void SetSelectedParameters(INakedObjectAction action) {
     var refItems = action.Parameters.Where(p => p.IsObject && !p.Specification.IsParseable).Where(p => ValueProvider.GetValue(p.Id) != null).ToList();
     if (refItems.Any()) {
         Dictionary<string, INakedObject> items = refItems.ToDictionary(p => IdHelper.GetParameterInputId(action, p), p => FrameworkHelper.GetNakedObjectFromId(ValueProvider.GetValue(p.Id).AttemptedValue));
         items.ForEach(kvp => ViewData[kvp.Key] = kvp.Value);
     }
 }
Ejemplo n.º 13
0
 internal static bool ActionExecutingAsContributed(INakedObjectAction action, INakedObject targetNakedObject) {
     return action.IsContributedMethod && action.OnType != targetNakedObject.Specification;
 }
Ejemplo n.º 14
0
 public ActionContext(bool embeddedInObject, object target, INakedObjectAction action)
     : base(target) {
     EmbeddedInObject = embeddedInObject;
     Action = action;
 }
Ejemplo n.º 15
0
 public ParameterContext(bool embeddedInObject, object target, INakedObjectAction action, INakedObjectActionParameter parameter, bool isEdit)
     : base(embeddedInObject, target, action) {
     Parameter = parameter;
     IsParameterEdit = isEdit;
 }
Ejemplo n.º 16
0
 public ActionContext(object target, INakedObjectAction action)
     : base(target) {
     EmbeddedInObject = false;
     Action = action;
 }
Ejemplo n.º 17
0
        private IDictionary<string, INakedObject> GetOtherValues(INakedObjectAction action) {
            var results = new Dictionary<string, INakedObject>();
            var parms = new FormCollection(HttpContext.Request.Params);

            Decrypt(parms);

            foreach (INakedObjectActionParameter parm in action.Parameters) {
                string[] values =  GetRawValues(parms, IdHelper.GetParameterInputId(action, parm));
                results[parm.Id.ToLower()] = GetValue(values, parm.Specification);
            }

            return results;
        }
 public OneToManyActionParameterImpl(int index, INakedObjectAction actionImpl, INakedObjectActionParamPeer peer)
     : base(index, actionImpl, peer) {}
Ejemplo n.º 19
0
 public TestAction(string contributor, INakedObjectAction action, ITestHasActions owningObject, ITestObjectFactory factory) {
     SubMenu = contributor;
     this.owningObject = owningObject;
     this.factory = factory;
     this.action = action;
 }
Ejemplo n.º 20
0
 public TestAction(INakedObjectAction action, ITestHasActions owningObject, ITestObjectFactory factory)
     : this(string.Empty, action, owningObject, factory) {}
Ejemplo n.º 21
0
        internal void SetSelectedParameters(INakedObject nakedObject, INakedObjectAction action, IDictionary<string, string> dict) {
            var refItems = action.Parameters.Where(p => p.IsObject && !p.Specification.IsParseable).Where(p => dict.ContainsKey(p.Id)).ToList();
            if (refItems.Any()) {

                refItems.ForEach(p => ValidateParameter(action, p, nakedObject, FrameworkHelper.GetNakedObjectFromId(dict[p.Id])));

                Dictionary<string, INakedObject> items = refItems.ToDictionary(p => IdHelper.GetParameterInputId(action, p), p => FrameworkHelper.GetNakedObjectFromId(dict[p.Id]));
                items.ForEach(kvp => ViewData[kvp.Key] = kvp.Value);
            }
        }
Ejemplo n.º 22
0
 public INakedObjectAction GetAction() {
     if (nakedObjectAction == null) {
         nakedObjectAction = FrameworkHelper.GetActions(GetNakedObject()).SingleOrDefault(a => a.Id == ActionId);
     }
     return nakedObjectAction;
 }
Ejemplo n.º 23
0
 public ITestAction CreateTestAction(string contributor, INakedObjectAction action, ITestHasActions owningObject) {
     return new TestAction(contributor, action, owningObject, this);
 }
Ejemplo n.º 24
0
 public static string GetParameterContainerId(INakedObjectAction action) {
     return  action.Id + sep + ParamListName;
 }
Ejemplo n.º 25
0
 public ITestAction CreateTestAction(INakedObjectAction action, ITestHasActions owningObject) {
     return new TestAction(action, owningObject, this);
 }
Ejemplo n.º 26
0
 public static string GetOverloadedUId(INakedObjectAction action, INakedObjectSpecification spec) {
     INakedObjectAction[] actions = spec.GetActionLeafNodes();
     Tuple<INakedObjectAction, string>[] overloadedActions = GetOverloadedActionsAndUIds(actions);
     return overloadedActions.Where(oa => oa.Item1 == action).Select(oa => oa.Item2).SingleOrDefault();
 }
Ejemplo n.º 27
0
 public ITestParameter CreateTestParameter(INakedObjectAction action, INakedObjectActionParameter parameter, ITestHasActions owningObject) {
     return new TestParameter(action, parameter, owningObject, this);
 }
Ejemplo n.º 28
0
 public NakedObjectActionWrapper(INakedObjectAction action, INakedObjectsSurface surface, string overloadedUniqueId) {
     this.action = action;
     this.overloadedUniqueId = overloadedUniqueId;
     Surface = surface;
 }
Ejemplo n.º 29
0
 public TestParameter(INakedObjectAction action, INakedObjectActionParameter parameter, ITestHasActions owningObject, ITestObjectFactory factory) {
     this.action = action;
     this.parameter = parameter;
     this.owningObject = owningObject;
     this.factory = factory;
 }
Ejemplo n.º 30
0
        internal bool ValidateParameters(INakedObject targetNakedObject, INakedObjectAction action, ObjectAndControlData controlData) {

            // check mandatory fields first to emulate WPF UI behaviour where no validation takes place until 
            // all mandatory fields are set. 
            foreach (INakedObjectActionParameter parm in action.Parameters) {
                object result = GetRawParameterValue(parm, controlData, IdHelper.GetParameterInputId(action, parm));
                var stringResult = result as string;

                if (parm.IsMandatory && (result == null || (result is string && string.IsNullOrEmpty(stringResult)))) {
                    ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), MvcUi.Mandatory);
                }
            }

            //check for individual parameter validity, including parsing of text input
            if (ModelState.IsValid) {
                foreach (INakedObjectActionParameter parm in action.Parameters) {
                    try {
                        INakedObject valueNakedObject = GetParameterValue(parm, IdHelper.GetParameterInputId(action, parm), controlData);

                        ValidateParameter(action, parm, targetNakedObject, valueNakedObject);
                    }
                    catch (InvalidEntryException) {
                        ModelState.AddModelError(IdHelper.GetParameterInputId(action, parm), MvcUi.InvalidEntry);
                    }
                }
            }

            // check for validity of whole set, including any 'co-validation' involving multiple parameters
            if (ModelState.IsValid) {
                IEnumerable<INakedObject> parms = action.Parameters.Select(p => GetParameterValue(p, IdHelper.GetParameterInputId(action, p), controlData));

                IConsent consent = action.IsParameterSetValid(targetNakedObject, parms.ToArray());
                if (!consent.IsAllowed) {
                    ModelState.AddModelError(string.Empty, consent.Reason);
                }
            }

            return ModelState.IsValid;
        }