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


C# IDirectoryInfo.ThrowIfNull方法代码示例

本文整理汇总了C#中IDirectoryInfo.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# IDirectoryInfo.ThrowIfNull方法的具体用法?C# IDirectoryInfo.ThrowIfNull怎么用?C# IDirectoryInfo.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDirectoryInfo的用法示例。


在下文中一共展示了IDirectoryInfo.ThrowIfNull方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDirectory

        /// <summary>
        /// Creates the specified directory in the target directory.
        /// </summary>
        /// <param name="sourceDirectory">The source directory.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <exception cref="AccessException">The directory could not be accessed.</exception>
        public void CreateDirectory(IDirectoryInfo sourceDirectory, IDirectoryInfo targetDirectory)
        {
            sourceDirectory.ThrowIfNull(() => sourceDirectory);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            try
            {
                Directory.CreateDirectory(this.CombinePath(targetDirectory.FullName, sourceDirectory.Name));
            }

            catch (DirectoryNotFoundException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (PathTooLongException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (IOException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (UnauthorizedAccessException ex)
            {
                throw new AccessException(ex.Message, ex);
            }
        }
开发者ID:SmartFire,项目名称:FlagSync,代码行数:36,代码来源:LocalFileSystem.cs

示例2: DirectoryCreationEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="DirectoryCreationEventArgs"/> class.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="targetDirectory">The target directory.</param>
        public DirectoryCreationEventArgs(IDirectoryInfo directory, IDirectoryInfo targetDirectory)
        {
            directory.ThrowIfNull(() => directory);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            this.Directory = directory;
            this.TargetDirectory = targetDirectory;
        }
开发者ID:SmartFire,项目名称:FlagSync,代码行数:13,代码来源:DirectoryCreationEventArgs.cs

示例3: FileCopyErrorEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="FileCopyErrorEventArgs"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="targetDirectory">The target directory.</param>
        public FileCopyErrorEventArgs(IFileInfo file, IDirectoryInfo targetDirectory)
        {
            file.ThrowIfNull(() => file);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            this.File = file;
            this.TargetDirectory = targetDirectory;
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:13,代码来源:FileCopyErrorEventArgs.cs

示例4: FileSystemScanner

        /// <summary>
        /// Initializes a new instance of the <see cref="FileSystemScanner"/> class.
        /// </summary>
        /// <param name="rootDirectory">The root directory.</param>
        /// <exception cref="System.ArgumentException">
        /// The exception that is thrown, if the root directory doesn't exists
        /// </exception>
        public FileSystemScanner(IDirectoryInfo rootDirectory)
        {
            rootDirectory.ThrowIfNull(() => rootDirectory);

            if (!rootDirectory.Exists)
                throw new ArgumentException("The root directory must exist!");

            this.rootDirectory = rootDirectory;
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:16,代码来源:FileSystemScanner.cs

示例5: FileCopyEventArgs

        /// <summary>
        /// Initializes a new instance of the <see cref="FileCopyEventArgs"/> class.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="sourceDirectory">The source directory.</param>
        /// <param name="targetDirectory">The target directory.</param>
        public FileCopyEventArgs(IFileInfo file, IDirectoryInfo sourceDirectory, IDirectoryInfo targetDirectory)
        {
            file.ThrowIfNull(() => file);
            sourceDirectory.ThrowIfNull(() => sourceDirectory);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            this.File = file;
            this.SourceDirectory = sourceDirectory;
            this.TargetDirectory = targetDirectory;
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:16,代码来源:FileCopyEventArgs.cs

示例6: CopyFile

        /// <summary>
        /// Copies the specified file to the target directory.
        /// </summary>
        /// <param name="sourceFileSystem">The source file system.</param>
        /// <param name="sourceFile">The source file.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <exception cref="AccessException">The source file or target directory could not be accessed.</exception>
        public void CopyFile(IFileSystem sourceFileSystem, IFileInfo sourceFile, IDirectoryInfo targetDirectory)
        {
            sourceFileSystem.ThrowIfNull(() => sourceFileSystem);
            sourceFile.ThrowIfNull(() => sourceFile);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            if (!(targetDirectory is LocalDirectoryInfo))
                throw new ArgumentException("The target directory must be of type LocalDirectoryInfo.", "targetDirectory");

            try
            {
                using (Stream sourceStream = sourceFileSystem.OpenFileStream(sourceFile))
                {
                    string targetFilePath = this.CombinePath(targetDirectory.FullName, sourceFile.Name);

                    try
                    {
                        using (FileStream targetStream = File.Create(targetFilePath))
                        {
                            if (sourceFile.Length > 0)
                            {
                                var copyOperation = new StreamCopyOperation(sourceStream, targetStream, 256 * 1024, true);

                                copyOperation.CopyProgressChanged +=
                                    (sender, e) => this.FileCopyProgressChanged.RaiseSafe(this, e);

                                copyOperation.Execute();
                            }
                        }
                    }

                    catch (IOException)
                    {
                        File.Delete(targetFilePath);

                        throw;
                    }
                }
            }

            catch (UnauthorizedAccessException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (SecurityException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (IOException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:62,代码来源:LocalFileSystem.cs

示例7: CountFiles

        /// <summary>
        /// Counts recursively the files of the directory.
        /// </summary>
        /// <param name="rootDirectory">The root directory.</param>
        /// <returns>
        /// A <see cref="FileCountResult"/> which indicates the result of the count.
        /// </returns>
        public static FileCountResult CountFiles(IDirectoryInfo rootDirectory)
        {
            rootDirectory.ThrowIfNull(() => rootDirectory);

            int files = 0;
            long bytes = 0;

            var scanner = new FileSystemScanner(rootDirectory);

            scanner.FileFound += (sender, e) =>
            {
                files++;
                bytes += e.File.Length;
            };

            scanner.Start();

            return new FileCountResult(files, bytes);
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:26,代码来源:FileCounter.cs

示例8: CopyFile

        /// <summary>
        /// Copies the specified file to the target directory.
        /// </summary>
        /// <param name="sourceFileSystem">The source file system.</param>
        /// <param name="sourceFile">The source file.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <exception cref="AccessException">The source file or target directory could not be accessed.</exception>
        /// /// <exception cref="ArgumentException">The target directory is not of type <see cref="FlagFtp.FtpDirectoryInfo"/>.</exception>
        public void CopyFile(IFileSystem sourceFileSystem, IFileInfo sourceFile, IDirectoryInfo targetDirectory)
        {
            sourceFileSystem.ThrowIfNull(() => sourceFileSystem);
            sourceFile.ThrowIfNull(() => sourceFile);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            if (!(targetDirectory is FtpDirectoryInfo))
                throw new ArgumentException("The target directory must be of type FtpDirectoryInfo.", "targetDirectory");

            Uri targetFilePath = new Uri(this.CombinePath(targetDirectory.FullName, sourceFile.Name));

            try
            {
                using (Stream sourceStream = sourceFileSystem.OpenFileStream(sourceFile))
                {
                    using (Stream targetStream = this.client.OpenWrite(targetFilePath))
                    {
                        if (sourceFile.Length > 0)
                        {
                            var copyOperation = new StreamCopyOperation(sourceStream, targetStream, 8 * 1024, true);

                            copyOperation.CopyProgressChanged +=
                                (sender, e) => this.FileCopyProgressChanged.RaiseSafe(this, e);

                            copyOperation.Execute();
                        }
                    }
                }
            }

            catch (WebException ex)
            {
                switch (ex.Status)
                {
                    case WebExceptionStatus.ConnectFailure:
                    case WebExceptionStatus.ProxyNameResolutionFailure:
                        throw new FileSystemUnavailableException("The FTP server is currently unavailable.", ex);
                }

                throw new AccessException("The file could not be accessed", ex);
            }
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:50,代码来源:FtpFileSystem.cs

示例9: Job

        /// <summary>
        /// Initializes a new instance of the <see cref="Job"/> class.
        /// </summary>
        /// <param name="name">The name of the job.</param>
        /// <param name="sourceFileSystem">The source file system.</param>
        /// <param name="targetFileSystem">The target file system.</param>
        /// <param name="directoryA">The directory A.</param>
        /// <param name="directoryB">The directory B.</param>
        protected Job(string name, IFileSystem sourceFileSystem, IFileSystem targetFileSystem, IDirectoryInfo directoryA, IDirectoryInfo directoryB)
        {
            sourceFileSystem.ThrowIfNull(() => sourceFileSystem);
            targetFileSystem.ThrowIfNull(() => targetFileSystem);
            directoryA.ThrowIfNull(() => directoryA);
            directoryB.ThrowIfNull(() => directoryB);

            if (String.IsNullOrEmpty(name))
                throw new ArgumentException("The name cannot be null or empty.", Reflector.GetMemberName(() => name));

            this.SourceFileSystem = sourceFileSystem;
            this.TargetFileSystem = targetFileSystem;

            this.DirectoryA = directoryA;
            this.DirectoryB = directoryB;

            this.Name = name;

            this.proceededFilePaths = new HashSet<string>();
            this.excludedPaths = new HashSet<string>();
            this.deletedDirectoryPaths = new HashSet<string>();

            this.pauseHandle = new AutoResetEvent(false);
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:32,代码来源:Job.cs

示例10: CreateDirectory

        /// <summary>
        /// Creates the specified directory in the target directory.
        /// </summary>
        /// <param name="sourceDirectory">The source directory.</param>
        /// <param name="targetDirectory">The target directory.</param>
        /// <exception cref="AccessException">The directory could not be accessed.</exception>
        public void CreateDirectory(IDirectoryInfo sourceDirectory, IDirectoryInfo targetDirectory)
        {
            sourceDirectory.ThrowIfNull(() => sourceDirectory);
            targetDirectory.ThrowIfNull(() => targetDirectory);

            Uri newDirectory = (new Uri(new Uri(targetDirectory.FullName + "//"), sourceDirectory.Name));

            try
            {
                this.client.CreateDirectory(newDirectory);
            }

            catch (WebException ex)
            {
                switch (ex.Status)
                {
                    case WebExceptionStatus.ConnectFailure:
                    case WebExceptionStatus.ProxyNameResolutionFailure:
                        throw new FileSystemUnavailableException("The FTP server is currently unavailable.", ex);
                }

                throw new AccessException("The directory could not be accessed", ex);
            }
        }
开发者ID:SmartFire,项目名称:FlagSync,代码行数:30,代码来源:FtpFileSystem.cs

示例11: DeleteDirectory

        /// <summary>
        /// Deletes the specified directory.
        /// </summary>
        /// <param name="directory">The directory to delete.</param>
        /// <exception cref="AccessException">The directory could not be accessed.</exception>
        public void DeleteDirectory(IDirectoryInfo directory)
        {
            directory.ThrowIfNull(() => directory);

            if (!(directory is LocalDirectoryInfo))
                throw new ArgumentException("The directory must be of type LocalDirectoryInfo.", "directory");

            try
            {
                Directory.Delete(directory.FullName, true);
            }

            catch (DirectoryNotFoundException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (IOException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }

            catch (UnauthorizedAccessException ex)
            {
                throw new AccessException("The file could not be accessed.", ex);
            }
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:32,代码来源:LocalFileSystem.cs

示例12: DeleteDirectory

        /// <summary>
        /// Deletes the specified directory.
        /// </summary>
        /// <param name="directory">The directory to delete.</param>
        /// <exception cref="AccessException">The directory could not be accessed.</exception>
        /// /// <exception cref="ArgumentException">The directory is not of type <see cref="FlagFtp.FtpDirectoryInfo"/>.</exception>
        public void DeleteDirectory(IDirectoryInfo directory)
        {
            directory.ThrowIfNull(() => directory);

            if (!(directory is FtpDirectoryInfo))
                throw new ArgumentException("The directory must be of type FtpDirectoryInfo.", "directory");

            try
            {
                this.client.DeleteDirectory(new Uri(directory.FullName + "/"));
            }

            catch (WebException ex)
            {
                switch (ex.Status)
                {
                    case WebExceptionStatus.ConnectFailure:
                    case WebExceptionStatus.ProxyNameResolutionFailure:
                        throw new FileSystemUnavailableException("The FTP server is currently unavailable.", ex);
                }

                throw new AccessException("The directory could not be accessed", ex);
            }
        }
开发者ID:dineshkummarc,项目名称:FlagSync,代码行数:30,代码来源:FtpFileSystem.cs


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