private async Task LoadCachedStatusAsync() { var localHelper = new LocalObjectStorageHelper(); Status status = null; if (await localHelper.FileExistsAsync("ConnectionStatus")) { status = await localHelper.ReadFileAsync <Status>("ConnectionStatus"); } if (status != null) { ConnectionStatus.Usage = status.Usage; ConnectionStatus.Balance = status.Balance; ConnectionStatus.Username = status.Username; ConnectionStatus.Session = status.Session; } if (await localHelper.FileExistsAsync("DetailUsage")) { DetailUsage = await localHelper.ReadFileAsync <List <UsageWithDate> >("DetailUsage"); } if (DetailUsage != null) { (DetailUsageChart.Series[0] as LineSeries).ItemsSource = DetailUsage; SetChartAxis(); if (this.Resources["FadeIn_Chart"] is Storyboard fadeIn) { fadeIn.Begin(); } } }
protected override async void OnLaunched(LaunchActivatedEventArgs e) { var localHelper = new LocalObjectStorageHelper(); FavoriteNetworks = new ObservableCollection <Network>(); Accounts = new ObservableCollection <Account>(); if (await localHelper.FileExistsAsync("Networks")) { FavoriteNetworks = await localHelper.ReadFileAsync <ObservableCollection <Network> >("Networks"); } if (FavoriteNetworks == null) { FavoriteNetworks = new ObservableCollection <Network>(); } if (await localHelper.FileExistsAsync("Accounts")) { Accounts = await localHelper.ReadFileAsync <ObservableCollection <Account> >("Accounts"); } if (Accounts == null) { Accounts = new ObservableCollection <Account>(); } CheckOnLaunch(); if (!(Window.Current.Content is Frame rootFrame)) { rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { } Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { if (Accounts.Count() == 0) { rootFrame.Navigate(typeof(WelcomePage), e.Arguments); } else { rootFrame.Navigate(typeof(RootPage), e.Arguments); } } Window.Current.Activate(); ExtendAcrylicIntoTitleBar(); } }
public async Task <IEnumerable <FinanceAccount> > LoadFinanceAccountsAsync() { IEnumerable <FinanceAccount> accountsToReturn = null; bool fileExists = await _objectHelper.FileExistsAsync(AccountsFileName); if (fileExists) { accountsToReturn = await _objectHelper.ReadFileAsync(AccountsFileName, default(IEnumerable <FinanceAccount>)); } return(accountsToReturn); }
private async Task GetRooms() { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); RestClient client = new RestClient(IP.Adress); RestRequest request = new RestRequest("Room/get_all", Method.GET); _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader); IRestResponse response = client.Execute(request); roomList = JsonConvert.DeserializeAnonymousType(response.Content, roomList); RoomList.ItemsSource = roomList; }
protected async override void OnNavigatedTo(NavigationEventArgs e) { try { var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; user = localSettings.Values["user"].ToString(); pass = localSettings.Values["pass"].ToString(); credentialEnterned = true; } catch { refershButton.IsEnabled = false; return; } if (credentialEnterned) { refershButton.IsEnabled = true; } var helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync(keyLargeObject)) { var dataList = await helper.ReadFileAsync <DataList>(keyLargeObject); dataLimit.Text = dataList.planList[0].ToString(); dataStartDate.Text = dataList.planList[1].ToString(); dataEndDate.Text = dataList.planList[2].ToString(); dataTime.Text = dataList.usageList[0].ToString(); dataUploaded.Text = dataList.usageList[1].ToString(); dataDownloaded.Text = dataList.usageList[2].ToString(); dataTotal.Text = dataList.usageList[3].ToString(); } }
private async void ResetSettings_Click(object sender, RoutedEventArgs e) { 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 == "重置") { App.Rules = await LocalObjectStorageHelper.ReadFileAsync <Rules>("rules_origin"); await LocalObjectStorageHelper.SaveFileAsync("rules", App.Rules); LocalObjectStorageHelper.Save("settings", App.Rules.GetSettings()); } md = new MessageDialog("是否重启应用?", "重启应用后设置才能生效"); md.Commands.Add(new UICommand("确定", cmd => { }, "重启")); md.Commands.Add(new UICommand("取消", cmd => { })); result = await md.ShowAsync(); if (result.Id as string == "重启") { await CoreApplication.RequestRestartAsync(string.Empty); } }
private async Task GetUsers() { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); RestClient client = new RestClient(IP.Adress); RestRequest request = new RestRequest("Users/get_all", Method.GET); _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader); IRestResponse response = client.Execute(request); usersList = JsonConvert.DeserializeAnonymousType(response.Content, usersList); usersList.ForEach(CheckActive); UsersList.ItemsSource = usersList; usersCount.Text = UsersList.Items.Count.ToString() + " użytkowników"; }
public async Task RunAsync(IBackgroundTaskInstance taskInstance) { // Create services var localObjectStorageHelper = new LocalObjectStorageHelper(); // Check if notifications are enabled var notificationsEnabled = localObjectStorageHelper.Read(LocalStorageConstants.EnableNewEpisodeNotificationsOption, true); if (!notificationsEnabled) { return; } // Retrieve token to access API string token = RetrieveToken(); // Create services (2) var tvshowtimeApiService = new TVShowTimeApiService(token); // Retrieve episodes from the agenda (episodes that will be aired soon) var agendaResponse = await tvshowtimeApiService.GetAgendaAsync(); if (agendaResponse.Result == "OK") { // Retrieve list of episodes already notified var newEpisodesIdsNotified = new List <long>(); if (await localObjectStorageHelper.FileExistsAsync(LocalStorageConstants.NewEpisodesIdsNotified)) { newEpisodesIdsNotified = await localObjectStorageHelper .ReadFileAsync(LocalStorageConstants.NewEpisodesIdsNotified, new List <long>()); } var episodesInAgenda = agendaResponse.Episodes; foreach (var episode in episodesInAgenda) { var timeSpanDiff = episode.AirDate.Value.Subtract(DateTime.Now.ToUniversalTime()); if (episode.AirTime.HasValue) { timeSpanDiff = timeSpanDiff .Add(TimeSpan.FromHours(episode.AirTime.Value.DateTime.Hour)); timeSpanDiff = timeSpanDiff .Add(TimeSpan.FromMinutes(episode.AirTime.Value.DateTime.Minute)); } if (newEpisodesIdsNotified.All(id => episode.Id != id) && timeSpanDiff.TotalDays <= 0) { // Create Toast notification when a new episode is out GenerateToastNotification(episode); newEpisodesIdsNotified.Add(episode.Id); } } // Save the updated list in local storage await localObjectStorageHelper.SaveFileAsync(LocalStorageConstants.NewEpisodesIdsNotified, newEpisodesIdsNotified); } }
private async Task GetIntervals() { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); RestClient client = new RestClient(IP.Adress); RestRequest request = new RestRequest("Room/get_room_availabilities", Method.GET); _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader); IRestResponse response = client.Execute(request); List <GetIntervalsModel> availabilityList = new List <GetIntervalsModel>(); availability.ItemsSource = JsonConvert.DeserializeAnonymousType(response.Content, availabilityList); if (!IsEditMode) { availability.SelectedIndex = 0; } }
public static async Task <T> Load <T>(string filename, T list) { var helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync(filename)) { return(await helper.ReadFileAsync <T>(filename)); } return(list); }
private async void CheckUserType() { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); UserText.Content = SavedResponseObj.Name + " - " + SavedResponseObj.role; if (SavedResponseObj.role == "User") { addroom.Visibility = Visibility.Collapsed; usersSeparator.Visibility = Visibility.Collapsed; users.Visibility = Visibility.Collapsed; } }
private static async Task dumpStorage() { if (await _helper.FileExistsAsync(fileName)) { BibleStorage content = null; try { content = await _helper.ReadFileAsync <BibleStorage>(fileName); Interlocked.Exchange(ref _storage, content); } catch (Exception) { } } }
private Task <string> GetFriendsAvtivitiesDataCache() { return(Task.Run(async() => { string activities = string.Empty; if (await _storageHelper.FileExistsAsync(StorageKeys.ACTIVITIESALL)) { activities = await _storageHelper.ReadFileAsync <string>(StorageKeys.ACTIVITIESALL); } return activities; })); }
public async Task LoadDataAsync() { if (!await LocalObjectStorageHelper.FileExistsAsync("docs.json")) { return; } DataChangedDisposable.Disposable = Disposable.Empty; var docs = await LocalObjectStorageHelper.ReadFileAsync("docs.json", Enumerable.Empty <Document>()); foreach (var doc in docs) { DocumentsSource.Add(doc); } StartObserveDataChanged(); }
private async Task rebuildForumListAsync(ApiConfig config) { List <Forum> pocos = null; if (await _storageHelper.FileExistsAsync(forum_cache_key)) { pocos = await _storageHelper.ReadFileAsync <List <Forum> >(forum_cache_key); } if ((pocos?.Count ?? 0) == 0) { pocos = await new ForumController(config).GetForumsAsync(); await _storageHelper.SaveFileAsync(forum_cache_key, pocos); } _forums.Clear(); pocos.ForEach(i => _forums.Add(new ForumViewModel(i, config))); SelectedForum = Forums.FirstOrDefault(); }
private async Task <string> GetRequest(string resource, bool hours) { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); RestClient client = new RestClient(IP.Adress); IRestRequest request = new RestRequest(resource, Method.GET).AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader); IRestResponse response = client.Execute(request); if (hours) { return(response.Content.Replace("\x22", "") + "h"); } else { return(response.Content.Replace("\x22", "")); } }
private async Task <object> getAmazonItemsAsync() { try { var helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync("AmazonItems")) { AmazonItems = await helper.ReadFileAsync <ObservableCollection <AmazonItem> >("AmazonItems"); return(null); } return(null); } catch (Exception e) { return(null); } }
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); } }
private async Task <object> getAmazonItemsAsync() { try { var helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync("AmazonItems")) { AmazonItems = await helper.ReadFileAsync <ObservableCollection <AmazonItem> >("AmazonItems"); } dataGrid.ItemsSource = AmazonItems; return(null); } catch (Exception e) { Debug.WriteLine(e.StackTrace); AmazonItems = new ObservableCollection <AmazonItem>(); Console.WriteLine(e.StackTrace); return(null); } }
public static async Task <StatusCode> LoadSaveAsync() { try { var helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync("data.txt")) { proj = await helper.ReadFileAsync <Project>(keyLargeObject); authTokenStored = proj.devices[1].token; return(StatusCode.Success); } else { return(StatusCode.NoData); } } catch { return(StatusCode.NoData); } }
private async Task Connect() { var localHelper = new LocalObjectStorageHelper(); ObservableCollection <Network> _favoriteNetworks = null; ObservableCollection <Account> _accounts = null; if (await localHelper.FileExistsAsync("Networks")) { _favoriteNetworks = await localHelper.ReadFileAsync <ObservableCollection <Network> >("Networks"); } if (_favoriteNetworks == null) { _favoriteNetworks = new ObservableCollection <Network>(); } if (await localHelper.FileExistsAsync("Accounts")) { _accounts = await localHelper.ReadFileAsync <ObservableCollection <Account> >("Accounts"); } if (_accounts == null) { _accounts = new ObservableCollection <Account>(); } var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (profile != null && _accounts.Count() > 0) { var currentAccount = _accounts.First(); var ssid = profile.ProfileName; var isWired = !profile.IsWlanConnectionProfile && !profile.IsWwanConnectionProfile; if (isWired) { var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } var response = await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); if (response == null) { return; } if (response.Contains("login_ok")) { ShowAutoLoginNotification(ssid); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else if (response == "ip_already_online_error") { ShowAutoLoginNotification(ssid); } else if (response.Contains("login_error")) { await Task.Delay(10100); await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else { ShowWrongPasswordNotification(ssid, currentAccount.Username); } } else if (!isWired && _favoriteNetworks.Where(u => u.Ssid == ssid).Count() != 0) { var response = await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); if (response == "Login is successful.") { ShowAutoLoginNotification(ssid); } else if (response == "E2620: You are already online." || response == "IP has been online, please logout.") { ShowAutoLoginNotification(ssid); } else if (response == "E2532: The two authentication interval cannot be less than 3 seconds.") { await Task.Delay(3500); await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); } else if (response == "E2553: Password is error.") { ShowWrongPasswordNotification(ssid, currentAccount.Username); } var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } response = await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); if (response == null) { return; } if (response.Contains("login_ok")) { ShowAutoLoginNotification(ssid); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else if (response == "ip_already_online_error") { ShowAutoLoginNotification(ssid); } else if (response.Contains("login_error")) { await Task.Delay(10100); await AuthHelper.LoginAsync(4, currentAccount.Username, credential.Password); await Task.Delay(10100); await AuthHelper.LoginAsync(6, currentAccount.Username, credential.Password); } else { ShowWrongPasswordNotification(ssid, currentAccount.Username); } } else if (ssid.Contains("Tsinghua")) { var response = await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); if (response == "Login is successful.") { ShowAutoLoginNotification(ssid); } else if (response == "E2620: You are already online." || response == "IP has been online, please logout.") { ShowAutoLoginNotification(ssid); } else if (response == "E2532: The two authentication interval cannot be less than 3 seconds.") { await Task.Delay(3500); await NetHelper.LoginAsync(currentAccount.Username, currentAccount.Password); } else if (response == "E2553: Password is error.") { ShowWrongPasswordNotification(ssid, currentAccount.Username); } var credential = CredentialHelper.GetCredentialFromLocker(currentAccount.Username); if (credential != null) { credential.RetrievePassword(); } else { return; } } } else { ToastNotificationManager.History.Clear(); } }
private async Task AddUser(string resource, Method method) { SubmitButton.IsEnabled = false; if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(password.Password) && !string.IsNullOrEmpty(passwordconfirm.Password) && password.Password == passwordconfirm.Password && TextBoxRegex.GetIsValid(email)) { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); AddUserModel userObj = new AddUserModel { UserName = username.Text.Trim(), Password = password.Password.Trim(), Name = name.Text.Trim(), Surname = surname.Text.Trim(), Email = email.Text.Trim(), Active = activity.IsChecked ?? true, UserType = usertype.SelectedItem.ToString() }; string json = JsonConvert.SerializeObject(userObj); RestClient client = new RestClient(IP.Adress); RestRequest request = new RestRequest(resource, method); _ = request.AddParameter("application/json", json, ParameterType.RequestBody); _ = request.AddParameter("Authorization", "Bearer " + SavedResponseObj.Token, ParameterType.HttpHeader); if (IsEditMode) { _ = request.AddParameter("id", UserID, ParameterType.UrlSegment); } IRestResponse response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { SubmitButton.IsEnabled = true; if (IsEditMode) { _ = await new CustomDialog("Użytkownik edytowany poprawnie.", null, CustomDialog.Type.Information).ShowAsync(); CleanupInput(); Frame rootFrame = Window.Current.Content as Frame; MainPage homePage = rootFrame.Content as MainPage; _ = homePage.NavigationFrame.Navigate(typeof(UsersPage), null, new DrillInNavigationTransitionInfo()); } else { _ = await new CustomDialog("Użytkownik stworzony poprawnie.", null, CustomDialog.Type.Information).ShowAsync(); CleanupInput(); } } else { _ = await new CustomDialog("Wystąpił błąd podczas komunikacji z serwerem.", response.StatusCode.ToString(), CustomDialog.Type.Error).ShowAsync(); SubmitButton.IsEnabled = true; } } else { _ = await new CustomDialog("Wprowadzono błędne dane.", null, CustomDialog.Type.Warning).ShowAsync(); SubmitButton.IsEnabled = true; } }
protected override async void OnLaunched(LaunchActivatedEventArgs e) { CoreApplicationViewTitleBar CoreTitleBar = CoreApplication.GetCurrentView().TitleBar; CoreTitleBar.ExtendViewIntoTitleBar = true; ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar; titleBar.ButtonBackgroundColor = Colors.Transparent; titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") { FocusVisualKind = FocusVisualKind.Reveal; } Frame 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(); 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 (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { LocalObjectStorageHelper helper = new LocalObjectStorageHelper(); if (await helper.FileExistsAsync("response")) { LoginModel SavedResponseObj = await helper.ReadFileAsync <LoginModel>("response"); if (!SavedResponseObj.IsLoged || SavedResponseObj == null) { _ = rootFrame.Navigate(typeof(LoginPage), e.Arguments); } else { _ = rootFrame.Navigate(typeof(MainPage), e.Arguments); } } else { _ = rootFrame.Navigate(typeof(LoginPage), e.Arguments); } } // Ensure the current window is active Window.Current.Activate(); } }