public IGH615MTrack GetTrack(Int16 id) { lock (this) { if (_tracks.ContainsKey(id)) { return(_tracks[id]); } if (!IsConnected) { return(null); } GH615MTrack result = null; using (var session = new SerialPortSession(_commport)) { var startLoadCommand = new StartLoadTrackCommand(id); startLoadCommand.Execute(session.Port); var total = startLoadCommand.Status.TrackInfo.TrackPointsCount; var current = startLoadCommand.Status.LastLoadedPointsCount; SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current, total); if (startLoadCommand.Status.IsFinished) { if (startLoadCommand.Status.TrackInfo != null) { result = new GH615MTrack(startLoadCommand.Status.TrackInfo, startLoadCommand.Status.TrackPoints.ToArray()); } } else { var command = new ContinueLoadTracksCommand(startLoadCommand.Status); do { command.Execute(session.Port); current += startLoadCommand.Status.LastLoadedPointsCount; SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current, total); }while (!command.Status.IsFinished); result = new GH615MTrack(command.Status.TrackInfo, command.Status.TrackPoints.ToArray()); } SendReadCompleted(); } if (result != null) { _tracks.Add(id, result); } return(result); } }
public IGH615MTrack GetTrack(Int16 id) { lock (this) { if (_tracks.ContainsKey(id)) { return _tracks[id]; } if (!IsConnected) { return null; } GH615MTrack result = null; using (var session = new SerialPortSession(_commport)) { var startLoadCommand = new StartLoadTrackCommand(id); startLoadCommand.Execute(session.Port); var total = startLoadCommand.Status.TrackInfo.TrackPointsCount; var current = startLoadCommand.Status.LastLoadedPointsCount; SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current, total); if (startLoadCommand.Status.IsFinished) { if (startLoadCommand.Status.TrackInfo != null) { result = new GH615MTrack(startLoadCommand.Status.TrackInfo, startLoadCommand.Status.TrackPoints.ToArray()); } } else { var command = new ContinueLoadTracksCommand(startLoadCommand.Status); do { command.Execute(session.Port); current += startLoadCommand.Status.LastLoadedPointsCount; SendProgressChanged(String.Format("Read track data... ({0}/{1})", current, total), current, total); } while (!command.Status.IsFinished); result = new GH615MTrack(command.Status.TrackInfo, command.Status.TrackPoints.ToArray()); } SendReadCompleted(); } if (result != null) { _tracks.Add(id, result); } return result; } }