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
38 //For the change to Merkle Hash, we need to return the final Merkle Hash
\r
39 var hash = FileState.NullSafe(f => f.Checksum);
\r
41 Debug.Assert(FileState==null || hash != null,"FileState without a checksum encountered");
\r
43 //var hash = FileState.NullSafe(f => f.ETag);
\r
45 //Ensure the hash size matches SHA256
\r
46 Debug.Assert(EmptyOrLength(hash, 64));
\r
48 return String.IsNullOrWhiteSpace(hash) ? null : hash;
\r
57 Debug.Assert(EmptyOrLength(_c, 64));
\r
61 if (!EmptyOrLength(value, 64))
\r
62 throw new ArgumentException("A proper hash value should have 64 characters");
\r
63 _c = String.IsNullOrWhiteSpace(value) ? null : value;
\r
71 //The Server hash will be the X-Object-Hash, not the ETag
\r
72 var hash= ObjectInfo.NullSafe(o => o.X_Object_Hash);
\r
74 Debug.Assert(EmptyOrLength(hash, 64));
\r
76 return String.IsNullOrWhiteSpace(hash) ? null : hash;
\r
80 private FileSystemInfo _fileInfo;
\r
81 private TreeHash _merkle;
\r
82 private string _md5;
\r
84 public FileSystemInfo FileInfo
\r
86 get { return _fileInfo; }
\r
90 FilePath = value.FullName;
\r
94 public FileState FileState { get; set; }
\r
95 public ObjectInfo ObjectInfo{ get; set; }
\r
98 public TreeHash Merkle
\r
105 C = _merkle.TopHash.ToHashString();
\r
109 public bool Locked { get; set; }
\r
111 public string NewFullPath { get; set; }
\r
113 public string OldMD5 { get; set; }
\r
115 public string OldFullPath { get; set; }
\r
117 public StateTuple() { }
\r
119 public StateTuple(FileSystemInfo info)
\r
124 public bool HashesValid()
\r
126 return (EmptyOrLength(C, 64)
\r
127 && EmptyOrLength(L, 64)
\r
128 && EmptyOrLength(S, 64)
\r