root / trunk / Pithos.Core / Agents / CloudTransferAction.cs @ 5120f3cb
History | View | Annotate | Download (3.1 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 |
|
56 |
} |
57 |
|
58 |
public class CloudDownloadAction:CloudAction |
59 |
{ |
60 |
public CloudDownloadAction(ObjectInfo cloudFile) |
61 |
:base(CloudActionType.DownloadUnconditional) |
62 |
{ |
63 |
CloudFile = cloudFile; |
64 |
} |
65 |
|
66 |
} |
67 |
public class CloudDeleteAction:CloudAction |
68 |
{ |
69 |
public CloudDeleteAction(string fileName, FileState fileState) |
70 |
: this(new ObjectInfo { Name = fileName },fileState) |
71 |
{ |
72 |
} |
73 |
|
74 |
public CloudDeleteAction(ObjectInfo cloudFile, FileState fileState) |
75 |
: base(CloudActionType.DeleteCloud) |
76 |
{ |
77 |
CloudFile = cloudFile; |
78 |
FileState = fileState; |
79 |
} |
80 |
} |
81 |
|
82 |
public class CloudUploadAction:CloudAction |
83 |
{ |
84 |
public CloudUploadAction(FileInfo fileInfo, FileState state, int blockSize, string algorithm) |
85 |
: base(CloudActionType.UploadUnconditional,fileInfo,ObjectInfo.Empty,state,blockSize,algorithm) |
86 |
{ |
87 |
} |
88 |
} |
89 |
|
90 |
public class CloudMoveAction:CloudAction |
91 |
{ |
92 |
public string OldFileName { get; set; } |
93 |
public string OldPath { get; set; } |
94 |
public string NewFileName { get; set; } |
95 |
public string NewPath { get; set; } |
96 |
|
97 |
public CloudMoveAction(CloudActionType action, string oldPath, string oldFileName, string newFileName, string newPath) |
98 |
:base(action) |
99 |
{ |
100 |
OldFileName = oldFileName; |
101 |
OldPath = oldPath; |
102 |
NewFileName = newFileName; |
103 |
NewPath = newPath; |
104 |
//This is a rename operation, a hash will not be used |
105 |
LocalHash = new Lazy<string>(() => String.Empty, LazyThreadSafetyMode.ExecutionAndPublication); |
106 |
} |
107 |
|
108 |
|
109 |
} |
110 |
|
111 |
} |