예제 #1
0
        private async void OkButtonClick(IUICommand command)
        {
            var authenticationManager = new AuthenticationManager();
            var result = await authenticationManager.Logout();

            var localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Values.ContainsKey(Constants.BOOKMARK_BACKGROUND))
            {
                BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                localSettings.Values[Constants.BOOKMARK_BACKGROUND] = false;
            }

            if (result)
            {
                Frame.Navigate(typeof(LoginPage));
            }
            else
            {
                var msgBox =
                    new MessageDialog("Could not log you out! You're stuck here forever! HA HA HA!",
                                      "Logout error");
                msgBox.ShowAsync();
            }
        }
예제 #2
0
        private async void SetupBackgroundServices()
        {
            IsIoT = ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController");

            if (IsIoT)
            {
                return;
            }

            TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
            BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.ToastBackgroundTaskName);
            var task2 = await
                        BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.ToastBackgroundTaskEntryPoint,
                                                                   BackgroundTaskUtils.ToastBackgroundTaskName, new ToastNotificationActionTrigger(),
                                                                   null);

            if (SettingsService.Instance.BackgroundEnable)
            {
                BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                var task = await
                           BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                      BackgroundTaskUtils.BackgroundTaskName,
                                                                      new TimeTrigger(15, false),
                                                                      null);
            }
        }
예제 #3
0
        private async void BookmarkLiveTiles_Toggled(object sender, RoutedEventArgs e)
        {
            try
            {
                var toggleSwitch = sender as ToggleSwitch;
                if (toggleSwitch == null)
                {
                    return;
                }
                if (toggleSwitch.IsOn)
                {
                    // Run bookmark live tile creator every 15 minutes.
                    // TODO: Change 15 to user selectable value.
                    BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                    BackgroundTaskRegistration task = await
                                                      BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                                                 BackgroundTaskUtils.BackgroundTaskName,
                                                                                                 new TimeTrigger(15, false),
                                                                                                 null);

                    _localSettings.Values[Constants.BOOKMARK_BACKGROUND] = true;
                }
                else
                {
                    BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                    _localSettings.Values[Constants.BOOKMARK_BACKGROUND] = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #4
0
        // Initialize Stuff
        public async void Initialize()
        {
            BackgroundTaskUtils.RegisterToastNotificationBackgroundTasks();
            ContactUtils.AssignAppToPhoneContacts();
            _store = await ChatMessageManager.RequestStoreAsync();

            ChatConversations = await GetChats();

            if (ChatConversations.Count != 0)
            {
                SelectedItem = ChatConversations[0];
            }

            if (!(await PerformMandatoryChecks()))
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              async() =>
                {
                    await new CellularUnavailableContentDialog().ShowAsync();
                });
            }

            _store.ChangeTracker.Enable();
            _store.StoreChanged += Store_StoreChanged;
        }
예제 #5
0
 private void RegisterBackgroundTask_Click(object sender, RoutedEventArgs e)
 {
     BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.SampleBackgroundTaskName);
     var task = BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.SampleBackgroundTaskEntryPoint,
                                                           BackgroundTaskUtils.SampleBackgroundTaskName,
                                                           new SystemTrigger(SystemTriggerType.UserAway, false),
                                                           null);
 }
예제 #6
0
        void LoadCompleted(object sender, NavigationEventArgs e)
        {
            //when load completed run some tasks in background

            BackgroundTaskUtils.RunBackgroundTaskWithParam("1", UpdateValuesFromPartitionTask, DoesNothing);
            BackgroundTaskUtils.RunBackgroundTaskWithParam("0", UpdateValuesFromPartitionTask, DoesNothing);
            BackgroundTaskUtils.RunBackgroundTask(CheckAudioTemperatureCommandTask);
        }
 private async void CreateBackgroundTask()
 {
     // We have login, so set up the background tasks.
     BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
     BackgroundTaskRegistration task = await
                                       BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                                  BackgroundTaskUtils.BackgroundTaskName,
                                                                                  new TimeTrigger(15, false),
                                                                                  null);
 }
예제 #8
0
        // runs even if restored from state
        public override async Task OnInitializeAsync(IActivatedEventArgs args)
        {
            // Setup Background
            var isIoT = ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController");

            if (!isIoT)
            {
                TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
                //BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.ToastBackgroundTaskName);
                //var task2 = await
                //    BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.ToastBackgroundTaskEntryPoint,
                //        BackgroundTaskUtils.ToastBackgroundTaskName, new ToastNotificationActionTrigger(),
                //        null);

                if (Settings.BackgroundEnable)
                {
                    BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                    var task = await
                               BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                          BackgroundTaskUtils.BackgroundTaskName,
                                                                          new TimeTrigger(15, false),
                                                                          null);
                }
            }

            var launch = args as LaunchActivatedEventArgs;

            if (launch?.PreviousExecutionState == ApplicationExecutionState.NotRunning ||
                launch?.PreviousExecutionState == ApplicationExecutionState.Terminated ||
                launch?.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
            {
                // setup hamburger shell
                Frame = new Frame();
                var nav   = NavigationServiceFactory(BackButton.Attach, ExistingContent.Include, Frame);
                var shell = new Shell(nav);
                if (Shell.Instance.ViewModel.CurrentUser == null)
                {
                    var userAccountDatabase = new UserAccountDatabase(new SQLitePlatformWinRT(), DatabaseWinRTHelpers.GetWinRTDatabasePath(StringConstants.UserDatabase));
                    if (await userAccountDatabase.HasDefaultAccounts())
                    {
                        try
                        {
                            var result = await Shell.Instance.ViewModel.LoginDefaultUser();
                        }
                        catch (Exception)
                        {
                            // error happened, send them to account page so we can check on it.
                        }
                    }
                }
                Window.Current.Content = shell;
            }

            await Task.CompletedTask;
        }
예제 #9
0
 public async void ChangeBackgroundStatus(bool value)
 {
     if (value)
     {
         var task = await
                    BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                               BackgroundTaskUtils.BackgroundTaskName,
                                                               new TimeTrigger(15, false),
                                                               null);
     }
     else
     {
         BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
     }
 }
예제 #10
0
        /*
         *  invoked when javascript invokes C#
         */
        async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            string value = e.Value;

            //invokes corresponding process depending on what value is sent by javascript
            if (value.Contains("temperature="))
            {
                var tempValueCommand = value;
                BackgroundTaskUtils.RunBackgroundTaskWithParam(tempValueCommand, SendCloudToDevice.SendCommand, UpdateCommandTimestampTask);
            }
            else if (value == "enable_speech")
            {
                SpeechRecognitionEngine.RecognizeSpeech();
                //uncomment row below and comment row above for continuous speech mechanism
                //ContinuousSpeechRecognitionEngine.InitContinuousSpeechRecognition();
            }
            else if (value == "disable_speech")
            {
                ContinuousSpeechRecognitionEngine.StopSpeechRecognitionMechanism();
            }
        }
예제 #11
0
        private async void Load()
        {
            BackgroundTaskUtils.RegisterToastNotificationBackgroundTasks();
            ContactUtils.AssignAppToPhoneContacts();
            ChatMessageStore store = await ChatMessageManager.RequestStoreAsync();

            var reader = store.GetConversationReader();
            var convos = await reader.ReadBatchAsync();

            bool initializedonce = false;

            foreach (var convo in convos)
            {
                NavigationView.MenuItems.Add(new ChatMenuItemControl(convo));

                if (!initializedonce)
                {
                    NavigationView.SelectedItem = NavigationView.MenuItems[0];
                }

                initializedonce = true;
            }
        }
예제 #12
0
        /// <summary>
        /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
        /// アプリケーションが特定のファイルを開くために起動されたときなどに使用されます。
        /// </summary>
        /// <param name="e">起動の要求とプロセスの詳細を表示します。</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            if (_localSettings.Values.ContainsKey(Constants.ThemeDefault))
            {
                var themeType = (ThemeTypes)_localSettings.Values[Constants.ThemeDefault];
                switch (themeType)
                {
                case ThemeTypes.YOSPOS:
                    ThemeManager.SetThemeManager(ElementTheme.Dark);
                    ThemeManager.ChangeTheme(new Uri("ms-appx:///Themes/Yospos.xaml"));
                    break;
                }
            }
            SystemNavigationManager.GetForCurrentView().BackRequested += BackPressed;
            RootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (RootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                RootFrame = new Frame();
                // Set the default language
                RootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                RootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = RootFrame;
            }

            if (_localSettings.Values.ContainsKey(Constants.BookmarkBackground) && (bool)_localSettings.Values[Constants.BookmarkBackground])
            {
                BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                var task = await
                           BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                      BackgroundTaskUtils.BackgroundTaskName,
                                                                      new TimeTrigger(15, false),
                                                                      null);
            }

            var             localStorageManager = new LocalStorageManager();
            CookieContainer cookieTest          = await localStorageManager.LoadCookie("SACookies2.txt");

            if (cookieTest.Count <= 0)
            {
                if (!RootFrame.Navigate(typeof(LoginPage)))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            else
            {
                if (!RootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
예제 #13
0
        /// <summary>
        /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
        /// アプリケーションが特定のファイルを開くために起動されたときなどに使用されます。
        /// </summary>
        /// <param name="e">起動の要求とプロセスの詳細を表示します。</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            await JumpListCreator.CreateDefaultList();

            if (_localSettings.Values.ContainsKey(Constants.ThemeDefault))
            {
                var themeType = (ThemeTypes)_localSettings.Values[Constants.ThemeDefault];
                switch (themeType)
                {
                case ThemeTypes.YOSPOS:
                    ThemeManager.SetThemeManager(ElementTheme.Dark);
                    ThemeManager.ChangeTheme(new Uri("ms-appx:///Themes/Yospos.xaml"));
                    break;
                }
            }
            SystemNavigationManager.GetForCurrentView().BackRequested += BackPressed;
            RootFrame = Window.Current.Content as Frame;
            if (_localSettings.Values.ContainsKey(Constants.NavigateBack) &&
                (bool)_localSettings.Values[Constants.NavigateBack])
            {
                if (RootFrame != null)
                {
                    return;
                }
            }
            var isIoT = ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController");

            if (!isIoT)
            {
                TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
            }

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (RootFrame == null)
            {
                CreateRootFrame();
            }
            if (!isIoT)
            {
                BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.ToastBackgroundTaskName);
                var task2 = await
                            BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.ToastBackgroundTaskEntryPoint,
                                                                       BackgroundTaskUtils.ToastBackgroundTaskName, new ToastNotificationActionTrigger(),
                                                                       null);

                if (_localSettings.Values.ContainsKey(Constants.BackgroundEnable) && (bool)_localSettings.Values[Constants.BackgroundEnable])
                {
                    BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                    var task = await
                               BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                          BackgroundTaskUtils.BackgroundTaskName,
                                                                          new TimeTrigger(15, false),
                                                                          null);
                }
            }

            var             localStorageManager = new LocalStorageManager();
            CookieContainer cookieContainer     = await localStorageManager.LoadCookie("SACookies2.txt");

            bool cookieTest = true;
            foreach (Cookie cookie in cookieContainer.GetCookies(new Uri(Constants.CookieDomainUrl)))
            {
                if (cookie.Expired)
                {
                    cookieTest = false;
                }
            }

            if (cookieContainer.Count <= 0)
            {
                if (!RootFrame.Navigate(typeof(LoginPage)))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            else
            {
                if (!cookieTest)
                {
                    if (!RootFrame.Navigate(typeof(LoginPage)))
                    {
                        throw new Exception("Failed to create initial page");
                    }
                }

                if (!RootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();

            try
            {
                // Install the main VCD. Since there's no simple way to test that the VCD has been imported, or that it's your most recent
                // version, it's not unreasonable to do this upon app load.
                StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"SomethingAwfulCommands.xml");

                await Windows.ApplicationModel.VoiceCommands.VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Installing Voice Commands Failed: " + ex.ToString());
            }
        }
예제 #14
0
        private async void SaveSettings_OnClick(object sender, RoutedEventArgs e)
        {
            if (BackgroundNotificationsSwitch.IsOn)
            {
                BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                var task = await
                           BackgroundTaskUtils.RegisterBackgroundTask(BackgroundTaskUtils.BackgroundTaskEntryPoint,
                                                                      BackgroundTaskUtils.BackgroundTaskName,
                                                                      new TimeTrigger(15, false),
                                                                      null);

                _localSettings.Values[Constants.BackgroundEnable] = true;
            }
            else
            {
                try
                {
                    BackgroundTaskUtils.UnregisterBackgroundTasks(BackgroundTaskUtils.BackgroundTaskName);
                }
                catch (Exception)
                {
                    // TODO: Tell user background task failed to unregister :(
                }
                _localSettings.Values[Constants.BackgroundEnable] = false;
            }

            _localSettings.Values[Constants.ThemeDefault] = ThemeComboBox.SelectedIndex;


            if (BookmarkLiveTiles.IsOn)
            {
                // Run bookmark live tile creator every 15 minutes.
                // TODO: Change 15 to user selectable value.
                _localSettings.Values[Constants.BookmarkBackground] = true;
            }
            else
            {
                _localSettings.Values[Constants.BookmarkBackground] = false;
            }

            if (BookmarkNotificationsSwitch.IsOn)
            {
                // Run bookmark live tile creator every 15 minutes.
                // TODO: Change 15 to user selectable value.
                _localSettings.Values[Constants.BookmarkNotifications] = true;
            }
            else
            {
                _localSettings.Values[Constants.BookmarkNotifications] = false;
            }

            if (KeepCurrentViewSwitch.IsOn)
            {
                _localSettings.Values[Constants.NavigateBack] = true;
            }
            else
            {
                _localSettings.Values[Constants.NavigateBack] = false;
            }

            if (InternetEnable.IsOn)
            {
                _localSettings.Values[Constants.OpenInBrowser] = true;
            }
            else
            {
                _localSettings.Values[Constants.OpenInBrowser] = false;
            }

            if (LoadBookmarksOnLoadSwitch.IsOn)
            {
                _localSettings.Values[Constants.BookmarkStartup] = true;
            }
            else
            {
                _localSettings.Values[Constants.BookmarkStartup] = false;
            }

            _localSettings.Values[Constants.BookmarkDefault] = FilterComboBox.SelectedIndex;

            if (DarkLightThemeSwitch.IsOn)
            {
                _localSettings.Values[Constants.DarkMode] = true;
            }
            else
            {
                _localSettings.Values[Constants.DarkMode] = false;
            }

            if (AutoReloadSwitch.IsOn)
            {
                _localSettings.Values[Constants.AutoRefresh] = true;
            }
            else
            {
                _localSettings.Values[Constants.AutoRefresh] = false;
            }
        }