Ejemplo n.º 1
0
        private async Task SaveHistories(List <TripHistory> histories)
        {
            var folderPath = _fileSystemService.GetApplicationFolder();

            var filePath = Path.Combine(folderPath, TRIP_HISTORY_FILE);

            using (var file = File.Open(filePath, FileMode.Create))
                using (var streamWriter = new StreamWriter(file))
                {
                    var fileText = JsonConvert.SerializeObject(histories);

                    await streamWriter.WriteAsync(fileText).ConfigureAwait(false);
                }
        }
        public async Task <IEnumerable <VehicleModel> > GetVehicleHistory()
        {
            var folderPath = _fileSystemService.GetApplicationFolder();

            var filePath = Path.Combine(folderPath, VEHICLE_HISTORY_FILE);

            using (var file = File.Open(filePath, FileMode.OpenOrCreate))
                using (var streamReader = new StreamReader(file))
                {
                    var fileText = await streamReader.ReadToEndAsync();

                    if (String.IsNullOrEmpty(fileText))
                    {
                        return(new List <VehicleModel>());
                    }

                    var collection = JsonConvert.DeserializeObject <List <VehicleModel> >(fileText);

                    return(collection);
                }
        }