void IAction.CopyFileItem(ProgressInfo progressInfo) { string fileName = System.IO.Path.Combine(target.FullName, child.FileName); bool duplicateFile = File.Exists(fileName); bool hashcodeMatches = duplicateFile ? Utility.GetMD5HashFromFile(fileName).Equals(child.Hash) : false; if (duplicateFile && actionType == ActionType.None) { throw new IOException("File already exist"); } else if (!duplicateFile || actionType == ActionType.Force || (actionType == ActionType.Sync && !hashcodeMatches)) { using (var fileStream = new FileStream(fileName, actionType == ActionType.Force || actionType == ActionType.Sync ? FileMode.Create : FileMode.CreateNew)) { var downloader = client.GetAsyncFileDownloader(child); progressInfo.ProgressTotal(progressInfo.FileIndex, child.FileSizeBytes.GetValueOrDefault()); downloader.OnTransferProgress = (sender, args) => { if (args.Progress.TotalBytes > 0) { progressInfo.ProgressTransferred(progressInfo.FileIndex, args.Progress.BytesTransferred); } }; downloader.DownloadToAsync(fileStream).Wait(); fileStream.Close(); fileSupportDelegate(fileName); } } }
void IAction.CopyFileItem(ProgressInfo progressInfo) { string fileName = System.IO.Path.Combine(target.FullName, child.FileName); bool duplicateFile = File.Exists(fileName); bool hashcodeMatches = duplicateFile ? Utility.GetMD5HashFromFile(fileName).Equals(child.Hash) : false; if (duplicateFile && actionType == ActionType.None) { throw new IOException("File already exist"); } else if (!duplicateFile || actionType == ActionType.Force || (actionType == ActionType.Sync && !hashcodeMatches)) { using (var fileStream = new FileStream(fileName, actionType == ActionType.Force || actionType == ActionType.Sync ? FileMode.Create : FileMode.CreateNew)) { var downloader = client.GetAsyncFileDownloader(child); progressInfo.ProgressTotal(progressInfo.FileIndex, child.FileSizeBytes.GetValueOrDefault()); downloader.OnTransferProgress = (sender, args) => { if (args.Progress.TotalBytes > 0) { progressInfo.ProgressTransferred(progressInfo.FileIndex, args.Progress.BytesTransferred); } }; downloader.DownloadToAsync(fileStream).Wait(); fileStream.Close(); fileSupportDelegate(fileName); } } }
void IAction.CopyFileItem(ProgressInfo progressInfo) { var fileInfo = (FileInfo)child; Models.Item fileItem = null; fileName = child.Name; try { fileItem = client.Items.ByPath(uploadTarget.url, "/" + child.Name).Execute(); } catch (ODataException e) { if (e.Code != System.Net.HttpStatusCode.NotFound) { throw e; } } bool duplicate = fileItem != null && fileItem is Models.File; bool hashcodeMatches = duplicate ? (fileItem as Models.File).Hash.Equals(Utility.GetMD5HashFromFile(child.FullName)) : false; if (duplicate && actionType == ActionType.None) { throw new IOException("File already exist"); } else if (!duplicate || actionType == ActionType.Force || (actionType == ActionType.Sync && !hashcodeMatches)) { var uploadSpec = new UploadSpecificationRequest { CanResume = false, Details = details, FileName = fileInfo.Name, FileSize = fileInfo.Length, Method = UploadMethod.Threaded, Parent = uploadTarget.url, ThreadCount = 4, Raw = true }; using (var platformFileInfo = new PlatformFileInfo(fileInfo)) { var uploader = client.GetAsyncFileUploader(uploadSpec, platformFileInfo); progressInfo.ProgressTotal(progressInfo.FileIndex, fileInfo.Length); uploader.OnTransferProgress = (sender, args) => { if (args.Progress.TotalBytes > 0) { progressInfo.ProgressTransferred(progressInfo.FileIndex, args.Progress.BytesTransferred); } }; Task.Run(() => uploader.UploadAsync()).Wait(); fileSupportDelegate(fileInfo.Name); } } }