Ejemplo n.º 1
0
        // Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            // Log unhandled exception
            AppLogs.WriteError("App", e.ExceptionObject);

            if (Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                Debugger.Break();
            }
        }
Ejemplo n.º 2
0
        public static async Task WriteText(string fileName, string content)
        {
            try
            {
                var folder = FileSystem.Current.LocalStorage;
                var file   = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                await file.WriteAllTextAsync(content);
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("UserStorage.WriteText", ex);
            }
        }
Ejemplo n.º 3
0
        private void StartBackgroundProcess()
        {
            // Obtain a reference to the period task, if one exists
            _periodicTask = ScheduledActionService.Find(_periodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (_periodicTask != null)
            {
                RemoveAgent(_periodicTaskName);
            }

            _periodicTask = new PeriodicTask(_periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            _periodicTask.Description = "This demonstrates a periodic task.";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(_periodicTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if DEBUG
                ScheduledActionService.LaunchForTest(_periodicTaskName, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    AppLogs.WriteWarning("StartBackgroundProcess", "Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    AppLogs.WriteWarning("StartBackgroundProcess", "The system prompts the user when the hard limit of periodic tasks has been reached.");
                }
            }
            catch (Exception ex)
            {
                AppLogs.WriteWarning("StartBackgroundProcess", ex.Message);
            }
        }
Ejemplo n.º 4
0
        public static async Task DeleteFileIfExists(string fileName)
        {
            try
            {
                var folder = FileSystem.Current.LocalStorage;
                var file   = await folder.GetFileAsync(fileName);

                if (file != null)
                {
                    await file.DeleteAsync();
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("UserStorage.DeleteFileIfExists", ex);
            }
        }
Ejemplo n.º 5
0
        public static async Task DeleteFileIfExists(string fileName)
        {
            try
            {
                var folder = ApplicationData.Current.LocalFolder;
                var file   = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);

                if (file != null)
                {
                    await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("UserStorage.DeleteFileIfExists", ex);
            }
        }
Ejemplo n.º 6
0
        public static async Task <string> ReadTextFromFile(string fileName)
        {
            try
            {
                var folder = FileSystem.Current.LocalStorage;
                var file   = await folder.GetFileAsync(fileName);

                if (file != null)
                {
                    return(await file.ReadAllTextAsync());
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("UserStorage.ReadTextFromFile", ex);
            }
            return(String.Empty);
        }
Ejemplo n.º 7
0
 static public string ReadTextFromFile(string fileName)
 {
     try
     {
         using (var userStorage = new UserStorage())
         {
             lock (_userStoreLock)
             {
                 if (userStorage.FileExists(fileName))
                 {
                     return(userStorage.ReadText(fileName));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         AppLogs.WriteError("UserStorage.ReadTextFromFile", ex);
     }
     return(String.Empty);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Log application start
            AppLogs.WriteInfo("App", "Started");

            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                //Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
        }