/// <summary> /// Action to do on take photo button press /// </summary> /// <param name="sender"></param> private async void GetPhoto(Page sender) { if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported) { MediaFile file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = false }); if (file == null) { return; } lock (syncObject) { FileStream s = (FileStream)file.GetStream(); string name = s.Name.Substring(s.Name.LastIndexOf('/') + 1, (int)s.Name.Length - s.Name.LastIndexOf('/') - 1); TransferQueue.Add(new TransferQueueItem(s, ImageSource.FromFile(file.Path), name)); } } else { await sender.DisplayAlert("Error", "Grant permissions to camera to make photos", "OK"); } }
/// <summary> /// Add a <see cref="MTransfer"/> to the corresponding transfers list if it is not already included. /// </summary> /// <param name="megaTransfers"><see cref="TransferQueue"/> which contains the transfers list(s).</param> /// <param name="transfer"><see cref="MTransfer"/> to be added to the corresponding transfer list.</param> /// <returns>The <see cref="TransferObjectModel"/> corresponding to the <see cref="MTransfer"/>.</returns> public static TransferObjectModel AddTransferToList(TransferQueue megaTransfers, MTransfer transfer) { // Folder transfers are not included into the transfers list. if (transfer == null || transfer.isFolderTransfer()) { return(null); } // Search if the transfer already exists into the transfers list. var megaTransfer = SearchTransfer(megaTransfers.SelectAll(), transfer); if (megaTransfer != null) { return(megaTransfer); } // If doesn't exist create a new one and add it to the transfers list megaTransfer = CreateTransferObjectModel(transfer); if (megaTransfer != null) { megaTransfers.Add(megaTransfer); } return(megaTransfer); }
private void AddDownloadSingle(TransferPacket packet) { FileInfoBase sourceFileInfo; try { sourceFileInfo = client.CreateFileInfo(packet.SourcePath); } catch (Exception ex) { packet.FireFailureEvent(ex.Message); return; } FileInfoBase targetFileInfo = DiskFileSystem.Default.CreateFileInfo(packet.TargetPath); ProgressFileItem pfi = queue.Add(sourceFileInfo, targetFileInfo, false, FileExistsAction.Overwrite, 1); packet.FileItem = pfi; transferPacketList.Add(packet); }
/// <summary> /// Update a transfers list. /// </summary> /// <param name="megaTransfers"><see cref="TransferQueue"/> which contains the transfers list(s).</param> /// <param name="type">Type of the transfers list to update (Download or Upload).</param> /// <param name="cleanTransfers">Boolean value which indicates if clean the transfers list before update or not.</param> public static void UpdateMegaTransferList(TransferQueue megaTransfers, MTransferType type, bool cleanTransfers = false) { var transferData = SdkService.MegaSdk.getTransferData(); switch (type) { case MTransferType.TYPE_DOWNLOAD: if (cleanTransfers) { megaTransfers.Downloads.Clear(); } for (int i = 0; i < transferData.getNumDownloads(); i++) { AddTransferToList(megaTransfers, SdkService.MegaSdk.getTransferByTag(transferData.getDownloadTag(i))); } break; case MTransferType.TYPE_UPLOAD: // List to store the uploads that are pending on preparation (copy file to the temporary upload folder), // because they have not already added to the SDK queue List <TransferObjectModel> uploadsInPreparation = new List <TransferObjectModel>(); if (cleanTransfers) { // Store the uploads pending on preparation and clear the list uploadsInPreparation = megaTransfers.Uploads.Where(t => t.PreparingUploadCancelToken != null).ToList(); megaTransfers.Uploads.Clear(); } for (int i = 0; i < transferData.getNumUploads(); i++) { AddTransferToList(megaTransfers, SdkService.MegaSdk.getTransferByTag(transferData.getUploadTag(i))); } foreach (var upload in uploadsInPreparation) { megaTransfers.Add(upload); } break; default: throw new ArgumentOutOfRangeException("type", type, null); } }
public async void Download(TransferQueue transferQueue) { // User must be online to perform this operation if ((this.Parent?.Type != ContainerType.FolderLink) && !await IsUserOnlineAsync()) { return; } if (transferQueue == null) { return; } var downloadFolder = await FolderService.SelectFolder(); if (downloadFolder == null) { return; } if (!await TransferService.CheckExternalDownloadPathAsync(downloadFolder.Path)) { return; } this.Transfer.ExternalDownloadPath = downloadFolder.Path; transferQueue.Add(this.Transfer); this.Transfer.StartTransfer(); // If is a file or folder link, navigate to the Cloud Drive page if (this.ParentContainerType == ContainerType.FileLink || this.ParentContainerType == ContainerType.FolderLink) { OnUiThread(() => { NavigateService.Instance.Navigate(typeof(CloudDrivePage), false, NavigationObject.Create(this.GetType())); }); } }