Ejemplo n.º 1
0
        public async Task DecodeAsync(MemoryActivity dest = null)
        {
            Name = _file.GetNameWithoutExtension();
            var input = await _file.OpenForReadAsync(); // file stream

            if (input.Length == 0)
            {
                return;
            }
            MemoryActivity activity = dest != null ? dest : new MemoryActivity();
            // use the appropriate importer type
            ActivityImporter importer = null;

            if (_file.Name.EndsWith(".fit", StringComparison.OrdinalIgnoreCase))
            {
                importer = new FitImporter(activity);
            }
            else if (_file.Name.EndsWith(".tcx", StringComparison.OrdinalIgnoreCase))
            {
                importer = new TcxImporter(activity);
            }
            if (importer != null)
            {
                await importer.LoadAsync(input);
            }

            await UpdateMetadata(ActivitySummary.FromActivity(dest));
        }
Ejemplo n.º 2
0
        public static ActivitySummary FromActivity(IActivitySummary activity)
        {
            var summary = new ActivitySummary();

            summary.CopyFrom(activity);
            return(summary);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// write properties into JSON metadata file
        /// </summary>
        /// <returns></returns>
        private async Task UpdateMetadata(ActivitySummary summary)
        {
            var folder = await GetFolderAsync();

            var metaDataFile = await folder.CreateFileAsync(MetaDataFileName, CreateFileOption.ReplaceExisting);

            using (var stream = await metaDataFile.OpenForWriteAsync())
            {
                using (var textWriter = new StreamWriter(stream))
                {
                    var serializer = new JsonSerializer();
                    serializer.Serialize(textWriter, summary);
                }
            }
        }