Statistics
| Branch: | Revision:

root / trunk / Pithos.Core / Agents / CloudAction.cs @ 1caef52e

History | View | Annotate | Download (1.6 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

    
25
        public Lazy<string> LocalHash { get; private set; }
26

    
27
        public string OldFileName { get; set; }
28
        public string OldPath { get; set; }
29
        public string NewFileName { get; set; }
30
        public string NewPath { get; set; }
31

    
32
        public CloudAction(CloudActionType action, string oldPath, string oldFileName, string newFileName, string newPath)
33
        {
34
            Action = action;
35
            OldFileName = oldFileName;
36
            OldPath = oldPath;
37
            NewFileName = newFileName;
38
            NewPath = newPath;
39
            LocalHash = new Lazy<string>(() => Signature.CalculateMD5(NewFileName), LazyThreadSafetyMode.ExecutionAndPublication);
40
        }
41

    
42
        public CloudAction(CloudActionType action, FileInfo localFile, ObjectInfo cloudFile)
43
        {
44
            Action = action;
45
            LocalFile = localFile;
46
            CloudFile = cloudFile;
47
            //Skip Hash calculation for folders
48
            if (LocalFile != null)
49
                LocalHash = new Lazy<string>(() => Signature.CalculateMD5(LocalFile.FullName), LazyThreadSafetyMode.ExecutionAndPublication);
50
        }
51

    
52
    }
53
}