public class QuickIOTransferDirectoryCopyService : QuickIOTransferServiceBase
Copy directory with progress monitoring
Copy complete directory
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" ) );
}
_running
thread safe indicator if copy is running
private Boolean _running
DirectoryCreated
This event is raised when a directory was created
public DirectoryCreated
DirectoryCreating
This event is raised before an upcoming directory creation operation is performed
public DirectoryCreating
DirectoryCreationError
This event is raised if directory creation operation fails
public DirectoryCreationError
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
QuickIOTransferDirectoryCopyService(QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount, Int32 retryCount, SearchOption searchOption, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService with default observer
public void QuickIOTransferDirectoryCopyService(QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount, Int32 retryCount, SearchOption searchOption, Boolean overwrite)
Parameters
sourceDirectoryInfo
QuickIODirectoryInfoDirectory 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
searchOption
SearchOptionSearchOptionof deepth to copy
overwrite
Booleantrue to overwrite existing files
Example
Copy complete directory
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" ) );
}
QuickIOTransferDirectoryCopyService(IQuickIOTransferObserver observer, QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount, Int32 retryCount, SearchOption searchOption, Boolean overwrite)
Creates new instance of QuickIOTransferDirectoryCopyService with specified observer
public void QuickIOTransferDirectoryCopyService(IQuickIOTransferObserver observer, QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount, Int32 retryCount, SearchOption searchOption, Boolean overwrite)
Parameters
observer
IQuickIOTransferObserverObserver
sourceDirectoryInfo
QuickIODirectoryInfoDirectory 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
searchOption
SearchOptionSearchOptionof deepth to copy
overwrite
Booleantrue to overwrite existing files
Example
Copy complete directory
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" ) );
}
private InternalDirectoryTransferPrefences DetermineDirectoryTransferPrefences(QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, SearchOption searchOption, Boolean overwrite)
OnDirectoryCreated(QuickIOTransferDirectoryCreatedEventArgs args)
Fire DirectoryCreated
public virtual void OnDirectoryCreated(QuickIOTransferDirectoryCreatedEventArgs args)
Parameters
args
QuickIOTransferDirectoryCreatedEventArgsHolds further event information
OnDirectoryCreating(QuickIOTransferDirectoryCreatingEventArgs args)
Fire DirectoryCreating
public virtual void OnDirectoryCreating(QuickIOTransferDirectoryCreatingEventArgs args)
Parameters
args
QuickIOTransferDirectoryCreatingEventArgsHolds further event information
OnDirectoryCreationError(QuickIOTransferDirectoryCreationErrorEventArgs args)
Fire DirectoryCreationError
public virtual void OnDirectoryCreationError(QuickIOTransferDirectoryCreationErrorEventArgs args)
Parameters
args
QuickIOTransferDirectoryCreationErrorEventArgsHolds further event information
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()
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()
IsRunning
true if copy process is running
public Boolean IsRunning { get; set; }
Overwrite
true to overwrite existing content
public Boolean Overwrite { get; set; }
SearchOption
Deepth to copy
public SearchOption SearchOption { get; set; }
SourceDirectoryInfo
Directory to copy
public QuickIODirectoryInfo SourceDirectoryInfo { get; set; }
TargetFullName
Target fullname
public String TargetFullName { get; set; }