Ejemplo n.º 1
0
        private async Task <MemoryActivity> LoadAsync(string fileName)
        {
            var activity = new MemoryActivity();

            using (var input = await TestFileHelper.OpenForReadAsync(fileName))
            {
                var importer = new FitImporter(activity);
                await importer.LoadAsync(input);
            }

            return(activity);
        }
Ejemplo n.º 2
0
        public async Task InitializeAsync()
        {
            if (_initialized)
            {
                return;
            }

            //    Activity.Sport = Settings.ActivityRecorder.Sport; // default sport

            // restore interrupted activity recording
            var folderActivities = await GetFolderAsync();

            _fileDest = await folderActivities.TryGetItemAsync(TempFileName);

            if (_fileDest != null)
            {
                // there is an already started, interrupted recording, load data from it
                var importer = new FitImporter(_activity);

                try
                {
                    using (var stream = await _fileDest.OpenForReadAsync())
                    {
                        await importer.LoadAsync(stream);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
                _activity.RecalculateCurrentLap();
                if (_activity.TimeFrames.Count > 0)
                {
                    await PrepareDestinationFileAsync();

                    IsStarted = true;
                }
            }

            SensorService.Clock.StatusChanged += OnClockTick;

            _initialized = true;
        }
Ejemplo n.º 3
0
        public override async Task <UploadStatus> UploadAsync(Stream source, UploadOptions options)
        {
            // TODO: UploadAsync should use MemoryActivity as a parameter instead of Stream
            var activity    = new MemoryActivity();
            var fitImporter = new FitImporter(activity);
            await fitImporter.LoadAsync(source);

            var activityToCreate = new FitnessActivitiesNewModel
            {
                StartTime        = activity.StartTime,
                AverageHeartRate = activity.AvgHeartRate,
                HeartRate        = new List <HeartRateModel>(),
                Path             = new List <PathModel>()
            };

            foreach (var timeFrame in activity.TimeFrames)
            {
                var timestamp = timeFrame.Timestamp.Subtract(activity.StartTime).TotalSeconds;
                var location  = timeFrame.Position.GetValueOrDefault(Position.Empty);

                activityToCreate.HeartRate.Add(new HeartRateModel
                {
                    HeartRate = timeFrame.HeartRate.GetValueOrDefault(),
                    Timestamp = timestamp
                });
                activityToCreate.Path.Add(new PathModel
                {
                    Timestamp = timestamp,
                    Altitude  = location.Altitude,
                    Longitude = location.Longitude,
                    Latitude  = location.Latitude,
                    Type      = "gps"
                });
            }

            var result = await _client.FitnessActivities.CreateActivity(activityToCreate);

            return(new HealthGraphUploadStatus {
                Status = result
            });
        }