public void DownloadFileSync(MegaNode node, string filename) { int? error = null; TransferHandle handle = null; var waitFile = new ManualResetEvent(false); DownloadFile(node, filename, (h) => { handle = h; h.TransferEnded += (s, e) => waitFile.Set(); }, (e) => error = e) .ResetEvent.WaitOne(); waitFile.WaitOne(); if (handle == null || error != null || handle.Node == null || handle.Error != null) { throw new MegaApiException(handle.Error == null ? (int)error : (int)handle.Error, "Could not upload the file"); } }
public MegaNode UploadStreamSync(string targetNodeId, string name, Stream inputStream, long size) { int? error = null; TransferHandle handle = null; var waitFile = new ManualResetEvent(false); UploadStream(targetNodeId, name, size, inputStream, (h) => { handle = h; h.TransferEnded += (s, e) => waitFile.Set(); }, (e) => error = e) .ResetEvent.WaitOne(); waitFile.WaitOne(); if (handle == null || error != null || handle.Node == null || handle.Error != null) { throw new MegaApiException(handle.Error == null ? (int)error : (int)handle.Error, "Could not upload the file"); } return(handle.Node); }
void AddDownloadHandle(TransferHandle h) { Invoke(() => transfers.Add(h)); SetStatusDone(); }
void AddUploadHandle(TransferHandle h) { Invoke(() => transfers.Add(h)); h.PropertyChanged += (s, ev) => { h.TransferEnded += (s1, e1) => ShowFiles(currentNode, true); }; SetStatusDone(); }
void CancelTransfer(TransferHandle handle, bool warn = true) { if (warn && (handle.Status == TransferHandleStatus.Downloading || handle.Status == TransferHandleStatus.Uploading)) { var type = (handle.Status == TransferHandleStatus.Downloading ? "download" : "upload"); var text = String.Format("Are you sure to cancel the {0} process for {1}?", type, handle.Node.Attributes.Name); if (MessageBox.Show(text, "Cancel " + type, MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } } handle.CancelTransfer(); }