示例#1
0
        /// <summary>
        /// Clear settings values we do no longer use.
        /// </summary>
        public static void ClearObsoleteSettings()
        {
            var lastAppVersion = SettingsService.Load <string>(
                ResourceService.SettingsResources.GetString("SR_LastAppVersion"), null);

            if (lastAppVersion == null)
            {
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Clear settings values we do no longer use.
        /// </summary>
        public static void ClearObsoleteSettings()
        {
            // If is the first run of the app, remove a possible session of a previous installation
            if (SettingsService.Load(ResourceService.SettingsResources.GetString("SR_AppFirstRun"), true))
            {
                SettingsService.RemoveSessionFromLocker();
                SettingsService.Save(ResourceService.SettingsResources.GetString("SR_AppFirstRun"), false);
            }

            var lastAppVersion = SettingsService.Load <string>(
                ResourceService.SettingsResources.GetString("SR_LastAppVersion"), null);

            if (lastAppVersion == null)
            {
                return;
            }
        }
示例#3
0
        /// <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");

            // Use custom DNS servers
            SetDnsServers();

            // Set the ID for statistics
            MegaSDK.setStatsID(DeviceService.GetDeviceId());

            // 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.Load(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), false))
            {
                MegaSdk.changeApiUrl(ResourceService.AppResources.GetString("AR_StagingUrl"));
                MegaSdkFolderLinks.changeApiUrl(ResourceService.AppResources.GetString("AR_StagingUrl"));
            }
            else if (SettingsService.Load(ResourceService.SettingsResources.GetString("SR_UseStagingServerPort444"), false))
            {
                MegaSdk.changeApiUrl(ResourceService.AppResources.GetString("AR_StagingUrlPort444"), true);
                MegaSdkFolderLinks.changeApiUrl(ResourceService.AppResources.GetString("AR_StagingUrlPort444"), true);
            }
        }
示例#4
0
        /// <summary>
        /// Change the API URL.
        /// </summary>
        private static async void ChangeApiUrl()
        {
            StopChangeApiUrlTimer();

            // If user was enabling the Debug Mode, abort the API URL change to avoid do it accidentally
            if (_enablingDebugMode)
            {
                _enablingDebugMode = false;
                return;
            }

            var useStagingServer = SettingsService.Load(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), false) ||
                                   SettingsService.Load(ResourceService.SettingsResources.GetString("SR_UseStagingServerPort444"), false);

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

                if (!result)
                {
                    return;
                }
            }
            else
            {
                SettingsService.Save(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), false);
                SettingsService.Save(ResourceService.SettingsResources.GetString("SR_UseStagingServerPort444"), false);
                MegaSdk.changeApiUrl(ResourceService.AppResources.GetString("AR_ApiUrl"));
                MegaSdkFolderLinks.changeApiUrl(ResourceService.AppResources.GetString("AR_ApiUrl"));
            }

            // Reset the "Camera Uploads" service if is enabled
            if (TaskService.IsBackGroundTaskActive(CameraUploadService.TaskEntryPoint, CameraUploadService.TaskName))
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Resetting CAMERA UPLOADS service (API URL changed)");
                await TaskService.RegisterBackgroundTaskAsync(
                    CameraUploadService.TaskEntryPoint, CameraUploadService.TaskName,
                    new TimeTrigger(CameraUploadService.TaskTimeTrigger, false));
            }

            OnApiUrlChanged();
        }
示例#5
0
        /// <summary>
        /// Change the API URL.
        /// </summary>
        private static async void ChangeApiUrl()
        {
            StopChangeApiUrlTimer();

            var useStagingServer = SettingsService.Load(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), false);

            if (!useStagingServer)
            {
                var result = await DialogService.ShowOkCancelAsync("Change to a testing server?",
                                                                   "Are you sure you want to change to a testing server? Your account may run irrecoverable problems.");

                if (!result)
                {
                    return;
                }
            }

            useStagingServer = !useStagingServer;

            var newApiUrl = useStagingServer ?
                            ResourceService.AppResources.GetString("AR_StagingUrl") :
                            ResourceService.AppResources.GetString("AR_ApiUrl");

            MegaSdk.changeApiUrl(newApiUrl);
            MegaSdkFolderLinks.changeApiUrl(newApiUrl);

            SettingsService.Save(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), useStagingServer);

            // Reset the "Camera Uploads" service if is enabled
            if (TaskService.IsBackGroundTaskActive(CameraUploadService.TaskEntryPoint, CameraUploadService.TaskName))
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Resetting CAMERA UPLOADS service (API URL changed)");
                await TaskService.RegisterBackgroundTaskAsync(
                    CameraUploadService.TaskEntryPoint, CameraUploadService.TaskName,
                    new TimeTrigger(CameraUploadService.TaskTimeTrigger, false));
            }

            OnApiUrlChanged();
        }
示例#6
0
        /// <summary>
        /// Check if unique receipt id is already stored in local user settings
        /// </summary>
        /// <param name="receipt">Windows Store receipt xml</param>
        /// <returns>True if already stored in settings, else False</returns>
        private static bool CheckReceiptIdStatus(string receipt)
        {
            try
            {
                var uniqueId = GetUniqueReceiptId(receipt);
                // return true to stop activation of receipt
                if (uniqueId == null)
                {
                    return(true);
                }

                var key            = ResourceService.SettingsResources.GetString("SR_Receipts");
                var currentIds     = SettingsService.Load(key, string.Empty);
                var currentIdsList = currentIds.Split(';');

                return(currentIdsList.Any(id => id.Equals(uniqueId)));
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failed to check receipt ID status", e);
                return(false);
            }
        }
示例#7
0
        /// <summary>
        /// Save the unique receipt id to local user settings
        /// </summary>
        /// <param name="receipt">Windows Store receipt xml</param>
        /// <returns>True if save succeeded, else False</returns>
        private static bool SaveUniqueReceiptId(string receipt)
        {
            try
            {
                var key        = ResourceService.SettingsResources.GetString("SR_Receipts");
                var currentIds = SettingsService.Load(key, string.Empty);
                var id         = GetUniqueReceiptId(receipt);

                if (id == null)
                {
                    return(false);
                }

                currentIds += id + ";";
                SettingsService.Save(key, currentIds);

                return(true);
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failed to save receipt ID", e);
                return(false);
            }
        }