本文整理汇总了C#中IFile.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.OpenRead方法的具体用法?C# IFile.OpenRead怎么用?C# IFile.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFile
的用法示例。
在下文中一共展示了IFile.OpenRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadLines
private List<string> ReadLines(IFile file, out bool needsPatching)
{
var existing = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
using (var stream = file.OpenRead())
using (var reader = new StreamReader(stream, true))
{
var readLines = new List<string>();
while (true)
{
var line = reader.ReadLine();
if (line == null)
{
break;
}
if (!_content.Contains(line, StringComparer.Ordinal))
{
readLines.Add(line);
}
else
{
existing.Add(line);
}
}
needsPatching = existing.Count != _content.Length;
return RemoveTrailingEmptyLines(readLines);
}
}
示例2: Read
// TODO: Read-retry should be part of an extension method that can be reused for reading the index in indexed folder repositories.
public IPackageDescriptor Read(IFile filePath)
{
if (!filePath.Exists)
return null;
IOException ioException = null;
int tries = 0;
while (tries < FILE_READ_RETRIES)
{
try
{
using (var fileStream = filePath.OpenRead())
{
var descriptor = new PackageDescriptorReader().Read(fileStream);
if (descriptor.Name == null)
descriptor.Name = PackageNameUtility.GetName(filePath.NameWithoutExtension);
return descriptor;
}
}
catch (InvalidPackageException ex)
{
throw new InvalidPackageException(String.Format("Invalid package for file '{0}'.", filePath.Path), ex);
}
catch (IOException ex)
{
ioException = ex;
tries++;
Thread.Sleep(FILE_READ_RETRIES_WAIT);
continue;
}
}
throw ioException;
}
示例3: Copy
private bool Copy(IFile source, IFile destination)
{
if (!source.Exists)
{
_log.Error("Could not find file {0}.", source.Path.FullPath);
return false;
}
if (destination.Exists)
{
_log.Error("The file {0} already exist.", destination.Path.FullPath);
return false;
}
using (var input = source.OpenRead())
using (var output = destination.OpenWrite())
{
using (var reader = new StreamReader(input))
using (var writer = new StreamWriter(output))
{
while (true)
{
var line = reader.ReadLine();
if (line == null)
{
break;
}
writer.WriteLine(line);
}
}
}
return true;
}
示例4: Read
public PackageDescriptor Read(IFile filePath)
{
if (!filePath.Exists)
return null;
IOException ioException = null;
int tries = 0;
while (tries < FILE_READ_RETRIES)
{
try
{
using (var fileStream = filePath.OpenRead())
{
var descriptor = Read(fileStream);
if (descriptor.Name == null)
descriptor.Name = PackageNameUtility.GetName(filePath.NameWithoutExtension);
return descriptor;
}
}
catch (IOException ex)
{
ioException = ex;
tries++;
Thread.Sleep(FILE_READ_RETRIES_WAIT);
continue;
}
}
throw ioException;
}
示例5: HashFileContents
string HashFileContents(IFile file)
{
using (var fileStream = file.OpenRead())
{
return fileStream.ComputeSHA1Hash().ToHexString();
}
}
示例6: SendFile
void SendFile(IFile file)
{
using (var stream = file.OpenRead())
{
response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
stream.CopyTo(response.OutputStream);
}
}
示例7: SendFile
void SendFile(IFile file)
{
using (var stream = file.OpenRead())
{
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
stream.CopyTo(response.OutputStream);
}
}
示例8: SendFile
void SendFile(IFile file)
{
//HttpResponseUtil.EncodeStreamAndAppendResponseHeaders(request, response);
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetExpires(DateTime.UtcNow.AddYears(1));
response.Cache.SetMaxAge(new TimeSpan(365, 0, 0, 0));
using (var stream = file.OpenRead())
{
stream.CopyTo(response.OutputStream);
}
}
示例9: AddFile
private void AddFile(IFile file)
{
using (var stream = file.OpenRead())
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
_messageBus.Publish(new AddTorrentMessage(ms.ToArray()));
}
// Add file to history
var hist = new History {Path = file.Path.FullPath};
_autoAddRepository.CreateHistory(hist);
}
示例10: TryGenerateAssemblyInfo
public static IFile TryGenerateAssemblyInfo(IFile descriptorPath, SemanticVersion providedVersion = null)
{
IPackageDescriptor descriptor;
using (var str = descriptorPath.OpenRead())
descriptor = new PackageDescriptorReader().Read(str);
var versionFile = descriptorPath.Parent.GetFile("version");
var version = providedVersion ?? GenerateVersion(descriptor, versionFile);
if (version == null) return null;
var generator = new AssemblyInfoGenerator(descriptor) { Version = version };
var projectAsmFile = descriptorPath.Parent.GetUniqueFile("SharedAssemblyInfo.cs");
generator.Write(projectAsmFile);
return projectAsmFile;
}
示例11: LoadRunner
ITestRunner LoadRunner(IFile tdnet)
{
using (var stream = tdnet.OpenRead())
using (var reader = new XmlTextReader(stream))
{
var xmlDoc = XDocument.Load(reader);
var friendlyName = GetChildNode(xmlDoc, "FriendlyName");
var typeName = GetChildNode(xmlDoc, "TypeName");
var assemblyPath = GetChildNode(xmlDoc, "AssemblyPath");
if (typeName != null && assemblyPath != null)
return new AppDomainTestRunner(tdnet.Parent.Path.Combine(assemblyPath), typeName);
}
return null;
}
示例12: ExtractPackage
// TODO: Replace with clean OFS-based zip methods
static void ExtractPackage(IFile wrapFile, IDirectory destinationDirectory)
{
var nt = new WindowsNameTransform(destinationDirectory.Path.FullPath);
using (var zipFile = new ZipFile(wrapFile.OpenRead()))
{
foreach (ZipEntry zipEntry in zipFile)
{
if (zipEntry.IsFile)
{
var filePath = nt.TransformFile(zipEntry.Name);
using (var targetFile = destinationDirectory.FileSystem.GetFile(filePath).MustExist().OpenWrite())
using (var sourceFile = zipFile.GetInputStream(zipEntry))
sourceFile.CopyTo(targetFile);
// TODO: restore last write time here by adding it to OFS
}
}
}
}
示例13: Compile
public Task<CompilationResult> Compile(IFile file)
{
string className = MakeClassName(file.Name);
RazorTemplateEngine engine = new RazorTemplateEngine(new RazorEngineHost(new CSharpRazorCodeLanguage())
{
DefaultBaseClass = "Edge.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 = file.OpenRead())
{
results = engine.GenerateCode(rdr, className, "EdgeCompiled", file.FullPath);
}
List<CompilationMessage> messages = new List<CompilationMessage>();
if (!results.Success)
{
foreach (var error in results.ParserErrors)
{
messages.Add(new CompilationMessage(
MessageLevel.Error,
error.Message,
new FileLocation(file.FullPath, error.Location.LineIndex, error.Location.CharacterIndex)));
}
}
// Regardless of success or failure, we're going to try and compile
return Task.FromResult(CompileCSharp("EdgeCompiled." + className, file, results.Success, messages, results.GeneratedCode));
}
示例14: ParseFile
public WrapDescriptor ParseFile(IFile filePath)
{
int tries = 0;
while (tries < FILE_READ_RETRIES)
{
try
{
using (var fileStream = filePath.OpenRead())
{
return ParseFile(filePath, fileStream);
}
}
catch (IOException)
{
tries++;
Thread.Sleep(FILE_READ_RETRIES_WAIT);
continue;
}
}
return null;
}
示例15: GetHash
/// <summary>
/// Gets the hash of a file
/// </summary>
/// <param name="file">The file to calculate the hash of</param>
/// <returns>The hash of a file.</returns>
public string GetHash(IFile file)
{
using (var md5 = MD5.Create())
{
using (var stream = file.OpenRead())
{
return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-","").ToLower();
}
}
}