public class QuickIOTransferFileCopyService : QuickIOTransferServiceBase
Copy directory with progress monitoring
Copy collection of files
class Program
{
static void Main( string[ ] args )
{
const string sourceDirectory = @"C:\transfer_test\source";
const string targetDirectory = @"C:\transfer_test\to";
// search files
var files = QuickIODirectory.EnumerateFiles( sourceDirectory, SearchOption.TopDirectoryOnly );
var service = new QuickIOTransferFileCopyService( files, targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
// Progress information
service.Started += transferHost_FileCopyStarted;
service.Progress += OnFileProgressUpdate;
service.Finished += transferHost_FileCopyFinished;
// Start progress
service.Start( ); // Blocks thread until finished
Console.WriteLine( "Finished" );
Console.ReadKey( );
}
static void transferHost_FileCopyFinished( object sender, QuickIOTransferFileCopyFinishedArgs e )
{
Console.WriteLine( "Finished: " + e.SourcePath + " - MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
}
static void transferHost_FileCopyStarted( object sender, QuickIOTransferFileCopyStartedArgs e )
{
Console.WriteLine( "Started: " + e.SourcePath + " to " + e.TargetPath + " (Bytes: " + e.TotalBytes + ")" );
}
static void OnFileProgressUpdate( object sender, QuickIOTransferFileCopyProgressArgs e )
{
Console.WriteLine( "Progress: " + e.SourcePath + " - %: " + e.Percentage + " MB/s: " + ( e.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
}
}
private UInt64 _totalBytes
private readonly object _totalBytesLock
private UInt64 _totalBytesTransfered
private readonly object _totalBytesTransferedLock
QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService
public void QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Parameters
observer
IQuickIOTransferObserverObserver for monitoring
sourceFileInfo
QuickIOFileInfoFile to copy
targetFullName
StringTarget fullname
threadCount
Int32Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares
retryCount
Int32Count of retries before copy is broken
overwrite
Booleantrue to overwrite existing files
Example
Copy file
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" ) );
}
}
QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService
public void QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Parameters
observer
IQuickIOTransferObserverObserver for monitoring
sourceFileInfos
IEnumerableFiles to copy
targetFullName
StringTarget fullname
threadCount
Int32Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares
retryCount
Int32Count of retries before copy is broken
overwrite
Booleantrue to overwrite existing files
Example
Copy collection of files
class Program
{
static void Main( string[ ] args )
{
const string sourceDirectory = @"C:\transfer_test\source";
const string targetDirectory = @"C:\transfer_test\to";
// search files
var files = QuickIODirectory.EnumerateFiles( sourceDirectory, SearchOption.TopDirectoryOnly );
var transferHost = new QuickIOMonitoredFileTransfer( files, 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" ) );
}
}
Start()
Starts the copy process. First it determines all content information of source. Then the target directory structure will be created before transfer begins
public void Start()
Exceptions
InvalidOperationException
Service is already running.
ObjectDisposedException
Fired if you try to start a same service multiple times.
StartAsync()
Starts the copy process as task. First it determines all content information of source. Then the target directory structure will be created before transfer begins
public Task StartAsync()
BytesPerSecond
Bytes per second
public Double BytesPerSecond { get; }
Duration
Total duration. If transfer is not finished the current timestamp is used for the calculation
public Nullable<TimeSpan> Duration { get; }
Overwrite
true to overwrite existing content
public Boolean Overwrite { get; set; }
Percentage
Bytes per second
public Double Percentage { get; }
SourceFileInfos
Directory to copy
public List<QuickIOFileInfo> SourceFileInfos { get; set; }
TargetFullName
Target fullname
public String TargetFullName { get; set; }
TotalBytes
Total bytes to transfer
public UInt64 TotalBytes { get; set; }
TotalBytesTransfered
Total bytes transfered
public UInt64 TotalBytesTransfered { get; set; }
TransferFinished
Null if not finished
public Nullable<DateTime> TransferFinished { get; set; }
TransferStarted
Null if not started
public Nullable<DateTime> TransferStarted { get; set; }