Ejemplo n.º 1
0
        public static void LogoutActions()
        {
            // Disable the "camera upload" service if is enabled
            if (MediaService.GetAutoCameraUploadStatus())
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Disabling CAMERA UPLOADS service (LOGOUT)");
                MediaService.SetAutoCameraUpload(false);
            }

            // Clear settings, cache, previews, thumbnails, etc.
            SettingsService.ClearSettings();
            SettingsService.ClearMegaLoginData();
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // Added extra checks preventing null reference exceptions
                if (App.MainPageViewModel == null)
                {
                    return;
                }

                if (App.MainPageViewModel.CloudDrive != null)
                {
                    App.MainPageViewModel.CloudDrive.ChildNodes.Clear();
                }

                if (App.MainPageViewModel.RubbishBin != null)
                {
                    App.MainPageViewModel.RubbishBin.ChildNodes.Clear();
                }
            });
            AppService.ClearAppCache(false);

            // Delete Account Details info
            AccountService.ClearAccountDetails();
        }
Ejemplo n.º 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();
        }