Exemple #1
0
        public static Task <ExitCode> CreateReport(ExcelReportOptions opts, TextWriter stdErr)
        {
            if (!File.Exists(opts.PathToHealthExportFile))
            {
                return(Task.FromResult(ExitCode.ExportFileNotFound(opts.PathToHealthExportFile)));
            }
            if (File.Exists(opts.OutputFilename))
            {
                return(Task.FromResult(ExitCode.ExportFileExists(opts.OutputFilename)));
            }

            var loader = Usable.Using(new StreamReader(opts.PathToHealthExportFile), reader =>
                                      ZipUtilities.ReadArchive(
                                          reader.BaseStream,
                                          entry => entry.FullName == "apple_health_export/export.xml",
                                          entry => new XmlReaderExportLoader(entry.Open()))
                                      .FirstOrDefault());

            var settings = GetSettings(opts, stdErr);

            var(package, customSheets) = GetCustomSheets(opts, stdErr);

            using (var excelFile = new ExcelPackage())
                using (package)
                {
                    var timeZone = DateTimeZone.ForOffset(Offset.FromHours(-5));
                    ExcelReport.BuildReport(loader.Records, loader.Workouts, excelFile.Workbook, settings, timeZone, customSheets);

                    excelFile.SaveAs(new FileInfo(opts.OutputFilename));
                }

            return(Task.FromResult(ExitCode.Success));
        }