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.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 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" ) );
}
}
private UInt64 _totalBytes
private readonly object _totalBytesLock
private UInt64 _totalBytesTransfered
private readonly object _totalBytesTransferedLock
FileCopyError
This event is raised if file copy operation fails
public FileCopyError
FileCopyFinished
This event is raised at the end of the file copy operation.
public FileCopyFinished
FileCopyProgress
This event is raised during a copy of a file. It provides current information such as progress, speed and estimated time.
public FileCopyProgress
FileCopyStarted
This event is triggered at the beginning of the file copy operation.
public FileCopyStarted
QuickIOTransferFileCopyService(QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService
public void QuickIOTransferFileCopyService(QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Parameters
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 sourceDirectory = @"C:\transfer_test\source";
const string targetDirectory = @"C:\transfer_test\to";
// search file
var file = new QuickIOFileInfo( "file" );
var service = new QuickIOTransferFileCopyService( file, targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
// Progress information
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 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" ) );
}
}
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 sourceDirectory = @"C:\transfer_test\source";
const string targetDirectory = @"C:\transfer_test\to";
// search files
var file = new QuickIOFileInfo( "file" );
var observer = new QuickIOTransferObserver( );
var service = new QuickIOTransferFileCopyService(observer, file, targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
// Progress information
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 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" ) );
}
}
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 observer = new QuickIOTransferObserver( );
var service = new QuickIOTransferFileCopyService( observer, files, targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
// Progress information
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 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" ) );
}
}
QuickIOTransferFileCopyService(IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService
public void QuickIOTransferFileCopyService(IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)
Parameters
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 service = new QuickIOTransferFileCopyService( files, targetDirectory, threadCount: 1, retryCount: 3, overwrite: true );
// Progress information
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 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" ) );
}
}
OnFileCopyError(QuickIOTransferFileCopyErrorEventArgs args)
Fire FileCopyError
public virtual void OnFileCopyError(QuickIOTransferFileCopyErrorEventArgs args)
Parameters
args
QuickIOTransferFileCopyErrorEventArgsHolds further event information
OnFileCopyFinished(QuickIOTransferFileCopyFinishedEventArgs args)
Fire FileCopyFinished
public virtual void OnFileCopyFinished(QuickIOTransferFileCopyFinishedEventArgs args)
Parameters
args
QuickIOTransferFileCopyFinishedEventArgsHolds further event information
OnFileCopyProgress(QuickIOTransferFileCopyProgressEventArgs args)
Fire FileCopyProgress
public virtual void OnFileCopyProgress(QuickIOTransferFileCopyProgressEventArgs args)
Parameters
args
QuickIOTransferFileCopyProgressEventArgsHolds further event information
OnFileCopyStarted(QuickIOTransferFileCopyStartedEventArgs args)
Fire FileCopyStarted
public virtual void OnFileCopyStarted(QuickIOTransferFileCopyStartedEventArgs args)
Parameters
args
QuickIOTransferFileCopyStartedEventArgsHolds further event information
RegisterInternalEventHandling()
Copy events from observer to current instance
private void RegisterInternalEventHandling()
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; }