Beispiel #1
0
        /// <summary>
        /// Log in to a MEGA account using a session key and show an alert if something went wrong.
        /// </summary>
        /// <param name="progressHeaderText">Customized header text to display during the process (optional).</param>
        /// <returns>TRUE if all was well or FALSE in other case.</returns>
        public async Task <bool> FastLoginAsync(string progressHeaderText = null)
        {
            // Reset the flag to store if the account has been blocked
            AccountService.IsAccountBlocked = false;

            var fastLogin = new FastLoginRequestListenerAsync();

            fastLogin.IsWaiting += OnIsWaiting;

            bool fastLoginResult;

            try
            {
                this.ControlState = false;
                this.IsBusy       = true;

                this.ProgressHeaderText = progressHeaderText ?? ResourceService.ProgressMessages.GetString("PM_FastLoginHeader");
                this.ProgressText       = ResourceService.ProgressMessages.GetString("PM_LoginSubHeader");

                fastLoginResult = await fastLogin.ExecuteAsync(async() =>
                                                               this.MegaSdk.fastLogin(await SettingsService.LoadSessionFromLockerAsync(), fastLogin));
            }
            // Do nothing, app is already logging out
            catch (BadSessionIdException)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Login failed. Bad session ID.");
                return(false);
            }

            if (!fastLoginResult)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Resume session failed.");

                if (!AccountService.IsAccountBlocked)
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.UiResources.GetString("UI_ResumeSession"),
                        ResourceService.AppMessages.GetString("AM_ResumeSessionFailed"));
                }

                return(false);
            }

            // Validate product subscription license on background thread
            Task.Run(() => LicenseService.ValidateLicensesAsync());

            // Fetch nodes from MEGA
            var fetchNodesResult = await this.FetchNodes();

            if (fetchNodesResult != FetchNodesResult.Success)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Fetch nodes failed.");
                if (!AccountService.IsAccountBlocked)
                {
                    this.ShowFetchNodesFailedAlertDialog();
                }
                return(false);
            }

            // If is required show the password reminder dialog on background thread
            Task.Run(async() =>
            {
                if (await AccountService.ShouldShowPasswordReminderDialogAsync(false))
                {
                    UiService.OnUiThread(() => DialogService.ShowPasswordReminderDialog(false));
                }
            });

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Change the API URL.
        /// </summary>
        private static async void ChangeApiUrl()
        {
            StopChangeApiUrlTimer();

            var usingStagingServer = SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServer, false) ||
                                     SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServerPort444, false);

            if (!usingStagingServer)
            {
                var result = await DialogService.ShowChangeToStagingServerDialog();

                if (!result)
                {
                    return;
                }
            }
            else
            {
                SettingsService.SaveSetting <bool>(SettingsResources.UseStagingServer, false);
                SettingsService.SaveSetting <bool>(SettingsResources.UseStagingServerPort444, false);
                MegaSdk.changeApiUrl(AppResources.AR_ApiUrl);
                MegaSdkFolderLinks.changeApiUrl(AppResources.AR_ApiUrl);
            }

            // If the user is logged in, do a new login with the current session
            if (Convert.ToBoolean(MegaSdk.isLoggedIn()))
            {
                bool fastLoginResult;
                try
                {
                    var fastLogin = new FastLoginRequestListenerAsync();
                    fastLoginResult = await fastLogin.ExecuteAsync(() =>
                                                                   MegaSdk.fastLogin(SettingsService.LoadSetting <string>(SettingsResources.UserMegaSession), fastLogin));
                }
                // Do nothing, app is already logging out
                catch (BadSessionIdException)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Login failed. Bad session ID.");
                    return;
                }

                if (fastLoginResult)
                {
                    // Fetch nodes from MEGA
                    var fetchNodes       = new FetchNodesRequestListenerAsync();
                    var fetchNodesResult = await fetchNodes.ExecuteAsync(() => MegaSdk.fetchNodes(fetchNodes));

                    if (fetchNodesResult != FetchNodesResult.Success)
                    {
                        LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Fetch nodes failed.");
                        new CustomMessageDialog(AppMessages.FetchingNodesFailed_Title, AppMessages.FetchingNodesFailed,
                                                App.AppInformation, MessageDialogButtons.Ok).ShowDialog();
                    }
                }
                else
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Resume session failed.");
                    new CustomMessageDialog(UiResources.UI_ResumeSession, AppMessages.AM_ResumeSessionFailed,
                                            App.AppInformation, MessageDialogButtons.Ok).ShowDialog();
                }
            }

            // Reset the "Camera Uploads" service if is enabled
            if (MediaService.GetAutoCameraUploadStatus())
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Resetting CAMERA UPLOADS service (API URL changed)");
                SettingsService.SaveSetting(SettingsResources.CameraUploadsIsEnabled,
                                            MediaService.SetAutoCameraUpload(true));
            }

            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "API URL changed");
            new CustomMessageDialog(null, "API URL changed",
                                    App.AppInformation, MessageDialogButtons.Ok).ShowDialog();

            OnApiUrlChanged();
        }