예제 #1
0
        public void SaveFile(SaveFileParameter param)
        {
            Guid   checksum;
            string path;

            if (!TryGetPath(param, out checksum, out path))
            {
                return;
            }
            File.WriteAllBytes(path, param.FileData);
            var repository = new InfrastructureRepository();

            repository.SaveFile(checksum.ToString(), param.FileName, path);
        }
예제 #2
0
        private static bool TryGetPath(SaveFileParameter param, out Guid checksum, out string path)
        {
            checksum = CryptoManaged.MD5Hash(new MemoryStream(param.FileData));
            path     = string.Format(@"{0}{1}\{2}{3}", InfrastructureRepository.RootPath, param.AppID.ToString("N"), checksum, Path.GetExtension(param.FileName));
            var        file = new FileInfo(path);
            FileStream x    = null;

            try
            {
                return(!(file.Exists && CryptoManaged.MD5Hash(x = file.OpenRead()) == checksum));
            }
            finally
            {
                if (x != null)
                {
                    x.Close();
                }
            }
        }