コード例 #1
0
        //[InlineData( "_TestFolders/ExistingFolder", "*.txt", 1 )]
        //[InlineData( "_TestFolders/ExistingFolder", "*.TXT", 1 )]
        public void QuickIODirectoryInfo_EnumerateFilesCount( bool isRelative, string path, string pattern, int expected )
        {
            if( isRelative )
            {
                path = QuickIOPath.Combine( CurrentPath(), path );
            }

            QuickIODirectoryInfo directoryInfo = new QuickIODirectoryInfo( path );
            IEnumerable<QuickIOFileInfo> result = ( pattern == null ? directoryInfo.EnumerateFiles() : directoryInfo.EnumerateFiles( pattern ) );

            List<QuickIOFileInfo> list = result.ToList();
            list.Count.Should().Be( expected );
        }
コード例 #2
0
        //[InlineData( "_TestFolders/ExistingFolder", "*.txt", 1 )]
        //[InlineData( "_TestFolders/ExistingFolder", "*.TXT", 1 )]
        public void QuickIODirectoryInfo_EnumerateFilesCount(bool isRelative, string path, string pattern, int expected)
        {
            if (isRelative)
            {
                path = QuickIOPath.Combine(CurrentPath(), path);
            }

            QuickIODirectoryInfo          directoryInfo = new QuickIODirectoryInfo(path);
            IEnumerable <QuickIOFileInfo> result        = (pattern == null ? directoryInfo.EnumerateFiles() : directoryInfo.EnumerateFiles(pattern));

            List <QuickIOFileInfo> list = result.ToList();

            list.Count.Should().Be(expected);
        }
コード例 #3
0
ファイル: InternalQuickIO.cs プロジェクト: Kudach/QuickIO
        /// <summary>
        /// Deletes all files in the given directory. On request  all contents, too.
        /// </summary>
        /// <param name="directoryInfo">Info of directory to clear</param>
        /// <param name="recursive">If <paramref name="recursive"/> is true then all subfolders are also deleted.</param>
        /// <exception cref="PathNotFoundException">This error is fired if the specified path or a part of them does not exist.</exception>
        /// <exception cref="DirectoryNotEmptyException">The directory is not empty.</exception>
        /// <remarks>Function loads every file and attribute. Alls read-only flags will be removed before removing.</remarks>
        public static void DeleteDirectory( QuickIODirectoryInfo directoryInfo, bool recursive = false )
        {
            // Contents
            if ( recursive )
            {
                // search all contents
                var subFiles = QuickIODirectory.EnumerateFilePaths( directoryInfo.FullNameUnc, QuickIOPatternConstants.All, SearchOption.TopDirectoryOnly, QuickIOPathType.UNC, QuickIOEnumerateOptions.None );
                #region delete all files
                foreach ( var item in subFiles )
                {
                    DeleteFile( item );
                }
                #endregion

                var subDirs = QuickIODirectory.EnumerateDirectories( directoryInfo, QuickIOPatternConstants.All, SearchOption.TopDirectoryOnly, QuickIOEnumerateOptions.None );

                foreach ( var subDir in subDirs )
                {
                    DeleteDirectory( subDir, recursive );
                }
            }

            // Remove specified
            var removed = Win32SafeNativeMethods.RemoveDirectory( directoryInfo.FullNameUnc );
            var win32Error = Marshal.GetLastWin32Error( );
            if ( !removed )
            {
                InternalQuickIOCommon.NativeExceptionMapping( directoryInfo.FullName, win32Error );
            }
        }
コード例 #4
0
 /// <summary>
 /// Returns the root information
 /// </summary>
 /// <param name="info">A file or directory. </param>
 /// <returns>A QuickIOPathInfo that represents the root or null if <paramref name="info"/> is root.</returns>
 /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot(v=vs.110).aspx</remarks>
 public static QuickIOPathInfo GetDirectoryRoot( QuickIODirectoryInfo info )
 {
     return info.IsRoot ? null : GetDirectoryRoot( info.Root );
 }
コード例 #5
0
 /// <summary>
 /// Returns the root information
 /// </summary>
 /// <param name="info">A file or directory. </param>
 /// <returns>A QuickIOPathInfo that represents the root or null if <paramref name="info"/> is root.</returns>
 /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot(v=vs.110).aspx</remarks>
 public static QuickIOPathInfo GetDirectoryRoot(QuickIODirectoryInfo info)
 {
     return(new QuickIOPathInfo(info.Root));
 }
コード例 #6
0
        private InternalDirectoryTransferPrefences DetermineDirectoryTransferPrefences( QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, SearchOption searchOption, Boolean overwrite )
        {
            var prefences = new InternalDirectoryTransferPrefences( );

            IEnumerable<KeyValuePair<string, QuickIOFileSystemEntryType>> allContentUncPaths = QuickIODirectory.EnumerateFileSystemEntryPaths( sourceDirectoryInfo, QuickIOPatternConstants.All, searchOption, QuickIOPathType.UNC );

            var targetPathInfo = new QuickIOPathInfo( targetFullName );

            prefences.CreateDirectoryJobs = new List<QuickIOTransferJob>( );
            prefences.FileTransferQueueItems = new List<QuickIOTransferJob>( );
            foreach ( var entry in allContentUncPaths )
            {
                var target = targetPathInfo.FullNameUnc + entry.Key.Substring( sourceDirectoryInfo.FullNameUnc.Length );

                switch ( entry.Value )
                {
                    case QuickIOFileSystemEntryType.Directory:
                        {
                            prefences.CreateDirectoryJobs.Add( new QuickIOTransferDirectoryCreationJob( target ) );
                        }
                        break;

                    case QuickIOFileSystemEntryType.File:
                        {
                            prefences.FileTransferQueueItems.Add( new QuickIOTransferFileCopyJob( entry.Key, target, MaxBufferSize, overwrite, false ) );
                        }
                        break;
                }
            }

            return prefences;
        }
コード例 #7
0
        /// <summary>
        /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/> with specified observer
        /// </summary>
        /// <param name="observer">Observer</param>
        /// <param name="sourceDirectoryInfo">Directory to copy</param>
        /// <param name="targetFullName">Target fullname</param>
        /// <param name="threadCount">Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares</param>
        /// <param name="retryCount">Count of retries before copy is broken</param>
        /// <param name="searchOption"><see cref="SearchOption"/>of deepth to copy</param>
        /// <param name="overwrite">true to overwrite existing files</param>
        /// <example>
        /// Copy complete directory
        /// <code>
        /// <![CDATA[
        /// static void Main( string[ ] args )
        /// {
        ///     const string sourceDirectory = @"C:\transfer_test\source";
        ///     const string targetDirectory = @"C:\transfer_test\to";
        /// 
        /// 
        ///     // With observer
        ///     IQuickIOTransferObserver observer = new QuickIOTransferObserver( );
        ///     var service = new QuickIOTransferDirectoryCopyService( observer, new QuickIODirectoryInfo( sourceDirectory ), targetDirectory, threadCount: 1, retryCount: 3, searchOption: SearchOption.AllDirectories, overwrite: true );
        ///     // or without overload, to use default internal observer
        ///     // var service = new QuickIOTransferDirectoryCopyService( new QuickIODirectoryInfo( sourceDirectory ), targetDirectory, threadCount: 1, retryCount: 3, searchOption: SearchOption.AllDirectories, overwrite: true );
        /// 
        ///     //  Progress information
        ///     service.Observer.DirectoryCreationError += ObserverOnDirectoryCreationError;
        ///     service.Observer.FileCopyStarted += OnFileCopyStarted;
        ///     service.Observer.FileCopyProgress += OnFileCopyProgress;
        ///     service.Observer.FileCopyFinished += OnFileCopyFinished;
        ///     service.Observer.FileCopyError += ObserverOnFileCopyError;
        ///     // Same as (observer events are called first!):
        ///     service.FileCopyStarted += OnFileCopyStarted;
        ///     service.FileCopyProgress += OnFileCopyProgress;
        ///     service.FileCopyFinished += OnFileCopyFinished;
        ///     service.FileCopyError += ObserverOnFileCopyError;
        /// 
        ///     // Start progress
        ///     service.Start( ); // Blocks thread until finished
        /// 
        ///     Console.WriteLine( "Finished" );
        ///     Console.ReadKey( );
        /// }
        /// 
        /// private static void ObserverOnDirectoryCreationError( object sender, QuickIOTransferDirectoryCreationErrorEventArgs e )
        /// {
        ///     Console.WriteLine( "Error: Dir create '" + e.TargetPath + "' failed: " + e.Exception.Message );
        /// }
        /// 
        /// private static void ObserverOnFileCopyError( object sender, QuickIOTransferFileCopyErrorEventArgs e )
        /// {
        ///     Console.WriteLine( "Error: " + e.SourcePath + " to " + e.TargetPath + ": " + e.Exception.Message );
        /// }
        /// 
        /// private static void OnFileCopyStarted( object sender, QuickIOTransferFileCopyStartedEventArgs e )
        /// {
        ///     Console.WriteLine( "Started: " + e.SourcePath + " to " + e.TargetPath + " (Bytes: " + e.TotalBytes + ")" );
        /// }
        /// 
        /// private static void OnFileCopyFinished( object sender, QuickIOTransferFileCopyFinishedEventArgs e )
        /// {
        ///     Console.WriteLine( "Finished: " + e.SourcePath + " - MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
        /// }
        /// 
        /// private static void OnFileCopyProgress( object sender, QuickIOTransferFileCopyProgressEventArgs e )
        /// {
        ///     Console.WriteLine( "Progress: " + e.SourcePath + " - %: " + e.Percentage + " MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
        /// }
        /// ]]>
        /// </code>
        /// </example>
        public QuickIOTransferDirectoryCopyService( IQuickIOTransferObserver observer, QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, SearchOption searchOption = SearchOption.TopDirectoryOnly, Boolean overwrite = false )
            : base(observer, threadCount, retryCount)
        {
            SourceDirectoryInfo = sourceDirectoryInfo;
            TargetFullName = targetFullName;
            SearchOption = searchOption;
            Overwrite = overwrite;

            // Register Events
            RegisterInternalEventHandling( );

            StartWorking( );
        }
コード例 #8
0
 /// <summary>
 /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/> with default observer
 /// </summary>
 /// <param name="sourceDirectoryInfo">Directory to copy</param>
 /// <param name="targetFullName">Target fullname</param>
 /// <param name="threadCount">Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares</param>
 /// <param name="retryCount">Count of retries before copy is broken</param>
 /// <param name="searchOption"><see cref="SearchOption"/>of deepth to copy</param>
 /// <param name="overwrite">true to overwrite existing files</param>
 /// <example>
 /// Copy complete directory
 /// <code>
 /// <![CDATA[
 /// static void Main( string[ ] args )
 /// {
 ///     const string sourceDirectory = @"C:\transfer_test\source";
 ///     const string targetDirectory = @"C:\transfer_test\to";
 /// 
 /// 
 ///     // With observer
 ///     IQuickIOTransferObserver observer = new QuickIOTransferObserver( );
 ///     var service = new QuickIOTransferDirectoryCopyService( observer, new QuickIODirectoryInfo( sourceDirectory ), targetDirectory, threadCount: 1, retryCount: 3, searchOption: SearchOption.AllDirectories, overwrite: true );
 ///     // or without overload, to use default internal observer
 ///     // var service = new QuickIOTransferDirectoryCopyService( new QuickIODirectoryInfo( sourceDirectory ), targetDirectory, threadCount: 1, retryCount: 3, searchOption: SearchOption.AllDirectories, overwrite: true );
 /// 
 ///     //  Progress information
 ///     service.Observer.DirectoryCreationError += ObserverOnDirectoryCreationError;
 ///     service.Observer.FileCopyStarted += OnFileCopyStarted;
 ///     service.Observer.FileCopyProgress += OnFileCopyProgress;
 ///     service.Observer.FileCopyFinished += OnFileCopyFinished;
 ///     service.Observer.FileCopyError += ObserverOnFileCopyError;
 ///     // Same as (observer events are called first!):
 ///     service.FileCopyStarted += OnFileCopyStarted;
 ///     service.FileCopyProgress += OnFileCopyProgress;
 ///     service.FileCopyFinished += OnFileCopyFinished;
 ///     service.FileCopyError += ObserverOnFileCopyError;
 /// 
 ///     // Start progress
 ///     service.Start( ); // Blocks thread until finished
 /// 
 ///     Console.WriteLine( "Finished" );
 ///     Console.ReadKey( );
 /// }
 /// 
 /// private static void ObserverOnDirectoryCreationError( object sender, QuickIOTransferDirectoryCreationErrorEventArgs e )
 /// {
 ///     Console.WriteLine( "Error: Dir create '" + e.TargetPath + "' failed: " + e.Exception.Message );
 /// }
 /// 
 /// private static void ObserverOnFileCopyError( object sender, QuickIOTransferFileCopyErrorEventArgs e )
 /// {
 ///     Console.WriteLine( "Error: " + e.SourcePath + " to " + e.TargetPath + ": " + e.Exception.Message );
 /// }
 /// 
 /// private static void OnFileCopyStarted( object sender, QuickIOTransferFileCopyStartedEventArgs e )
 /// {
 ///     Console.WriteLine( "Started: " + e.SourcePath + " to " + e.TargetPath + " (Bytes: " + e.TotalBytes + ")" );
 /// }
 /// 
 /// private static void OnFileCopyFinished( object sender, QuickIOTransferFileCopyFinishedEventArgs e )
 /// {
 ///     Console.WriteLine( "Finished: " + e.SourcePath + " - MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
 /// }
 /// 
 /// private static void OnFileCopyProgress( object sender, QuickIOTransferFileCopyProgressEventArgs e )
 /// {
 ///     Console.WriteLine( "Progress: " + e.SourcePath + " - %: " + e.Percentage + " MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public QuickIOTransferDirectoryCopyService( QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, SearchOption searchOption = SearchOption.TopDirectoryOnly, Boolean overwrite = false )
     : this(null, sourceDirectoryInfo, targetFullName, threadCount, retryCount, searchOption, overwrite)
 {
 }
コード例 #9
0
 /// <summary>
 /// Returns the root information
 /// </summary>
 /// <param name="info">A file or directory. </param>
 /// <returns>A QuickIOPathInfo that represents the root or null if <paramref name="info"/> is root.</returns>
 /// <remarks>http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot(v=vs.110).aspx</remarks>
 public static QuickIOPathInfo GetDirectoryRoot( QuickIODirectoryInfo info )
 {
     return info.Root;
 }