当前位置: 首页>>代码示例>>C#>>正文


C# Abstractions.DirectoryInfoBase类代码示例

本文整理汇总了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);
        }
开发者ID:robzelt,项目名称:kudu,代码行数:30,代码来源:ZipController.cs

示例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);
        }
开发者ID:dipeshc,项目名称:MediaPod,代码行数:31,代码来源:TVDBCacheExtensions.cs

示例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;
        }
开发者ID:orloffm,项目名称:OrlovMikhail.Tools,代码行数:25,代码来源:IOTools.cs

示例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")));
        }
开发者ID:projectkudu,项目名称:KuduVfs,代码行数:25,代码来源:Program.cs

示例5: GetFiles

 internal static IDictionary<string, FileInfoBase> GetFiles(DirectoryInfoBase info)
 {
     if (info == null)
     {
         return null;
     }
     return info.GetFilesWithRetry().ToDictionary(f => f.Name, StringComparer.OrdinalIgnoreCase);
 }
开发者ID:amitapl,项目名称:KuduSync.NET,代码行数:8,代码来源:FileSystemHelpers.cs

示例6: GetDirectories

 internal static IDictionary<string, DirectoryInfoBase> GetDirectories(DirectoryInfoBase info)
 {
     if (info == null)
     {
         return null;
     }
     return info.GetDirectories().ToDictionary(d => d.Name, StringComparer.OrdinalIgnoreCase);
 }
开发者ID:amitapl,项目名称:KuduSync.NET,代码行数:8,代码来源:FileSystemHelpers.cs

示例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);
        }
开发者ID:dipeshc,项目名称:MediaOrganiser,代码行数:58,代码来源:Organiser.cs

示例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();
        }
开发者ID:defrancea,项目名称:Projbook,代码行数:13,代码来源:SnippetExtractorFactory.cs

示例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);
        }
开发者ID:visualeyes,项目名称:cabinet,代码行数:10,代码来源:PathExtensions.cs

示例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();
     }
 }
开发者ID:40a,项目名称:kudu,代码行数:12,代码来源:RuntimeController.cs

示例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);
        }
开发者ID:pianovelty,项目名称:pickles,代码行数:13,代码来源:HtmlTableOfContentsFormatter.cs

示例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);
 }
开发者ID:Zocdoc,项目名称:ZocBuild.Database,代码行数:23,代码来源:FileSystemScriptRepository.cs

示例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);
        }
开发者ID:Nexus6studio,项目名称:kudu,代码行数:13,代码来源:ZipController.cs

示例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();
        }
开发者ID:dipeshc,项目名称:MediaPod,代码行数:51,代码来源:ResourceManager.cs

示例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;
        }
开发者ID:visualeyes,项目名称:cabinet,代码行数:14,代码来源:PathExtensions.cs


注:本文中的System.IO.Abstractions.DirectoryInfoBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。