コード例 #1
0
ファイル: HostingEnvironment.cs プロジェクト: mdae/MonoRT
        public static void RegisterVirtualPathProvider(VirtualPathProvider virtualPathProvider)
        {
            if (HttpRuntime.AppDomainAppVirtualPath == null)
            {
                throw new InvalidOperationException();
            }

            if (virtualPathProvider == null)
            {
                throw new ArgumentNullException("virtualPathProvider");
            }

            VirtualPathProvider previous = vpath_provider;

            vpath_provider = virtualPathProvider;
            vpath_provider.InitializeAndSetPrevious(previous);
            if (!(virtualPathProvider is DefaultVirtualPathProvider))
            {
                HaveCustomVPP = true;
            }
            else
            {
                HaveCustomVPP = false;
            }
        }
 public void RegisterVirtualPathProvider(VirtualPathProvider virtualPathProvider)
 {
     // Sets up the provider chain
     var previousField = typeof(VirtualPathProvider).GetField("_previous", BindingFlags.NonPublic | BindingFlags.Instance);
     previousField.SetValue(virtualPathProvider, VirtualPathProvider);
     VirtualPathProvider = virtualPathProvider;
 }
コード例 #3
0
    /// <summary>
    /// 利用指定 VirtualPathProvider 将虚拟路径所指向文件当作静态文件加载。
    /// </summary>
    /// <param name="provider">指定的 VirtualPathProvider</param>
    /// <param name="virtualPath">虚拟路径</param>
    /// <returns>加载结果</returns>
    public HtmlContentResult LoadContent( VirtualPathProvider provider, string virtualPath )
    {

      if ( !VirtualPathUtility.IsAppRelative( virtualPath ) )
        return null;

      if ( !provider.FileExists( virtualPath ) )
        return null;

      var file = provider.GetFile( virtualPath );

      if ( file == null )
        return null;



      var key = provider.GetCacheKey( virtualPath ) ?? "StaticFile_" + virtualPath;

      var content = HttpRuntime.Cache.Get( key ) as string;


      if ( content == null )
      {
        var dependency = HtmlServices.CreateCacheDependency( provider, virtualPath );
        content = LoadContent( file );

        HttpRuntime.Cache.Insert( key, content, dependency );
      }


      return new HtmlContentResult( content, key );
    }
コード例 #4
0
        /*
         * Helper method to open a file from its virtual path
         */

        public static Stream OpenFile(string virtualPath)
        {
            VirtualPathProvider vpathProvider = HostingEnvironment.VirtualPathProvider;
            VirtualFile         vfile         = vpathProvider.GetFileWithCheck(virtualPath);

            return(vfile.Open());
        }
コード例 #5
0
 public EPiServerHostingEnvironment()
 {
     //We need the first provider to be one that doesn't delegates to its parent.
     //The default hosting environment uses a MapPathBasedVirtualPathProvider but that's internal
     //so we use our custom dummy provider.
     _provider = new DummyVirtualPathProvider();
 }
コード例 #6
0
		public void Register(VirtualPathProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");

			_providers.Add(provider);
		}
コード例 #7
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)
                {
                    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;
            }
        }
コード例 #8
0
        internal BuildManagerViewEngine(IViewPageActivator viewPageActivator, IResolver<IViewPageActivator> activatorResolver,
            IDependencyResolver dependencyResolver, VirtualPathProvider pathProvider)
        {
            if (viewPageActivator != null)
            {
                _viewPageActivator = viewPageActivator;
            }
            else
            {
                _activatorResolver = activatorResolver ?? new SingleServiceResolver<IViewPageActivator>(
                                                              () => null,
                                                              new DefaultViewPageActivator(dependencyResolver),
                                                              "BuildManagerViewEngine constructor");
            }

            if (pathProvider != null)
            {
                Func<VirtualPathProvider> providerFunc = () => pathProvider;
                _fileExistsCache = new FileExistenceCache(providerFunc);
                VirtualPathProviderFunc = providerFunc;
            }
            else
            {
                if (_sharedFileExistsCache == null)
                {
                    // Startup initialization race is OK providing service remains read-only
                    _sharedFileExistsCache = new FileExistenceCache(() => HostingEnvironment.VirtualPathProvider);
                }

                _fileExistsCache = _sharedFileExistsCache;
            }
        }
コード例 #9
0
		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;
		}
コード例 #10
0
        internal static CacheDependency GetCacheDependency(VirtualPath virtualPath)
        {
            VirtualPathProvider vpathProvider = HostingEnvironment.VirtualPathProvider;

            return(vpathProvider.GetCacheDependency(virtualPath,
                                                    new SingleObjectCollection(virtualPath.VirtualPathString), DateTime.MaxValue));
        }
コード例 #11
0
        private void Write(HttpContext context, VirtualPathProvider vpp, string cssPath)
        {
            var mappedPath = context.Server.MapPath(cssPath);
            if(File.Exists(mappedPath))
                context.Response.AddFileDependency(mappedPath);

            var file = vpp.GetFile(cssPath);
            using (var s = file.Open())
            using (var tr = new StreamReader(s))
            {
                while (tr.Peek() >= 0)
                {
                    var line = tr.ReadLine();
                    string importPath = GetImportedPath(context, vpp, cssPath, line);

                    if (string.IsNullOrEmpty(importPath))
                        // process all lines except imports
                        context.Response.Write(Process(line, VirtualPathUtility.GetDirectory(cssPath)));
                    else if (vpp.FileExists(importPath))
                        // recurse into imports and output
                        Write(context, vpp, importPath);
                    else
                        // fallback just write the line
                        context.Response.Write(line);

                    context.Response.Write(Environment.NewLine);
            
                }
            }
        }
コード例 #12
0
ファイル: ContentPathProvider.cs プロジェクト: GStore/Meek
        public ContentPathProvider(VirtualPathProvider baseProvider, Configuration.Configuration services)
        {
            _baseProvider = baseProvider;
            _config = services;
            _internalResources = new Dictionary<string, string>();

            switch (_config.ViewEngineOptions.Type)
            {
                case Configuration.ViewEngineType.Razor:
                    _extension = ".cshtml";
                    break;
                case Configuration.ViewEngineType.ASPX:
                    _extension = ".aspx";
                    break;
                default:
                    throw new ArgumentException("Invalid ViewEngine Specified.");
            }

            Action<string> addResource = (file) =>
                _internalResources.Add(file + _extension, string.Format("Meek.Content.{0}.{1}{2}", _config.ViewEngineOptions.Type.ToString(), file, _extension));

            addResource("Manage");
            addResource("CreatePartial");
            addResource("List");
            addResource("BrowseFiles");
            addResource("UploadFileSuccess");
        }
コード例 #13
0
 public FileExistenceCache(VirtualPathProvider virtualPathProvider, int milliSecondsBeforeReset = 1000)
 {
     Contract.Assert(virtualPathProvider != null);
     _virtualPathProvider = virtualPathProvider;
     _virtualPathFileExists = virtualPathProvider.FileExists;
     _ticksBeforeReset = milliSecondsBeforeReset * TicksPerMillisecond;
     Reset();
 }
コード例 #14
0
ファイル: XsltViewTest.cs プロジェクト: JonKruger/MvcContrib
 public override void SetUp()
 {
     base.SetUp();
     var routeData = new RouteData();
     routeData.Values["controller"] = "MyController";
     virtualPathProvider = new XsltTestVirtualPathProvider();
     _context = new ControllerContext(HttpContext, routeData, MockRepository.GenerateStub<ControllerBase>());
     mockRepository.ReplayAll();
 }
コード例 #15
0
		public BuildManagerDirectoryBuilder (VirtualPath virtualPath)
		{
			if (virtualPath == null)
				throw new ArgumentNullException ("virtualPath");

			this.vpp = HostingEnvironment.VirtualPathProvider;
			this.virtualPath = virtualPath;
			this.virtualPathDirectory = VirtualPathUtility.GetDirectory (virtualPath.Absolute);
		}
コード例 #16
0
 /// <summary>
 /// Initialise a new Pattern Lab view
 /// </summary>
 /// <param name="engine">The current view engine</param>
 /// <param name="controllerContext">The current controller context</param>
 /// <param name="virtualPathProvider">The current virtual path provider</param>
 /// <param name="viewPath">The path to the view</param>
 /// <param name="masterPath">The optional path to the master view</param>
 /// <param name="parameters">Any pattern parameters</param>
 public MustacheView(MustacheViewEngine engine, ControllerContext controllerContext,
     VirtualPathProvider virtualPathProvider, string viewPath, string masterPath, Dictionary<string, object> parameters)
 {
     _engine = engine;
     _controllerContext = controllerContext;
     _masterPath = masterPath;
     _parameters = parameters;
     _viewPath = viewPath;
     _virtualPathProvider = virtualPathProvider;
 }
コード例 #17
0
        internal static VirtualPath CombineVirtualPathsInternal(VirtualPath basePath, VirtualPath relativePath)
        {
            VirtualPathProvider virtualPathProvider = HostingEnvironment.VirtualPathProvider;

            if (virtualPathProvider != null)
            {
                return(virtualPathProvider.CombineVirtualPaths(basePath, relativePath));
            }
            return(basePath.Parent.Combine(relativePath));
        }
コード例 #18
0
        /*
         * Helper method to call CombineVirtualPaths if there is a VirtualPathProvider
         */
        internal static VirtualPath CombineVirtualPathsInternal(VirtualPath basePath, VirtualPath relativePath)
        {
            VirtualPathProvider vpathProvider = HostingEnvironment.VirtualPathProvider;

            if (vpathProvider != null)
            {
                return(vpathProvider.CombineVirtualPaths(basePath, relativePath));
            }

            // If there is no provider, just combine them normally
            return(basePath.Parent.Combine(relativePath));
        }
コード例 #19
0
        private static string ResolveThemedContent(HttpContextBase httpContext, VirtualPathProvider vpp, string contentPath)
        {
            string theme = httpContext.GetTheme();
            if (string.IsNullOrEmpty(theme))
                return Url.ToAbsolute(contentPath);

            string themeContentPath = "~/Themes/" + theme + contentPath.TrimStart('~');
            if (!vpp.FileExists(themeContentPath))
                return Url.ToAbsolute(contentPath);

            return Url.ToAbsolute(themeContentPath);
        }
コード例 #20
0
ファイル: ViewTemplateAnalyzer.cs プロジェクト: kodeo/n2cms
		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;
		}
コード例 #21
0
 public ResourcePathProvider(IEnumerable<Assembly> assemblies, VirtualPathProvider previous)
 {
     this.previous = previous;
     resources = new Dictionary<string, EmbeddedFile>();
     foreach (var embeddedFile in assemblies.SelectMany(a => a.GetManifestResourceNames().Select(n => new EmbeddedFile(a, n))))
     {
         if (!resources.ContainsKey(embeddedFile.Key))
         {
             resources.Add(embeddedFile.Key, embeddedFile);
         }
     }
 }
コード例 #22
0
        public static Stream OpenFile(string virtualPath)
        {
            // This thing throws a nullref when we're not inside an ASP.NET appdomain, which is what MS does.
            VirtualPathProvider provider = HostingEnvironment.VirtualPathProvider;
            VirtualFile         file     = provider.GetFile(virtualPath);

            if (file != null)
            {
                return(file.Open());
            }

            return(null);
        }
コード例 #23
0
        public ContentPathProvider(VirtualPathProvider baseProvider, Configuration.Configuration services)
        {
            _baseProvider = baseProvider;
            _config = services;

            _internalResources = new Dictionary<string, string>()
                                    {
                                        {"Manage.cshtml",  "Meek.Content.Manage.cshtml"},
                                        {"CreatePartial.cshtml", "Meek.Content.CreatePartial.cshtml"},
                                        {"List.cshtml", "Meek.Content.List.cshtml"},
                                        {"BrowseFiles.cshtml", "Meek.Content.BrowseFiles.cshtml"},
                                        {"UploadFileSuccess.cshtml", "Meek.Content.UploadFileSuccess.cshtml"}
                                    };
        }
コード例 #24
0
		public BuildManagerDirectoryBuilder (VirtualPath virtualPath)
		{
			if (virtualPath == null)
				throw new ArgumentNullException ("virtualPath");

			this.vpp = HostingEnvironment.VirtualPathProvider;
			this.virtualPath = virtualPath;
			this.virtualPathDirectory = VirtualPathUtility.GetDirectory (virtualPath.Absolute);
			if (HttpRuntime.CaseInsensitive) {
				this.stringComparer = StringComparison.OrdinalIgnoreCase;
				this.dictionaryComparer = StringComparer.OrdinalIgnoreCase;
			} else {
				this.stringComparer = StringComparison.Ordinal;
				this.dictionaryComparer = StringComparer.Ordinal;
			}
		}
コード例 #25
0
        public XsltViewFactory(VirtualPathProvider virtualPathProvider)
        {
            if(virtualPathProvider != null)
            {
                VirtualPathProvider = virtualPathProvider;
            }

            MasterLocationFormats = new string[0];

            ViewLocationFormats = new[]
                                  	{
                                  		"~/Views/{1}/{0}.xslt",
                                  		"~/Views/Shared/{0}.xslt"
                                  	};

            PartialViewLocationFormats = ViewLocationFormats;
        }
コード例 #26
0
ファイル: ThemeExtensions.cs プロジェクト: Biswo/n2cms
        private static string ResolveThemedContent(RequestContext requestContext, VirtualPathProvider vpp, string contentPath)
        {
            string themeFolderPath = requestContext.RouteData.DataTokens["ThemeViewEngine.ThemeFolderPath"] as string 
                ?? Url.ResolveTokens(Url.ThemesUrlToken);

            string theme = requestContext.HttpContext.GetTheme();
            if (!string.IsNullOrEmpty(theme))
            {
                string themeContentPath = themeFolderPath + theme + contentPath.TrimStart('~');
                if (vpp.FileExists(themeContentPath))
                    return Url.ToAbsolute(themeContentPath);
            }

            string defaultThemeContentPath = themeFolderPath + "Default" + contentPath.TrimStart('~');
            if (vpp.FileExists(defaultThemeContentPath))
                return Url.ToAbsolute(defaultThemeContentPath);

            return Url.ToAbsolute(contentPath);
        }
コード例 #27
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;
            }
        }
コード例 #28
0
ファイル: VirtualPathHelper.cs プロジェクト: ajayumi/Jumony
    /// <summary>
    /// 在指定虚拟路径上溯搜索指定文件名的文件
    /// </summary>
    /// <param name="provider">自定义的虚拟路径提供程序</param>
    /// <param name="virtualPath">要搜索的虚拟路径</param>
    /// <param name="fileNames">要搜索的文件名列表</param>
    /// <returns>返回找到的文件路径,若无法找到匹配的文件,则返回null</returns>
    public static string FallbackSearch( VirtualPathProvider provider, string virtualPath, params string[] fileNames )
    {
      if ( !VirtualPathUtility.IsAppRelative( virtualPath ) )
        throw VirtualPathFormatError( "virtualPath" );


      while ( true )
      {

        virtualPath = GetParentDirectory( virtualPath );
        if ( virtualPath == null )
          break;

        foreach ( var name in fileNames )
        {
          var filePath = VirtualPathUtility.Combine( virtualPath, name );
          if ( provider.FileExists( filePath ) )
            return filePath;
        }
      }

      return null;
    }
コード例 #29
0
 public FileExistenceCache(VirtualPathProvider virtualPathProvider, int milliSecondsBeforeReset = 1000)
 {
     _virtualPathProvider = virtualPathProvider;
     _ticksBeforeReset = milliSecondsBeforeReset * TickPerMiliseconds;
     Reset();
 }
コード例 #30
0
 private FileMonitor(VirtualPathProvider vpp,
     Action<string> changeCallback)
 {
     _vpp = vpp;
     _changeCallback = changeCallback;
 }
コード例 #31
0
 public ThemeVarsVirtualPathProvider(VirtualPathProvider previous)
 {
     _previous = previous;
 }
コード例 #32
0
		public VirtualPathFileHandler(VirtualPathProvider vpp)
		{
			this.vpp = vpp;
		}
コード例 #33
0
		public VirtualPathFileHandler()
		{
			vpp = HostingEnvironment.VirtualPathProvider;
		}
コード例 #34
0
 // for testing purposes
 internal FilterFactory(VirtualPathProvider vpp)
     : this() {
     _templateFactory.VirtualPathProvider = vpp;
 }
コード例 #35
0
 private ConfigFileChangeNotifier(VirtualPathProvider vpp,
     Action<string> changeCallback)
 {
     _vpp = vpp;
     _changeCallback = changeCallback;
 }
コード例 #36
0
ファイル: BundleConfig.cs プロジェクト: jschwarty/wraith
 public ScriptBundlePathProvider(VirtualPathProvider virtualPathProvider)
 {
     _virtualPathProvider = virtualPathProvider;
 }
 public static void RegisterVirtualPathProvider(VirtualPathProvider virtualPathProvider)
 {
 }
コード例 #38
0
 internal void InitializeAndSetPrevious(VirtualPathProvider prev)
 {
     this.prev = prev;
     Initialize();
 }
コード例 #39
0
 internal virtual void Initialize(VirtualPathProvider previous)
 {
     this._previous = previous;
     this.Initialize();
 }