Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
        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) { }
            }
        }
Ejemplo n.º 9
0
        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;
            }));
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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 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);
            }
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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();
            }
        }
Ejemplo n.º 16
0
        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();
            }
        }