Exemple #1
0
        public IEnumerable <IViewToken> FindViews(TypePool types, BehaviorGraph graph)
        {
            var viewTokens = new List <IViewToken>();

            graph
            .Actions()
            .Where(call => _policyResolver.HasMatchFor(call))
            .Each(call =>
            {
                var sparkBatchEntry = new SparkBatchEntry {
                    ControllerType = call.HandlerType
                };
                string viewLocatorName = _policyResolver.ResolveViewLocator(call);
                IList <SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, viewLocatorName);
                viewTokens.Add(new SparkViewToken(descriptors));
            });
            return(viewTokens);
        }
Exemple #2
0
        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}{2}".ToFormat(viewLocatorName, Path.DirectorySeparatorChar, view) : view;
                var descriptor   = token
                                   .Descriptors
                                   .FirstOrDefault(d => d.Templates.Any(template => template.RemoveSuffix(".spark").ToLower().Equals(templatePath.ToLower())));

                if (descriptor != null)
                {
                    matchedDescriptor = descriptor;
                    break;
                }
            }

            if (matchedDescriptor == null)
            {
                return(new IViewToken[0]);
            }

            _visitorRegistry
            .VisitorsFor(call)
            .Each(visitor => visitor.Visit(matchedDescriptor, call));

            return(new IViewToken[] { new SparkViewToken(call, matchedDescriptor, viewLocatorName, viewName) });
        }