当前位置: 首页>>代码示例>>C#>>正文


C# VirtualPath.OpenFile方法代码示例

本文整理汇总了C#中System.Web.VirtualPath.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPath.OpenFile方法的具体用法?C# VirtualPath.OpenFile怎么用?C# VirtualPath.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.VirtualPath的用法示例。


在下文中一共展示了VirtualPath.OpenFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateCodeCompileUnit

 internal CodeCompileUnit GenerateCodeCompileUnit(VirtualPath virtualPath, string virtualFileString, out Type codeDomProviderType, out CompilerParameters compilerParameters, out IDictionary linePragmasTable)
 {
     CodeCompileUnit codeCompileUnit;
     this.AddPendingCall();
     try
     {
         BuildManager.SkipTopLevelCompilationExceptions = true;
         this._buildManager.EnsureTopLevelFilesCompiled();
         if (virtualFileString == null)
         {
             using (Stream stream = virtualPath.OpenFile())
             {
                 virtualFileString = Util.ReaderFromStream(stream, virtualPath).ReadToEnd();
             }
         }
         this._virtualPathProvider.RegisterVirtualFile(virtualPath, virtualFileString);
         string cacheKey = BuildManager.GetCacheKeyFromVirtualPath(virtualPath) + "_CBMResult";
         BuildResultCodeCompileUnit buildResultFromCache = (BuildResultCodeCompileUnit) BuildManager.GetBuildResultFromCache(cacheKey, virtualPath);
         if (buildResultFromCache == null)
         {
             lock (this._lock)
             {
                 DateTime utcNow = DateTime.UtcNow;
                 System.Web.Compilation.BuildProvider provider = this.GetCompilerParamsAndBuildProvider(virtualPath, out codeDomProviderType, out compilerParameters);
                 if (provider == null)
                 {
                     linePragmasTable = null;
                     return null;
                 }
                 CodeCompileUnit unit2 = provider.GetCodeCompileUnit(out linePragmasTable);
                 buildResultFromCache = new BuildResultCodeCompileUnit(codeDomProviderType, unit2, compilerParameters, linePragmasTable) {
                     VirtualPath = virtualPath
                 };
                 buildResultFromCache.SetCacheKey(cacheKey);
                 this.FixupReferencedAssemblies(virtualPath, compilerParameters);
                 if (unit2 != null)
                 {
                     foreach (string str2 in compilerParameters.ReferencedAssemblies)
                     {
                         unit2.ReferencedAssemblies.Add(str2);
                     }
                 }
                 ICollection virtualPathDependencies = provider.VirtualPathDependencies;
                 if (virtualPathDependencies != null)
                 {
                     buildResultFromCache.AddVirtualPathDependencies(virtualPathDependencies);
                 }
                 BuildManager.CacheBuildResult(cacheKey, buildResultFromCache, utcNow);
                 return unit2;
             }
         }
         codeDomProviderType = buildResultFromCache.CodeDomProviderType;
         compilerParameters = buildResultFromCache.CompilerParameters;
         linePragmasTable = buildResultFromCache.LinePragmasTable;
         this.FixupReferencedAssemblies(virtualPath, compilerParameters);
         codeCompileUnit = buildResultFromCache.CodeCompileUnit;
     }
     finally
     {
         if (virtualFileString != null)
         {
             this._virtualPathProvider.RevertVirtualFile(virtualPath);
         }
         BuildManager.SkipTopLevelCompilationExceptions = false;
         this.RemovePendingCall();
     }
     return codeCompileUnit;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:68,代码来源:BuildManagerHost.cs

示例2: GenerateCodeCompileUnit

    internal CodeCompileUnit GenerateCodeCompileUnit(
        VirtualPath virtualPath, string virtualFileString, out Type codeDomProviderType,
        out CompilerParameters compilerParameters, out IDictionary linePragmasTable) {

        // Add a pending call to make sure our thread doesn't get killed
        AddPendingCall();

        try {
            BuildManager.SkipTopLevelCompilationExceptions = true;
            _buildManager.EnsureTopLevelFilesCompiled();

            // Get the virtual file content so that we can use the correct hash code.
            if (virtualFileString == null) {
                using (Stream stream = virtualPath.OpenFile()) {
                    TextReader reader = Util.ReaderFromStream(stream, virtualPath);
                    virtualFileString = reader.ReadToEnd();
                }
            }

            _virtualPathProvider.RegisterVirtualFile(virtualPath, virtualFileString);

            string cacheKey = BuildManager.GetCacheKeyFromVirtualPath(virtualPath) + "_CBMResult";
            BuildResultCodeCompileUnit result = (BuildResultCodeCompileUnit)BuildManager.GetBuildResultFromCache(cacheKey, virtualPath);

            if (result == null) {
                lock (_lock) {
                    // Don't need to check the result again since it's very unlikely in CBM scenarios.
                    DateTime utcStart = DateTime.UtcNow;

                    BuildProvider internalBuildProvider = GetCompilerParamsAndBuildProvider(
                        virtualPath, out codeDomProviderType, out compilerParameters);

                    // This is the no-compile case
                    if (internalBuildProvider == null) {
                        linePragmasTable = null;
                        return null;
                    }

                    CodeCompileUnit ccu = internalBuildProvider.GetCodeCompileUnit(out linePragmasTable);

                    result = new BuildResultCodeCompileUnit(codeDomProviderType, ccu, compilerParameters, linePragmasTable);
                    result.VirtualPath = virtualPath;
                    result.SetCacheKey(cacheKey);

                    FixupReferencedAssemblies(virtualPath, compilerParameters);

                    // CodeCompileUnit could be null, do not try to fix referenced assemblies.
                    // This happens for example when an .asmx file does not contain any code.
                    if (ccu != null) {
                        // VSWhidbey 501260 Add all the referenced assemblies to the CodeCompileUnit
                        // in case the CodeDom provider needs them for code generation
                        foreach (String assemblyString in compilerParameters.ReferencedAssemblies) {
                            ccu.ReferencedAssemblies.Add(assemblyString);
                        }
                    }

                    // Add all the dependencies, so that the ccu gets cached correctly (VSWhidbey 275091)
                    ICollection dependencies = internalBuildProvider.VirtualPathDependencies;
                    if (dependencies != null)
                        result.AddVirtualPathDependencies(dependencies);

                    BuildManager.CacheBuildResult(cacheKey, result, utcStart);

                    return ccu;
                }
            }

            codeDomProviderType = result.CodeDomProviderType;
            compilerParameters = result.CompilerParameters;
            linePragmasTable = result.LinePragmasTable;

            FixupReferencedAssemblies(virtualPath, compilerParameters);

            return result.CodeCompileUnit;
        } 
        finally {
            if (virtualFileString != null) {
                _virtualPathProvider.RevertVirtualFile(virtualPath);
            }
            BuildManager.SkipTopLevelCompilationExceptions = false;

            RemovePendingCall();
        }
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:84,代码来源:BuildManagerHost.cs

示例3: StringFromVirtualPath

 internal static string StringFromVirtualPath(VirtualPath virtualPath)
 {
     using (Stream stream = virtualPath.OpenFile())
     {
         return ReaderFromStream(stream, virtualPath).ReadToEnd();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Util.cs

示例4: ParseFile

 private void ParseFile(string physicalPath, VirtualPath virtualPath)
 {
     string o = (physicalPath != null) ? physicalPath : virtualPath.VirtualPathString;
     if (this._circularReferenceChecker.Contains(o))
     {
         throw new HttpException(System.Web.SR.GetString("Circular_include"));
     }
     this._circularReferenceChecker.Add(o);
     try
     {
         TextReader reader;
         if (physicalPath != null)
         {
             using (reader = Util.ReaderFromFile(physicalPath, virtualPath))
             {
                 this.ParseReader(reader);
                 return;
             }
         }
         using (Stream stream = virtualPath.OpenFile())
         {
             reader = Util.ReaderFromStream(stream, virtualPath);
             this.ParseReader(reader);
         }
     }
     finally
     {
         this._circularReferenceChecker.Remove(o);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:DependencyParser.cs

示例5: OpenFileAndGetDependency

 internal Stream OpenFileAndGetDependency(VirtualPath virtualPath, string physicalPath, out CacheDependency dependency)
 {
     Stream stream;
     if ((physicalPath == null) && HostingEnvironment.UsingMapPathBasedVirtualPathProvider)
     {
         physicalPath = virtualPath.MapPathInternal(this.TemplateControlVirtualDirectory, true);
     }
     if (physicalPath != null)
     {
         HttpRuntime.CheckFilePermission(physicalPath);
         stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
         dependency = new CacheDependency(0, physicalPath);
         return stream;
     }
     stream = virtualPath.OpenFile();
     dependency = VirtualPathProvider.GetCacheDependency(virtualPath);
     return stream;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:Control.cs


注:本文中的System.Web.VirtualPath.OpenFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。