本文整理汇总了C#中System.IO.Abstractions.FileInfoBase.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfoBase.OpenRead方法的具体用法?C# FileInfoBase.OpenRead怎么用?C# FileInfoBase.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Abstractions.FileInfoBase
的用法示例。
在下文中一共展示了FileInfoBase.OpenRead方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadResultsFile
private XDocument ReadResultsFile(FileInfoBase testResultsFile)
{
XDocument document;
using (var stream = testResultsFile.OpenRead())
{
using (var streamReader = new System.IO.StreamReader(stream))
{
string content = streamReader.ReadToEnd();
int begin = content.IndexOf("<!-- Pickles Begin", StringComparison.Ordinal);
content = content.Substring(begin);
content = content.Replace("<!-- Pickles Begin", string.Empty);
int end = content.IndexOf("Pickles End -->", System.StringComparison.Ordinal);
content = content.Substring(0, end);
content = content.Replace("<", "<").Replace(">", ">");
var xmlReader = XmlReader.Create(new System.IO.StringReader(content));
document = XDocument.Load(xmlReader);
}
}
return document;
}
示例2: AddFile
public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, string directoryNameInArchive)
{
string fileName = Path.Combine(directoryNameInArchive, file.Name);
ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
using (Stream zipStream = entry.Open(),
fileStream = file.OpenRead())
{
fileStream.CopyTo(zipStream);
}
}
示例3: Load
public XDocument Load(FileInfoBase fileInfo)
{
XDocument document;
using (var stream = fileInfo.OpenRead())
{
document = this.Load(stream);
}
return document;
}
示例4: Load
public XDocument Load(FileInfoBase fileInfo)
{
XDocument document;
using (var stream = fileInfo.OpenRead())
{
XmlReader xmlReader = XmlReader.Create(stream);
document = XDocument.Load(xmlReader);
stream.Close();
}
return document;
}
示例5: ReadResultsFile
private List<Feature> ReadResultsFile(FileInfoBase testResultsFile)
{
List<Feature> result;
using (var stream = testResultsFile.OpenRead())
{
using (var reader = new StreamReader(stream))
{
result = JsonConvert.DeserializeObject<List<Feature>>(reader.ReadToEnd());
}
}
return result;
}
示例6: LoadFile
/// <summary>
/// Loads a file from the file name.
/// </summary>
/// <param name="fileInfo">The file info.</param>
/// <returns>The file's content.</returns>
protected string LoadFile(FileInfoBase fileInfo)
{
// Data validation
if (null == fileInfo)
throw new ArgumentNullException("fileInfo");
// Load the file content
MemoryStream memoryStream = new MemoryStream();
using (StreamReader streamReader = new StreamReader(fileInfo.OpenRead()))
using (var fileWriter = new StreamWriter(memoryStream))
{
fileWriter.Write(streamReader.ReadToEnd());
}
// Read the code snippet from the file
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
示例7: CreateFromFileName
public static IFileReader CreateFromFileName(FileInfoBase fileInfoBase)
{
if (IsCsvFile(fileInfoBase.FullName))
{
var reader = new CsvHelper.CsvReader(new StreamReader(fileInfoBase.OpenRead()), new CsvConfiguration
{
HasHeaderRecord = true,
Delimiter = ";"
});
return new CsvReader(reader);
}
if (IsExcelFile(fileInfoBase.FullName))
{
var excelReader = ExcelReaderFactory.CreateOpenXmlReader(fileInfoBase.Open(FileMode.Open, FileAccess.Read));
excelReader.IsFirstRowAsColumnNames = true;
return new ExcelReader(excelReader);
}
throw new InvalidOperationException();
}
示例8: HashDelivery
private static string HashDelivery(FileInfoBase file)
{
using (var fs = file.OpenRead())
using (var bs = new BufferedStream(fs))
{
using (var sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(bs);
var formatted = new StringBuilder(2 * hash.Length);
foreach (var b in hash)
{
formatted.AppendFormat("{0:X2}", b);
}
return formatted.ToString();
}
}
}
示例9: ReadResultsFile
private XDocument ReadResultsFile(FileInfoBase testResultsFile)
{
XDocument document;
using (var stream = testResultsFile.OpenRead())
{
var xmlReader = XmlReader.Create(stream);
document = XDocument.Load(xmlReader);
stream.Close();
}
return document;
}
示例10: GetHeightToWidthRatio
public static double GetHeightToWidthRatio(FileInfoBase relativePath)
{
using (var stream = relativePath.OpenRead())
{
var image = Image.FromStream(stream);
return ((double)image.Height) / ((double)image.Width);
}
}
示例11: GetScriptAsync
/// <summary>
/// Retrieves the build script contained in the given file.
/// </summary>
/// <param name="file">The file containing a build script</param>
/// <returns>A build script.</returns>
protected async Task<ScriptFile> GetScriptAsync(FileInfoBase file)
{
// Parse file name and path
var typeName = file.Directory.Name;
var schemaName = file.Directory.Parent.Name;
var fileName = Path.GetFileNameWithoutExtension(file.FullName);
if(!_objectTypes.ContainsKey(typeName))
{
return new ScriptFile(new DatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName()), new UnexpectedObjectTypeError(typeName));
}
var objectType = _objectTypes[typeName];
var dbObject = new TypedDatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName(), objectType);
// Read file contents
string content;
try
{
using (var fileInputStream = file.OpenRead())
{
using (var fileReader = new StreamReader(fileInputStream))
{
content = await fileReader.ReadToEndAsync();
}
}
}
catch (DirectoryNotFoundException)
{
return new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser);
}
catch (FileNotFoundException)
{
return new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser);
}
// Parse script file
var script = new ScriptFile(dbObject, content, _sqlParser);
return script;
}
示例12: BytesEqual
private static bool BytesEqual(FileInfoBase file1, FileInfoBase file2)
{
if (file1.Length != file2.Length)
{
return false;
}
int bufferCount = (int)Math.Ceiling((double)file1.Length / BufferSize);
using (Stream sourceStream = file1.OpenRead())
using (Stream targetStream = file2.OpenRead())
{
byte[] sourceBuffer = new byte[BufferSize];
byte[] targetBuffer = new byte[BufferSize];
for (int i = 0; i < bufferCount; i++)
{
sourceStream.Read(sourceBuffer, 0, BufferSize);
targetStream.Read(targetBuffer, 0, BufferSize);
if (BitConverter.ToInt64(sourceBuffer, 0) != BitConverter.ToInt64(targetBuffer, 0))
{
return false;
}
}
}
return true;
}
示例13: AddFile
public static void AddFile(this ZipArchive zipArchive, FileInfoBase file, ITracer tracer, string directoryNameInArchive)
{
Stream fileStream = null;
try
{
fileStream = file.OpenRead();
}
catch (Exception ex)
{
// tolerate if file in use.
// for simplicity, any exception.
tracer.TraceError(String.Format("{0}, {1}", file.FullName, ex));
return;
}
try
{
string fileName = ForwardSlashCombine(directoryNameInArchive, file.Name);
ZipArchiveEntry entry = zipArchive.CreateEntry(fileName, CompressionLevel.Fastest);
entry.LastWriteTime = file.LastWriteTime;
using (Stream zipStream = entry.Open())
{
fileStream.CopyTo(zipStream);
}
}
finally
{
fileStream.Dispose();
}
}