-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSender.cs
84 lines (73 loc) · 2.31 KB
/
Sender.cs
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
using System;
using System.IO;
using System.ComponentModel;
namespace gutenberg.collect
{
public class Sender
{
public Sender(ScanDirectory scanDir)
{
this.scanDir = scanDir;
asleep = true;
}
public void Execute(Object o, DoWorkEventArgs args)
{
asleep = false;
Scan scan = null;
string[] scanFiles = scanDir.GetFiles(Scan.TO_SEND);
FaTaPhat fataphat = new FaTaPhat();
fataphat.Connect();
while (scanFiles.Length != 0)
{
int fileCount = 0;
int progress = (int)(fileCount * 100.00 / scanFiles.Length);
((BackgroundWorker)o).ReportProgress(progress, "TASK_START");
foreach (string scanFile in scanFiles)
{
if (((BackgroundWorker)o).CancellationPending)
{
args.Cancel = true;
break;
}
fileCount++;
progress = (int)(fileCount * 100.00 / scanFiles.Length);
((BackgroundWorker)o).ReportProgress(progress);
scan = new Scan(scanFile);
if (scan.IsLocked())
continue;
try
{
scan.Process(fataphat);
}
catch
{
fataphat.Dispose();
fataphat = null;
throw;
}
}
if (((BackgroundWorker)o).CancellationPending)
{
break;
}
scanFiles = scanDir.GetFiles(Scan.TO_SEND);
}
((BackgroundWorker)o).ReportProgress(100, "TASK_END");
fataphat.Disconnect();
asleep = true;
}
public bool Asleep
{
get
{
return asleep;
}
set
{
asleep = value;
}
}
private ScanDirectory scanDir;
private bool asleep;
}
}