/// <summary> /// Binds the model to a value by using the specified controller context and binding context. /// </summary> /// <param name="actionContext">The action context.</param> /// <param name="bindingContext">The binding context.</param> /// <returns> /// The bound value. /// </returns> public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { Debug.Assert(bindingContext.ModelType == typeof(ActionEventArgs)); string args = GetStringValue(bindingContext.ValueProvider, bindingContext.ModelName); if (args != null) { string salt = GetStringValue(bindingContext.ValueProvider, "salt"); var model = ActionEventConverter.DecodeActionEvent(args, salt); if (model != null) { bindingContext.Model = model; return(true); } } return(false); }
/// <summary> /// Replaces all the placeholders using the specified source object. /// </summary> /// <param name="template">The template to parse.</param> /// <param name="accessors">The accessor functions.</param> /// <param name="options">A set of key/value pairs that can be used to configure the HTML compiler.</param> /// <returns></returns> private string ReplaceAll(string template, ImmutableDictionary <string, object> options, ImmutableDictionary <string, ObjectDescriptor> accessors) { Debug.Assert(template != null); Debug.Assert(options != null); Debug.Assert(accessors != null); object temp; var hasContactId = options.TryGetValue(IdentityIdProperty, out temp); var contactId = hasContactId ? (int?)temp : null; template = s_exprRegex.Replace(template, match => { if (match.Groups.Count >= 3) { string type = match.Groups[1].Value; string value = match.Groups[2].Value; int actionLinkId; if (type.Equals("#a", StringComparison.OrdinalIgnoreCase) && int.TryParse(value, out actionLinkId)) { return(ActionEventConverter.ActionLink(new ActionEventArgs(ObjectType.Action, actionLinkId, contactId))); } ObjectDescriptor descriptor; if (accessors.TryGetValue(type, out descriptor)) { Func <object, object> accessor; if (descriptor.Instance != null && descriptor.Accessors.TryGetValue(value, out accessor)) { return(accessor(descriptor.Instance)?.ToString() ?? string.Empty); } return(string.Empty); } } return(string.Empty); }); if (hasContactId) { template = ActionLinkService.ReplaceLinks(template, p => p.ContactId = contactId); } return(template); }