Esempio n. 1
0
 /// <summary>
 /// Helper that writes objects to the local storage
 /// </summary>
 /// <param name="name"></param>
 /// <param name="obj"></param>
 public void WriteToLocalSettings <T>(string name, T obj)
 {
     try
     {
         LocalSettings[name] = JsonConvert.SerializeObject(obj);
     }
     catch (Exception e)
     {
         _baconMan.MessageMan.DebugDia("failed to write setting " + name, e);
         TelemetryManager.ReportUnexpectedEvent(this, "failedToWriteSetting" + name, e);
     }
 }
Esempio n. 2
0
 public async void ShowRedditDownMessage()
 {
     await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
     {
         try
         {
             var showStatus = await ShowYesNoMessage("Reddit is Down", "It looks like reddit is down right now. Go outside for a while and try again in a few minutes.", "Check Reddit's Status", "Go Outside");
             if (showStatus.HasValue && showStatus.Value)
             {
                 _baconMan.ShowGlobalContent("http://www.redditstatus.com/");
             }
         }
         catch (Exception e)
         {
             TelemetryManager.ReportUnexpectedEvent(this, "FailedToShowMessage", e);
         }
     });
 }
Esempio n. 3
0
        private async void ShowMessage(string content, string title)
        {
            // Don't show messages if we are in the background.
            if (_baconMan.IsBackgroundTask)
            {
                return;
            }

            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    var message = new MessageDialog(content, title);
                    await message.ShowAsync();
                }
                catch (Exception e)
                {
                    TelemetryManager.ReportUnexpectedEvent(this, "FailedToShowMessage", e);
                }
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Saves a current post to the draft file.
        /// </summary>
        /// <param name="data"></param>
        public async Task <bool> SavePostSubmissionDraft(PostSubmissionDraftData data)
        {
            try
            {
                // Get the folder and file.
                var folder = ApplicationData.Current.LocalFolder;
                var file   = await folder.CreateFileAsync(PostDraftFile, CreationCollisionOption.ReplaceExisting);

                // Serialize the data
                var fileData = JsonConvert.SerializeObject(data);

                // Write to the file
                await FileIO.WriteTextAsync(file, fileData);
            }
            catch (Exception e)
            {
                _baconMan.MessageMan.DebugDia("failed to write draft", e);
                TelemetryManager.ReportUnexpectedEvent(this, "FailedToWriteDraftFile", e);
                return(false);
            }
            return(true);
        }
Esempio n. 5
0
        public BaconManager(bool isBackgroundTask)
        {
            // Set background task flag
            IsBackgroundTask = isBackgroundTask;

            // Init managers
            UserMan = new UserManager(this);
            CacheMan = new CacheManager(this);
            ImageMan = new ImageManager(this);
            SubredditMan = new SubredditManager(this);
            SettingsMan = new SettingsManager(this);
            NetworkMan = new NetworkManager(this);
            MessageMan = new MessageManager(this);
            UiSettingsMan = new UiSettingManager(this);
            TelemetryMan = new TelemetryManager();
            BackgroundMan = new BackgroundManager(this);
            MotdMan = new MessageOfTheDayManager(this);

            // Don't do this if we are a background task; it will
            // call this when it is ready.
            if (!isBackgroundTask)
            {
                FireOffUpdate();
            }
        }
Esempio n. 6
0
        public BaconManager(bool isBackgroundTask)
        {
            // Set background task flag
            IsBackgroundTask = isBackgroundTask;

            // Init managers
            UserMan = new UserManager(this);
            CacheMan = new CacheManager(this);
            ImageMan = new ImageManager(this);
            SubredditMan = new SubredditManager(this);
            SettingsMan = new SettingsManager(this);
            NetworkMan = new NetworkManager(this);
            MessageMan = new MessageManager(this);
            UiSettingsMan = new UiSettingManager(this);
            TelemetryMan = new TelemetryManager();
            BackgroundMan = new BackgroundManager(this);
            MotdMan = new MessageOfTheDayManager(this);
            TileMan = new TileManager(this);
            DraftMan = new DraftManager(this);

            // Don't do this if we are a background task; it will
            // call this when it is ready.
            if (!isBackgroundTask)
            {
                FireOffUpdate();
            }

            // Setup the in between invoke handler for the onBackButton event. This will allow us to stop
            // calling the handlers when one returns true.
            m_onBackButton.SetInBetweenInvokesAction(new Func<EventArgs, bool>(InBetweenInvokeHandlerForOnBackButton));
        }
Esempio n. 7
0
        /// <summary>
        /// Used to make sure the background task is setup.
        /// </summary>
        public async Task EnsureBackgroundSetup()
        {
            // Try to find any task that we might have
            IBackgroundTaskRegistration foundTask = null;

            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                if (task.Value.Name.Equals(BackgroundTaskName))
                {
                    foundTask = task.Value;
                }
            }

            // For some dumb reason in WinRT we have to ask for permission to run in the background each time
            // our app is updated....
            var currentAppVersion =
                $"{Package.Current.Id.Version.Build}.{Package.Current.Id.Version.Major}.{Package.Current.Id.Version.Minor}.{Package.Current.Id.Version.Revision}";

            if (string.IsNullOrWhiteSpace(AppVersionWithBackgroundAccess) || !AppVersionWithBackgroundAccess.Equals(currentAppVersion))
            {
                // Update current version
                AppVersionWithBackgroundAccess = currentAppVersion;

                // Remove access... stupid winrt.
                BackgroundExecutionManager.RemoveAccess();
            }

            // Request access to run in the background.
            var status = await BackgroundExecutionManager.RequestAccessAsync();

            LastSystemBackgroundUpdateStatus = (int)status;
            if (status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy && status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                _baconMan.MessageMan.DebugDia("System denied us access from running in the background");
            }

            if (ImageUpdaterMan.IsLockScreenEnabled || ImageUpdaterMan.IsDesktopEnabled || MessageUpdaterMan.IsEnabled)
            {
                if (foundTask == null)
                {
                    // We need to make a new task
                    var builder = new BackgroundTaskBuilder
                    {
                        Name = BackgroundTaskName, TaskEntryPoint = "BaconBackground.BackgroundEntry"
                    };
                    builder.SetTrigger(new TimeTrigger(BackgroundUpdateTime, false));
                    builder.SetTrigger(new MaintenanceTrigger(BackgroundUpdateTime, false));

                    try
                    {
                        builder.Register();
                    }
                    catch (Exception e)
                    {
                        TelemetryManager.ReportUnexpectedEvent(this, "failed to register background task", e);
                        _baconMan.MessageMan.DebugDia("failed to register background task", e);
                    }
                }
            }
            else
            {
                // We need to stop and unregister the background task.
                foundTask?.Unregister(true);
            }
        }