2 using System.Diagnostics;
\r
4 using Pithos.Interfaces;
\r
5 using Pithos.Network;
\r
7 namespace Pithos.Core.Agents
\r
9 [DebuggerDisplay("{FilePath} C:{C} L:{L} S:{S}")]
\r
10 public class StateTuple
\r
12 public string FilePath { get; private set; }
\r
18 // Debug.Assert(EmptyOrLength(_md5, 32));
\r
23 // if (!EmptyOrLength(value, 32))
\r
24 // throw new ArgumentException("A proper MD5 hash value should have 32 characters");
\r
29 private bool EmptyOrLength(string value, int length)
\r
31 return String.IsNullOrWhiteSpace(value) || value.Length == length;
\r
35 /// Last encountered server hash, stored in the State
\r
41 //For the change to Merkle Hash, we need to return the final Merkle Hash
\r
42 var hash = FileState.NullSafe(f => f.Checksum);
\r
44 // Debug.Assert(FileState==null || hash != null,"FileState without a checksum encountered");
\r
46 //var hash = FileState.NullSafe(f => f.ETag);
\r
48 //Ensure the hash size matches SHA256
\r
49 //Debug.Assert(EmptyOrLength(hash, 64));
\r
51 return String.IsNullOrWhiteSpace(hash) ? null : hash;
\r
57 /// Current local file Hash
\r
63 Debug.Assert(EmptyOrLength(_c, 64));
\r
67 if (!EmptyOrLength(value, 64))
\r
68 throw new ArgumentException("A proper hash value should have 64 characters");
\r
69 _c = String.IsNullOrWhiteSpace(value) ? null : value;
\r
74 /// Server file hash
\r
80 //The Server hash will be the X-Object-Hash, not the ETag
\r
81 var hash= ObjectInfo.NullSafe(o => o.X_Object_Hash);
\r
83 Debug.Assert(EmptyOrLength(hash, 64));
\r
85 return String.IsNullOrWhiteSpace(hash) ? null : hash;
\r
89 private FileSystemInfo _fileInfo;
\r
90 private TreeHash _merkle;
\r
91 //private string _md5;
\r
93 public FileSystemInfo FileInfo
\r
95 get { return _fileInfo; }
\r
99 FilePath = value.FullName;
\r
103 public FileState FileState { get; set; }
\r
104 public ObjectInfo ObjectInfo{ get; set; }
\r
107 public TreeHash Merkle
\r
114 C = _merkle.TopHash.ToHashString();
\r
118 public bool Locked { get; set; }
\r
120 public string NewFullPath { get; set; }
\r
122 public string OldChecksum { get; set; }
\r
124 public string OldFullPath { get; set; }
\r
126 public StateTuple() { }
\r
128 public StateTuple(FileSystemInfo info)
\r
133 public bool HashesValid()
\r
135 return (EmptyOrLength(C, 64)
\r
136 && EmptyOrLength(L, 64)
\r
137 && EmptyOrLength(S, 64)
\r