Ejemplo n.º 1
0
        protected MemoryActivity ExportAndReload(MemoryActivity activity)
        {
            var exporter = new FitExporter(activity);
            var stream   = new MemoryStream();

            exporter.Save(stream);
            // reimport the activity
            stream.Seek(0, SeekOrigin.Begin);
            var activityReloaded = new MemoryActivity();
            var importer         = new FitImporter(activityReloaded);

            importer.Load(stream);
            return(importer.Activity);
        }
Ejemplo n.º 2
0
        public async Task Recode()
        {
            var activity = new MemoryActivity();

            using (var input = await TestFileHelper.OpenForReadAsync(GetFileName("2015-10-31-100331.fit")))
            {
                var importer = new FitImporter(activity);
                importer.Load(input);
            }

            var activityRepaired = activity.Repair();

            Assert.AreEqual(26.092411, activityRepaired.AvgSpeed.GetValueAs(SpeedUnit.KilometerPerHour), 0.05);
        }
Ejemplo n.º 3
0
        public async Task Import()
        {
            var activity = new MemoryActivity();

            using (var input = await TestFileHelper.OpenForReadAsync(Test2FileName))
            {
                var importer = new FitImporter(activity);
                importer.MessageBroadcaster.SessionMesgEvent += (sender, args) =>
                {
                    var msg     = args.mesg as SessionMesg;
                    var summary = msg.ToSummary();
                };
                importer.Load(input);
                Assert.AreEqual(activity.AvgHeartRate, 153);
                Assert.AreEqual(activity.MaxHeartRate, 180);
            }
        }
Ejemplo n.º 4
0
        protected void Start(Stream source, int millisecondsDelay)
        {
            if (_task != null)
            {
                return;
            }

            _task = Task.Run(() =>
            {
                // import activity from GPX
                var activity = new MemoryActivity();
                var importer = new FitImporter(activity);
                importer.Load(source);
                // mock positions from the activity
                var moveCalculator = new MoveCalculator();
                while (true)
                {
                    foreach (var frame in activity.TimeFrames)
                    {
                        Task.Delay(millisecondsDelay).Wait(); // wait for 1 second
                        if (!_isConnected)
                        {
                            continue;
                        }

                        if (frame.Position.HasValue)
                        {
                            moveCalculator.Add(frame.Position.Value, TimeSpan.FromSeconds(1));
                            if (StatusChanged != null)
                            {
                                _status.Position = frame.Position.Value;
                                _status.Speed    = moveCalculator.CurrentSpeed;
                                var args         = new GeoLocatorStatusChangedEventArgs(_status);
                                StatusChanged(this, args);
                            }
                        }
                    }
                }
            });
            _task.ConfigureAwait(false);
        }