Exemple #1
0
        /// <summary>
        /// Get a name for mutex base on the path.
        /// </summary>
        /// <param name="path">Custom file or directory path.</param>
        /// <param name="isGlobal">The name is for global mutex?</param>
        /// <returns>A name for mutex base on the path.</returns>
        public static string GetMutexNameForPath(string path, bool isGlobal = true)
        {
            var fullPath = Path.GetFullPath(path);
            var pathMd5  = MD5CryptoUtility.ComputeHash(fullPath);

            return(GetMutexName(pathMd5, isGlobal));
        }
Exemple #2
0
        public void ComputeHashTest()
        {
            var buffer = new byte[] { 0, 1, 2 };
            var hash   = MD5CryptoUtility.ComputeHash(buffer);

            Assert.IsNotNull(hash);
            Console.WriteLine(hash);
        }
Exemple #3
0
        public void ComputeHashTest1()
        {
            var source = "ComputeHashTest1";
            var hash   = MD5CryptoUtility.ComputeHash(source);

            Assert.IsNotNull(hash);
            Console.WriteLine(hash);
        }
Exemple #4
0
        /// <summary>
        /// Copy the file in to cache.
        /// </summary>
        /// <param name="file">The target file path.</param>
        /// <param name="key">Key for cache file [Use md5 hash of file path as key if the value is null or empty].</param>
        /// <returns>The key for cache file.</returns>
        public string CopyFrom(string file, string key = null)
        {
            if (!File.Exists(file))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(key))
            {
                key = MD5CryptoUtility.ComputeHash(file);
            }

            var cacheFile = ResolveFile(key);

            DirectoryUtility.RequireDirectory(cacheFile);
            File.Copy(file, cacheFile, true);
            return(key);
        }