Esempio n. 1
0
        /// <summary>
        /// Returns a unique hash for a combination of FileInfo objects.
        /// </summary>
        /// <param name="filesAndFolders">A collection of files.</param>
        /// <param name="logger">A profiling logger.</param>
        /// <returns>The hash.</returns>
        // internal for tests
        public static string GetFileHash(IEnumerable <FileSystemInfo> filesAndFolders, IProfilingLogger logger)
        {
            using (logger.DebugDuration <TypeLoader>("Determining hash of code files on disk", "Hash determined"))
            {
                using (var generator = new HashGenerator())
                {
                    // get the distinct file infos to hash
                    var uniqInfos = new HashSet <string>();

                    foreach (var fileOrFolder in filesAndFolders)
                    {
                        if (uniqInfos.Contains(fileOrFolder.FullName))
                        {
                            continue;
                        }
                        uniqInfos.Add(fileOrFolder.FullName);
                        generator.AddFileSystemItem(fileOrFolder);
                    }
                    return(generator.GenerateHash());
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Returns a unique hash for a combination of FileInfo objects.
 /// </summary>
 /// <param name="filesAndFolders">A collection of files.</param>
 /// <param name="logger">A profiling logger.</param>
 /// <returns>The hash.</returns>
 /// <remarks>Each file is a tuple containing the FileInfo object and a boolean which indicates whether to hash the
 /// file properties (false) or the file contents (true).</remarks>
 private static string GetFileHash(IEnumerable <Tuple <FileSystemInfo, bool> > filesAndFolders, IProfilingLogger logger)
 {
     using (logger.DebugDuration <TypeLoader>("Determining hash of code files on disk", "Hash determined"))
     {
         // get the distinct file infos to hash
         var uniqInfos   = new HashSet <string>();
         var uniqContent = new HashSet <string>();
         using (var generator = new HashGenerator())
         {
             foreach (var fileOrFolder in filesAndFolders)
             {
                 var info = fileOrFolder.Item1;
                 if (fileOrFolder.Item2)
                 {
                     // add each unique file's contents to the hash
                     // normalize the content for cr/lf and case-sensitivity
                     if (uniqContent.Add(info.FullName))
                     {
                         if (File.Exists(info.FullName) == false)
                         {
                             continue;
                         }
                         var content = RemoveCrLf(File.ReadAllText(info.FullName));
                         generator.AddCaseInsensitiveString(content);
                     }
                 }
                 else
                 {
                     // add each unique folder/file to the hash
                     if (uniqInfos.Add(info.FullName))
                     {
                         generator.AddFileSystemItem(info);
                     }
                 }
             }
             return(generator.GenerateHash());
         }
     }
 }