Esempio n. 1
0
        public IEnumerable<IViewToken> FindViews(TypePool types)
        {
            IEnumerable<Type> actionTypes = types.TypesMatching(_sparkActionEndPointConventionFilter);

            var viewTokens = new List<IViewToken>();
            actionTypes.Each(actionType =>
                                 {
                                     var sparkBatchEntry = new SparkBatchEntry {ControllerType = actionType};
                                     IList<SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, _getActionNameFromCallConvention);
                                     viewTokens.Add(new SparkViewToken(descriptors));
                                 });
            return viewTokens;
        }
Esempio n. 2
0
        public IEnumerable<IViewToken> FindViews(TypePool types)
        {
            IEnumerable<Type> actionTypes = types.TypesMatching(_actionEndPointFilter);

            var viewTokens = new List<IViewToken>();
            actionTypes.Each(actionType =>
                                 {
                                     var sparkBatchEntry = new SparkBatchEntry { ControllerType = actionType };
                                     string viewLocatorName = _getViewLocatorNameFromActionType(actionType);
                                     IList<SparkViewDescriptor> descriptors = _viewFactory.CreateDescriptors(sparkBatchEntry, viewLocatorName);
                                     viewTokens.Add(new SparkViewToken(descriptors));
                                 });
            return viewTokens;
        }
Esempio n. 3
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;
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public IList<SparkViewDescriptor> CreateDescriptors(SparkBatchEntry entry)
        {
            var descriptors = new List<SparkViewDescriptor>();

            var controllerName = RemoveSuffix(entry.ControllerType.Name, "Controller");

            var viewNames = new List<string>();
            var includeViews = entry.IncludeViews;
            if (includeViews.Count == 0)
                includeViews = new[] { "*" };

            foreach (var include in includeViews)
            {
                if (include.EndsWith("*"))
                {
                    foreach (var fileName in ViewFolder.ListViews(controllerName))
                    {
                        if (!string.Equals(Path.GetExtension(fileName), ".spark", StringComparison.InvariantCultureIgnoreCase))
                            continue;

                        var potentialMatch = Path.GetFileNameWithoutExtension(fileName);
                        if (!TestMatch(potentialMatch, include))
                            continue;

                        var isExcluded = false;
                        foreach (var exclude in entry.ExcludeViews)
                        {
                            if (!TestMatch(potentialMatch, RemoveSuffix(exclude, ".spark")))
                                continue;

                            isExcluded = true;
                            break;
                        }
                        if (!isExcluded)
                            viewNames.Add(potentialMatch);
                    }
                }
                else
                {
                    // explicitly included views don't test for exclusion
                    viewNames.Add(RemoveSuffix(include, ".spark"));
                }
            }

            foreach (var viewName in viewNames)
            {
                if (entry.LayoutNames.Count == 0)
                {
                    descriptors.Add(CreateDescriptor(
                                        entry.ControllerType.Namespace,
                                        controllerName,
                                        viewName,
                                        null /*masterName*/,
                                        true));
                }
                else
                {
                    foreach (var masterName in entry.LayoutNames)
                    {
                        descriptors.Add(CreateDescriptor(
                                            entry.ControllerType.Namespace,
                                            controllerName,
                                            viewName,
                                            string.Join(" ", masterName.ToArray()),
                                            false));
                    }
                }
            }

            return descriptors;
        }
        public IList <SparkViewDescriptor> CreateDescriptors(SparkBatchEntry entry)
        {
            var descriptors = new List <SparkViewDescriptor>();

            var controllerName = RemoveSuffix(entry.ControllerType.Name, "Controller");

            var viewNames    = new List <string>();
            var includeViews = entry.IncludeViews;

            if (includeViews.Count == 0)
            {
                includeViews = new[] { "*" }
            }
            ;

            foreach (var include in includeViews)
            {
                if (include.EndsWith("*"))
                {
                    foreach (var fileName in ViewFolder.ListViews(controllerName))
                    {
                        if (!string.Equals(Path.GetExtension(fileName), ".spark", StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        var potentialMatch = Path.GetFileNameWithoutExtension(fileName);
                        if (!TestMatch(potentialMatch, include))
                        {
                            continue;
                        }

                        var isExcluded = false;
                        foreach (var exclude in entry.ExcludeViews)
                        {
                            if (!TestMatch(potentialMatch, RemoveSuffix(exclude, ".spark")))
                            {
                                continue;
                            }

                            isExcluded = true;
                            break;
                        }
                        if (!isExcluded)
                        {
                            viewNames.Add(potentialMatch);
                        }
                    }
                }
                else
                {
                    // explicitly included views don't test for exclusion
                    viewNames.Add(RemoveSuffix(include, ".spark"));
                }
            }

            foreach (var viewName in viewNames)
            {
                if (entry.LayoutNames.Count == 0)
                {
                    descriptors.Add(CreateDescriptor(
                                        entry.ControllerType.Namespace,
                                        controllerName,
                                        viewName,
                                        null /*masterName*/,
                                        true));
                }
                else
                {
                    foreach (var masterName in entry.LayoutNames)
                    {
                        descriptors.Add(CreateDescriptor(
                                            entry.ControllerType.Namespace,
                                            controllerName,
                                            viewName,
                                            string.Join(" ", masterName.ToArray()),
                                            false));
                    }
                }
            }

            return(descriptors);
        }
Esempio n. 7
0
        public IList <SparkViewDescriptor> CreateDescriptors(SparkBatchEntry entry)
        {
            var descriptors = new List <SparkViewDescriptor>();

            var metaDesc = _controllerDescriptorProvider.BuildDescriptor(entry.ControllerType);

            var controllerName = metaDesc.ControllerDescriptor.Name;
            var controllerPath = controllerName;

            if (!string.IsNullOrEmpty(metaDesc.ControllerDescriptor.Area))
            {
                controllerPath = metaDesc.ControllerDescriptor.Area + "\\" + controllerName;
            }

            var viewNames    = new List <string>();
            var includeViews = entry.IncludeViews;

            if (includeViews.Count == 0)
            {
                includeViews = new[] { "*" }
            }
            ;

            var accessors = new List <SparkViewDescriptor.Accessor>();

            foreach (var helper in metaDesc.Helpers)
            {
                var typeName     = helper.HelperType.FullName;
                var propertyName = helper.Name ?? helper.HelperType.Name;
                accessors.Add(new SparkViewDescriptor.Accessor
                {
                    Property = typeName + " " + propertyName,
                    GetValue = "Helper<" + typeName + ">(\"" + propertyName + "\")"
                });
            }

            foreach (var include in includeViews)
            {
                if (include.EndsWith("*"))
                {
                    foreach (var fileName in ViewSourceLoader.ListViews(controllerPath))
                    {
                        // ignore files which are not spark extension
                        if (!string.Equals(Path.GetExtension(fileName), ".spark", StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        var potentialMatch = Path.GetFileNameWithoutExtension(fileName);
                        if (!TestMatch(potentialMatch, include))
                        {
                            continue;
                        }

                        var isExcluded = false;
                        foreach (var exclude in entry.ExcludeViews)
                        {
                            if (!TestMatch(potentialMatch, RemoveSuffix(exclude, ".spark")))
                            {
                                continue;
                            }

                            isExcluded = true;
                            break;
                        }
                        if (!isExcluded)
                        {
                            viewNames.Add(potentialMatch);
                        }
                    }
                }
                else
                {
                    // explicitly included views don't test for exclusion
                    viewNames.Add(RemoveSuffix(include, ".spark"));
                }
            }

            foreach (var viewName in viewNames)
            {
                var layoutNamesList = entry.LayoutNames;
                if (layoutNamesList.Count == 0)
                {
                    var action = metaDesc.Actions[viewName];
                    if (action != null)
                    {
                        var actionDesc = metaDesc.ActionDescriptors[action];
                        if (actionDesc != null && actionDesc.Layout != null)
                        {
                            layoutNamesList = new[] { actionDesc.Layout.LayoutNames }
                        }
                        ;
                    }
                }
                if (layoutNamesList.Count == 0)
                {
                    if (metaDesc.Layout != null)
                    {
                        layoutNamesList = new[] { metaDesc.Layout.LayoutNames }
                    }
                    ;
                    else
                    {
                        layoutNamesList = new[] { new string[0] }
                    };
                }

                foreach (var layoutNames in layoutNamesList)
                {
                    descriptors.Add(CreateDescriptor(
                                        entry.ControllerType.Namespace,
                                        controllerPath,
                                        viewName,
                                        layoutNames,
                                        accessors));
                }
            }

            return(descriptors);
        }
Esempio n. 8
0
        public IList<SparkViewDescriptor> CreateDescriptors(SparkBatchEntry entry)
        {
            var descriptors = new List<SparkViewDescriptor>();

            var metaDesc = _controllerDescriptorProvider.BuildDescriptor(entry.ControllerType);

            var controllerName = metaDesc.ControllerDescriptor.Name;
            var controllerPath = controllerName;
            if (!string.IsNullOrEmpty(metaDesc.ControllerDescriptor.Area))
                controllerPath = string.Format("{0}{1}{2}", metaDesc.ControllerDescriptor.Area, Path.DirectorySeparatorChar, controllerName);

            var viewNames = new List<string>();
            var includeViews = entry.IncludeViews;
            if (includeViews.Count == 0)
                includeViews = new[] { "*" };

            var accessors = new List<SparkViewDescriptor.Accessor>();
            foreach (var helper in metaDesc.Helpers)
            {
                var typeName = helper.HelperType.FullName;
                var propertyName = helper.Name ?? helper.HelperType.Name;
                accessors.Add(new SparkViewDescriptor.Accessor
                                  {
                                      Property = typeName + " " + propertyName,
                                      GetValue = "Helper<" + typeName + ">(\"" + propertyName + "\")"
                                  });
            }

            foreach (var include in includeViews)
            {
                if (include.EndsWith("*"))
                {
                    foreach (var fileName in ViewSourceLoader.ListViews(controllerPath))
                    {
                        // ignore files which are not spark extension
                        if (!string.Equals(Path.GetExtension(fileName), ".spark", StringComparison.InvariantCultureIgnoreCase))
                            continue;

                        var potentialMatch = Path.GetFileNameWithoutExtension(fileName);
                        if (!TestMatch(potentialMatch, include))
                            continue;

                        var isExcluded = false;
                        foreach (var exclude in entry.ExcludeViews)
                        {
                            if (!TestMatch(potentialMatch, RemoveSuffix(exclude, ".spark")))
                                continue;

                            isExcluded = true;
                            break;
                        }
                        if (!isExcluded)
                            viewNames.Add(potentialMatch);
                    }
                }
                else
                {
                    // explicitly included views don't test for exclusion
                    viewNames.Add(RemoveSuffix(include, ".spark"));
                }
            }

            foreach (var viewName in viewNames)
            {
                var layoutNamesList = entry.LayoutNames;
                if (layoutNamesList.Count == 0)
                {
                    var action = metaDesc.Actions[viewName];
                    if (action != null)
                    {
                        var actionDesc = metaDesc.ActionDescriptors[action];
                        if (actionDesc != null && actionDesc.Layout != null)
                            layoutNamesList = new[] { actionDesc.Layout.LayoutNames };
                    }
                }
                if (layoutNamesList.Count == 0)
                {
                    if (metaDesc.Layout != null)
                        layoutNamesList = new[] { metaDesc.Layout.LayoutNames };
                    else
                        layoutNamesList = new[] { new string[0] };
                }

                foreach (var layoutNames in layoutNamesList)
                {
                    descriptors.Add(CreateDescriptor(
                                        entry.ControllerType.Namespace,
                                        controllerPath,
                                        viewName,
                                        layoutNames,
                                        accessors));
                }
            }

            return descriptors;
        }