示例#1
0
		public virtual IEnumerable<ContentRegistration> AnalyzeViews(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
		{
			var registrations = new List<ContentRegistration>();
			foreach (var source in sources)
			{
				var virtualDirList = new List<string>
				{
					Url.ResolveTokens(Url.ThemesUrlToken) + "Default/Views/" + source.ControllerName,
					"~/Views/" + source.ControllerName
				};

				virtualDirList.AddRange(
					from virtualDirectory in vpp.GetDirectory("~/Areas/").Directories.Cast<VirtualDirectory>()
					let virtualPath = String.Format("~/Areas/{0}/Views/{1}", virtualDirectory.Name, source.ControllerName)
					select virtualPath);

				foreach (var virtualDir in virtualDirList.Where(vpp.DirectoryExists))
				{
					logger.Debug(String.Format("Analyzing directory {0}", virtualDir));
					foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>())
					{
						Debug.Assert(file.Name != null, "file.Name != null");
						if (!file.Name.EndsWith(source.ViewFileExtension) || file.Name.StartsWith("_"))
						{
							logger.Info(String.Format("Skipping file {0}", file.VirtualPath));
							continue;
						}
						logger.Debug(String.Format("Analyzing file {0}", file.VirtualPath));

						ContentRegistration registration = null;
						if (httpContext.IsDebuggingEnabled)
						{
							registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
						}
						else
						{
							try
							{
								registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
							}
							catch (Exception ex)
							{
								logger.Error(ex);
							}
						}

						if (registration != null)
							registrations.Add(registration);
					}
				}
			}
			return registrations;
		}
		public virtual IEnumerable<ContentRegistration> AnalyzeViews(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
		{
			var registrations = new List<ContentRegistration>();
			foreach (var source in sources)
			{
				string virtualDir = Url.ResolveTokens(Url.ThemesUrlToken) + "Default/Views/" + source.ControllerName;

				logger.DebugFormat("Analyzing directory {0}", virtualDir);

				if (!vpp.DirectoryExists(virtualDir))
				{
					virtualDir = "~/Views/" + source.ControllerName;
					if (!vpp.DirectoryExists(virtualDir))
						continue;
				}

				foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>().Where(f => f.Name.EndsWith(source.ViewFileExtension)))
				{
					logger.DebugFormat("Analyzing file {0}", file.VirtualPath);

					var registration = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
					if (registration != null)
						registrations.Add(registration);
				}
			}
			return registrations;
		}
        public virtual IEnumerable<ViewTemplateDescription> FindRegistrations(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
        {
            foreach (var source in sources)
            {
                string virtualDir = "~/Views/" + source.ControllerName;
                if (!vpp.DirectoryExists(virtualDir))
                    continue;

                List<ViewTemplateDescription> descriptions = new List<ViewTemplateDescription>();
                foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>().Where(f => f.Name.EndsWith(source.ViewFileExtension)))
                {
                    var description = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
                    if (description != null)
                        descriptions.Add(description);
                }

                foreach (var description in descriptions)
                {
                    description.Definition.Add(new TemplateSelectorAttribute
                    {
                        Name = "TemplateName",
                        Title = "Template",
                        AllTemplates = descriptions.Select(d => new TemplateSelectorAttribute.Info { Name = d.Registration.Template, Title = d.Registration.Title }).ToArray(),
                        ContainerName = source.TemplateSelectorContainerName,
                        Required = true,
                        HelpTitle = "The page must be saved for another template's fields to appear",
                        RequiredPermission = Security.Permission.Administer
                    });
                }

                foreach (var description in descriptions)
                    yield return description;
            }
        }
示例#4
0
        public virtual VirtualDirectory GetDirectory(string virtualDir)
        {
            if (prev != null)
            {
                return(prev.GetDirectory(virtualDir));
            }

            return(null);
        }
示例#5
0
        /*
         * Returns a VirtualDirectory object for the passed in virtual path
         */

        public virtual VirtualDirectory GetDirectory(string virtualDir)
        {
            // Delegate to the previous VirtualPathProvider, if any

            if (_previous == null)
            {
                return(null);
            }

            return(_previous.GetDirectory(virtualDir));
        }
示例#6
0
        public virtual IEnumerable<ViewTemplateDescription> FindRegistrations(VirtualPathProvider vpp, HttpContextBase httpContext, IEnumerable<ViewTemplateSource> sources)
        {
            foreach (var source in sources)
            {
                string virtualDir = "~/Views/" + source.ControllerName;
                if (!vpp.DirectoryExists(virtualDir))
                    continue;

                List<ViewTemplateDescription> descriptions = new List<ViewTemplateDescription>();
                foreach (var file in vpp.GetDirectory(virtualDir).Files.OfType<VirtualFile>().Where(f => f.Name.EndsWith(source.ViewFileExtension)))
                {
                    var description = AnalyzeView(httpContext, file, source.ControllerName, source.ModelType);
                    if (description != null)
                        descriptions.Add(description);
                }

                foreach (var description in descriptions)
                    yield return description;
            }
        }
示例#7
0
        /// <summary>
        /// Try and find a file in the specified folder that matches name.
        /// </summary>
        /// <returns>The full path to the file that matches the requested file
        /// or null if no matching file is found</returns>
        internal static string FindMatchingFile(VirtualPathProvider vpp, string folder, string name) {
            Debug.Assert(vpp != null);
            Debug.Assert(!String.IsNullOrEmpty(folder));
            Debug.Assert(!String.IsNullOrEmpty(name));

            // Get the virtual path information
            VirtualDirectory directory = vpp.GetDirectory(folder);

            // If the folder specified doesn't exist
            // or it doesn't contain any files
            if (directory == null || directory.Files == null) {
                return null;
            }

            // Go through every file in the directory
            foreach (VirtualFile file in directory.Files) {
                string path = file.VirtualPath;

                // Compare the filename to the filename that we passed
                if (Path.GetFileName(path).Equals(name, StringComparison.OrdinalIgnoreCase)) {
                    return path;
                }
            }

            // If no matching files, return null
            return null;
        }
示例#8
0
        internal static ReadOnlyCollection<string> GetAvailableThemes(VirtualPathProvider vpp, string themeDirectory) {
            VirtualDirectory directory = vpp.GetDirectory(themeDirectory);

            var themes = new List<string>();

            // Go through every file in the directory
            foreach (VirtualDirectory dir in directory.Directories) {
                themes.Add(dir.Name);
            }
            return themes.AsReadOnly();
        }