コード例 #1
0
ファイル: Mega.cs プロジェクト: pedro2555/mega-sdk
        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");
            }
        }
コード例 #2
0
ファイル: Mega.cs プロジェクト: pedro2555/mega-sdk
        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);
        }
コード例 #3
0
 void AddDownloadHandle(TransferHandle h)
 {
     Invoke(() => transfers.Add(h));
     SetStatusDone();
 }
コード例 #4
0
 void AddUploadHandle(TransferHandle h)
 {
     Invoke(() => transfers.Add(h));
     h.PropertyChanged += (s, ev) =>
     {
         h.TransferEnded += (s1, e1) => ShowFiles(currentNode, true);
     };
     SetStatusDone();
 }
コード例 #5
0
 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();
 }