Ejemplo n.º 1
0
        public void ComputeFileHashTest()
        {
            var filePath = string.Format("{0}/MGS.Common.xml", Environment.CurrentDirectory);
            var hash     = MD5CryptoUtility.ComputeFileHash(filePath);

            Assert.IsNotNull(hash);
            Console.WriteLine(hash);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find the cache file from cache by key.
        /// </summary>
        /// <param name="key">Key for cache file.</param>
        /// <param name="md5Hash">Matching file md5 hash [Do not check md5 hash if the value is null or empty].</param>
        /// <returns>The path of cache file from cache by key.</returns>
        public string FindFile(string key, string md5Hash)
        {
            var filePath = ResolveFile(key);

            if (File.Exists(filePath))
            {
                if (string.IsNullOrEmpty(md5Hash))
                {
                    return(filePath);
                }

                var fileMd5 = MD5CryptoUtility.ComputeFileHash(filePath);
                if (fileMd5.Equals(md5Hash))
                {
                    return(filePath);
                }
            }
            return(null);
        }