/// <summary> /// Returns the hash string for all found plugins/folders /// </summary> /// <returns></returns> internal static string GetPluginsHash(IEnumerable <FileInfo> plugins, bool generateNew = false) { if (generateNew || _pluginsHash.IsNullOrWhiteSpace()) { using (DisposableTimer.TraceDuration <PluginManager>("Determining hash of plugins on disk", "Hash determined")) { var hashCombiner = new HashCodeCombiner(); //add each unique folder to the hash foreach (var i in plugins.Select(x => x.Directory).DistinctBy(x => x.FullName)) { hashCombiner.AddFolder(i); } _pluginsHash = hashCombiner.GetCombinedHashCode(); } } return(_pluginsHash); }
public void HashCombiner_Test_Folder() { var dir = PrepareFolder(); var file1Path = Path.Combine(dir.FullName, "hastest1.txt"); File.Delete(file1Path); using (var file1 = File.CreateText(Path.Combine(dir.FullName, "hastest1.txt"))) { file1.WriteLine("hello"); } //first test the whole folder var combiner1 = new HashCodeCombiner(); combiner1.AddFolder(dir); var combiner2 = new HashCodeCombiner(); combiner2.AddFolder(dir); Assert.AreEqual(combiner1.GetCombinedHashCode(), combiner2.GetCombinedHashCode()); //now add a file to the folder var file2Path = Path.Combine(dir.FullName, "hastest2.txt"); File.Delete(file2Path); using (var file2 = File.CreateText(Path.Combine(dir.FullName, "hastest2.txt"))) { //even though files are the same, the dates are different file2.WriteLine("hello"); } var combiner3 = new HashCodeCombiner(); combiner3.AddFolder(dir); Assert.AreNotEqual(combiner1.GetCombinedHashCode(), combiner3.GetCombinedHashCode()); }