public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { string viewName = _getViewNameFromActionCall(call); string viewLocatorName = _getViewLocatorNameFromActionType(call.HandlerType); 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 void Configure(BehaviorGraph graph) { var views = _facilities.SelectMany(x => x.FindViews(_types)); var bag = new ViewBag(views); graph.Actions().Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer)); }
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 IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { if(call.OutputType() == typeof(FubuContinuation) || !_policyResolver.HasMatchFor(call)) { return new IViewToken[0]; } var viewName = _policyResolver.ResolveViewName(call); var viewLocatorName = _policyResolver.ResolveViewLocator(call); var allViewTokens = views .Views .Where(view => view.GetType().CanBeCastTo<SparkViewToken>()) .Cast<SparkViewToken>(); SparkViewDescriptor matchedDescriptor = null; foreach(var token in allViewTokens) { var view = viewName.RemoveSuffix(".spark"); var templatePath = !string.IsNullOrEmpty(viewLocatorName) ? "{0}\\{1}".ToFormat(viewLocatorName, view) : view; var descriptor = token .Descriptors .FirstOrDefault(d => d.Templates.Any(template => template.RemoveSuffix(".spark").Equals(templatePath))); if(descriptor != null) { matchedDescriptor = descriptor; break; } } return matchedDescriptor != null ? new IViewToken[] { new SparkViewToken(call, matchedDescriptor, viewLocatorName, viewName) } : new IViewToken[0]; }
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 void Configure(BehaviorGraph graph) { var discoveredViewTokens = _facilities.SelectMany(x => x.FindViews(_types)); var bag = new ViewBag(discoveredViewTokens); graph.Actions().Each(a => attachView(bag, a)); }
public void Configure(BehaviorGraph graph) { IEnumerable<IViewToken> views = _facilities.SelectMany(x => x.FindViews(_types)); var bag = new ViewBag(views); graph.Actions().Each(a => { attachView(bag, a); }); }
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 IViewToken Find(ActionCall call, ViewBag views) { return views .ViewsFor(call.OutputType()) .Where(view => view.ViewType.Namespace == call.HandlerType.Namespace) .FirstOrDefault(); }
private void attachView(ViewBag bag, ActionCall call) { foreach (var strategy in _strategies) { var token = strategy.Find(call, bag); if (token == null) continue; call.Append(token.ToBehavioralNode()); break; } }
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { var proposedFolder = GetSparkViewPath(call); var proposedFile = GetSparkViewFile(call); var sparkFolder = new VirtualPathProviderViewFolder(proposedFolder); return ( sparkFolder.HasView(proposedFile)) ? new IViewToken[]{new SparkViewToken(proposedFolder + "/" + proposedFile)} : new IViewToken[0]; }
private void attachView(ViewBag bag, ActionCall call) { foreach (IViewAttachmentStrategy strategy in _strategies) { IEnumerable<IViewToken> tokens = strategy.Find(call, bag); if (tokens.Count() == 1) { IViewToken token = tokens.First(); call.Append(token.ToBehavioralNode()); break; } } }
public void Setup() { var types = new TypePool(); _observer = new RecordingConfigurationObserver(); _action = ActionCall.For<ViewsForActionFilterTesterController>(x => x.AAction()); _fromFindsOne = new FakeViewToken(); _fromSecondFindsOne = new FakeViewToken(); _views = new ViewBag(new IViewToken[] { _fromFindsOne, _fromSecondFindsOne }); _filterThatFindsNone = createFilterThatReturns(new IViewToken[0]); _firstFilterThatFindsExactlyOne = createFilterThatReturns(_fromFindsOne); _secondFilterThatFindsExactlyOne = createFilterThatReturns(_fromSecondFindsOne); _filterThatFindsMultiple = createFilterThatReturns(_fromFindsOne, _fromSecondFindsOne); _viewAttacher = new ViewAttacher(types); }
public void Configure(BehaviorGraph graph) { var views = new List<IViewToken>(); foreach (var facility in _facilities) { views.AddRange(facility.FindViews(_types)); } //= _facilities.SelectMany(x => x.FindViews(_types)); var bag = new ViewBag(views); graph.Actions().Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer)); }
public void Configure(BehaviorGraph graph) { _types.ShouldScanAssemblies = true; var views = new List <IViewToken>(); foreach (var facility in _facilities) { views.AddRange(facility.FindViews(_types, graph)); } //= _facilities.SelectMany(x => x.FindViews(_types)); var bag = new ViewBag(views); graph.Behaviors .Select(x => x.FirstCall()) .Where(x => x != null) .Each(a => AttemptToAttachViewToAction(bag, a, graph.Observer)); }
public IEnumerable <IViewToken> Apply(ActionCall call, ViewBag views) { return(views.ViewsFor(call.OutputType()).Where(view => view.Name == call.Method.Name && view.Folder == call.HandlerType.Namespace)); }
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { return views.ViewsFor(call.OutputType()); }
public void SetUp() { token = new FakeViewToken { Name = "A", Namespace = GetType().Namespace, ViewModelType = typeof (ViewModel1) }; var views = new List<IViewToken> { token }; bag = new ViewBag(views); strategy = new TypeAndNamespace(); }
public IEnumerable<IViewToken> Find(ActionCall call, ViewBag views) { return views.ViewsFor(call.OutputType()).Where( view => { return view.Name == call.Method.Name && view.Namespace == call.HandlerType.Namespace; }); }
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views) { return views.ViewsFor(call.OutputType()).Where(view => view.Folder == call.HandlerType.Namespace); }
public IEnumerable <IViewToken> Apply(ActionCall call, ViewBag views) { return(views.ViewsFor(call.OutputType())); }
public void SetUp() { token = new FakeViewToken { ViewType = typeof(AAction), ViewModelType = typeof (ViewModel1) }; var views = new List<IViewToken> { token }; bag = new ViewBag(views); strategy = new TypeAndNamespaceAndName(); }
public void SetUp() { token = new FakeViewToken { Name = "AAction", Folder = GetType().Namespace, ViewType = typeof(AAction), ViewModelType = typeof (ViewModel1) }; var views = new List<IViewToken> { token }; bag = new ViewBag(views); filter = new ActionWithSameNameAndFolderAsViewReturnsViewModelType(); }