// Anzahl Threads = Anzahl der Konsumenten, die Elemente /// <summary> /// Creates a new instance of <see cref="QuickIOTransferServiceBase"/> /// </summary> /// <param name="observer">Required server. Can be null to create default observer</param> /// <param name="maxWorkerCount">Count of parallel workers to transfer the files</param> /// <param name="maxFileRetry">Max retry on transfer failure</param> protected QuickIOTransferServiceBase( IQuickIOTransferObserver observer, int maxWorkerCount = 1, int maxFileRetry = 3 ) : this(observer ?? new QuickIOTransferObserver( )) { MaxWorkerCount = maxWorkerCount; _maxJobRetryAttempts = Math.Max( 1, maxFileRetry ); _workerThreads = new Dictionary<int, Thread>( ); }
/// <summary> /// Creates a new instance of <see cref="QuickIOTransferServiceBase"/> and sets required properties /// </summary> private QuickIOTransferServiceBase( IQuickIOTransferObserver observer ) { PriorityComparer = new QuickIOTransferJobPriorityComparer( ); Observer = observer; }
/// <summary> /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/> /// </summary> /// <param name="observer">Observer for monitoring</param> /// <param name="sourceFileInfo">File to copy</param> /// <param name="targetFullName">Target fullname</param> /// <param name="threadCount">Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares</param> /// <param name="retryCount">Count of retries before copy is broken</param> /// <param name="overwrite">true to overwrite existing files</param> /// <example> /// Copy file /// /// <code> /// <![CDATA[ /// 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" ) ); /// } /// } /// ]]> /// </code> /// </example> public QuickIOTransferFileCopyService( IQuickIOTransferObserver observer, QuickIOFileInfo sourceFileInfo, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, Boolean overwrite = false ) : this(observer, new List<QuickIOFileInfo> { sourceFileInfo }, targetFullName, threadCount, retryCount, overwrite) { }
/// <summary> /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/> /// </summary> /// <param name="observer">Observer for monitoring</param> /// <param name="sourceFileInfos">Files to copy</param> /// <param name="targetFullName">Target fullname</param> /// <param name="threadCount">Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares</param> /// <param name="retryCount">Count of retries before copy is broken</param> /// <param name="overwrite">true to overwrite existing files</param> /// <example> /// Copy collection of files /// <code> /// <![CDATA[ /// 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" ) ); /// } /// } /// ]]></code> /// </example> public QuickIOTransferFileCopyService( IQuickIOTransferObserver observer, IEnumerable<QuickIOFileInfo> sourceFileInfos, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, Boolean overwrite = false ) : base(observer, threadCount, retryCount) { SourceFileInfos = new List<QuickIOFileInfo>( sourceFileInfos ); TargetFullName = targetFullName; Overwrite = overwrite; }
/// <summary> /// Creates a new instance if <see cref="QuickIOTransferFileCreationJob"/> /// </summary> /// <param name="contents">Contents to write</param> /// <param name="overwrite">true to overwrite existing elements</param> /// <param name="maxBufferSize">Set max buffer size for copy transfer</param> /// <param name="observer">Observer</param> /// <param name="targetDirectory">Target directory fullname</param> /// <param name="fileName">Target filename</param> /// <param name="parentExistanceCheck">true to verify parent existance</param> /// <param name="prorityLevel">Priority level of directory creation should be higher than file creation without parent check</param> public QuickIOTransferFileCreationJob( IQuickIOTransferObserver observer, String targetDirectory, String fileName, Byte[ ] contents, Int32 maxBufferSize = 1024, bool overwrite = false, bool parentExistanceCheck = true, Int32 prorityLevel = 0 ) : base(observer, prorityLevel) { Invariant.NotEmpty( targetDirectory ); Invariant.NotEmpty( fileName ); // Parent Overwrite = overwrite; //Own MaxBufferSize = Math.Max( 1024, maxBufferSize ); TargetDirectory = targetDirectory; FileName = fileName; Contents = contents; ParentExistanceCheck = parentExistanceCheck; TargetFullName = QuickIOPath.Combine( TargetDirectory, FileName ); }
/// <summary> /// Job for creating directories with default observer /// </summary> /// <param name="observer">Observer</param> /// <param name="directoryToCreatePath">Directory fullname to create</param> /// <param name="overwrite">true to overwrite</param> /// <param name="prorityLevel">Priority level of directory creation should be higher than file creation without parent check</param> public QuickIOTransferDirectoryCreationJob( IQuickIOTransferObserver observer, String directoryToCreatePath, bool overwrite = true, Int32 prorityLevel = 1 ) : base(observer, prorityLevel) { DirectoryToCreatePath = directoryToCreatePath; }
/// <summary> /// Creates a new instance of <see cref="QuickIOTransferJob"/> /// </summary> /// <param name="observer">Observer for file monitoring by service</param> /// <param name="priorityLevel">Default priority</param> /// <param name="overwrite">true to overwrite existing elements</param> /// <remarks>Thread-safe</remarks> protected QuickIOTransferJobWriteJob( IQuickIOTransferObserver observer, Int32 priorityLevel = 0, Boolean overwrite = false ) { Observer = observer; _overwrite = overwrite; }
/// <summary> /// Creates new instance of <see cref="QuickIOTransferDirectoryCopyService"/> with specified observer /// </summary> /// <param name="observer">Observer</param> /// <param name="sourceDirectoryInfo">Directory to copy</param> /// <param name="targetFullName">Target fullname</param> /// <param name="threadCount">Copy Worker Counts. Use 1 on local systems. Use >2 with SMB shares</param> /// <param name="retryCount">Count of retries before copy is broken</param> /// <param name="searchOption"><see cref="SearchOption"/>of deepth to copy</param> /// <param name="overwrite">true to overwrite existing files</param> /// <example> /// Copy complete directory /// <code> /// <![CDATA[ /// 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" ) ); /// } /// ]]> /// </code> /// </example> public QuickIOTransferDirectoryCopyService( IQuickIOTransferObserver observer, QuickIODirectoryInfo sourceDirectoryInfo, String targetFullName, Int32 threadCount = 1, Int32 retryCount = 3, SearchOption searchOption = SearchOption.TopDirectoryOnly, Boolean overwrite = false ) : base(observer, threadCount, retryCount) { SourceDirectoryInfo = sourceDirectoryInfo; TargetFullName = targetFullName; SearchOption = searchOption; Overwrite = overwrite; // Register Events RegisterInternalEventHandling( ); StartWorking( ); }
/// <summary> /// Creates a new queue item /// </summary> /// <param name="observer">Observer</param> /// <param name="source">Fullname source</param> /// <param name="target">Fullname target</param> /// <param name="maxBufferSize">Set max buffer size for copy transfer</param> /// <param name="overwrite">true overwrites existing files</param> /// <param name="parentExistanceCheck">true to verify parent existance</param> /// <param name="prorityLevel">Priority level of directory creation should be higher than file creation without parent check</param> public QuickIOTransferFileCopyJob( IQuickIOTransferObserver observer, string source, string target, Int32 maxBufferSize = 1024, bool overwrite = false, bool parentExistanceCheck = true, Int32 prorityLevel = 0 ) : base(observer, prorityLevel) { Invariant.NotEmpty( source ); Invariant.NotEmpty( target ); // Parent Overwrite = overwrite; // Own MaxBufferSize = Math.Max( 1024, maxBufferSize ); Source = source; Target = target; ParentExistanceCheck = parentExistanceCheck; }
/// <summary> /// Creates an instance for <see cref="QuickIOTransferBackgroundService"/> with specified observer /// </summary> /// <param name="observer">Observer for monitoring</param> /// <param name="workerCount"></param> /// <param name="maxFileRetry"></param> /// <param name="autostart">true to auto start. false to start service by using <see cref="QuickIOTransferServiceBase.StartWorking"/></param> public QuickIOTransferBackgroundService( IQuickIOTransferObserver observer, int workerCount, int maxFileRetry = 3, bool autostart = true ) : base(observer, workerCount, maxFileRetry) { if ( autostart ) { Start( ); } }
/// <summary> /// Creates a new instance of <see cref="QuickIOTransferJob"/> /// </summary> /// <param name="observer">Observer for file monitoring by service</param> /// <param name="priorityLevel">Default priority</param> /// <remarks>Thread-safe</remarks> protected QuickIOTransferJob( IQuickIOTransferObserver observer, Int32 priorityLevel = 0 ) { Observer = observer; _priorityLevel = priorityLevel; }