private void onRequestFinishFolderLink(MegaSDK api, MRequest request, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); ProgressService.SetProgressIndicator(false); if (apiErrorTimer != null) { apiErrorTimer.Stop(); } }); if (e.getErrorCode() == MErrorType.API_OK) { //If getFlag() returns true, the folder link key is invalid. if (request.getFlag()) { // First logout from the folder api.logout(); // Set the empty state and disable the app bar buttons Deployment.Current.Dispatcher.BeginInvoke(() => { _folderLinkViewModel.FolderLink.SetEmptyContentTemplate(false); _folderLinkViewModel._folderLinkPage.SetApplicationBarData(false); }); //If the user have written the key if (_decryptionAlert) { ShowDecryptionKeyNotValidAlert(api, request); } else { ShowFolderLinkNoValidAlert(); } } else { OnSuccesAction(api, request); } } else { Deployment.Current.Dispatcher.BeginInvoke(() => { _folderLinkViewModel.FolderLink.SetEmptyContentTemplate(false); _folderLinkViewModel._folderLinkPage.SetApplicationBarData(false); }); switch (e.getErrorCode()) { case MErrorType.API_ETOOMANY: // Taken down link and the link owner's account is blocked ShowAssociatedUserAccountTerminatedFolderLinkAlert(); break; case MErrorType.API_ENOENT: // Link not exists or has been deleted by user case MErrorType.API_EBLOCKED: // Taken down link ShowUnavailableFolderLinkAlert(); break; default: ShowFolderLinkNoValidAlert(); break; } } }
public override void onRequestFinish(MegaSDK api, MRequest request, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); ProgressService.SetProgressIndicator(false); _createAccountViewModel.ControlState = true; _loginPage.SetApplicationBar(true); }); if (request.getType() == MRequestType.TYPE_QUERY_SIGNUP_LINK) { switch (e.getErrorCode()) { case MErrorType.API_OK: // Valid and operative #newsignup link Deployment.Current.Dispatcher.BeginInvoke(() => { _createAccountViewModel.Email = request.getEmail(); if (!String.IsNullOrWhiteSpace(_createAccountViewModel.Email)) { this._loginPage.txtEmail_CreateAccount.IsReadOnly = true; } }); break; case MErrorType.API_EARGS: // Invalid #newsignup link Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.AM_InvalidLink, AppMessages.AM_NewSignUpInvalidLink, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; default: // Default error processing base.onRequestFinish(api, request, e); break; } } if (request.getType() == MRequestType.TYPE_CREATE_ACCOUNT) { switch (e.getErrorCode()) { case MErrorType.API_OK: // Successfull create account process base.onRequestFinish(api, request, e); break; case MErrorType.API_EEXIST: // Email already registered Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( ErrorMessageTitle, AppMessages.AM_EmailAlreadyRegistered, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; default: // Default error processing base.onRequestFinish(api, request, e); break; } } }
public override void onRequestFinish(MegaSDK api, MRequest request, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); ProgressService.SetProgressIndicator(false); this._confirmAccountViewModel.ControlState = true; if (request.getType() == MRequestType.TYPE_QUERY_SIGNUP_LINK) { switch (e.getErrorCode()) { case MErrorType.API_OK: // Valid and operative confirmation link this._confirmAccountViewModel.Email = request.getEmail(); break; case MErrorType.API_ENOENT: // Already confirmed account ShowErrorMesageAndNavigate(AppMessages.AlreadyConfirmedAccount_Title, AppMessages.AlreadyConfirmedAccount); break; case MErrorType.API_EINCOMPLETE: // Incomplete confirmation link ShowErrorMesageAndNavigate(AppMessages.ConfirmAccountFailed_Title, AppMessages.AM_IncompleteConfirmationLink); break; case MErrorType.API_EOVERQUOTA: base.onRequestFinish(api, request, e); break; default: // Other error ShowDefaultErrorMessage(e); break; } } else if (request.getType() == MRequestType.TYPE_CONFIRM_ACCOUNT) { switch (e.getErrorCode()) { case MErrorType.API_OK: // Successfull confirmation process var customMessageDialog = new CustomMessageDialog( SuccessMessageTitle, SuccessMessage, App.AppInformation, MessageDialogButtons.Ok); customMessageDialog.OkOrYesButtonTapped += (sender, args) => OnSuccesAction(api, request); customMessageDialog.ShowDialog(); break; case MErrorType.API_ENOENT: // Wrong password new CustomMessageDialog( AppMessages.WrongPassword_Title, AppMessages.WrongPassword, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); break; case MErrorType.API_EOVERQUOTA: base.onRequestFinish(api, request, e); break; default: // Other error ShowDefaultErrorMessage(e); break; } } }); }
public async void onTransferFinish(MegaSDK api, MTransfer transfer, MError e) #endif { // Extra checking to avoid NullReferenceException if (transfer == null) { return; } // Use a temp variable to avoid InvalidOperationException var transfersList = Transfers.ToList(); // Extra checking during finding to avoid NullReferenceException var megaTransfer = transfersList.FirstOrDefault(t => (t.Transfer != null) && (t.Transfer.getTag() == transfer.getTag())); if (megaTransfer != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); TransfersService.GetTransferAppData(transfer, megaTransfer); megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferedBytes = transfer.getTransferredBytes(); megaTransfer.TransferSpeed = transfer.getSpeed().ToStringAndSuffixPerSecond(); megaTransfer.IsBusy = false; megaTransfer.CancelButtonState = false; }); switch (e.getErrorCode()) { case MErrorType.API_OK: { Deployment.Current.Dispatcher.BeginInvoke(() => { megaTransfer.TransferedBytes = megaTransfer.TotalBytes; megaTransfer.TransferButtonIcon = new Uri("/Assets/Images/completed transfers.Screen-WXGA.png", UriKind.Relative); megaTransfer.TransferButtonForegroundColor = (SolidColorBrush)Application.Current.Resources["MegaRedSolidColorBrush"]; }); switch (megaTransfer.Type) { case TransferType.Download: if (megaTransfer.IsSaveForOfflineTransfer) //If is a save for offline download transfer { var node = megaTransfer.SelectedNode as NodeViewModel; if (node != null) { // Need get the path on the transfer finish because the file name can be changed // if already exists in the destiny path. var newOfflineLocalPath = Path.Combine(transfer.getParentPath(), transfer.getFileName()).Replace("/", "\\"); var sfoNode = new SavedForOffline { Fingerprint = App.MegaSdk.getNodeFingerprint(node.OriginalMNode), Base64Handle = node.OriginalMNode.getBase64Handle(), LocalPath = newOfflineLocalPath, IsSelectedForOffline = true }; // If is a public node (link) the destination folder is the SFO root, so the parent handle // is the handle of the root node. if (node.ParentContainerType != ContainerType.PublicLink) { sfoNode.ParentBase64Handle = (App.MegaSdk.getParentNode(node.OriginalMNode)).getBase64Handle(); } else { sfoNode.ParentBase64Handle = App.MegaSdk.getRootNode().getBase64Handle(); } if (!(SavedForOffline.ExistsNodeByLocalPath(sfoNode.LocalPath))) { SavedForOffline.Insert(sfoNode); } else { SavedForOffline.UpdateNode(sfoNode); } Deployment.Current.Dispatcher.BeginInvoke(() => node.IsAvailableOffline = node.IsSelectedForOffline = true); #if WINDOWS_PHONE_80 //If is download transfer of an image file var imageNode = node as ImageNodeViewModel; if (imageNode != null) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.ImageUri = new Uri(megaTransfer.FilePath)); bool exportToPhotoAlbum = SettingsService.LoadSetting <bool>(SettingsResources.ExportImagesToPhotoAlbum, false); if (exportToPhotoAlbum) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.SaveImageToCameraRoll(false)); } } #endif } } else //If is a standard download transfer (no for save for offline) { //If is download transfer of an image file var imageNode = megaTransfer.SelectedNode as ImageNodeViewModel; if (imageNode != null) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.ImageUri = new Uri(megaTransfer.FilePath)); if (megaTransfer.AutoLoadImageOnFinish) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (imageNode.OriginalMNode.hasPreview()) { return; } imageNode.PreviewImageUri = new Uri(imageNode.PreviewPath); imageNode.IsBusy = false; }); } #if WINDOWS_PHONE_81 if (!await megaTransfer.FinishDownload(megaTransfer.FilePath, imageNode.Name)) { Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Error); break; } #endif } #if WINDOWS_PHONE_81 else //If is a download transfer of other file type { var node = megaTransfer.SelectedNode as FileNodeViewModel; if (node != null) { if (!await megaTransfer.FinishDownload(megaTransfer.FilePath, node.Name)) { Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Error); break; } } } #endif } Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Downloaded); break; case TransferType.Upload: Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Uploaded); break; default: throw new ArgumentOutOfRangeException(); } break; } case MErrorType.API_EOVERQUOTA: { Deployment.Current.Dispatcher.BeginInvoke(() => { // Stop all upload transfers api.cancelTransfers((int)MTransferType.TYPE_UPLOAD); // Disable the "camera upload" service MediaService.SetAutoCameraUpload(false); SettingsService.SaveSetting(SettingsResources.CameraUploadsIsEnabled, false); DialogService.ShowOverquotaAlert(); }); break; } case MErrorType.API_EINCOMPLETE: { Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Canceled); break; } default: { Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.Status = TransferStatus.Error); switch (megaTransfer.Type) { case TransferType.Download: Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.DownloadNodeFailed_Title, String.Format(AppMessages.DownloadNodeFailed, e.getErrorString()), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; case TransferType.Upload: Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.UploadNodeFailed_Title, String.Format(AppMessages.UploadNodeFailed, e.getErrorString()), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; default: throw new ArgumentOutOfRangeException(); } break; } } } }
public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); ProgressService.SetProgressIndicator(false); }); switch (e.getErrorCode()) { case MErrorType.API_OK: if (ShowSuccesMessage) { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( SuccessMessageTitle, SuccessMessage, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } if (ActionOnSucces) { OnSuccesAction(api, request); } if (NavigateOnSucces) { Deployment.Current.Dispatcher.BeginInvoke(() => NavigateService.NavigateTo(NavigateToPage, NavigationParameter)); } break; case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota case MErrorType.API_EOVERQUOTA: //Storage overquota error // Stop all upload transfers LogService.Log(MLogLevel.LOG_LEVEL_INFO, string.Format("Storage quota exceeded ({0}) - Canceling uploads", e.getErrorCode().ToString())); api.cancelTransfers((int)MTransferType.TYPE_UPLOAD); // Disable the "camera upload" service if is enabled if (MediaService.GetAutoCameraUploadStatus()) { LogService.Log(MLogLevel.LOG_LEVEL_INFO, string.Format("Storage quota exceeded ({0}) - Disabling CAMERA UPLOADS service", e.getErrorCode().ToString())); MediaService.SetAutoCameraUpload(false); SettingsService.SaveSetting(SettingsResources.CameraUploadsIsEnabled, false); } Deployment.Current.Dispatcher.BeginInvoke(() => DialogService.ShowOverquotaAlert()); break; default: if (e.getErrorCode() != MErrorType.API_EINCOMPLETE) { if (ShowErrorMessage) { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( ErrorMessageTitle, String.Format(ErrorMessage, e.getErrorString()), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } } break; } }
public virtual void onRequestUpdate(MegaSDK api, MRequest request) { Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"])); }
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 async void onTransferFinish(MegaSDK api, MTransfer transfer, MError e) #endif { // Search the corresponding transfer in the transfers list var megaTransfer = TransfersService.SearchTransfer(TransfersService.MegaTransfers.SelectAll(), transfer); if (megaTransfer == null) { return; } Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); megaTransfer.Transfer = transfer; megaTransfer.TransferState = transfer.getState(); megaTransfer.TransferPriority = transfer.getPriority(); TransfersService.GetTransferAppData(transfer, megaTransfer); megaTransfer.TotalBytes = transfer.getTotalBytes(); megaTransfer.TransferedBytes = transfer.getTransferredBytes(); megaTransfer.TransferSpeed = string.Empty; }); switch (e.getErrorCode()) { case MErrorType.API_OK: Deployment.Current.Dispatcher.BeginInvoke(() => { megaTransfer.TransferedBytes = megaTransfer.TotalBytes; megaTransfer.TransferButtonIcon = new Uri("/Assets/Images/completed transfers.Screen-WXGA.png", UriKind.Relative); }); switch (megaTransfer.Type) { case MTransferType.TYPE_DOWNLOAD: if (megaTransfer.IsSaveForOfflineTransfer) //If is a save for offline download transfer { var node = megaTransfer.SelectedNode as NodeViewModel; if (node != null) { // Need get the path on the transfer finish because the file name can be changed // if already exists in the destiny path. var newOfflineLocalPath = Path.Combine(transfer.getParentPath(), transfer.getFileName()).Replace("/", "\\"); var sfoNode = new SavedForOffline { Fingerprint = SdkService.MegaSdk.getNodeFingerprint(node.OriginalMNode), Base64Handle = node.OriginalMNode.getBase64Handle(), LocalPath = newOfflineLocalPath, IsSelectedForOffline = true }; // If is a public node (link) the destination folder is the SFO root, so the parent handle // is the handle of the root node. if (node.ParentContainerType != ContainerType.PublicLink) { sfoNode.ParentBase64Handle = (SdkService.MegaSdk.getParentNode(node.OriginalMNode)).getBase64Handle(); } else { sfoNode.ParentBase64Handle = SdkService.MegaSdk.getRootNode().getBase64Handle(); } if (!(SavedForOffline.ExistsNodeByLocalPath(sfoNode.LocalPath))) { SavedForOffline.Insert(sfoNode); } else { SavedForOffline.UpdateNode(sfoNode); } Deployment.Current.Dispatcher.BeginInvoke(() => { node.IsAvailableOffline = node.IsSelectedForOffline = true; TransfersService.MoveMegaTransferToCompleted(TransfersService.MegaTransfers, megaTransfer); }); #if WINDOWS_PHONE_80 //If is download transfer of an image file var imageNode = node as ImageNodeViewModel; if (imageNode != null) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.ImageUri = new Uri(megaTransfer.TransferPath)); bool exportToPhotoAlbum = SettingsService.LoadSetting <bool>(SettingsResources.ExportImagesToPhotoAlbum, false); if (exportToPhotoAlbum) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.SaveImageToCameraRoll(false)); } } #endif } } else //If is a standard download transfer (no for save for offline) { bool result = false; //If is download transfer of an image file var imageNode = megaTransfer.SelectedNode as ImageNodeViewModel; if (imageNode != null) { Deployment.Current.Dispatcher.BeginInvoke(() => imageNode.ImageUri = new Uri(megaTransfer.TransferPath)); if (megaTransfer.AutoLoadImageOnFinish) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (imageNode.OriginalMNode.hasPreview()) { return; } imageNode.PreviewImageUri = new Uri(imageNode.PreviewPath); }); } #if WINDOWS_PHONE_81 try { result = await megaTransfer.FinishDownload(megaTransfer.TransferPath, imageNode.Name); } catch (Exception exception) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error finishing a download to an external location", exception); } #endif } #if WINDOWS_PHONE_81 else //If is a download transfer of other file type { var node = megaTransfer.SelectedNode as FileNodeViewModel; if (node != null) { try { result = await megaTransfer.FinishDownload(megaTransfer.TransferPath, node.Name); } catch (Exception exception) { LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error finishing a download to an external location", exception); } } } #endif Deployment.Current.Dispatcher.BeginInvoke(() => { if (!result) { megaTransfer.TransferState = MTransferState.STATE_FAILED; } else { TransfersService.MoveMegaTransferToCompleted(TransfersService.MegaTransfers, megaTransfer); } }); } break; case MTransferType.TYPE_UPLOAD: Deployment.Current.Dispatcher.BeginInvoke(() => TransfersService.MoveMegaTransferToCompleted(TransfersService.MegaTransfers, megaTransfer)); break; default: throw new ArgumentOutOfRangeException(); } break; case MErrorType.API_EGOINGOVERQUOTA: // Not enough storage quota LogService.Log(MLogLevel.LOG_LEVEL_INFO, string.Format("Not enough storage quota ({0})", e.getErrorCode().ToString())); UiService.OnUiThread(() => { megaTransfer.TransferState = MTransferState.STATE_FAILED; DialogService.ShowStorageOverquotaAlert(true); }); break; case MErrorType.API_EOVERQUOTA: // Storage overquota error LogService.Log(MLogLevel.LOG_LEVEL_INFO, string.Format("Storage quota exceeded ({0})", e.getErrorCode().ToString())); UiService.OnUiThread(() => { megaTransfer.TransferState = MTransferState.STATE_FAILED; DialogService.ShowStorageOverquotaAlert(false); }); break; case MErrorType.API_EINCOMPLETE: Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.TransferState = MTransferState.STATE_CANCELLED); break; default: Deployment.Current.Dispatcher.BeginInvoke(() => megaTransfer.TransferState = MTransferState.STATE_FAILED); switch (megaTransfer.Type) { case MTransferType.TYPE_DOWNLOAD: Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.DownloadNodeFailed_Title, String.Format(AppMessages.DownloadNodeFailed, e.getErrorString()), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; case MTransferType.TYPE_UPLOAD: Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.UploadNodeFailed_Title, String.Format(AppMessages.UploadNodeFailed, e.getErrorString()), App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); break; default: throw new ArgumentOutOfRangeException(); } break; } }
public override void onRequestFinish(MegaSDK api, MRequest request, MError e) { Deployment.Current.Dispatcher.BeginInvoke(() => { ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]); ProgressService.SetProgressIndicator(false); }); if (e.getErrorCode() == MErrorType.API_OK) { //If getFlag() returns true, the file link key is invalid. if (request.getFlag()) { if (_decryptionAlert) { ShowDecryptionKeyNotValidAlert(api, request); } else { ShowFileLinkNoValidAlert(); } } else { OnSuccesAction(api, request); } } else { switch (e.getErrorCode()) { case MErrorType.API_EARGS: if (_decryptionAlert) { ShowDecryptionKeyNotValidAlert(api, request); } else { ShowFileLinkNoValidAlert(); } break; case MErrorType.API_ETOOMANY: // Taken down link and the link owner's account is blocked ShowAssociatedUserAccountTerminatedFileLinkAlert(); break; case MErrorType.API_ENOENT: // Link not exists or has been deleted by user case MErrorType.API_EBLOCKED: // Taken down link ShowUnavailableFileLinkAlert(); break; case MErrorType.API_EINCOMPLETE: // Link has not decryption key ShowDecryptionAlert(api, request); break; default: ShowFileLinkNoValidAlert(); break; } } }