8 |
|
{ |
9 |
|
public abstract class SerializationReader : ISerializationResultCount, IDisposable |
10 |
|
{ |
11 |
+ |
private static string CreateFilename(Guid guid) |
12 |
+ |
{ |
13 |
+ |
if (guid == Guid.Empty) |
14 |
+ |
{ |
15 |
+ |
return DEFAULT_PATH; |
16 |
+ |
} |
17 |
+ |
else |
18 |
+ |
{ |
19 |
+ |
return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString())); |
20 |
+ |
} |
21 |
+ |
} |
22 |
|
private const string DEFAULT_FOLDER = "tmp"; |
23 |
|
private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp"; |
24 |
|
private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME); |
25 |
< |
public SerializationReader() : this(DEFAULT_PATH) { } |
26 |
< |
protected SerializationReader(string filename) { FileName = filename; CreateReader(); } |
25 |
> |
//public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); } |
26 |
> |
public SerializationReader(Guid guid) : this(CreateFilename(guid)) { CreateReader(guid); } |
27 |
> |
protected SerializationReader(string filename) { FileName = filename; } |
28 |
> |
|
29 |
> |
|
30 |
> |
protected bool Cancelled { get; set; } |
31 |
|
|
32 |
+ |
public void CancelRequest() { Cancelled = true; } |
33 |
|
|
34 |
|
#region ISerializationResultCount members |
35 |
|
public int ResultCount { get; protected set; } |
37 |
|
private FileStream fileStream; |
38 |
|
protected BinaryReader binReader; |
39 |
|
protected string FileName { get; private set; } |
40 |
< |
private void CreateReader() |
40 |
> |
private void CreateReader(Guid guid) |
41 |
|
{ |
42 |
+ |
if (Cancelled) { return; } |
43 |
|
fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); |
44 |
|
binReader = new BinaryReader(fileStream); |
45 |
|
} |