Пример #1
0
        private void CalculateMd5()
        {
            EntityDownload.Status = EnumFileDownloader.DownloadStatus.CalculatingMd5;
            _serviceExternalDownload.Update(EntityDownload);

            using (var unc = new UncServices())
            {
                if (unc.NetUseWithCredentials() || unc.LastError == 1219)
                {
                    try
                    {
                        _hasher = new ServiceFileHash(MD5.Create());
                        _hasher.FileHashingProgress += OnFileHashingProgress;
                        using (var stream = new BufferedStream(File.OpenRead(Path.Combine(_destinationDir, EntityDownload.FileName)), 1200000))
                            _hasher.ComputeHash(stream);
                        EntityDownload.Md5Hash = _hasher.ToString();
                        EntityDownload.Status  = EnumFileDownloader.DownloadStatus.Complete;
                    }
                    catch (Exception ex)
                    {
                        EntityDownload.Status       = EnumFileDownloader.DownloadStatus.Error;
                        EntityDownload.ErrorMessage = ex.Message;
                    }
                }
            }

            _serviceExternalDownload.Update(EntityDownload);
        }
Пример #2
0
        private void CalculateSha256()
        {
            EntityDownload.Status = EnumFileDownloader.DownloadStatus.CalculatingSha256;
            _serviceExternalDownload.Update(EntityDownload);

            try
            {
                _hasher = new ServiceFileHash(SHA256.Create());
                _hasher.FileHashingProgress += OnFileHashingProgress;
                using (var stream = new BufferedStream(File.OpenRead(Path.Combine(_destinationDir, EntityDownload.FileName)), 1200000))
                    _hasher.ComputeHash(stream);
                EntityDownload.Sha256Hash = _hasher.ToString();
                EntityDownload.Status     = EnumFileDownloader.DownloadStatus.Complete;
            }
            catch (Exception ex)
            {
                EntityDownload.Status       = EnumFileDownloader.DownloadStatus.Error;
                EntityDownload.ErrorMessage = ex.Message;
            }

            _serviceExternalDownload.Update(EntityDownload);
        }