root / trunk / Pithos.Core / Agents / CloudTransferAction.cs @ cfed7823
History | View | Annotate | Download (2.4 kB)
1 |
using System; |
---|---|
2 |
using System.IO; |
3 |
using System.Threading; |
4 |
using Pithos.Interfaces; |
5 |
using Pithos.Network; |
6 |
|
7 |
namespace Pithos.Core.Agents |
8 |
{ |
9 |
public enum CloudActionType |
10 |
{ |
11 |
MustSynch, |
12 |
UploadUnconditional, |
13 |
DownloadUnconditional, |
14 |
DeleteLocal, |
15 |
DeleteCloud, |
16 |
RenameCloud |
17 |
} |
18 |
|
19 |
public class CloudAction |
20 |
{ |
21 |
public CloudActionType Action { get; set; } |
22 |
public FileInfo LocalFile { get; set; } |
23 |
public ObjectInfo CloudFile { get; set; } |
24 |
public FileState FileState { get; set; } |
25 |
public string Container { get; set; } |
26 |
|
27 |
|
28 |
public Lazy<string> LocalHash { get; protected set; } |
29 |
private Lazy<string> _topHash; |
30 |
public Lazy<string> TopHash |
31 |
{ |
32 |
get { return _topHash; } |
33 |
set { _topHash = value; } |
34 |
} |
35 |
|
36 |
|
37 |
protected CloudAction(CloudActionType action) |
38 |
{ |
39 |
Action = action; |
40 |
} |
41 |
|
42 |
public CloudAction(CloudActionType action, FileInfo localFile, ObjectInfo cloudFile,FileState state,int blockSize, string algorithm) : this(action) |
43 |
{ |
44 |
LocalFile = localFile; |
45 |
CloudFile = cloudFile; |
46 |
FileState = state; |
47 |
if (LocalFile != null) |
48 |
{ |
49 |
LocalHash = new Lazy<string>(() => LocalFile.CalculateHash(blockSize,algorithm), |
50 |
LazyThreadSafetyMode.ExecutionAndPublication); |
51 |
} |
52 |
} |
53 |
|
54 |
|
55 |
//Constructor for downloading files |
56 |
public CloudAction(CloudActionType action, ObjectInfo cloudFile) |
57 |
{ |
58 |
Action = action; |
59 |
CloudFile = cloudFile; |
60 |
} |
61 |
|
62 |
} |
63 |
|
64 |
public class CloudMoveAction:CloudAction |
65 |
{ |
66 |
public string OldFileName { get; set; } |
67 |
public string OldPath { get; set; } |
68 |
public string NewFileName { get; set; } |
69 |
public string NewPath { get; set; } |
70 |
|
71 |
public CloudMoveAction(CloudActionType action, string oldPath, string oldFileName, string newFileName, string newPath) |
72 |
:base(action) |
73 |
{ |
74 |
OldFileName = oldFileName; |
75 |
OldPath = oldPath; |
76 |
NewFileName = newFileName; |
77 |
NewPath = newPath; |
78 |
//This is a rename operation, a hash will not be used |
79 |
LocalHash = new Lazy<string>(() => String.Empty, LazyThreadSafetyMode.ExecutionAndPublication); |
80 |
} |
81 |
|
82 |
|
83 |
} |
84 |
|
85 |
} |