Fields (4) Methods (4) 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.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" ) );
}
}

Uses

Fields

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

Methods

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

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_totalBytesTransferedLockStartStartAsyncQuickIOTransferFileCopyServiceQuickIOTransferFileCopyServiceBytesPerSecond { 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; }public static classQuickIOPathDirectorySeparatorCharMaxRegularPathLengthMaxSimpleDirectoryPathLengthMaxUncPathLengthRegularLocalPathPrefixRegularSharePathPrefixRegularSharePathPrefixLengthUncLocalPathPrefixUncLocalPathPrefixLengthUncSharePathPrefixUncSharePathPrefixLengthCombineExistsGetFullPathGetFullPathInfoGetNameGetParentPathGetRandomDirectoryNameGetRandomFileNameGetRootGetRootFromLocalPathIsLocalRegularPathIsLocalUncPathIsShareRegularPathIsShareUncPathThrowIfPathContainsInvalidCharsToLocalRegularPathToLocalUncPathToRegularPathToShareRegularPathToShareUncPathToUncPathTrimTrailingSepartorTryParseLocalRegularPathTryParseLocalUncPathTryParsePathTryParseShareRegularPathTryParseShareUncPathpublic 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