예제 #1
0
        public async Task ExportEventsSummary(int?count, CloudDataExporter exporter, string fileName, IProgress <BandCloudExportProgress> progress)
        {
            var settings = exporter.Settings;

            // TODO: Still need to find a better way to load events incrementally
            if (count == null)
            {
                count = 10000000; // suitably large number to encompass "everything".
            }
            if (Events.Count < count)
            {
                // clear out our existing events, since they're going to be replaced
                Events.Clear();

                progress.Report(new BandCloudExportProgress()
                {
                    TotalEventsToExport = 0, StatusMessage = "Downloading Events..."
                });

                await LoadEvents((int)count);
            }

            // we have now downloaded the correct number of events, export them
            // Note: Take will take min(Events.Count, count)
            await ExportEventsSummary(
                Events.Where(e =>
            {
                return((settings.IncludeRuns && e.Event.EventType == BandEventType.Running) ||
                       (settings.IncludeSleep && e.Event.EventType == BandEventType.Sleeping) ||
                       (settings.IncludeWorkouts && (e.Event.EventType == BandEventType.GuidedWorkout || e.Event.EventType == BandEventType.Workout)));
            }
                             )
                .Take((int)count),
                exporter,
                fileName,
                progress
                );
        }
예제 #2
0
        private async Task ExportEventsSummary(IEnumerable <BandEventViewModel> bandEvents, CloudDataExporter exporter, string fileName, IProgress <BandCloudExportProgress> progress)
        {
            // TODO: set more logical initial capacity?
            var csv        = new StringBuilder(500000);
            var dataToDump = new List <Dictionary <string, object> >(100);

            var progressReport = new BandCloudExportProgress()
            {
                TotalEventsToExport = bandEvents.Count(), StatusMessage = "Exporting Events..."
            };

            progress.Report(progressReport);
            await Task.Yield();

            foreach (var bandEvent in bandEvents)
            {
                // TODO: I hate this pattern. I should be able to just tell the CloudClient to download all of the data for my event,
                //       or tell the event to download the data itself
                // TODO: This fits ExportsEventsFull, not Summary
                //var data = await _cloud.GetFullEventData(bandEvent.Event.EventID, bandEvent.Event.Expanders);
                //bandEvent.Event.InitFullEventData(data);

                dataToDump.Add(bandEvent.Event.DumpBasicEventData());

                progressReport.ExportedEventsCount++;
                progress.Report(progressReport);

                await Task.Yield(); // since we need to update progress, make sure to yield for a bit
            }

            exporter.ExportToFile(dataToDump, fileName);

            //TODO: dump data
            System.Diagnostics.Debug.WriteLine(dataToDump.Count);
        }