Exemple #1
0
 /// <summary>
 /// Removes a file.
 /// </summary>
 /// <param name="fileInfo">FileInfo of the file to remove</param>
 /// <exception cref="PathNotFoundException">This error will be fired if the specified path or a part of them does not exist.</exception>
 /// <exception cref="FileNotFoundException">This error will be fired when attempting a file to delete, which does not exist.</exception>
 public static void DeleteFile( QuickIOFileInfo fileInfo )
 {
     RemoveAttribute( fileInfo.PathInfo, FileAttributes.ReadOnly );
     DeleteFile( fileInfo.PathInfo );
 }
 /// <summary>
 /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/>
 /// </summary>
 /// <param name="observer">Observer for monitoring</param>
 /// <param name="sourceFileInfo">File 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="overwrite">true to overwrite existing files</param>
 /// <example>
 /// Copy file
 /// 
 /// <code>
 /// <![CDATA[
 /// class Program
 /// {
 ///     static void Main( string[ ] args )
 ///     {
 ///         const string sourceFile = @"C:\transfer_test\source\test.txt";
 ///         const string targetDirectory = @"C:\transfer_test\to";
 /// 
 ///         var transferHost = new QuickIOMonitoredFileTransfer( new QuickIOFileInfo( sourceFile ), targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
 /// 
 ///         //  Progress information
 ///         transferHost.FileTransferProgress += OnFileProgressUpdate;
 /// 
 ///         // Start progress
 ///         transferHost.Start( ); // Blocks thread until finished
 /// 
 ///         Console.WriteLine( "Finished" );
 ///         Console.ReadKey( );
 ///     }
 /// 
 ///     static void OnFileProgressUpdate( Object sender, QuickIODataTransferItemTransferProgressArgs args )
 ///     {
 ///         Console.WriteLine( "File: " + args.SourcePath + " - %: " + args.Percentage + " MB/s: " + ( args.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public QuickIOTransferFileCopyService( IQuickIOTransferObserver observer, QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, Boolean overwrite = false )
     : this(observer, new List<QuickIOFileInfo> { sourceFileInfo }, targetFullName, threadCount, retryCount, overwrite)
 {
 }
Exemple #3
0
 /// <summary>
 /// Removes a file.
 /// </summary>
 /// <param name="fileInfo">FileInfo of the file to remove</param>
 /// <exception cref="PathNotFoundException">This error will be fired if the specified path or a part of them does not exist.</exception>
 /// <exception cref="FileNotFoundException">This error will be fired when attempting a file to delete, which does not exist.</exception>
 public static void DeleteFile( QuickIOFileInfo fileInfo )
 {
     DeleteFile( fileInfo.PathInfo );
 }
Exemple #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( QuickIOFileInfo info )
 {
     return info.Root;
 }
Exemple #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(QuickIOFileInfo info)
 {
     return(GetDirectoryRoot(info.Root));
 }
        /// <summary>
        /// Executes the Copy process
        /// </summary>
        protected override void Implementation( )
        {
            TransferStarted = DateTime.Now;

            var sourceInfo = new QuickIOFileInfo( Source );
            var targetFilePathInfo = new QuickIOPathInfo( Target );

            if ( targetFilePathInfo.Exists && !Overwrite )
            {
                throw new FileAlreadyExistsException( Target );
            }

            if ( ParentExistanceCheck )
            {
                OnDirectoryCreating( targetFilePathInfo.Parent.FullName );

                QuickIODirectory.Create( targetFilePathInfo.Parent, true );

                OnDirectoryCreated( targetFilePathInfo.Parent.FullName );
            }

            long totalBytes;
            using ( var rs = sourceInfo.OpenRead( ) )
            using ( var ws = QuickIOFile.Open( targetFilePathInfo, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None ) )
            {
                totalBytes = rs.Length;

                OnCopyStarted( totalBytes );

                // set target stream length
                ws.SetLength( totalBytes );

                int bytesRead;
                UInt64 bytesTransfered = 0;

                // check buffer for small files; will be faster
                var bytes = new byte[ Math.Min( totalBytes, MaxBufferSize ) ];

                // transfer chunks
                while ( ( bytesRead = rs.Read( bytes, 0, bytes.Length ) ) > 0 )
                {
                    // Write
                    ws.Write( bytes, 0, bytesRead );

                    // Calculation
                    bytesTransfered = ( bytesTransfered + ( UInt64 ) bytesRead );

                    OnCopyProgress( totalBytes, bytesTransfered );
                }
            }

            // Copy Timestamps
            if ( CopyTimestamps )
            {
                QuickIOFile.SetAllFileTimes( targetFilePathInfo, sourceInfo.CreationTime, sourceInfo.LastAccessTime, sourceInfo.LastWriteTime );
            }

            // Copy Attributes
            if ( CopyAttributes )
            {

                QuickIOFile.SetAttributes( targetFilePathInfo, sourceInfo.Attributes );
            }

            OnCopyFinished( totalBytes );
        }