From b22c35f8419932039e6a22180e8ab0f2b8df964f Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 11 Sep 2020 21:07:20 -0400 Subject: [PATCH] new feature: json export --- ApplicationServices/UNTESTED/LibraryExporter.cs | 17 +++++++++-------- LibationLauncher/LibationLauncher.csproj | 2 +- LibationWinForms/UNTESTED/Form1.cs | 6 +++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ApplicationServices/UNTESTED/LibraryExporter.cs b/ApplicationServices/UNTESTED/LibraryExporter.cs index 5880b2d5..ab84d0c5 100644 --- a/ApplicationServices/UNTESTED/LibraryExporter.cs +++ b/ApplicationServices/UNTESTED/LibraryExporter.cs @@ -138,6 +138,15 @@ namespace ApplicationServices csv.WriteRecords(dtos); } + public static void ToJson(string saveFilePath) + { + using var context = DbContexts.GetContext(); + var dtos = context.GetLibrary_Flat_NoTracking().ToDtos(); + + var json = Newtonsoft.Json.JsonConvert.SerializeObject(dtos, Newtonsoft.Json.Formatting.Indented); + System.IO.File.WriteAllText(saveFilePath, json); + } + public static void ToXlsx(string saveFilePath) { using var context = DbContexts.GetContext(); @@ -220,13 +229,5 @@ namespace ApplicationServices public bool IsApproved { get; set; } public string Comment { get; set; } } - - public static void ToJson(string saveFilePath) - { - using var context = DbContexts.GetContext(); - - var library = context.GetLibrary_Flat_NoTracking(); - - } } } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 8f5b6829..1fe8a363 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 4.0.4.4 + 4.0.5.3 diff --git a/LibationWinForms/UNTESTED/Form1.cs b/LibationWinForms/UNTESTED/Form1.cs index 7be82178..cc7954d0 100644 --- a/LibationWinForms/UNTESTED/Form1.cs +++ b/LibationWinForms/UNTESTED/Form1.cs @@ -310,14 +310,18 @@ namespace LibationWinForms var saveFileDialog = new SaveFileDialog { Title = "Where to export Library", - Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*" + Filter = "CSV files (*.csv)|*.csv|JSON files (*.json)|*.json|All files (*.*)|*.*" }; if (saveFileDialog.ShowDialog() != DialogResult.OK) return; + // FilterIndex is 1-based, NOT 0-based switch (saveFileDialog.FilterIndex) { + case 2: // json + LibraryExporter.ToJson(saveFileDialog.FileName); + break; case 1: // csv default: LibraryExporter.ToCsv(saveFileDialog.FileName);