2 using System.Collections.Generic;
3 using Pithos.Core.Agents;
7 public class LocalFileComparer:EqualityComparer<CloudAction>
9 public override bool Equals(CloudAction x, CloudAction y)
11 if (x.Action != y.Action)
13 if (x.LocalFile != null && y.LocalFile != null && !x.LocalFile.FullName.Equals(y.LocalFile.FullName))
15 if (x.CloudFile != null && y.CloudFile != null )
17 if (x.CloudFile.Hash == null & y.CloudFile.Hash != null)
19 if (x.CloudFile.Hash != null & y.CloudFile.Hash == null)
21 if (x.CloudFile.Hash == null & y.CloudFile.Hash == null)
22 return (x.CloudFile.Name == y.CloudFile.Name);
24 if (!x.CloudFile.Hash.Equals(y.CloudFile.Hash))
26 //All directories have the same hash. Compare them using their names instead
27 if (x.CloudFile.Content_Type == y.CloudFile.Content_Type && x.CloudFile.Content_Type == "application/directory")
29 return (x.CloudFile.Name == y.CloudFile.Name);
32 if (x.CloudFile == null ^ y.CloudFile == null ||
33 x.LocalFile == null ^ y.LocalFile == null)
38 public override int GetHashCode(CloudAction obj)
42 var hash1 = (obj.LocalFile == null) ? Int32.MaxValue : obj.LocalFile.FullName.GetHashCode();
43 var hash2 = Int32.MaxValue;
44 if (obj.CloudFile != null)
46 //All directories have the same hash code. Use their name's hash code instead
47 hash2 = obj.CloudFile.Content_Type == "application/directory"
48 ? obj.CloudFile.Name.GetHashCode()
49 : (obj.CloudFile.Hash ?? obj.CloudFile.Name ?? "").GetHashCode();
51 var hash3 = obj.Action.GetHashCode();
52 return hash1 ^ hash2 & hash3;