internal async Task Log(GeofenceState newState, Geoposition position) { StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( this.fileName, CreationCollisionOption.OpenIfExists); PositionLogEntry entry = PositionLogEntry.FromFenceDetails(newState, position); await FileIO.AppendLinesAsync(file, new string[] { entry.ToLogEntry() }); }
internal static PositionLogEntry FromLogEntry(string logFileEntry) { string[] pieces = logFileEntry.Split('|'); PositionLogEntry entry = new PositionLogEntry() { Date = DateTimeOffset.Parse(pieces[0]), Latitude = double.Parse(pieces[1]), Longitude = double.Parse(pieces[2]), Altitude = double.Parse(pieces[3]), State = (GeofenceState)Enum.Parse(typeof(GeofenceState), pieces[4]) }; return(entry); }
internal static PositionLogEntry FromFenceDetails( GeofenceState newState, Geoposition position) { PositionLogEntry entry = new PositionLogEntry() { Date = DateTimeOffset.Now, Latitude = position.Coordinate.Latitude, Longitude = position.Coordinate.Longitude, Altitude = position.Coordinate.Altitude ?? 0.0d, State = newState }; return(entry); }
internal async Task <IEnumerable <PositionLogEntry> > ReadEntriesAsync() { List <PositionLogEntry> list = new List <PositionLogEntry>(); try { StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync( this.fileName); IList <string> lines = await FileIO.ReadLinesAsync(file); list.AddRange( lines.Select( line => PositionLogEntry.FromLogEntry(line) ) ); } catch (FileNotFoundException) { } return(list); }