Пример #1
0
        private void SaveListToFile()
        {
            if (NumberOfDetectedAccessPoints == 0)
            {
                Toast.MakeText(Android.App.Application.Context, "There is nothing to be saved!", ToastLength.Short).Show();
                AutoSaveToFile = false;
                return;
            }

            var    sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path;
            string filePath   = Path.Combine(sdCardPath, FileName + ".json");

            foreach (var wifiNetwork in ListOfWifiNetworks)
            {
                ListOfWifiNetworksFromFile.Add(wifiNetwork);
            }

            if (!File.Exists(filePath))
            {
                WifiParametersJSON.ToJson(filePath, ListOfWifiNetworks);
                Toast.MakeText(Android.App.Application.Context, "List of wifi networks has been saved to file successfully.", ToastLength.Short).Show();
            }
            else
            {
                foreach (var wifiNetwork in WifiParametersJSON.FromJson(filePath))
                {
                    ListOfWifiNetworksFromFile.Add(wifiNetwork);
                }
                WifiParametersJSON.ToJson(filePath, ListOfWifiNetworksFromFile);
                Toast.MakeText(Android.App.Application.Context, "List of wifi networks has been saved to file successfully.", ToastLength.Short).Show();
            }
            ListOfWifiNetworksFromFile.Clear();
        }
Пример #2
0
        private async Task SaveFileToDatabase()
        {
            var    sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path;
            string filePath   = Path.Combine(sdCardPath, FileName + ".json");

            foreach (var wifiNetwork in ListOfWifiNetworks)
            {
                ListOfWifiNetworksFromFile.Add(wifiNetwork);
            }

            if (File.Exists(filePath))
            {
                foreach (var wifiNetwork in WifiParametersJSON.FromJson(filePath))
                {
                    ListOfWifiNetworksFromFile.Add(wifiNetwork);
                }
                await App.Database.SaveCollectionOfWifiParameters(ListOfWifiNetworksFromFile);

                Toast.MakeText(Android.App.Application.Context, "List of wifi networks from file has been added to database successfully.", ToastLength.Short).Show();
            }
            else
            {
                Toast.MakeText(Android.App.Application.Context, "File with such name does not exist!", ToastLength.Short).Show();
            }
            ListOfWifiNetworksFromFile.Clear();
        }
        private async Task LoadDataFromFile()
        {
            IsBusy = true;
            CollectionOfWifiNetworksToAnalyze.Clear();
            await Task.Delay(2000);

            var    sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path;
            string filePath   = Path.Combine(sdCardPath, FileNameToAnalyze + ".json");

            if (File.Exists(filePath))
            {
                foreach (var wifiNetwork in WifiParametersJSON.FromJson(filePath))
                {
                    CollectionOfWifiNetworksToAnalyze.Add(wifiNetwork);
                }
                collectionOfWifiParametersToAnalyzeTrafficChannel = CollectionOfWifiNetworksToAnalyze;
                NumberOfWifiNetworksToAnalyze = CollectionOfWifiNetworksToAnalyze.Count;
                Toast.MakeText(Android.App.Application.Context, "Data from file was loaded successfully.", ToastLength.Short).Show();
            }
            else
            {
                Toast.MakeText(Android.App.Application.Context, "File with such name does not exist!", ToastLength.Short).Show();
                NumberOfWifiNetworksToAnalyze = 0;
            }
            IsBusy = false;
        }