本文整理汇总了C#中System.IO.Abstractions.DirectoryInfoBase类的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfoBase类的具体用法?C# DirectoryInfoBase怎么用?C# DirectoryInfoBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryInfoBase类属于System.IO.Abstractions命名空间,在下文中一共展示了DirectoryInfoBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDirectoryGetResponse
protected override Task<HttpResponseMessage> CreateDirectoryGetResponse(DirectoryInfoBase info, string localFilePath)
{
HttpResponseMessage response = Request.CreateResponse();
var ms = new MemoryStream();
using (var zip = new ZipArchive(ms, ZipArchiveMode.Create, leaveOpen: true))
{
foreach (FileSystemInfoBase fileSysInfo in info.GetFileSystemInfos())
{
var directoryInfo = fileSysInfo as DirectoryInfoBase;
if (directoryInfo != null)
{
zip.AddDirectory(directoryInfo, fileSysInfo.Name);
}
else
{
// Add it at the root of the zip
zip.AddFile(fileSysInfo.FullName, String.Empty);
}
}
}
ms.Seek(0, SeekOrigin.Begin);
response.Content = new StreamContent(ms);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
// Name the zip after the folder. e.g. "c:\foo\bar\" --> "bar"
response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(Path.GetDirectoryName(localFilePath)) + ".zip";
return Task.FromResult(response);
}
示例2: Search
public static IEnumerable<int> Search(this TvdbHandler tvdbHandler, IFileSystem fileSystem, DirectoryInfoBase cacheDirectory, string term)
{
// Initalise cache if it does not exist.
if (_searchCache == null)
{
_searchCache = new SearchCache(fileSystem, cacheDirectory);
}
// If not in cache then search online.
if(!_searchCache.Contains(term))
{
// HACK: TVDB fails on concurrent search, needs a lock to only allow one search.
lock(_lock)
{
// Search.
var results = tvdbHandler.SearchSeries(term);
// Return null if no results found.
if(results.Count==0)
{
return null;
}
// Set cache.
_searchCache.Insert(term, results.Select(result => result.Id).ToList());
}
}
// Return series id.
return _searchCache.Get(term);
}
示例3: 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;
}
示例4: ListDirectory
static void ListDirectory(DirectoryInfoBase dir)
{
FileSystemInfoBase[] children = dir.GetFileSystemInfos();
Console.WriteLine();
Console.WriteLine(" Directory of {0}", dir.FullName.TrimEnd('\\'));
Console.WriteLine();
foreach (DirectoryInfoBase info in children.Where(d => d is DirectoryInfoBase))
{
Console.WriteLine(String.Format("{0} <DIR> {1}", ToDisplayString(info.LastWriteTime), info.Name));
}
int count = 0;
long total = 0;
foreach (FileInfoBase info in children.Where(d => !(d is DirectoryInfoBase)))
{
FileInfoBase file = (FileInfoBase)info;
Console.WriteLine(String.Format("{0} {1,17} {2}", ToDisplayString(info.LastWriteTime), file.Length.ToString("#,##0"), info.Name));
total += file.Length;
++count;
}
Console.WriteLine(String.Format("{0,16} File(s) {1,14} bytes", count.ToString("#,##0"), total.ToString("#,##0")));
}
示例5: GetFiles
internal static IDictionary<string, FileInfoBase> GetFiles(DirectoryInfoBase info)
{
if (info == null)
{
return null;
}
return info.GetFilesWithRetry().ToDictionary(f => f.Name, StringComparer.OrdinalIgnoreCase);
}
示例6: GetDirectories
internal static IDictionary<string, DirectoryInfoBase> GetDirectories(DirectoryInfoBase info)
{
if (info == null)
{
return null;
}
return info.GetDirectories().ToDictionary(d => d.Name, StringComparer.OrdinalIgnoreCase);
}
示例7: Organise
public void Organise(IMedia media, DirectoryInfoBase outputDirectory, OrganiserConversionOptions conversionOption, bool strictSeason)
{
// Create working directory.
WorkingDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(_fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), "WorkingArea"));
// Create working directory if it does not exist.
if(!WorkingDirectory.Exists)
{
WorkingDirectory.Create();
}
// Copy to working area.
CopyMediaToWorkingArea(media);
// Convert if required.
if(conversionOption == OrganiserConversionOptions.Force)
{
Logger.Log("Organiser").StdOut.WriteLine("Conversion set to \"force\". Will convert. {0}", media.MediaFile.FullName);
ConvertMedia(media);
}
else if(media.RequiresConversion)
{
if(conversionOption == OrganiserConversionOptions.Skip)
{
Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
}
else
{
Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Will convert. {0}", media.MediaFile.FullName);
ConvertMedia(media);
}
}
// Extract media details exhaustivly.
ExtractExhaustiveMediaDetails(media, strictSeason);
// Save media meta data.
var saveResponse = SaveMediaMetaData(media);
if(!saveResponse)
{
if(conversionOption == OrganiserConversionOptions.Skip)
{
Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
}
else
{
Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Will convert. {0}", media.MediaFile.FullName);
ConvertMedia(media);
SaveMediaMetaData(media);
}
}
// Rename media.
RenameMediaToCleanFileName(media);
// If output directory not provided, delete file. Otherwise move to output directory.
MoveMediaToOutputDirectory(media, outputDirectory);
}
示例8: SnippetExtractorFactory
/// <summary>
/// Initializes a new instance of <see cref="SnippetExtractorFactory"/>.
/// </summary>
/// <param name="extensionDirectory">The extension directory.</param>
public SnippetExtractorFactory(DirectoryInfoBase extensionDirectory)
{
// Initialize
this.defaultExtractorFactory = () => new DefaultSnippetExtractor();
this.extensionDirectory = extensionDirectory;
// Load extensions
this.LoadExtensions();
}
示例9: IsSameDirectory
public static bool IsSameDirectory(this DirectoryInfoBase item1, DirectoryInfoBase item2) {
if (item1 == null) throw new ArgumentNullException(nameof(item1));
if (item2 == null) throw new ArgumentNullException(nameof(item2));
string dir1Path = GetNormalisedFullPath(item1);
string dir2Path = GetNormalisedFullPath(item2);
return dir1Path.Equals(dir2Path, StringComparison.OrdinalIgnoreCase);
}
示例10: TryReadNpmVersion
private static string TryReadNpmVersion(DirectoryInfoBase nodeDir)
{
var npmRedirectionFile = nodeDir.GetFiles("npm.txt").FirstOrDefault();
if (npmRedirectionFile == null)
{
return null;
}
using (StreamReader reader = new StreamReader(npmRedirectionFile.OpenRead()))
{
return reader.ReadLine();
}
}
示例11: Format
public XElement Format(Uri file, GeneralTree<INode> features, DirectoryInfoBase outputFolder)
{
XNamespace xmlns = HtmlNamespace.Xhtml;
XElement ul = this.BuildListItems(xmlns, file, features);
ul.AddFirst(AddNodeForHome(xmlns, file, outputFolder));
return new XElement(
xmlns + "div",
new XAttribute("id", "toc"),
this.BuildCollapser(xmlns),
ul);
}
示例12: FileSystemScriptRepository
/// <summary>
/// Instantiates a file system repository for the given database at the specified directory location.
/// </summary>
/// <param name="scriptDirectory">The directory where build scripts are located.</param>
/// <param name="serverName">The name of the database server.</param>
/// <param name="databaseName">The name of the database.</param>
/// <param name="fileSystem">An object that provides access to the file system.</param>
/// <param name="sqlParser">The sql script parser for reading the SQL file contents.</param>
/// <param name="logger">A Logger</param>
/// <param name="ignoreUnsupportedSubdirectories">A flag indicating whether to ignore subdirectories that don't conform to the expected naming convention.</param>
public FileSystemScriptRepository(DirectoryInfoBase scriptDirectory, string serverName, string databaseName, IFileSystem fileSystem, IParser sqlParser, ILogger logger, bool ignoreUnsupportedSubdirectories)
{
Logger = logger;
ScriptDirectory = scriptDirectory;
ServerName = serverName.TrimObjectName();
DatabaseName = databaseName.TrimObjectName();
IgnoreUnsupportedSubdirectories = ignoreUnsupportedSubdirectories;
_objectTypes = Enum.GetValues(typeof(DatabaseObjectType)).Cast<DatabaseObjectType>()
.ToDictionary(x => x.ToString(), y => y, StringComparer.InvariantCultureIgnoreCase);
this.FileSystem = fileSystem;
this._sqlParser = sqlParser;
this.IsFileInSupportedDirectory = f => _objectTypes.ContainsKey(f.Directory.Name);
}
示例13: CreateDirectoryPutResponse
protected override async Task<HttpResponseMessage> CreateDirectoryPutResponse(DirectoryInfoBase info, string localFilePath)
{
using (var stream = await Request.Content.ReadAsStreamAsync())
{
// The unzipping is done over the existing folder, without first removing existing files.
// Hence it's more of a PATCH than a PUT. We should consider supporting both with the right semantic.
// Though a true PUT at the root would be scary as it would wipe all existing files!
var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read);
zipArchive.Extract(localFilePath);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
示例14: Initialise
public static void Initialise(IFileSystem fileSystem, int webserverPort, DirectoryInfoBase tvShowDirectory, DirectoryInfoBase unorganisedDirectory, string tvdbApiKey, DirectoryInfoBase logDirectory=null)
{
// Initalise.
if (logDirectory == null)
{
LogManager = new LogManager(Console.Out, Console.Error);
}
else
{
LogManager = new LogManager (fileSystem, logDirectory);
}
NotificationManager = new NotificationManager();
MetadataSource = new TVDBTVShowMetadataSource(fileSystem, tvdbApiKey);
QueuedTaskManager = new QueuedTaskManager();
TVShowLibrary = new TVShowLibrary(tvShowDirectory, new List<ITVShowMetadataSource>() { MetadataSource });
UnorganisedLibrary = new UnorganisedLibrary(unorganisedDirectory);
WebserverManager = new WebserverManager(webserverPort);
// Sta
QueuedTaskManager.Start();
// Setup keep alive thread..
_keepAliveThread = CreateIntervalThread(() =>
{
// Create threads if not alive.
if(_fileSystemReloaderThread==null || !_fileSystemReloaderThread.IsAlive)
{
_fileSystemReloaderThread = CreateIntervalThread(() =>
{
TVShowLibrary.Load();
}, _fileSystemReloaderSleepTime);
_fileSystemReloaderThread.Priority = ThreadPriority.Lowest;
_fileSystemReloaderThread.Start();
}
if(_webserverThread==null || !_webserverThread.IsAlive)
{
_webserverThread = new Thread(() =>
{
// Run webserver and block from terminating.
WebserverManager.Run();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
});
_webserverThread.Priority = ThreadPriority.Normal;
_webserverThread.Start();
}
}, _keepAliveSleepTime);
// Set priority and start.
_keepAliveThread.Priority = ThreadPriority.Lowest;
_keepAliveThread.Start();
}
示例15: IsChildOf
public static bool IsChildOf(this DirectoryInfoBase subDir, DirectoryInfoBase baseDir) {
var isChild = false;
while (subDir?.Parent != null) {
if (subDir.Parent.IsSameDirectory(baseDir)) {
isChild = true;
break;
} else {
subDir = subDir.Parent;
}
}
return isChild;
}