本文整理汇总了C#中IFileInfo.CreateReadStream方法的典型用法代码示例。如果您正苦于以下问题:C# IFileInfo.CreateReadStream方法的具体用法?C# IFileInfo.CreateReadStream怎么用?C# IFileInfo.CreateReadStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileInfo
的用法示例。
在下文中一共展示了IFileInfo.CreateReadStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileCore
private async Task<CompilationResult> CompileCore(IFileInfo file)
{
var host = new MvcRazorHost();
var engine = new RazorTemplateEngine(host);
GeneratorResults results;
using (TextReader rdr = new StreamReader(file.CreateReadStream()))
{
results = engine.GenerateCode(rdr, '_' + Path.GetFileNameWithoutExtension(file.Name), "Asp", file.PhysicalPath ?? file.Name);
}
string generatedCode;
using (var writer = new StringWriter())
using (var codeProvider = new CSharpCodeProvider())
{
codeProvider.GenerateCodeFromCompileUnit(results.GeneratedCode, writer, new CodeGeneratorOptions());
generatedCode = writer.ToString();
}
if (!results.Success)
{
return CompilationResult.Failed(generatedCode, results.ParserErrors.Select(e => new CompilationMessage(e.Message)));
}
Directory.CreateDirectory(_tempPath);
string tempFile = Path.Combine(_tempPath, Path.GetRandomFileName() + ".cs");
File.WriteAllText(tempFile, generatedCode);
_tempFileSystem.TryGetFileInfo(tempFile, out file);
return await _baseCompilationService.Compile(file);
}
示例2: GetHashForFile
private string GetHashForFile(IFileInfo fileInfo)
{
using (var sha256 = SHA256.Create())
{
using (var readStream = fileInfo.CreateReadStream())
{
var hash = sha256.ComputeHash(readStream);
return WebEncoders.Base64UrlEncode(hash);
}
}
}
示例3: Parse
public PlacementFile Parse(IFileInfo fileInfo)
{
if (!fileInfo.Exists)
{
return null;
}
var element = XElement.Load(fileInfo.CreateReadStream());
return new PlacementFile
{
Nodes = Accept(element).ToList()
};
}
示例4: CompileCore
// TODO: Make this internal
public CompilationResult CompileCore(IFileInfo file)
{
GeneratorResults results;
using (var inputStream = file.CreateReadStream())
{
Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase));
var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length);
results = _razorHost.GenerateCode(rootRelativePath, inputStream);
}
if (!results.Success)
{
var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message));
throw new CompilationFailedException(messages, results.GeneratedCode);
}
return _baseCompilationService.Compile(results.GeneratedCode);
}
示例5: Compile
public Task<CompilationResult> Compile(IFileInfo file)
{
string className = MakeClassName(file.Name);
var engine = new RazorTemplateEngine(new RazorEngineHost(new CSharpRazorCodeLanguage())
{
DefaultBaseClass = "Microsoft.AspNet.Razor.Owin.PageBase",
GeneratedClassContext = new GeneratedClassContext(
executeMethodName: "Execute",
writeMethodName: "Write",
writeLiteralMethodName: "WriteLiteral",
writeToMethodName: "WriteTo",
writeLiteralToMethodName: "WriteLiteralTo",
templateTypeName: "Template",
defineSectionMethodName: "DefineSection")
{
ResolveUrlMethodName = "Href"
}
});
engine.Host.NamespaceImports.Add("System");
engine.Host.NamespaceImports.Add("System.Linq");
engine.Host.NamespaceImports.Add("System.Collections.Generic");
GeneratorResults results;
using (TextReader rdr = new StreamReader(file.CreateReadStream()))
{
results = engine.GenerateCode(rdr, className, "RazorCompiled", file.PhysicalPath ?? file.Name);
}
var messages = new List<CompilationMessage>();
if (!results.Success)
{
foreach (var error in results.ParserErrors)
{
messages.Add(new CompilationMessage(
MessageLevel.Error,
error.Message,
new FileLocation(file.PhysicalPath ?? file.Name, error.Location.LineIndex, error.Location.CharacterIndex)));
}
}
// Regardless of success or failure, we're going to try and compile
return Task.FromResult(CompileCSharp("RazorCompiled." + className, file, results.Success, messages, results.GeneratedCode));
}
示例6: ReadContent
private IPublishedContent ReadContent(IFileInfo fileInfo)
{
using (var file = fileInfo.CreateReadStream())
using (var reader = new StreamReader(file))
{
var serializer = new JsonSerializer
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var content = (IPublishedContent)serializer.Deserialize(reader, typeof(PublishedContent));
return content;
}
}
示例7: ParseViewFile
private static ChunkTree ParseViewFile(
RazorTemplateEngine engine,
IFileInfo fileInfo,
string viewImportsPath)
{
using (var stream = fileInfo.CreateReadStream())
{
using (var streamReader = new StreamReader(stream))
{
var parseResults = engine.ParseTemplate(streamReader, viewImportsPath);
var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
var language = engine.Host.CodeLanguage;
var chunkGenerator = language.CreateChunkGenerator(
className,
engine.Host.DefaultNamespace,
viewImportsPath,
engine.Host);
chunkGenerator.Visit(parseResults);
// Rewrite the location of inherited chunks so they point to the global import file.
var chunkTree = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree;
foreach (var chunk in chunkTree.Chunks)
{
chunk.Start = new SourceLocation(
viewImportsPath,
chunk.Start.AbsoluteIndex,
chunk.Start.LineIndex,
chunk.Start.CharacterIndex);
}
return chunkTree;
}
}
}
示例8: GetFileStream
/// <summary>
/// Returns <see cref="Stream"/> for the specified <paramref name="fileInfo"/>.
/// </summary>
/// <param name="fileInfo">The <see cref="IFileInfo"/> for which the stream is needed.</param>
/// <returns><see cref="Stream"/> for the specified <paramref name="fileInfo"/>.</returns>
protected virtual Stream GetFileStream(IFileInfo fileInfo)
{
if (fileInfo == null)
{
throw new ArgumentNullException(nameof(fileInfo));
}
return fileInfo.CreateReadStream();
}
示例9: ReadFileContentsSafely
private static string ReadFileContentsSafely(IFileInfo fileInfo)
{
try
{
using (var reader = new StreamReader(fileInfo.CreateReadStream()))
{
return reader.ReadToEnd();
}
}
catch
{
// Ignore any failures
return null;
}
}
示例10: ReadLines
private static IEnumerable<string> ReadLines(IFileInfo fileInfo)
{
using (var reader = new StreamReader(fileInfo.CreateReadStream()))
{
string line;
while ((line = reader.ReadLine()) != null)
{
yield return line;
}
}
}
示例11: ParseViewFile
private static CodeTree ParseViewFile(RazorTemplateEngine engine,
IFileInfo fileInfo,
string viewStartPath)
{
using (var stream = fileInfo.CreateReadStream())
{
using (var streamReader = new StreamReader(stream))
{
var parseResults = engine.ParseTemplate(streamReader, viewStartPath);
var className = ParserHelpers.SanitizeClassName(fileInfo.Name);
var language = engine.Host.CodeLanguage;
var codeGenerator = language.CreateCodeGenerator(className,
engine.Host.DefaultNamespace,
viewStartPath,
engine.Host);
codeGenerator.Visit(parseResults);
return codeGenerator.Context.CodeTreeBuilder.CodeTree;
}
}
}
示例12: GetFileStream
protected virtual Stream GetFileStream(IFileInfo fileInfo)
{
return fileInfo.CreateReadStream();
}
示例13: ReadAllText
private string ReadAllText(IFileInfo fileInfo)
{
using (var stream = fileInfo.CreateReadStream())
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
示例14: ReadLines
private static IEnumerable<string> ReadLines(IFileInfo fileInfo)
{
var result = new List<string>();
using (var reader = new StreamReader(fileInfo.CreateReadStream()))
{
string line;
while ((line = reader.ReadLine()) != null)
{
result.Add(line);
}
}
return result;
}