-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
289 lines (260 loc) · 12.3 KB
/
index.html
File metadata and controls
289 lines (260 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
---
layout: page
title: QuickIO.NET Examples
---
<div class="post-item ">
<div class="post-title"><h2>Examples - Part #1</h2></div>
<div class="post-desc clearfix">
<h3>Enumerate folder contents</h3>
<pre><code>// Get subfolders
IEnumerable< QuickIODirectoryInfo > allSubFolders =
QuickIODirectory.EnumerateDirectories( @"C:\temp\QuickIO", SearchOption.AllDirectories );
foreach ( QuickIODirectoryInfo directoryInfo in allSubFolders )
{
Console.WriteLine( "Directory found: {0} Readonly: {1}", directoryInfo.FullName, directoryInfo.IsReadOnly );
}
</code></pre>
<br />
<pre><code>// Get subfiles
IEnumerable< QuickIOFileInfo > allSubFiles = QuickIODirectory.EnumerateFiles( @"C:\temp\QuickIO", SearchOption.AllDirectories );
foreach ( QuickIOFileInfo fileInfo in allSubFiles )
{
Console.WriteLine( "File found: {0} Readonly: {1}", fileInfo.FullName, fileInfo.IsReadOnly );
}
</code></pre>
<br />
<pre><code>// Get all with one call
IEnumerable< KeyValuePair< QuickIOPathInfo, QuickIOFileSystemEntryType > > allSubEntries = QuickIODirectory.EnumerateFileSystemEntries( @"C:\temp\QuickIO", SearchOption.AllDirectories );
foreach ( KeyValuePair< QuickIOPathInfo, QuickIOFileSystemEntryType > subEntry in allSubEntries )
{
var pathInfo = subEntry.Key;
var type = subEntry.Value;
Console.WriteLine( "Entry found: {0} Readonly: {1}", pathInfo.FullName, type );
}
</code></pre>
<br />
<h5>More examples are on the <a href="http://quickio.codeplex.com/documentation" target="_blank">CodePlex QuickIO.NET project site</a> or available in the <a href="http://quickIO.NET/help" target="_blank">official online help</a>.</h5>
</div>
</div>
<div class="post-item ">
<div class="post-title"><h2>Examples - Part #2</h2></div>
<div class="post-desc clearfix">
<h3>Permanent watching service for file copy operations with progress information</h3>
<pre><code>// Example of QuickIO Background Transfer service
class Program
{
const string dropDirectory = @"C:\transfer_test\dropfolder";
const string pictureFolder = @"C:\transfer_test\pictures";
const string movieFolder = @"C:\transfer_test\movies";
protected static QuickIOTransferBackgroundService TransferBackgroundService = new QuickIOTransferBackgroundService( workerCount: 2, maxFileRetry: 5 );
protected static FileSystemWatcher PictureWatcher = new FileSystemWatcher( dropDirectory, "*.png" );
protected static FileSystemWatcher MovieWatcher = new FileSystemWatcher( dropDirectory, "*.mp4" );
static void Main( string[ ] args )
{
// events to watch on filesystem
PictureWatcher.Created += OnCreated_Picture;
MovieWatcher.Created += OnCreated_MovieFile;
// Event definitions
TransferBackgroundService.JobEnqueued += OnJobEnqueued;
TransferBackgroundService.JobDequeued += OnJobDequeued;
TransferBackgroundService.JobRequeued += OnJobRequeued;
TransferBackgroundService.WorkerPickedJob += OnServiceWorkerPickedJob;
TransferBackgroundService.WorkerCreated += OnServiceWorkerCreated;
TransferBackgroundService.WorkerStarted += OnServiceWorkerStarted;
TransferBackgroundService.WorkerPickedJob += OnServiceWorkerPickedJob;
TransferBackgroundService.FileCopyStarted += OnFileCopyStarted;
TransferBackgroundService.FileCopyProgress += OnFileCopyProgress;
TransferBackgroundService.FileCopyFinished += OnFileCopyFinished;
// start service, if autostart is false
TransferBackgroundService.StartService( );
Console.WriteLine( "Service is running." );
Console.ReadKey( ); // wait to finish, blocks here
// Ends on key input
}
/// <summary>
/// worker started
/// </summary>
private static void OnServiceWorkerStarted( object sender, QuickIOTransferWorkerStartedEventArgs e )
{
Console.WriteLine( "[!] Worker Started. ID: " + e.WorkerID );
}
/// <summary>
/// new worker
/// </summary>
static void OnServiceWorkerCreated( object sender, QuickIOTransferWorkerCreatedEventArgs e )
{
Console.WriteLine( "[!] New Worker. ID: " + e.WorkerID );
}
/// <summary>
/// worker catched a job
/// </summary>
static void OnServiceWorkerPickedJob( object sender, QuickIOTransferWorkerPickedJobEventArgs e )
{
Console.WriteLine( "[!] Worker ID# " + e.WorkerID + " picked job: " + e.GetType( ) );
}
/// <summary>
/// job was broken by an exception, but requred
/// </summary>
static void OnJobRequeued( object sender, QuickIOTransferJobRequeuedArgs e )
{
Console.WriteLine( "[JOB REQUEUED] Try: #" + e.Job.CurrentRetryCount + " - " + e.Job.GetType( ) + " failed: " + e.Exception.Message );
}
/// <summary>
/// Report of job was taken from queue
/// </summary>
static void OnJobDequeued( object sender, QuickIOTransferJobDequeuedArgs e )
{
Console.WriteLine( "[JOB DEQUEUED] " + e.Job.GetType( ) );
}
/// <summary>
/// Report for new jobs
/// </summary>
static void OnJobEnqueued( object sender, QuickIOTransferJobEnqueuedArgs e )
{
Console.WriteLine( "[NEW JOB] " + e.Job.GetType( ) );
}
/// <summary>
/// Progress Report
/// </summary>
static void OnFileCopyStarted( object sender, QuickIOTransferFileCopyStartedArgs args )
{
Console.WriteLine( ">>>>>> STARTED " + args.SourcePath + " to " + args.TargetPath );
}
/// <summary>
/// Progress Report
/// </summary>
static void OnFileCopyFinished( object sender, QuickIOTransferFileCopyFinishedArgs args )
{
Console.WriteLine( ">>>>>> FINISHED " + args.SourcePath + " to " + args.TargetPath + " - MB/s: " + ( args.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
}
/// <summary>
/// Progress Report
/// </summary>
static void OnFileCopyProgress( object sender, QuickIOTransferFileCopyProgressArgs args )
{
Console.WriteLine( "Transfering " + args.SourcePath + " to " + args.TargetPath + " - %: " + args.Percentage + " MB/s: " + ( args.BytesPerSecond / 1024.0 / 1024.0 ).ToString( "0.0" ) );
}
/// <summary>
/// Copy movie file from drop folder to internal movie folder
/// </summary>
static void OnCreated_MovieFile( object sender, FileSystemEventArgs e )
{
var queueItem = new QuickIOTransferFileCopyJob( e.FullPath, movieFolder, overwrite: true );
TransferBackgroundService.Add( queueItem );
}
/// <summary>
/// Copy picture file from drop folder to internal picture folder
/// </summary>
static void OnCreated_Picture( object sender, FileSystemEventArgs e )
{
var queueItem = new QuickIOTransferFileCopyJob( e.FullPath, pictureFolder, overwrite: true, parentExistanceCheck: false );
TransferBackgroundService.Add( queueItem );
}
}
</code></pre>
<br />
</div>
</div>
<div class="post-item ">
<div class="post-title"><h2>Examples - Part #3</h2></div>
<div class="post-desc clearfix">
<h3>Copy directory with monitoring and progress information</h3>
<pre><code>
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></pre>
<br />
</div>
</div>
<div class="post-item ">
<div class="post-title"><h2>Examples - Part #4</h2></div>
<div class="post-desc clearfix">
<h3>Copy file(s) with monitoring and progress information</h3>
<pre><code> /// 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" ) );
}
}
</code></pre>
<br />
</div>
</div>