本文整理汇总了C#中System.IO.Abstractions.FileInfoBase类的典型用法代码示例。如果您正苦于以下问题:C# FileInfoBase类的具体用法?C# FileInfoBase怎么用?C# FileInfoBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileInfoBase类属于System.IO.Abstractions命名空间,在下文中一共展示了FileInfoBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public SingleTestRunBase Load(FileInfoBase fileInfo)
{
var document = this.ReadResultsFile(fileInfo);
var features = this.ToFeatures(document);
return new SpecRunSingleResults(features);
}
示例2: 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;
}
示例3: SpecRunSingleResults
public SpecRunSingleResults(FileInfoBase fileInfo)
{
var resultsDocument = this.ReadResultsFile(fileInfo);
this.specRunFeatures =
resultsDocument.Descendants("feature").Select(Parser.SpecRun.Factory.ToSpecRunFeature).ToList();
}
示例4: MakeRelativePath
public static string MakeRelativePath(DirectoryInfoBase fromPath, FileInfoBase toPath)
{
if (fromPath == null) throw new ArgumentNullException("fromPath");
if (toPath == null) throw new ArgumentNullException("toPath");
string root = fromPath.FullName;
if (!(root.EndsWith("\\") || root.EndsWith("/")))
root += "\\";
root += "a.txt";
Uri fromUri = new Uri(root);
Uri toUri = new Uri(toPath.FullName);
if (fromUri.Scheme != toUri.Scheme) { return toPath.FullName; } // path can't be made relative.
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
if (toUri.Scheme.ToUpperInvariant() == "FILE")
{
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
}
return relativePath;
}
示例5: Load
public XDocument Load(FileInfoBase fileInfo)
{
XDocument document;
using (var stream = fileInfo.OpenRead())
{
document = this.Load(stream);
}
return document;
}
示例6: 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);
}
}
示例7: AddTestResultFileIfItExists
private void AddTestResultFileIfItExists(FileInfoBase fileInfoBase)
{
if (fileInfoBase.Exists)
{
this.testResultsFiles.Add(fileInfoBase);
}
else
{
Log.Error("A test result file could not be found, it will be skipped: {0}", fileInfoBase.FullName);
}
}
示例8: StreamFile
private void StreamFile(FileInfoBase file)
{
// Set varaibles.
const int bufferReadSize = 1024 * 8;
var fileSize = file.Length;
long start = 0;
long end = fileSize - 1;
// Check if range specified.
if(Request.Headers.AllKeys.Contains("Range"))
{
// Extract range details.
var range = Request.Headers.Get("Range");
var rangeRegex = new Regex(@"^bytes=(\d+)-(\d*)", RegexOptions.IgnoreCase);
var match = rangeRegex.Match(range);
// Extract start.
if(match.Groups.Count>1 && !string.IsNullOrEmpty(match.Groups[1].Value))
{
long.TryParse(match.Groups[1].Value, out start);
}
// Extract end.
if(match.Groups.Count>2 && !string.IsNullOrEmpty(match.Groups[2].Value))
{
long.TryParse(match.Groups[2].Value, out end);
}
// Check if Offset is valid.
if(start < 0 || start > end)
{
Response.StatusCode = 416;
Response.StatusDescription = "Requested Range Not Satisfiable";
Response.End();
return;
}
}
if(start != 0)
{
Response.StatusCode = 206;
Response.StatusDescription = "Partial Content";
}
// Set headers.
Response.ContentType = file.Name.ResoveContentType();
Response.AddHeader("Accept-Ranges", "bytes");
Response.AddHeader("Content-Range", string.Format("bytes {0}-{1}/{2}", start, end, fileSize));
Response.AddHeader("Content-Length", (end + 1 - start).ToString());
// Transmit the file.
Response.OutputStream.TransmitFile(file, start, (end + 1 - start));
Response.End();
}
示例9: 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;
}
示例10: Create
public static ICsvWriter Create(FileInfoBase fileInfo)
{
var csvConfiguration = new CsvConfiguration
{
Delimiter = ";",
HasHeaderRecord = true
};
var streamWriter = new StreamWriter(fileInfo.OpenWrite(), Encoding.UTF8);
return new CsvHelper.CsvWriter(streamWriter, csvConfiguration);
}
示例11: 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;
}
示例12: ListFile
static void ListFile(FileInfoBase file)
{
if (!file.Exists)
{
throw new FileNotFoundException(file.FullName + " does not exist.");
}
Console.WriteLine();
Console.WriteLine(" Directory of {0}", file.Directory.FullName.TrimEnd('\\'));
Console.WriteLine();
Console.WriteLine(String.Format("{0} {1,17} {2}", ToDisplayString(file.LastWriteTime), file.Length.ToString("#,##0"), file.Name));
Console.WriteLine(String.Format("{0,16} File(s) {1,14} bytes", 1, file.Length.ToString("#,##0")));
}
示例13: ExtractDetails
public bool ExtractDetails(FileInfoBase showFile)
{
// Run AtomicParsley to get details.
var details = new Dictionary<string, string>();
if(!AtomicParsley.AtomicParsley.ExtractDetails(showFile.FullName, out details))
{
return false;
}
// Extract the details out of the output.
if(!details.ContainsKey("tvsh") || !details.ContainsKey("tves"))
{
return false;
}
// Set default values.
ShowName = details["tvsh"];
SeasonNumber = null;
EpisodeNumber = Convert.ToInt32(details["tves"]);
EpisodeName = null;
AiredDate = null;
Overview = null;
TVNetwork = null;
Artworks = null;
// Set optional values.
if(details.ContainsKey("tvsn"))
{
SeasonNumber = Convert.ToInt32(details["tvsn"]);
}
if(details.ContainsKey("@nam"))
{
EpisodeName = details["@nam"];
}
if(details.ContainsKey("@day"))
{
AiredDate = DateTime.Parse(details["@day"]);
}
if(details.ContainsKey("@desc"))
{
Overview = details["desc"];
}
if(details.ContainsKey("tvnn"))
{
TVNetwork = details["tvnn"];
}
HasDetails = true;
return true;
}
示例14: IsRelevant
public bool IsRelevant(FileInfoBase fileInfo)
{
if (fileInfo == null)
{
return false;
}
string extension = fileInfo.Extension.ToUpperInvariant();
if (this.validExtensions.Contains(extension))
{
return true;
}
return false;
}
示例15: 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());
}