public void CanListenPositionChangeEvents() { // ARRANGE var waitEvent = new ManualResetEvent(false); var messageBus = new MessageBus(); NmeaPositionMocker mocker; int count = 0; messageBus.AsObservable <GeoPosition>() .ObserveOn(Scheduler.ThreadPool) .Subscribe(position => count++); // ACT Action <TimeSpan> delayAction = _ => Thread.Sleep(0); // do not wait to make test faster using (Stream stream = new FileStream(TestHelper.NmeaFilePath, FileMode.Open)) { mocker = new NmeaPositionMocker(stream, messageBus); mocker.OnDone += (s, e) => waitEvent.Set(); mocker.Start(delayAction); } // ASSERT if (!waitEvent.WaitOne(TimeSpan.FromSeconds(60))) { throw new TimeoutException(); } mocker.Stop(); Assert.Greater(count, 1); }
public void RunMocker() { Action <TimeSpan> delayAction = Thread.Sleep; using (Stream stream = new FileStream(_nmeaFilePath, FileMode.Open)) { var mocker = new NmeaPositionMocker(stream, _messageBus); mocker.OnDone += (s, e) => _waitEvent.Set(); mocker.Start(delayAction); } }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService<ITileController>(); _messageBus = appManager.GetService<IMessageBus>(); _trace = appManager.GetService<ITrace>(); var elevationProvider = appManager.GetService<IElevationProvider>(); _messageBus.AsObservable<GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable<TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService <ITileController>(); _messageBus = appManager.GetService <IMessageBus>(); _trace = appManager.GetService <ITrace>(); var elevationProvider = appManager.GetService <IElevationProvider>(); _messageBus.AsObservable <GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable <TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }