public static bool IsRedirectable(ActionCall action) { var outputType = action.OutputType(); if (outputType == null) return false; return outputType.CanBeCastTo<FubuContinuation>() || outputType.CanBeCastTo<IRedirectable>(); }
public void append_json() { action = ActionCall.For<ControllerTarget>(x => x.OneInOneOut(null)); action.AddToEnd(new RenderJsonNode(action.OutputType())); action.Next.ShouldBeOfType<RenderJsonNode>().ModelType.ShouldEqual(action.OutputType()); }
public IViewToken Find(ActionCall call, ViewBag views) { return views .ViewsFor(call.OutputType()) .Select(view => view.ToViewToken()) .FirstOrDefault(); }
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { if(call.OutputType() == typeof(FubuContinuation) || !_policyResolver.HasMatchFor(call)) { return new IViewToken[0]; } string viewName = _policyResolver.ResolveViewName(call); string viewLocatorName = _policyResolver.ResolveViewLocator(call); IEnumerable<SparkViewToken> allViewTokens = views.Views.Where(view => view.GetType().CanBeCastTo<SparkViewToken>()).Cast<SparkViewToken>(); SparkViewDescriptor matchedDescriptor = null; allViewTokens.FirstOrDefault( token => { matchedDescriptor = token.Descriptors .Where(e => e.Templates .Any(template => template.Contains(viewLocatorName) && template.Contains(viewName))) .SingleOrDefault(); return matchedDescriptor != null; }); IEnumerable<IViewToken> viewsBoundToActions = matchedDescriptor != null ? new IViewToken[] { new SparkViewToken(call, matchedDescriptor, viewLocatorName, viewName) } : new IViewToken[0]; return viewsBoundToActions; }
public IRouteDefinition Build(ActionCall call) { var routeDefinition = call.ToRouteDefinition(); routeDefinition.Append(call.HandlerType.Namespace.Replace(GetType().Namespace + ".", string.Empty).ToLower()); routeDefinition.Append(call.HandlerType.Name.Replace("Handler", string.Empty).ToLower()); return routeDefinition; }
public IRouteDefinition Build(ActionCall call) { var route = call.ToRouteDefinition(); route.Append(call.HandlerType.Name.RemoveSuffix("Controller")); route.Append(call.Method.Name); return route; }
public void should_log_when_default_route_found() { var call = new ActionCall(typeof(TestController), _method); _policy.Matches(call, _log); _log.GetLog(call).ShouldNotBeEmpty(); }
public IRouteDefinition Build(ActionCall call) { var routeDefinition = call.ToRouteDefinition(); var urlAttribute = call.Method.GetAttribute<FubuDiagnosticsUrlAttribute>(); routeDefinition.Append(DiagnosticsUrls.ToRelativeUrl(urlAttribute.Url)); return routeDefinition; }
public IRouteDefinition Build(ActionCall call) { var routeDefinition = call.ToRouteDefinition(); routeDefinition.Append(call.HandlerType.Namespace.Substring(call.HandlerType.Namespace.LastIndexOf('.') + 1)); routeDefinition.Append(call.HandlerType.Name.Substring(0, call.HandlerType.Name.LastIndexOf("Projection"))); return routeDefinition; }
private DataType BuildGraph( DataType parent, Type type, bool inputGraph, IEnumerable<Type> ancestors, MemberDescription memberDescription = null, ActionCall action = null) { var description = _typeConvention.GetDescription(type); var dataType = new DataType { Name = !type.IsSimpleType() && memberDescription != null ? memberDescription.Name : description.Name, LongNamespace = parent.MapOrEmpty(x => x.LongNamespace.Concat(x.Name).ToList(), new List<string>()), ShortNamespace = new List<string>(), Comments = description.Comments }; if (type.IsDictionary()) BuildDictionary(dataType, type, description, inputGraph, ancestors, memberDescription); else if (type.IsArray || type.IsList()) BuildArray(dataType, type, description, inputGraph, ancestors, memberDescription); else if (type.IsSimpleType()) BuildSimpleType(dataType, type); else BuildComplexType(dataType, type, inputGraph, ancestors, action); return _configuration.TypeOverrides.Apply(type, dataType); }
public IRouteDefinition Build(ActionCall call) { IRouteDefinition route = call.ToRouteDefinition(); if (!IgnoreControllerNamespaceEntirely) { addNamespace(route, call); } if (!IgnoreControllerNamesEntirely) addClassName(route, call); addMethodName(route, call); if (call.HasInput) { _routeInputPolicy.AlterRoute(route, call); } _modifications.Each(m => { if (m.Filter(call)) m.Modify(route); }); return route; }
private SparkViewToken GetJavaScriptViewToken(ActionCall call) { var response = JavaScriptResponse.GetResponse(call); string viewName = response.ViewName; string controllerName = call.HandlerType.Name.RemoveSuffix("Controller"); return _viewFactory.GetViewToken(call, controllerName, viewName, Spark.LanguageType.Javascript); }
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { string viewName = call.Method.Name; string actionName = _actionNameFromActionCallConvention(call.HandlerType.Name); IEnumerable<SparkViewToken> allViewTokens = views.Views.Cast<SparkViewToken>(); SparkViewDescriptor matchedDescriptor = null; allViewTokens.FirstOrDefault( token => { matchedDescriptor = token.Descriptors .Where(e => e.Templates .Exists(template => template.Contains(actionName) && template.Contains(viewName))) .SingleOrDefault(); return matchedDescriptor != null; }); IEnumerable<IViewToken> viewsBoundToActions = matchedDescriptor != null ? new IViewToken[] { new SparkViewToken(call, matchedDescriptor, actionName) } : new IViewToken[0]; return viewsBoundToActions; }
public IRouteDefinition Build(ActionCall call) { var routeDefinition = call.ToRouteDefinition(); var strippedNamespace = call .HandlerType .Namespace .Replace(typeof (EndpointMarker).Namespace + ".", string.Empty); if (strippedNamespace != call.HandlerType.Namespace) { if (!strippedNamespace.Contains(".")) { routeDefinition.Append(BreakUpCamelCaseWithHypen(strippedNamespace)); } else { var patternParts = strippedNamespace.Split(new[] { "." }, StringSplitOptions.None); foreach (var patternPart in patternParts) { routeDefinition.Append(BreakUpCamelCaseWithHypen(patternPart.Trim())); } } } routeDefinition.Append(BreakUpCamelCaseWithHypen(call.HandlerType.Name.Replace(ENDPOINT, string.Empty))); routeDefinition.ApplyRouteInputAttributes(call); routeDefinition.ApplyQueryStringAttributes(call); return routeDefinition; }
// TODO -- sucks, but need to break the IUrlPolicy signature to add diagnostics public IRouteDefinition Build(ActionCall call) { var route = call.ToRouteDefinition(); // TODO -- far better diagnostics here if (MethodToUrlBuilder.Matches(call.Method.Name)) { MethodToUrlBuilder.Alter(route, call); return route; } if (!IgnoreControllerNamespaceEntirely) { addNamespace(route, call); } if (!IgnoreControllerNamesEntirely) { addClassName(route, call); } AddMethodName(route, call); if (call.HasInput) { _routeInputPolicy.AlterRoute(route, call); } _modifications.Where(m => m.Filter(call)).Each(m => m.Modify(route)); return route; }
public void ShouldReturnNullForUnregisteredAction() { var call = new ActionCall(typeof(UnRegisteredAction), ReflectionHelper.GetMethod<UnRegisteredAction>(a => a.Get(new object()))); var context = new ValidationFailure(call, new Notification(typeof(object)), new object()); var request = descriptor.DescribeModelFor(context); request.ShouldBeNull(); }
public virtual void Attach(IViewProfile viewProfile, ViewBag bag, ActionCall action) { // No duplicate views! var outputNode = action.ParentChain().Output; if (outputNode.HasView(viewProfile.ConditionType)) return; var log = new ViewAttachmentLog(viewProfile); action.Trace(log); foreach (var filter in _filters) { var viewTokens = filter.Apply(action, bag); var count = viewTokens.Count(); if (count > 0) { log.FoundViews(filter, viewTokens.Select(x => x.Resolve())); } if (count != 1) continue; var token = viewTokens.Single().Resolve(); outputNode.AddView(token, viewProfile.ConditionType); break; } }
public IRouteDefinition Build(ActionCall call) { var route = call.ToRouteDefinition(); Alter(route, call); return route; }
public void ShouldGetRequestForViewModel() { var call = new ActionCall(typeof (RegisterAction),ReflectionHelper.GetMethod<RegisterAction>(a => a.Post(new RegisterViewModel()))); var context = new ValidationFailure(call, new Notification(typeof(RegisterViewModel)), new RegisterViewModel()); var request = descriptor.DescribeModelFor(context); request.ShouldEqual(typeof (RegisterRequest)); }
public IEnumerable<ActionCall> FindActions(TypePool types) { //var tpes = types.TypesMatching(t => t.Closes(typeof (StateMachine<>))); foreach(var sm in new List<Type>{typeof(TicketStateMachine)}) { //TODO: Where can I load things into the container - using ObjDef? var machine = (StateMachine)Activator.CreateInstance(sm); var t = typeof (StateMachineOptionsAction<>).MakeGenericType(sm); var ta = new ActionCall(t, t.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance)); //can I build the route here? yield return ta; var tt = typeof(StateMachineInstanceOptionsAction<>).MakeGenericType(sm); yield return new ActionCall(tt, tt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance)); var ttt = typeof(StateMachineCurrentStateAction<>).MakeGenericType(sm); yield return new ActionCall(ttt, ttt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance)); foreach (var @event in machine.Events) { //need to track the event name //between here and the event url generation //so I used a custom ActionCall extension var eventName = @event.Name; var et = typeof (StateMachineRaiseEventAction<,>).MakeGenericType(sm, @event.GetType()); var call = new EventActionCall(eventName, et, et.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance)); yield return call; } } }
public void SetUp() { action1 = ActionCall.For<ControllerTarget>(x => x.OneInZeroOut(null)); action2 = ActionCall.For<ActionCallFilterController>(x => x.DifferentMethod()); filter = new CompositeFilter<ActionCall>(); expression = new ActionCallFilterExpression(filter); }
public void AttemptToAttachViewToAction(ViewBag bag, ActionCall call, IConfigurationObserver observer) { foreach (var filter in _filters) { var viewTokens = filter.Apply(call, bag); var count = viewTokens.Count(); observer.RecordCallStatus(call, "View filter '{0}' found {1} view token{2}".ToFormat( filter.GetType().Name, count, (count != 1) ? "s" : "" )); if( count > 0 ) { viewTokens.Each(t => observer.RecordCallStatus(call, "Found view token: {0}".ToFormat(t))); } // if the filter returned more than one, consider it "failed", ignore it, and move on to the next if (count == 1) { var token = viewTokens.First(); observer.RecordCallStatus(call, "Selected view token: {0}".ToFormat(token)); call.AddToEnd(token.ToBehavioralNode()); break; } } }
public Task TransferToCall(ActionCall call, string categoryOrHttpMethod = null) { var chain = _resolver.Find(call.HandlerType, call.Method, categoryOrHttpMethod); var partial = _factory.BuildBehavior(chain); return partial.InvokePartial(); }
public string BuildViewLocator(ActionCall call) { var strippedName = call.HandlerType.FullName.RemoveSuffix(DiagnosticsEndpointUrlPolicy.ENDPOINT); _markerTypes.Each(type => strippedName = strippedName.Replace(type.Namespace + ".", string.Empty)); if (!strippedName.Contains(".")) { return string.Empty; } var viewLocator = new StringBuilder(); while (strippedName.Contains(".")) { viewLocator.Append(strippedName.Substring(0, strippedName.IndexOf("."))); strippedName = strippedName.Substring(strippedName.IndexOf(".") + 1); var hasNext = strippedName.Contains("."); if (hasNext) { viewLocator.Append(Path.DirectorySeparatorChar); } } return viewLocator.ToString(); }
public void should_log_when_default_route_found() { var call = new ActionCall(typeof (TestController), _method); _policy.Matches(call); call.As<ITracedModel>().StagedEvents.OfType<Traced>().Any().ShouldBeTrue(); }
public override void Alter(ActionCall call) { var chain = call.ParentChain(); if (_formatters == FormatterOptions.All) { chain.Input.AllowHttpFormPosts = true; chain.UseFormatter<JsonFormatter>(); chain.UseFormatter<XmlFormatter>(); return; } if ((_formatters & FormatterOptions.Json) != 0) { chain.UseFormatter<JsonFormatter>(); } if ((_formatters & FormatterOptions.Xml) != 0) { chain.UseFormatter<XmlFormatter>(); } if ((_formatters & FormatterOptions.Html) != 0) { chain.Input.AllowHttpFormPosts = true; } else { chain.Input.AllowHttpFormPosts = false; } }
public SparkViewToken(ActionCall actionCall, SparkViewDescriptor matchedDescriptor, string actionName, string viewName) { _actionCall = actionCall; _matchedDescriptor = matchedDescriptor; _actionName = actionName; _viewName = viewName; }
public IRouteDefinition Build(ActionCall call) { var className = call.HandlerType.Name.ToLower() .Replace("endpoints", "") .Replace("endpoint", "") .Replace("controller", ""); RouteDefinition route = null; if (RouteDefinition.VERBS.Any(x => x.EqualsIgnoreCase(call.Method.Name))) { route = new RouteDefinition(className); route.AddHttpMethodConstraint(call.Method.Name.ToUpper()); } else { route = new RouteDefinition("{0}/{1}".ToFormat(className, call.Method.Name.ToLowerInvariant())); } if (call.InputType() != null) { if (call.InputType().CanBeCastTo<ResourcePath>()) { ResourcePath.AddResourcePathInputs(route); } else { AddBasicRouteInputs(call, route); } } return route; }
public bool Matches(ActionCall call, IConfigurationObserver log) { var result = call.InputType() == _inputType; if (result && _foundCallAlready) { throw new FubuException(1003, "Cannot make input type '{0}' the default route as there is more than one action that uses that input type. Either choose a input type that is used by only one action, or use the other overload of '{1}' to specify the actual action method that will be called by the default route.", _inputType.Name, ReflectionHelper.GetMethod<RouteConventionExpression>(r => r.HomeIs<object>()). Name ); } if (result) _foundCallAlready = true; if (result && log.IsRecording) { log.RecordCallStatus(call, "Action '{0}' is the default route since its input type is {1} which was specified in the configuration as the input model for the default route" .ToFormat(call.Method.Name, _inputType.Name)); } return result; }
public void Matches_should_return_true_for_GetEntityList_action_call_handlers() { var policy = new ListingHandlerUrlPolicy(); var action = new ActionCall(typeof(ListingHandler<StubViewModel, StubEntity>), null); Assert.IsTrue(policy.Matches(action, null)); }
public static ActionCall VerbHandler() { return(ActionCall.For <Handlers.Posts.Sub.Route.PostHandler>(h => h.Execute(new Handlers.Posts.Sub.Route.ViewPostHandlerRequestModel()))); }
public IRouteDefinition Build(ActionCall call) { return(call.ToRouteDefinition()); }
public bool Matches(ActionCall call) { return(call.Method.DeclaringType.Name == DefaultHomeControllerConvention && call.Method.Name == DefaultHomeMethodConvention); }
public void RedirectToCall(ActionCall call, string categoryOrHttpMethod = null) { string url = _registry.UrlFor(call.HandlerType, call.Method, categoryOrHttpMethod ?? "GET"); _writer.RedirectToUrl(url); }
public IEnumerable <ActionCall> FindActions(TypePool types) { yield return(ActionCall.For <SimpleController>(c => c.Action())); }
public IEnumerable <ActionCall> FindActions(Assembly assembly) { yield return(ActionCall.For <WindowsController>(x => x.Login(null))); }
public static ActionCall HandlerCall() { return(ActionCall.For <get_handler>(h => h.Execute(new CreatePostRequestModel()))); }
public static ActionCall HandlerWithAttributeCall() { return(ActionCall.For <UrlPatternHandler>(h => h.Execute())); }
public static ActionCall ComplexHandlerCall() { return(ActionCall.For <Handlers.Posts.ComplexRoute.GetHandler>(h => h.Execute())); }
public static ActionCall HandlerWithRouteInput() { return(ActionCall.For <get_Year_Month_Title_handler>(h => h.Execute(new ViewPostRequestModel()))); }
private void addWritingAction(BehaviorChain chain) { var call = ActionCall.For <AssetWriter>(x => x.Write(null)); chain.AddToEnd(call); }
public static ActionCall NonHandlerCall() { return(ActionCall.For <SampleController>(c => c.Hello())); }
public bool Matches(ActionCall call) { return(call.Method.Matches(_method)); }
public bool Matches(ActionCall call, IConfigurationObserver log) { return(call.HandlerType.Name.EndsWith("Controller")); }
private bool callMatches(ActionCall call) { return(_call != null && call.HandlerType == _call.HandlerType && call.Method == _call.Method); }
public static bool ShouldBePartial(ActionCall call) { return(call.Method.Name.EndsWith(Partial)); }
public RouteBuilderInfo(ActionCall call, RoutingConventions conventions) { _conventions = conventions; ActionCall = call; }
public void AssertWasTransferedTo <T>(Expression <Action <T> > expression) { ActionCall call = ActionCall.For(expression); assertMatches(_type == ContinuationType.Transfer && callMatches(call)); }
public ActionUrl(IRouteDefinition route, ActionCall call) { _route = route; HandlerType = call.HandlerType; Method = call.Method; }
public void AssertWasRedirectedTo <T>(Expression <Action <T> > expression) { ActionCall call = ActionCall.For(expression); assertMatches(_type == ContinuationType.Redirect && callMatches(call)); }
public static void ApplyRouteInputAttributes(this IRouteDefinition routeDefinition, ActionCall call) { if (call.HasInput) { call .InputType() .PropertiesWhere(p => p.HasAttribute <RouteInputAttribute>()) .Each(p => routeDefinition.Input.AddRouteInput(new RouteParameter(new SingleProperty(p)), true)); } }
public override void Alter(ActionCall call) { call.ParentChain().MakeAsymmetricJson(); }
public bool Matches(ActionCall call) { return(Matches(call.Method.Name)); }
public static void ApplyQueryStringAttributes(this IRouteDefinition routeDefinition, ActionCall call) { if (call.HasInput) { call .InputType() .PropertiesWhere(p => p.HasAttribute <QueryStringAttribute>()) .Each(routeDefinition.Input.AddQueryInput); } }
public override void Alter(ActionCall call) { call.ParentChain().UrlCategory.Creates.Add(Type); }
static public ActionBase Create(string ActionObjectString) { ActionBase output = null; try { output = Activator.CreateInstance("AutoRobo.Core", "AutoRobo.Core.Actions." + ActionObjectString).Unwrap() as ActionBase; } catch { //兼容老版本数据 switch (ActionObjectString) { case "BrowserClick": output = new ActionClick(); break; case "Navigate": output = new ActionNavigate(); break; case "ScriptPart": output = new ActionScriptPart(); break; case "AlertHandler": output = new ActionAlertHandler(); break; case "ActionDoubleClick": output = new ActionDoubleClick(); break; case "ActionFireEvent": output = new ActionFireEvent(); break; case "ActionKey": output = new ActionKey(); break; case "Mouse": output = new ActionMouse(); break; case "RadioButton": output = new ActionRadio(); break; case "Checkbox": output = new ActionCheckbox(); break; case "SelectList": output = new ActionSelectList(); break; case "TypeText": output = new ActionTypeText(); break; case "DirectionKey": output = new ActionDirectionKey(); break; case "Sleep": output = new ActionSleep(); break; case "Wait": output = new ActionWait(); break; case "ValidateCode": output = new ActionValidateCode(); break; case "FileUpload": output = new ActionFileDialog(); break; case "ValidateImage": output = new ActionValidateImage(); break; case "JavascriptInterpreter": output = new ActionJavascriptInterpreter(); break; case "SubmitClick": output = new ActionSubmitClick(); break; case "CloseWindow": output = new ActionCloseWindow(); break; case "WindowBack": output = new ActionBack(); break; case "WindowForward": output = new ActionForward(); break; case "WindowOpen": output = new ActionOpenWindow(); break; case "WindowRefresh": output = new ActionRefresh(); break; case "SubElementFinder": output = new ActionSubElements(); break; case "CallFunction": output = new ActionCall(); break; case "ActionForeach": output = new ActionForeach(); break; case "ActionBrowser": output = new ActionBrowser(); break; case "ActionThread": output = new ActionThread(); break; //case "AddChildrenToList": output = new AddChildrenToList(); break; } } //if (output == null) //{ // throw new ApplicationException(string.Format("{0}对应的活动未找到", ActionObjectString)); //} return(output); }
public IActionBehavior BuildPartial(ActionCall call) { Guid id = _graph.IdForCall(call); return(_factory.BuildBehavior(_arguments, id)); }
public new static DiagnosticChain For <T>(Expression <Action <T> > method) { var call = ActionCall.For(method); return(new DiagnosticChain(call)); }
public string BuildViewName(ActionCall call) { return(call.InputType().Name.RemoveSuffix("Model")); }
public JavaScriptOutputNode(SparkViewToken viewToken, ActionCall actionCall) : base(viewToken, actionCall) { }