Fields (4) Events (4) Methods (11) Properties (10)
Namespace: SchwabenCode.QuickIO.Transfer

Syntax

public class QuickIOTransferFileCopyService : QuickIOTransferServiceBase

Basetype

Summary

Copy directory with progress monitoring

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" ) );
}
}

Fields

private  UInt64 _totalBytes
private readonly object _totalBytesLock
private  UInt64 _totalBytesTransfered
private readonly object _totalBytesTransferedLock

Events

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

Methods

public void QuickIOTransferFileCopyService(QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)

Parameters

sourceFileInfo

QuickIOFileInfo

File to copy

targetFullName

String

Target fullname

threadCount

Int32

Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares

retryCount

Int32

Count of retries before copy is broken

overwrite

Boolean

true 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" ) );
}
}
public void QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)

Parameters

observer

IQuickIOTransferObserver

Observer for monitoring

sourceFileInfo

QuickIOFileInfo

File to copy

targetFullName

String

Target fullname

threadCount

Int32

Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares

retryCount

Int32

Count of retries before copy is broken

overwrite

Boolean

true 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" ) );
}
}
public void QuickIOTransferFileCopyService(IQuickIOTransferObserver observer, IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)

Parameters

observer

IQuickIOTransferObserver

Observer for monitoring

sourceFileInfos

IEnumerable

Files to copy

targetFullName

String

Target fullname

threadCount

Int32

Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares

retryCount

Int32

Count of retries before copy is broken

overwrite

Boolean

true 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" ) );
}
}
public void QuickIOTransferFileCopyService(IEnumerable sourceFileInfos, String targetFullName, Int32 threadCount, Int32 retryCount, Boolean overwrite)

Parameters

sourceFileInfos

IEnumerable

Files to copy

targetFullName

String

Target fullname

threadCount

Int32

Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares

retryCount

Int32

Count of retries before copy is broken

overwrite

Boolean

true 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" ) );
}
}
public virtual void OnFileCopyError(QuickIOTransferFileCopyErrorEventArgs args)

Parameters

args

QuickIOTransferFileCopyErrorEventArgs

Holds further event information

public virtual void OnFileCopyFinished(QuickIOTransferFileCopyFinishedEventArgs args)

Parameters

args

QuickIOTransferFileCopyFinishedEventArgs

Holds further event information

public virtual void OnFileCopyProgress(QuickIOTransferFileCopyProgressEventArgs args)

Parameters

args

QuickIOTransferFileCopyProgressEventArgs

Holds further event information

public virtual void OnFileCopyStarted(QuickIOTransferFileCopyStartedEventArgs args)

Parameters

args

QuickIOTransferFileCopyStartedEventArgs

Holds 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()

Properties

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; }

Classdiagram

public classQuickIOTransferFileCopyService_totalBytes_totalBytesLock_totalBytesTransfered_totalBytesTransferedLockFileCopyErrorFileCopyFinishedFileCopyProgressFileCopyStartedOnFileCopyErrorOnFileCopyFinishedOnFileCopyProgressOnFileCopyStartedRegisterInternalEventHandlingStartStartAsyncQuickIOTransferFileCopyServiceQuickIOTransferFileCopyServiceQuickIOTransferFileCopyServiceQuickIOTransferFileCopyServiceBytesPerSecond { get; }Duration { get; }Overwrite { get; set; }Percentage { get; }SourceFileInfos { get; set; }TargetFullName { get; set; }TotalBytes { get; set; }TotalBytesTransfered { get; set; }TransferFinished { get; set; }TransferStarted { get; set; }public classQuickIOTransferServiceBase_jobQueue_jobQueueLock_maxBufferSize_maxJobRetryAttempts_maxWorkerCount_workerCountRemoveRequested_workerCountRemoveRequestedLock_workerShutdownLock_workerThreads_workerThreadsLockCancellationRequestedCompletedAddingRequestedJobDequeuedJobEnqueuedJobRequeuedJobRetryMaxReachedWorkerCreatedWorkerIsWaitingWorkerPickedJobWorkerShutdownWorkerStartedWorkerWokeUpAddWorkerCancelClearCompleteAddingCreateWorkersInternalAddInternalAddRangeInternalCreateNewWorkerInternalReSortLockedQueueInternalStartWorkerInternalWaitForNewQueueItemsJobExecuteSwitchOnCancellationRequestedOnCompletedAddingRequestedOnJobDequeuedOnJobEnqueuedOnJobRequeuedOnJobRetryMaxReachedOnWorkerCreatedOnWorkerIsWaitingOnWorkerPickedJobOnWorkerShutdownOnWorkerStartedOnWorkerWokeUpRemoveThreadRemoveWorkerStartConsumingStartWorkersStartWorkingWaitForFinishWakeUpSleepingWorkersQuickIOTransferServiceBaseQuickIOTransferServiceBaseAddingCompleted { get; set; }CancelRequested { get; set; }IsWorking { get; }MaxBufferSize { get; set; }MaxJobRetryAttempts { get; set; }MaxWorkerCount { get; set; }Observer { get; set; }PriorityComparer { get; set; }WorkerCount { get; }

save

reset

Drag to pan - Use Mousewheel + Ctrl to zoom