public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (apiErrorTimer != null)
                {
                    apiErrorTimer.Stop();
                }
            });

            switch (e.getErrorCode())
            {
            case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota
            case MErrorType.API_EOVERQUOTA:      // Storage overquota error
                Deployment.Current.Dispatcher.BeginInvoke(DialogService.ShowOverquotaAlert);

                // 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 Uploads" 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);
                }
                break;
            }
        }
Пример #2
0
        private async void Initialize()
        {
            if (SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServer, false))
            {
                this.AppVersion = string.Format("{0} (staging)", AppService.GetAppVersion());
            }
            else if (SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServerPort444, false))
            {
                this.AppVersion = string.Format("{0} (staging:444)", AppService.GetAppVersion());
            }
            else
            {
                this.AppVersion = AppService.GetAppVersion();
            }

            this.MegaSdkVersion = AppService.GetMegaSDK_Version();

            // Initialize the PIN lock code setting
            SetField(ref this._isPinLockEnabled,
                     SettingsService.LoadSetting <bool>(SettingsResources.UserPinLockIsEnabled, false),
                     "IsMultiFactorAuthEnabled");

            // Do not set the property on initialize, because it fill fire the SetAutoCameraUploadStatus
            _cameraUploadsIsEnabled         = MediaService.GetAutoCameraUploadStatus();
            this.CameraUploadsIsEnabledText = _cameraUploadsIsEnabled ? UiResources.On : UiResources.Off;

            #if WINDOWS_PHONE_80
            this.ExportIsEnabled = SettingsService.LoadSetting <bool>(SettingsResources.ExportImagesToPhotoAlbum, false);
            #elif WINDOWS_PHONE_81
            this.AskDownloadLocationIsEnabled = SettingsService.LoadSetting <bool>(SettingsResources.AskDownloadLocationIsEnabled, false);
            this.StandardDownloadLocation     = SettingsService.LoadSetting <string>(
                SettingsResources.DefaultDownloadLocation, UiResources.DefaultDownloadLocation);
            #endif

            this.IsMultiFactorAuthAvailable = SdkService.MegaSdk.multiFactorAuthAvailable();
            if (this.IsMultiFactorAuthAvailable)
            {
                var mfaStatus = await AccountService.CheckMultiFactorAuthStatusAsync();

                switch (mfaStatus)
                {
                case MultiFactorAuthStatus.Enabled:
                    SetField(ref this._isMultiFactorAuthEnabled, true, "IsMultiFactorAuthEnabled");
                    break;

                case MultiFactorAuthStatus.Disabled:
                    SetField(ref this._isMultiFactorAuthEnabled, false, "IsMultiFactorAuthEnabled");
                    break;

                case MultiFactorAuthStatus.Unknown:
                    OnUiThread(() =>
                    {
                        new CustomMessageDialog(UiResources.UI_Warning, AppMessages.AM_MFA_CheckStatusFailed,
                                                App.AppInformation, MessageDialogButtons.Ok).ShowDialog();
                    });
                    break;
                }
            }
        }
Пример #3
0
        public SettingsViewModel(MegaSDK megaSdk, AppInformation appInformation)
            : base(megaSdk, appInformation)
        {
            this.AppVersion              = AppService.GetAppVersion();
            this.MegaSdkVersion          = AppService.GetMegaSDK_Version();
            this.ShareRecoveryKeyCommand = new DelegateCommand(ShareRecoveryKey);
            this.CopyRecoveryKeyCommand  = new DelegateCommand(CopyRecoveryKey);
            this.ChangePinLockCommand    = new DelegateCommand(ChangePinLock);
            this.ViewRecoveryKeyCommand  = new DelegateCommand(ViewRecoveryKey);

            #if WINDOWS_PHONE_80
            this.SelectDownloadLocationCommand = null;
            #elif WINDOWS_PHONE_81
            this.SelectDownloadLocationCommand = new DelegateCommand(SelectDownloadLocation);
            #endif

            this.MegaSdkCommand                  = new DelegateCommand(NavigateToMegaSdk);
            this.GoedWareCommand                 = new DelegateCommand(NavigateToGoedWare);
            this.TermsOfServiceCommand           = new DelegateCommand(NavigateToTermsOfService);
            this.PrivacyPolicyCommand            = new DelegateCommand(NavigateToPrivacyPolicy);
            this.CopyrightCommand                = new DelegateCommand(NavigateToCopyright);
            this.TakedownGuidanceCommand         = new DelegateCommand(NavigateToTakedownGuidance);
            this.GeneralCommand                  = new DelegateCommand(NavigateToGeneral);
            this.DataProtectionRegulationCommand =
                new DelegateCommand(NavigateToDataProtectionRegulation);

            this.PinLockIsEnabled = SettingsService.LoadSetting <bool>(SettingsResources.UserPinLockIsEnabled, false);

            // Do not set the property on initialize, because it fill fire the SetAutoCameraUploadStatus
            _cameraUploadsIsEnabled         = MediaService.GetAutoCameraUploadStatus();
            this.CameraUploadsIsEnabledText = _cameraUploadsIsEnabled ? UiResources.On : UiResources.Off;

            #if WINDOWS_PHONE_80
            this.ExportIsEnabled = SettingsService.LoadSetting <bool>(SettingsResources.ExportImagesToPhotoAlbum, false);
            #elif WINDOWS_PHONE_81
            this.AskDownloadLocationIsEnabled = SettingsService.LoadSetting <bool>(SettingsResources.AskDownloadLocationIsEnabled, false);
            this.StandardDownloadLocation     = SettingsService.LoadSetting <string>(
                SettingsResources.DefaultDownloadLocation, UiResources.DefaultDownloadLocation);
            #endif

            UpdateUserData();

            InitializeMenu(HamburgerMenuItemType.Settings);
        }
        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 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;

            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 virtual 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 (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));
                }
            }
            else if (e.getErrorCode() == MErrorType.API_EBLOCKED)
            {
                // If the account has been blocked
                api.logout(new LogOutRequestListener(false));

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                          NavigateService.NavigateTo(typeof(InitTourPage), NavigationParameter.API_EBLOCKED));
            }
            else if (e.getErrorCode() == MErrorType.API_EOVERQUOTA)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    // Stop all upload transfers
                    api.cancelTransfers((int)MTransferType.TYPE_UPLOAD);

                    // Disable the "camera upload" service if is enabled
                    if (MediaService.GetAutoCameraUploadStatus())
                    {
                        LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Disabling CAMERA UPLOADS service (API_EOVERQUOTA)");
                        MediaService.SetAutoCameraUpload(false);
                        SettingsService.SaveSetting(SettingsResources.CameraUploadsIsEnabled, false);
                    }

                    DialogService.ShowOverquotaAlert();
                });
            }
            else 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();
                    });
                }
            }
        }
Пример #6
0
        public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            this.api = api;

            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;
            }
        }