private void SerializePath(IRouteAction action, IPathStack path, bool requireEntry) { IControllerBinding[] bindings = GetControllerBindings(action.ControllerType); if (bindings == null || bindings.Length == 0) throw new BindingException(String.Format("Type \"{0}\" is not bindable.", action.ControllerType.FullName)); IPathStack bestStack = null; foreach (IControllerBinding b in bindings) if (!requireEntry || b is IEntryControllerBinding) { IPathStack trialStack = new PathStack(false); if (requireEntry) ((IEntryControllerBinding)b).SerializeToPath(action, trialStack); else b.SerializeToPath(action, trialStack); IRouteAction childAction = action.ChildAction; if (childAction != null) { SerializePath(childAction, trialStack, false); } if (bestStack == null || trialStack.Index > bestStack.Index || (trialStack.Index == bestStack.Index && trialStack.QueryString.Count > bestStack.QueryString.Count)) bestStack = trialStack; } if (bestStack != null) { path.Push(bestStack); } else throw new BindingException(String.Format("Type \"{0}\" is not a bindable EntryController.", action.ControllerType.FullName)); }
public virtual void SerializeToPath(IRouteAction action, IPathStack path) { // TODO: child action binding if (_handlers == null) return; IPathStack bestStack = null; foreach (ActionHandler handler in _handlers) { if (handler.Action == action.Method) { IPathStack trialStack = new PathStack(false); handler.Binding.SerializePath(trialStack, action.Parameters); if (action.ChildAction != null) { if (!(handler is ParentActionHandler)) throw new BindingException("Method is not a parent action and can't handle further calls."); } else { if (handler is ParentActionHandler) throw new BindingException("Method is a parent action. You should add the default sub-action."); } if (trialStack.Index == 0) trialStack.TrailingSlash = !DisableTrailingSlash; if (bestStack == null || trialStack.Index > bestStack.Index || (trialStack.Index == bestStack.Index && trialStack.QueryString.Count > bestStack.QueryString.Count)) bestStack = trialStack; } } if (bestStack != null) { path.Push(bestStack); } else throw new BindingException(String.Format("Method \"{0}\" is not bindable.", action.Method.Name)); }
public void SerializeToPath(IPathStack path) { foreach (string keyword in keywords) path.Push(keyword); }
protected override void SerializePath(IPathStack path, object value) { if (value == null || value as string == "" || value == DefaultValue) { _emptyPath.SerializeToPath(path); return; } IPathSerializable serializable = value as IPathSerializable; if (serializable != null) serializable.SerializeToPath(path); else { try { path.Push(SerializationHelper.Serialize(value) + Extension); } catch (Exception e) { throw new BindingException(e.Message, e); } } }