public static void ClearObsoleteSettings() { var lastAppVersion = SettingsService.LoadSetting <string>(SettingsResources.LastAppVersion, null); if (lastAppVersion == null) { SettingsService.DeleteSetting(SettingsResources.QuestionAskedDownloadOption); } }
/// <summary> /// Clear settings values we do no longer use. /// </summary> public static void ClearObsoleteSettings() { var lastAppVersion = SettingsService.LoadSetting <string>(SettingsResources.LastAppVersion, null); if (lastAppVersion == null) { return; } }
public static bool HasValidSession() { try { if (SettingsService.LoadSetting <string>(SettingsResources.UserMegaSession) != null) { return(true); } else { return(false); } } catch (ArgumentNullException) { return(false); } }
/// <summary> /// Initialize all the SDK parameters /// </summary> public static void InitializeSdkParams() { //The next line enables a custom logger, if this function is not used OutputDebugString() is called //in the native library and log messages are only readable with the native debugger attached. //The default behavior of MegaLogger() is to print logs using Debug.WriteLine() but it could //be used to sends log to a file, for example. LogService.AddLoggerObject(LogService.MegaLogger); //You can select the maximum output level for debug messages. //By default FATAL, ERROR, WARNING and INFO will be enabled //DEBUG and MAX can only be enabled in Debug builds, they are ignored in Release builds MegaSDK.setLogLevel(MLogLevel.LOG_LEVEL_DEBUG); //You can send messages to the logger using MEGASDK.log(), those messages will be received //in the active logger LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Example log message"); // Set the ID for statistics try { MegaSDK.setStatsID(Convert.ToBase64String((byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"))); } catch (NotSupportedException e) { LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Error setting the device unique ID for statistics", e); } // Set the language code used by the app var appLanguageCode = AppService.GetAppLanguageCode(); if (!MegaSdk.setLanguage(appLanguageCode) || !MegaSdkFolderLinks.setLanguage(appLanguageCode)) { LogService.Log(MLogLevel.LOG_LEVEL_WARNING, string.Format("Invalid app language code '{0}'", appLanguageCode)); } // Change the API URL if required by settings if (SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServer, false)) { MegaSdk.changeApiUrl(AppResources.AR_StagingUrl); MegaSdkFolderLinks.changeApiUrl(AppResources.AR_StagingUrl); } else if (SettingsService.LoadSetting <bool>(SettingsResources.UseStagingServerPort444, false)) { MegaSdk.changeApiUrl(AppResources.AR_StagingUrlPort444, true); MegaSdkFolderLinks.changeApiUrl(AppResources.AR_StagingUrlPort444, true); } }
public static string GetSelectedDownloadDirectoryPath() { return(Path.Combine(SettingsService.LoadSetting <string>(SettingsResources.DefaultDownloadLocation, UiResources.DefaultDownloadLocation))); }
/// <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(); }