本文整理汇总了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;
}
示例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();
}
}
示例3: StringFromVirtualPath
internal static string StringFromVirtualPath(VirtualPath virtualPath)
{
using (Stream stream = virtualPath.OpenFile())
{
return ReaderFromStream(stream, virtualPath).ReadToEnd();
}
}
示例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);
}
}
示例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;
}