public void onTransferTemporaryError(MegaSDK api, MTransfer transfer, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (DebugService.DebugSettings.IsDebugMode || Debugger.IsAttached) { if (ProgressService.GetProgressBarBackgroundColor() != (Color)Application.Current.Resources["MegaRedColor"]) { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["MegaRedColor"]); } } }); switch (e.getErrorCode()) { case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota case MErrorType.API_EOVERQUOTA: // Overquota error ProcessOverquotaError(api, e); break; } // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Search the corresponding transfer in the transfers list var megaTransfer = TransfersService.SearchTransfer(TransfersService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } var isBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; var transferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); var transferPriority = transfer.getPriority(); Deployment.Current.Dispatcher.BeginInvoke(() => { // Only update the values if they have changed to improve the UI performance if (megaTransfer.Transfer != transfer) { megaTransfer.Transfer = transfer; } if (megaTransfer.IsBusy != isBusy) { megaTransfer.IsBusy = isBusy; } if (megaTransfer.TransferState != transferState) { megaTransfer.TransferState = transferState; } if (megaTransfer.TransferPriority != transferPriority) { megaTransfer.TransferPriority = transferPriority; } }); }
public void onTransferTemporaryError(MegaSDK api, MTransfer transfer, MError e) { // Transfer overquota error if (e.getErrorCode() == MErrorType.API_EOVERQUOTA) { UiService.OnUiThread(() => { AccountService.AccountDetails.IsInTransferOverquota = true; DialogService.ShowTransferOverquotaWarning(); }); } // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Search the corresponding transfer in the transfers list var megaTransfer = TransferService.SearchTransfer(TransferService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } var isBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; var transferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); var transferPriority = transfer.getPriority(); UiService.OnUiThread(() => { // Only update the values if they have changed to improve the UI performance if (megaTransfer.Transfer != transfer) { megaTransfer.Transfer = transfer; } if (megaTransfer.IsBusy != isBusy) { megaTransfer.IsBusy = isBusy; } if (megaTransfer.TransferState != transferState) { megaTransfer.TransferState = transferState; } if (megaTransfer.TransferPriority != transferPriority) { megaTransfer.TransferPriority = transferPriority; } }); }
public void onTransferTemporaryError(MegaSDK api, MTransfer transfer, MError e) { switch (e.getErrorCode()) { case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota case MErrorType.API_EOVERQUOTA: // Overquota error ProcessOverquotaError(api, e); break; } // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Search the corresponding transfer in the transfers list var megaTransfer = TransferService.SearchTransfer(TransferService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } var isBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; var transferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); var transferPriority = transfer.getPriority(); UiService.OnUiThread(() => { // Only update the values if they have changed to improve the UI performance if (megaTransfer.Transfer != transfer) { megaTransfer.Transfer = transfer; } if (megaTransfer.IsBusy != isBusy) { megaTransfer.IsBusy = isBusy; } if (megaTransfer.TransferState != transferState) { megaTransfer.TransferState = transferState; } if (megaTransfer.TransferPriority != transferPriority) { megaTransfer.TransferPriority = transferPriority; } }); }
public void onTransferStart(MegaSDK api, MTransfer transfer) { // Extra checking to avoid NullReferenceException if (transfer == null) { return; } UiService.OnUiThread(() => { var megaTransfer = TransferService.AddTransferToList(TransferService.MegaTransfers, transfer); if (megaTransfer != null) { megaTransfer.Transfer = transfer; megaTransfer.IsBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; megaTransfer.TransferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferPriority = transfer.getPriority(); } }); }
/// <summary> /// This function is called when a folder transfer has finished /// </summary> /// <param name="api">MegaApi object that started the transfer</param> /// <param name="transfer">Information about the transfer</param> /// <param name="e">Error information</param> private async void FolderTransferFinish(MegaSDK api, MTransfer transfer, MError e) { // In this case the transfer is not included in the transfers list. // We need to create a new 'TransferObjectModel' to work with it. var megaTransfer = TransferService.CreateTransferObjectModel(transfer); if (megaTransfer == null) { return; } megaTransfer.Transfer = transfer; UiService.OnUiThread(() => { megaTransfer.TransferState = transfer.getState(); megaTransfer.TransferPriority = transfer.getPriority(); }); switch (e.getErrorCode()) { case MErrorType.API_OK: if (transfer.getType() == MTransferType.TYPE_DOWNLOAD) { if (megaTransfer.IsSaveForOfflineTransfer) { this.AddOfflineNodeFromTransfer(megaTransfer); return; } if (!await megaTransfer.FinishDownload(megaTransfer.TransferPath, megaTransfer.SelectedNode.Name)) { UiService.OnUiThread(() => megaTransfer.TransferState = MTransferState.STATE_FAILED); } } break; case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota case MErrorType.API_EOVERQUOTA: //Storage overquota error ProcessOverquotaError(api, e); break; case MErrorType.API_EINCOMPLETE: if (megaTransfer.IsSaveForOfflineTransfer) { this.RemoveOfflineNodeFromTransfer(megaTransfer); } break; default: ProcessDefaultError(transfer); break; } }
public void onTransferStart(MegaSDK api, MTransfer transfer) { // Extra checking to avoid NullReferenceException if (transfer == null) { return; } Deployment.Current.Dispatcher.BeginInvoke(() => { var megaTransfer = TransfersService.AddTransferToList(TransfersService.MegaTransfers, transfer); if (megaTransfer != null) { TransfersService.GetTransferAppData(transfer, megaTransfer); megaTransfer.Transfer = transfer; megaTransfer.IsBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; megaTransfer.TransferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferPriority = transfer.getPriority(); megaTransfer.TransferButtonIcon = new Uri("/Assets/Images/cancel transfers.Screen-WXGA.png", UriKind.Relative); } }); }
public void onTransferStart(MegaSDK api, MTransfer transfer) { TransferObjectModel megaTransfer = null; if (transfer.getType() == MTransferType.TYPE_DOWNLOAD) { // If is a public node MNode node = transfer.getPublicMegaNode(); if (node == null) // If not { node = api.getNodeByHandle(transfer.getNodeHandle()); } if (node != null) { megaTransfer = new TransferObjectModel(api, NodeService.CreateNew(api, App.AppInformation, node, ContainerType.CloudDrive), TransferType.Download, transfer.getPath()); } } else { megaTransfer = new TransferObjectModel(api, App.MainPageViewModel.CloudDrive.FolderRootNode, TransferType.Upload, transfer.getPath()); } if (megaTransfer != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { TransfersService.GetTransferAppData(transfer, megaTransfer); megaTransfer.Transfer = transfer; megaTransfer.Status = TransferStatus.Queued; megaTransfer.CancelButtonState = true; megaTransfer.TransferButtonIcon = new Uri("/Assets/Images/cancel transfers.Screen-WXGA.png", UriKind.Relative); megaTransfer.TransferButtonForegroundColor = new SolidColorBrush(Colors.White); megaTransfer.IsBusy = true; megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferedBytes = transfer.getTransferredBytes(); megaTransfer.TransferSpeed = transfer.getSpeed().ToStringAndSuffixPerSecond(); App.MegaTransfers.Add(megaTransfer); Transfers.Add(megaTransfer); }); } }
/// <summary> /// This function is called when a transfer fails by a default error. /// It does the needed actions to process this kind of error. /// </summary> /// <param name="transfer"></param> private void ProcessDefaultError(MTransfer transfer) { string message, title = string.Empty; switch (transfer.getType()) { case MTransferType.TYPE_DOWNLOAD: title = ResourceService.AppMessages.GetString("AM_DownloadFailed_Title"); if (transfer.isFolderTransfer()) { message = ResourceService.AppMessages.GetString("AM_DownloadFolderFailed"); } else { message = ResourceService.AppMessages.GetString("AM_DownloadFileFailed"); } break; case MTransferType.TYPE_UPLOAD: title = ResourceService.AppMessages.GetString("AM_UploadFailed_Title"); if (transfer.isFolderTransfer()) { message = ResourceService.AppMessages.GetString("AM_UploadFolderFailed"); } else { message = ResourceService.AppMessages.GetString("AM_UploadFileFailed"); } break; default: throw new ArgumentOutOfRangeException(); } UiService.OnUiThread(async() => { await DialogService.ShowAlertAsync(title, string.Format(message, transfer.getFileName())); }); }
/// <summary> /// Get the transfer "AppData" (substrings separated by '#') /// <para>- Substring 1: Boolean value to indicate if the download is for Save For Offline (SFO).</para> /// <para>- Substring 2: String which contains the download folder path external to the app sandbox cache.</para> /// </summary> /// <param name="transfer">MEGA SDK transfer to obtain the "AppData".</param> /// <param name="megaTransfer">App transfer object to be displayed.</param> /// <returns>Boolean value indicating if all was good.</returns> public static bool GetTransferAppData(MTransfer transfer, TransferObjectModel megaTransfer) { // Default values megaTransfer.IsSaveForOfflineTransfer = false; megaTransfer.ExternalDownloadPath = null; // Only the downloads can contain app data if (transfer.getType() != MTransferType.TYPE_DOWNLOAD) { return(false); } // Get the transfer "AppData" String transferAppData = transfer.getAppData(); if (String.IsNullOrWhiteSpace(transferAppData)) { return(false); } // Split the string into the substrings separated by '#' string[] splittedAppData = transferAppData.Split("#".ToCharArray(), 2); if (splittedAppData.Count() < 1) { return(false); } // Set the corresponding values megaTransfer.IsSaveForOfflineTransfer = Convert.ToBoolean(splittedAppData[0]); if (splittedAppData.Count() >= 2) { megaTransfer.ExternalDownloadPath = splittedAppData[1]; } return(true); }
public void onTransferUpdate(MegaSDK api, MTransfer transfer) { // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Search the corresponding transfer in the transfers list var megaTransfer = TransfersService.SearchTransfer(TransfersService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } var isBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; var transferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); var totalBytes = transfer.getTotalBytes(); var transferedBytes = transfer.getTransferredBytes(); var transferSpeed = transfer.getSpeed().ToStringAndSuffixPerSecond(); var transferMeanSpeed = transfer.getMeanSpeed(); var transferPriority = transfer.getPriority(); Deployment.Current.Dispatcher.BeginInvoke(() => { if (ProgressService.GetProgressBarBackgroundColor() != (Color)Application.Current.Resources["PhoneChromeColor"]) { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); } // Only update the values if they have changed to improve the UI performance if (megaTransfer.Transfer != transfer) { megaTransfer.Transfer = transfer; } if (megaTransfer.IsBusy != isBusy) { megaTransfer.IsBusy = isBusy; } if (megaTransfer.TransferState != transferState) { megaTransfer.TransferState = transferState; } if (megaTransfer.TotalBytes != totalBytes) { megaTransfer.TotalBytes = totalBytes; } if (megaTransfer.TransferedBytes != transferedBytes) { megaTransfer.TransferedBytes = transferedBytes; } if (megaTransfer.TransferSpeed != transferSpeed) { megaTransfer.TransferSpeed = transferSpeed; } if (megaTransfer.TransferMeanSpeed != transferMeanSpeed) { megaTransfer.TransferMeanSpeed = transferMeanSpeed; } if (megaTransfer.TransferPriority != transferPriority) { megaTransfer.TransferPriority = transferPriority; } }); }
public void onTransferUpdate(MegaSDK api, MTransfer transfer) { // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Search the corresponding transfer in the transfers list var megaTransfer = TransferService.SearchTransfer(TransferService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } var isBusy = api.areTransfersPaused((int)transfer.getType()) ? false : true; var transferState = api.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : transfer.getState(); var totalBytes = transfer.getTotalBytes(); var transferedBytes = transfer.getTransferredBytes(); var transferSpeed = transfer.getSpeed().ToStringAndSuffixPerSecond(); var transferMeanSpeed = transfer.getMeanSpeed(); var transferPriority = transfer.getPriority(); UiService.OnUiThread(() => { // Only update the values if they have changed to improve the UI performance if (megaTransfer.Transfer != transfer) { megaTransfer.Transfer = transfer; } if (megaTransfer.IsBusy != isBusy) { megaTransfer.IsBusy = isBusy; } if (megaTransfer.TransferState != transferState) { megaTransfer.TransferState = transferState; } if (megaTransfer.TotalBytes != totalBytes) { megaTransfer.TotalBytes = totalBytes; } if (megaTransfer.TransferedBytes != transferedBytes) { megaTransfer.TransferedBytes = transferedBytes; } if (megaTransfer.TransferSpeed != transferSpeed) { megaTransfer.TransferSpeed = transferSpeed; } if (megaTransfer.TransferMeanSpeed != transferMeanSpeed) { megaTransfer.TransferMeanSpeed = transferMeanSpeed; } if (megaTransfer.TransferPriority != transferPriority) { megaTransfer.TransferPriority = transferPriority; } }); }
/// <summary> /// Create a <see cref="TransferObjectModel"/> from a <see cref="MTransfer"/>. /// </summary> /// <param name="transfer"></param> /// <returns>The new <see cref="TransferObjectModel"/></returns> public static TransferObjectModel CreateTransferObjectModel(MTransfer transfer) { if (transfer == null) { return(null); } try { TransferObjectModel megaTransfer = null; switch (transfer.getType()) { case MTransferType.TYPE_DOWNLOAD: MNode node = transfer.getPublicMegaNode() ?? // If is a public node SdkService.MegaSdk.getNodeByHandle(transfer.getNodeHandle()); // If not if (node == null) { return(null); } megaTransfer = new TransferObjectModel(SdkService.MegaSdk, NodeService.CreateNew(SdkService.MegaSdk, App.AppInformation, node, ContainerType.CloudDrive), MTransferType.TYPE_DOWNLOAD, transfer.getPath()); break; case MTransferType.TYPE_UPLOAD: var parentNode = SdkService.MegaSdk.getNodeByHandle(transfer.getParentHandle()); if (parentNode == null) { return(null); } megaTransfer = new TransferObjectModel(SdkService.MegaSdk, NodeService.CreateNew(SdkService.MegaSdk, App.AppInformation, parentNode, ContainerType.CloudDrive), MTransferType.TYPE_UPLOAD, transfer.getPath()); break; default: throw new ArgumentOutOfRangeException(); } if (megaTransfer != null) { GetTransferAppData(transfer, megaTransfer); megaTransfer.Transfer = transfer; megaTransfer.TransferState = transfer.getState(); megaTransfer.TransferPriority = transfer.getPriority(); megaTransfer.IsBusy = false; megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferedBytes = transfer.getTransferredBytes(); megaTransfer.TransferSpeed = string.Empty; megaTransfer.TransferMeanSpeed = 0; megaTransfer.TransferState = !SdkService.MegaSdk.areTransfersPaused((int)transfer.getType()) ? MTransferState.STATE_QUEUED : MTransferState.STATE_PAUSED; } return(megaTransfer); } catch (Exception) { return(null); } }