Example #1
0
        private void NavSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            var item = args.SelectedItem as NavigationViewItem;

            switch (item.Tag)
            {
            case "UserTile":
                ContentFrame.Navigate(typeof(Settings));
                break;

            case "ProfessorList":
                ContentFrame.Navigate(typeof(Professors));
                break;

            default:
                foreach (var course in CurrentUserCourses)
                {
                    if ($"course{course.CourseID}" != item.Tag.ToString())
                    {
                        continue;
                    }
                    LocalStorage.Save("currentCourseName", course.Name);
                    LocalStorage.Save("currentCourseID", course.CourseID);
                }

                ContentFrame.Navigate(typeof(Views.Pages.Course));

                break;
            }
        }
Example #2
0
        public static void Save()
        {
            var localObjectStorageHelper = new LocalObjectStorageHelper();

            localObjectStorageHelper.Save <int>("LaunchCount", launchCount);
            localObjectStorageHelper.Save <List <Drink> >("PersonalDrinks", PersonalList);
            localObjectStorageHelper.Save <List <Drink> >("FavoriteDrinks", FavoritesList);
            localObjectStorageHelper.Save <List <string> >("DefaultSelectedIngredients", DefaultSelectedIngredients);
        }
Example #3
0
        private async void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            if (!loaded)
            {
                return;
            }
            await Task.Delay(1);

            LocalObjectStorageHelper.Save("rules", rules);
        }
Example #4
0
 protected override void OnApiModeChanged(ApiConfig config)
 {
     //This needs UI context since we're dealing with ObservableCollection
     rebuildForumListAsync(config);
     //
     Task.Run(async() =>
     {
         //nothing big deal, thread pool should suffice
         await _storageHelper.SaveFileAsync(forum_cache_key, new List <Forum>());
         _storageHelper.Save(current_api_key, config);
     });
 }
Example #5
0
        private void UserPicker_OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var id = (UserSelectList.SelectedItem as User).UserID;

            LocalStorage.Save("currentUserId", id);

            LoadCurrentUserInfo();

            var rootFrame = Window.Current.Content as Frame;

            rootFrame.Navigate(typeof(MainPage));
        }
Example #6
0
        private async void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            //开关在初始化的时候会自动触发,原因不明
            if (!PageLoaded)
            {
                return;
            }
            //等待数据绑定同步
            await Task.Delay(1);

            LocalObjectStorageHelper.Save("settings", App.Rules.GetSettings());
        }
        private async void EmpIdNextButton_Click(object sender, RoutedEventArgs e)
        {
            EmpIdNextButton.IsEnabled       = false;
            ProgressRingPassword.IsActive   = true;
            ProgressRingPassword.Visibility = Visibility.Visible;

            await EmployeeSync.GetLoginEmployeesAsnc(EmployeeLoginCharacters, EmployeeCharacters[0].EmpId, EmppasswordBox.Password);

            if (EmployeeLoginCharacters.Count > 0)
            {
                var localObjectStorageHelper = new LocalObjectStorageHelper();
                // Read and Save with simple objects for login page
                string keySimpleObject = "47";
                localObjectStorageHelper.Save(keySimpleObject, EmployeeCharacters[0].EmpId);

                if (EmployeeLoginCharacters[0].EmpGroup == 1)
                {
                    Frame.Navigate(typeof(NonAdminPage));
                }
                else if (EmployeeLoginCharacters[0].EmpGroup == 2)
                {
                    Frame.Navigate(typeof(LeaveListPageAdmin));
                }

                //
            }
            else if (EmployeeLoginCharacters.Count == 0)
            {
                NotFindErrorTextBlock.Visibility = Visibility.Visible;
            }

            ProgressRingPassword.IsActive   = false;
            ProgressRingPassword.Visibility = Visibility.Collapsed;
            EmpIdNextButton.IsEnabled       = true;
        }
Example #8
0
        private async void RootPage_Loaded(object sender, RoutedEventArgs e)
        {
            var    localHelper = new LocalObjectStorageHelper();
            string oldImgaeUri = null;

            if (localHelper.KeyExists("BackgroundImage"))
            {
                oldImgaeUri = localHelper.Read <string>("BackgroundImage");
            }

            if (oldImgaeUri != null)
            {
                OldBackgroundImage.Source = await ImageCache.Instance.GetFromCacheAsync(new Uri(oldImgaeUri));
            }

            var imageSource = await AssetsHelper.GetBingWallpaperAsync();

            if (imageSource != null)
            {
                NewBackgroundImage.Source = new BitmapImage(imageSource);
                localHelper.Save("BackgroundImage", imageSource.OriginalString);
            }

            if (imageSource != null)
            {
                if (this.Resources["FadeIn_Image"] is Storyboard fadeIn)
                {
                    fadeIn.Begin();
                }
            }
        }
Example #9
0
        private async void Init()
        {
            LocalObjectStorageHelper LocalObjectStorageHelper = new LocalObjectStorageHelper();

            if (!LocalObjectStorageHelper.KeyExists("rules"))
            {
                StorageFile JsonRules = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/rules.json"));

                string StringRules = await FileIO.ReadTextAsync(JsonRules);

                Rules = JsonConvert.DeserializeObject <Rules>(StringRules);
                LocalObjectStorageHelper.Save("rules", Rules);
            }
            else
            {
                Rules = LocalObjectStorageHelper.Read("rules", Rules);
            }
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            var TitleBar = ApplicationView.GetForCurrentView().TitleBar;

            TitleBar.BackgroundColor               = Colors.Transparent;
            TitleBar.ButtonBackgroundColor         = Colors.Transparent;
            TitleBar.ButtonInactiveForegroundColor = Colors.Transparent;
            TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            MainFrame.Navigate(typeof(ShellPage));
        }
Example #10
0
        public static async Task <int> RestoreLegacyLocalMylistGroups(LocalMylistManager manager)
        {
            try
            {
                var localStorage         = new LocalObjectStorageHelper();
                var isMigrateLocalMylist = localStorage.Read("is_migrate_local_mylist_0_17_0", false);
                if (!isMigrateLocalMylist)
                {
                    var items = await LoadLegacyLocalMylistGroups();

                    foreach (var regacyItem in items)
                    {
                        manager.Mylists.Add(new LocalMylistGroup(regacyItem.Id, regacyItem.Label, new ObservableCollection <string>(regacyItem.PlaylistItems.Select(x => x.ContentId))));
                    }
                    localStorage.Save("is_migrate_local_mylist_0_17_0", true);

                    return(items.Count);
                }
                else
                {
                    return(0);
                }
            }
            catch
            {
                return(0);
            }
        }
Example #11
0
        public static async void EnsureCacheLatest()
        {
            var settingsStorage = new LocalObjectStorageHelper();

            var onlineDocsSHA = await GetDocsSHA();

            var cacheSHA = settingsStorage.Read <string>(_cacheSHAKey);

            bool outdatedCache = onlineDocsSHA != null && cacheSHA != null && onlineDocsSHA != cacheSHA;
            bool noCache       = onlineDocsSHA != null && cacheSHA == null;

            if (outdatedCache || noCache)
            {
                // Delete everything in the Cache Folder. Could be Pre 3.0.0 Cache data.
                foreach (var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync())
                {
                    try
                    {
                        await item.DeleteAsync(StorageDeleteOption.Default);
                    }
                    catch
                    {
                    }
                }

                // Update Cache Version info.
                settingsStorage.Save(_cacheSHAKey, onlineDocsSHA);
            }
        }
 private void LowBalanceAlertToggleSwitchToggled(object sender, RoutedEventArgs e)
 {
     if (sender is ToggleSwitch toggleSwitch)
     {
         var localHelper = new LocalObjectStorageHelper();
         localHelper.Save("IsLowBalanceAlertEnabled", toggleSwitch.IsOn);
     }
 }
 private void Slider_ValueChanged(object sender, RoutedEventArgs e)
 {
     if (sender is Slider slider)
     {
         var localHelper = new LocalObjectStorageHelper();
         localHelper.Save("BalanceThreshold", slider.Value);
     }
 }
Example #14
0
        public WatchItLater(
            IScheduler scheduler,
            SubscriptionManager subscriptionManager,
            Models.Provider.LoginUserHistoryProvider loginUserDataProvider,
            UseCase.Playlist.PlaylistAggregateGetter playlistAggregate
            )
        {
            Scheduler             = scheduler;
            SubscriptionManager   = subscriptionManager;
            LoginUserDataProvider = loginUserDataProvider;
            _playlistAggregate    = playlistAggregate;
            Refresh = new AsyncReactiveCommand();
            Refresh.Subscribe(async() => await Update())
            .AddTo(_disposables);

            {
                var localObjectStorageHelper = new LocalObjectStorageHelper();
                IsAutoUpdateEnabled = localObjectStorageHelper.Read(nameof(IsAutoUpdateEnabled), true);
                AutoUpdateInterval  = localObjectStorageHelper.Read(nameof(AutoUpdateInterval), DefaultAutoUpdateInterval);
            }

            this.ObserveProperty(x => x.IsAutoUpdateEnabled)
            .Subscribe(x =>
            {
                var localObjectStorageHelper = new LocalObjectStorageHelper();
                localObjectStorageHelper.Save(nameof(IsAutoUpdateEnabled), IsAutoUpdateEnabled);
            })
            .AddTo(_disposables);

            this.ObserveProperty(x => x.AutoUpdateInterval)
            .Subscribe(x =>
            {
                var localObjectStorageHelper = new LocalObjectStorageHelper();
                localObjectStorageHelper.Save(nameof(AutoUpdateInterval), AutoUpdateInterval);
            })
            .AddTo(_disposables);

            Observable.Merge(new[]
            {
                this.ObserveProperty(x => x.IsAutoUpdateEnabled).ToUnit(),
                this.ObserveProperty(x => x.AutoUpdateInterval).ToUnit()
            })
            .Subscribe(x =>
            {
                if (IsAutoUpdateEnabled)
                {
                    StartOrResetAutoUpdate();
                }
                else
                {
                    StopAutoUpdate();
                }
            })
            .AddTo(_disposables);

            App.Current.Suspending += Current_Suspending;
            App.Current.Resuming   += Current_Resuming;
        }
Example #15
0
 public void Save_Settings(PiHoleServerInfo serverInfo)
 {
     helper.Save(serverNumber, serverInfo);
     //var index = serverlist.IndexOf(serverInfo);
     this.serverlist.Add(new PiHoleServerInfo()
     {
         PiHoleServerName = serverInfo.PiHoleServerName, PiHoleServerAddress = serverInfo.PiHoleServerAddress, PiHoleServerAuthKey = serverInfo.PiHoleServerAuthKey
     });
 }
Example #16
0
        private static void SaveRecentSamples()
        {
            if (_recentSamples == null)
            {
                return;
            }

            var str = string.Join(";", _recentSamples.Take(10).Select(s => s.Name).ToArray());

            _localObjectStorageHelper.Save <string>(_recentSamplesStorageKey, str);
        }
Example #17
0
        public async Task <Passenger> GetLoggedInPassengerAsync()
        {
            var json = await client.GetStringAsync(new Uri("http://localhost:5000/api/passenger/"));

            var passenger = JsonConvert.DeserializeObject <Passenger>(json);

            LocalObjectStorageHelper localObjectStorage = new LocalObjectStorageHelper();

            localObjectStorage.Save("passenger", passenger);

            return(passenger);
        }
Example #18
0
        public static void MigrateFeedGroupToSubscriptionManager(SubscriptionManager instance)
        {
            var localObjectStorageHelper = new LocalObjectStorageHelper();

            if (!localObjectStorageHelper.Read(nameof(MigrateFeedGroupToSubscriptionManager), false))
            {
                Debug.WriteLine("フィードを購読に移行:開始");

                var feedGroups = Database.FeedDb.GetAll();

                var subsc = SubscriptionManager.CreateNewSubscription("旧 新着");

                subsc.Destinations.Add(new SubscriptionDestination(
                                           "@view".ToCulturelizeString(),
                                           SubscriptionDestinationTarget.LocalPlaylist,
                                           HohoemaPlaylist.WatchAfterPlaylistId)
                                       );

                foreach (var feedSource in feedGroups.SelectMany(x => x.Sources))
                {
                    SubscriptionSourceType?sourceType = null;
                    switch (feedSource.BookmarkType)
                    {
                    case Database.BookmarkType.User: sourceType = SubscriptionSourceType.User; break;

                    case Database.BookmarkType.Mylist: sourceType = SubscriptionSourceType.Mylist; break;

                    case Database.BookmarkType.SearchWithTag: sourceType = SubscriptionSourceType.TagSearch; break;

                    case Database.BookmarkType.SearchWithKeyword: sourceType = SubscriptionSourceType.KeywordSearch; break;
                    }
                    if (sourceType.HasValue)
                    {
                        subsc.Sources.Add(new SubscriptionSource(feedSource.Label, sourceType.Value, feedSource.Content));
                    }
                }

                if (subsc.Sources.Any())
                {
                    instance.Subscriptions.Add(subsc);

                    localObjectStorageHelper.Save(nameof(MigrateFeedGroupToSubscriptionManager), true);
                }

                Debug.WriteLine("フィードを購読に移行:完了!");
            }
        }
        public async static void GetLatestRules()
        {
            Rules Rules;

            using (HttpClient HttpClient = new HttpClient())
            {
                HttpClient.Timeout = TimeSpan.FromSeconds(10);
                var HttpResopnse = await HttpClient.GetAsync(UpdateRulesUri);

                if (HttpResopnse.StatusCode == HttpStatusCode.OK)
                {
                    string StringRules = await HttpResopnse.Content.ReadAsStringAsync();

                    Rules = JsonConvert.DeserializeObject <Rules>(StringRules);
                    if (Rules == null)
                    {
                        return;
                    }
                    if (Rules.version > App.Rules.version)
                    {
                        LocalObjectStorageHelper LocalObjectStorageHelper = new LocalObjectStorageHelper();
                        await LocalObjectStorageHelper.SaveFileAsync("rules_origin", Rules);

                        await LocalObjectStorageHelper.SaveFileAsync("rules", Rules);

                        var NewSettings = Rules.GetSettings();
                        var OldSettings = App.Rules.GetSettings();
                        foreach (var Item in OldSettings)
                        {
                            if (NewSettings.ContainsKey(Item.Key))
                            {
                                NewSettings[Item.Key] = Item.Value;
                            }
                        }
                        LocalObjectStorageHelper.Save("settings", NewSettings);
                        Rules.SetSettings(NewSettings);
                        App.Rules = Rules;
                    }
                }
            }
        }
        private async void InitRules()
        {
            LocalObjectStorageHelper LocalObjectStorageHelper = new LocalObjectStorageHelper();

            if (!await LocalObjectStorageHelper.FileExistsAsync("rules_origin"))
            {
                var Folder = await Package.Current.InstalledLocation.GetFolderAsync("Data");

                var FileRules = await Folder.GetFileAsync("rules.json");

                string StringRules = await FileIO.ReadTextAsync(FileRules);

                var TempRules = JsonConvert.DeserializeObject <Rules>(StringRules);
                await LocalObjectStorageHelper.SaveFileAsync("rules_origin", TempRules);
            }
            if (!await LocalObjectStorageHelper.FileExistsAsync("rules"))
            {
                var Folder = await Package.Current.InstalledLocation.GetFolderAsync("Data");

                var FileRules = await Folder.GetFileAsync("rules.json");

                string StringRules = await FileIO.ReadTextAsync(FileRules);

                Rules = JsonConvert.DeserializeObject <Rules>(StringRules);
                await LocalObjectStorageHelper.SaveFileAsync("rules", Rules);
            }
            else
            {
                Rules = await LocalObjectStorageHelper.ReadFileAsync <Rules>("rules");
            }
            if (!LocalObjectStorageHelper.KeyExists("settings"))
            {
                LocalObjectStorageHelper.Save("settings", Rules.GetSettings());
            }
            else
            {
                var settings = LocalObjectStorageHelper.Read <Dictionary <string, bool> >("settings");
                Rules.SetSettings(settings);
            }
        }
        public void Test_StorageHelper_LegacyIntTest()
        {
            string key = "LifeUniverseAndEverything";

            int input = 42;

            // simulate previous version by generating json and manually inserting it as string
            string jsonInput = JsonConvert.SerializeObject(input);

            storageHelper.Save <string>(key, jsonInput);

            // now read it as int to valid that the change works
            int output = storageHelper.Read <int>(key, 0);

            Assert.AreEqual(input, output);
        }
Example #22
0
        public async Task Login()
        {
            try
            {
                WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, new Uri(_stravaService.AuthorizationURL), new Uri(_stravaService.AuthorityRedirectURL));

                if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var responseData          = webAuthenticationResult.ResponseData;
                    var tempAuthorizationCode = _stravaService.ParseAuthorizationResponse(responseData);
                    var accessToken           = await _stravaService.GetAccessToken(tempAuthorizationCode);

                    //TODO: Store accessToken in secure location, needed for each Strava Service request!
                    var storageHelper = new LocalObjectStorageHelper();
                    storageHelper.Save <string>(StorageKeys.ACCESSTOKEN, accessToken);
                }
            }
            catch (Exception ex)
            {
                //OnStatusEvent(new StravaServiceEventArgs(StravaServiceStatus.Failed, ex));
            }
        }
Example #23
0
        private async void UpdateSettings_Click(object sender, RoutedEventArgs e)
        {
            Rules Rules;

            using (HttpClient HttpClient = new HttpClient())
            {
                HttpClient.Timeout = TimeSpan.FromSeconds(10);
                var HttpResopnse = await HttpClient.GetAsync(Utils.UpdateRulesUri);

                if (HttpResopnse.StatusCode == HttpStatusCode.OK)
                {
                    string StringRules = await HttpResopnse.Content.ReadAsStringAsync();

                    Rules = JsonConvert.DeserializeObject <Rules>(StringRules);
                    if (Rules == null)
                    {
                        MessageDialog md = new MessageDialog("未知错误", "更新失败");
                        md.Commands.Add(new UICommand("确定", cmd => { }));
                        await md.ShowAsync();

                        return;
                    }
                    if (Rules.version > App.Rules.version)
                    {
                        MessageDialog md = new MessageDialog("请问是否更新?", "已检测到新的更新");
                        md.Commands.Add(new UICommand("确定", cmd => { }, "更新"));
                        md.Commands.Add(new UICommand("取消", cmd => { }));
                        var result = await md.ShowAsync();

                        if (result.Id as string == "更新")
                        {
                            LocalObjectStorageHelper LocalObjectStorageHelper = new LocalObjectStorageHelper();
                            await LocalObjectStorageHelper.SaveFileAsync("rules_origin", Rules);

                            await LocalObjectStorageHelper.SaveFileAsync("rules", Rules);

                            var NewSettings = Rules.GetSettings();
                            var OldSettings = App.Rules.GetSettings();
                            foreach (var Item in OldSettings)
                            {
                                if (NewSettings.ContainsKey(Item.Key))
                                {
                                    NewSettings[Item.Key] = Item.Value;
                                }
                            }
                            LocalObjectStorageHelper.Save("settings", NewSettings);
                            Rules.SetSettings(NewSettings);
                            App.Rules = Rules;
                            md        = new MessageDialog("某些设置将在重启后生效", "更新成功!");
                            md.Commands.Add(new UICommand("确定", cmd => { }));
                            await md.ShowAsync();
                        }
                    }
                    else
                    {
                        MessageDialog md = new MessageDialog("您无需更新", "已经是最新版本了");
                        md.Commands.Add(new UICommand("确定", cmd => { }));
                        await md.ShowAsync();
                    }
                }
                else
                {
                    MessageDialog md = new MessageDialog("请检查您的网络", "更新失败");
                    md.Commands.Add(new UICommand("确定", cmd => { }));
                    await md.ShowAsync();
                }
            }
        }
Example #24
0
        public static void SkipMigrate_0_17_0()
        {
            var localStorage = new LocalObjectStorageHelper();

            localStorage.Save("is_migrate_local_mylist_0_17_0", true);
        }
Example #25
0
 internal static void Reset()
 {
     _localSettings.Save(HasShown, false);
 }
 void SaveDisplayMode()
 {
     _localObjectStorage.Save(nameof(PlayerDisplayView), DisplayMode);
 }
Example #27
0
 private void Save <T>(T value, [CallerMemberName] string propertyName = null)
 {
     _LocalStorageHelper.Save(propertyName, value);
 }
Example #28
0
 public void Set <T>(string key, T value)
 {
     _helper.Save(key, value);
 }
Example #29
0
        private void SaveDialog(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var helper = new LocalObjectStorageHelper();

            helper.Save(App.EnableDownload, EnableBackgroundDownloading.IsOn);
        }
Example #30
0
        private void SaveTheme(MarkdownSetting setting)
        {
            var wCache = new LocalObjectStorageHelper();

            wCache.Save(CacheKeys.ReadmeTheme, Newtonsoft.Json.JsonConvert.SerializeObject(setting));
        }