本文整理汇总了C#中IVirtualFile类的典型用法代码示例。如果您正苦于以下问题:C# IVirtualFile类的具体用法?C# IVirtualFile怎么用?C# IVirtualFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IVirtualFile类属于命名空间,在下文中一共展示了IVirtualFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileHash
public virtual string GetFileHash(IVirtualFile virtualFile)
{
if (virtualFile == null)
return String.Empty;
return virtualFile.GetFileHash();
}
示例2: MemCachedFile
MemCachedFile( IVirtualFile file )
{
if (file == null) throw new FileNotFoundException();
this.path = file.VirtualPath;
using (Stream s = file.Open()) {
this.data = StreamExtensions.CopyToBytes(s);
}
}
示例3: ConvertFileNameToTreeableData
private List<string> ConvertFileNameToTreeableData(IVirtualFile fi)
{
List<string> result = fi.VirtualPath.Split('\\').ToList();
if(result.Count < 3)
result.Add("CD1");
result.Add(fi.Name);
return result;
}
示例4: WriteFile
public static void WriteFile(this IVirtualPathProvider pathProvider, IVirtualFile file, string filePath = null)
{
var writableFs = pathProvider as IVirtualFiles;
if (writableFs == null)
throw new InvalidOperationException(ErrorNotWritable.Fmt(pathProvider.GetType().Name));
using (var stream = file.OpenRead())
{
writableFs.WriteFile(filePath ?? file.VirtualPath, stream);
}
}
示例5: RazorPageHost
public RazorPageHost(IVirtualPathProvider pathProvider,
IVirtualFile file,
IRazorCodeTransformer codeTransformer,
CodeDomProvider codeDomProvider,
IDictionary<string, string> directives)
: base(new CSharpRazorCodeLanguage())
{
this.PathProvider = pathProvider;
this.File = file;
if (codeTransformer == null)
{
throw new ArgumentNullException("codeTransformer");
}
if (this.PathProvider == null)
{
throw new ArgumentNullException("pathProvider");
}
if (this.File == null)
{
throw new ArgumentNullException("file");
}
if (codeDomProvider == null)
{
throw new ArgumentNullException("codeDomProvider");
}
_codeTransformer = codeTransformer;
_codeDomProvider = codeDomProvider;
_directives = directives;
base.DefaultNamespace = "ASP";
EnableLinePragmas = true;
base.GeneratedClassContext = new GeneratedClassContext(
executeMethodName: GeneratedClassContext.DefaultExecuteMethodName,
writeMethodName: GeneratedClassContext.DefaultWriteMethodName,
writeLiteralMethodName: GeneratedClassContext.DefaultWriteLiteralMethodName,
writeToMethodName: "WriteTo",
writeLiteralToMethodName: "WriteLiteralTo",
templateTypeName: typeof(HelperResult).FullName,
defineSectionMethodName: "DefineSection",
beginContextMethodName: "BeginContext",
endContextMethodName: "EndContext"
)
{
ResolveUrlMethodName = "Href",
};
base.DefaultBaseClass = typeof(ViewPage).FullName;
foreach (var import in _defaultImports)
{
base.NamespaceImports.Add(import);
}
}
示例6: HttpResult
public HttpResult(IVirtualFile fileResponse, string contentType = null, bool asAttachment = false)
: this(null, contentType ?? MimeTypes.GetMimeType(fileResponse.Name), HttpStatusCode.OK)
{
this.AllowsPartialResponse = true;
this.ResponseStream = fileResponse.OpenRead();
if (!asAttachment) return;
var headerValue = $"attachment; filename=\"{fileResponse.Name}\"; size={fileResponse.Length}; modification-date={fileResponse.LastModified.ToString("R").Replace(",", "")}";
this.Headers = new Dictionary<string, string>
{
{ HttpHeaders.ContentDisposition, headerValue },
};
}
示例7: FileListItem
/// <summary>
/// Creates file list item object.
/// </summary>
/// <param name="file">actual file it presents.</param>
/// <param name="window">window it belongs to.</param>
public FileListItem(IVirtualFile file, Window window)
: base(window, CreationFlag.FlagsNone)
{
if (null == file)
{
throw new Exception("file can not be null");
}
this.file = file;
this.NeedTranslation = false;
this.Text = file.Name;
this.Name = file.Name;
this.ListStyle = ListStyle.Details;
this.BackColor = Colors.None;
SetFileIcon();
}
示例8: TrackRazorPage
protected virtual void TrackRazorPage( IVirtualFile file )
{
//get the base type.
var pageBaseType = this.Config.PageBaseType;
var transformer = new RazorViewPageTransformer( pageBaseType );
//create a RazorPage
var page = new RazorPage
{
PageHost = new RazorPageHost( PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>() ),
IsValid = false,
File = file
};
//add it to our pages dictionary.
AddRazorPage(page);
}
示例9: WriteToStream
/// <summary>
/// The write to stream.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
/// <param name="sw">
/// The sw.
/// </param>
/// <param name="vf">
/// The vf.
/// </param>
/// <param name="type">
/// The type.
/// </param>
/// <param name="origUrl">
/// The orig url.
/// </param>
/// <param name="http">
/// The http.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool WriteToStream(BaseCompositeFileProcessingProvider provider, StreamWriter sw, IVirtualFile vf, ClientDependencyType type, string origUrl, HttpContextBase http)
{
try
{
using (var readStream = vf.Open())
using (var streamReader = new StreamReader(readStream))
{
var output = streamReader.ReadToEnd();
DefaultFileWriter.WriteContentToStream(provider, sw, output, type, http, origUrl);
return true;
}
}
catch (Exception)
{
// the file must have failed to open
return false;
}
}
示例10: WriteToStream
/// <summary>
/// Writes the virtual file to a stream for serving.
/// </summary>
/// <param name="provider">The file processing provider.</param>
/// <param name="streamWriter">The <see cref="StreamWriter"/>.</param>
/// <param name="virtualFile">The <see cref="IVirtualFile"/> to write.</param>
/// <param name="type">The <see cref="ClientDependencyType"/> the virtual file matches.</param>
/// <param name="originalUrl">The original url to the virtual file.</param>
/// <param name="context">The <see cref="HttpContextBase"/>.</param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool WriteToStream(
BaseCompositeFileProcessingProvider provider,
StreamWriter streamWriter,
IVirtualFile virtualFile,
ClientDependencyType type,
string originalUrl,
HttpContextBase context)
{
try
{
using (Stream readStream = virtualFile.Open())
using (StreamReader streamReader = new StreamReader(readStream))
{
string output = streamReader.ReadToEnd();
DefaultFileWriter.WriteContentToStream(provider, streamWriter, output, type, context, originalUrl);
return true;
}
}
catch (Exception)
{
// The file must have failed to open
return false;
}
}
示例11: IsViewFile
public virtual bool IsViewFile(IVirtualFile virtualFile)
{
return virtualFile.RealPath != null
&& virtualFile.RealPath.Contains("{0}{1}".Fmt(RealPathSeparator, "Views"));
}
示例12: GetFileIfCached
public IVirtualFile GetFileIfCached(string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original)
{
//Use alternate cache key if provided
string key = original is IVirtualFileSourceCacheKey ? ((IVirtualFileSourceCacheKey)original).GetCacheKey(true) : original.VirtualPath;
//If cached, serve it.
CachedVirtualFile c = cache.Get(key);
if (c != null) return c;
//If not, let's cache it.
if ("mem".Equals(queryString["scache"], StringComparison.OrdinalIgnoreCase)) {
locks.TryExecute(key, 3000, delegate() {
c = cache.Get(key);
if (c == null) {
using (Stream data = original.Open()) {//Very long-running call
c = new CachedVirtualFile(original.VirtualPath, StreamExtensions.CopyToBytes(data, true));
}
cache.Set(key, c);//Save to cache (may trigger cleanup)
}
});
return c;
}
return null;
}
示例13: IsViewFile
public override bool IsViewFile(IVirtualFile virtualFile)
{
return virtualFile.VirtualPathProvider.IsViewFile(virtualFile);
}
示例14: AddPage
public virtual RazorPage AddPage(IVirtualFile file)
{
return IsWatchedFile(file)
? TrackPage(file)
: null;
}
示例15: TrackPage
public virtual RazorPage TrackPage(IVirtualFile file)
{
//get the base type.
var pageBaseType = this.Config.PageBaseType;
var transformer = new RazorViewPageTransformer(pageBaseType);
//create a RazorPage
var page = new RazorPage
{
PageHost = new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()),
IsValid = false,
File = file
};
//add it to our pages dictionary.
AddPage(page);
if (Config.PrecompilePages.GetValueOrDefault())
PrecompilePage(page);
return page;
}