From 7a34fc2dbb087fdbf1bea9de2367b1627dbfd934 Mon Sep 17 00:00:00 2001 From: retr0volkov <68907954+retr0volkov@users.noreply.github.com> Date: Thu, 10 Jul 2025 11:13:40 +0300 Subject: [PATCH] JSON import added --- Utils/DataSerialization.cs | 5 +-- Utils/PropertyParentHelper.cs | 34 ++++++++++++++++++ ViewModels/MainWindowViewModel.cs | 23 +++++++++--- Views/MainWindow.axaml | 3 +- obj/Debug/net8.0/Avalonia/resources | Bin 343491 -> 343584 bytes obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs | 2 +- .../GazpromApp.AssemblyInfoInputs.cache | 2 +- 7 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 Utils/PropertyParentHelper.cs diff --git a/Utils/DataSerialization.cs b/Utils/DataSerialization.cs index 0513333..6117dfd 100644 --- a/Utils/DataSerialization.cs +++ b/Utils/DataSerialization.cs @@ -13,7 +13,8 @@ public static class DataSerialization private static string LoadData(string path) { - return System.IO.File.ReadAllText(path); + string text = System.IO.File.ReadAllText(path); + return text; } public static void SavePoint(Point point, string path) @@ -41,7 +42,7 @@ public static class Deserialization { try { - return string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize(point) : null; + return !string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize(point) : null; } catch { diff --git a/Utils/PropertyParentHelper.cs b/Utils/PropertyParentHelper.cs new file mode 100644 index 0000000..011ce83 --- /dev/null +++ b/Utils/PropertyParentHelper.cs @@ -0,0 +1,34 @@ +using GazpromApp.Models; +using System.Collections.Generic; +using System.Linq; + +namespace GazpromApp.Utils +{ + public static class PropertyParentHelper + { + public static void SetPropertyParents(this Point point) + { + // Set parents for properties in point + foreach (var prop in point.Properties) + { + SetParentsRecursively(prop); + } + + // Set parents for properties in equipment + foreach (var prop in point.Equipment.SelectMany(equipment => equipment.Properties)) + { + SetParentsRecursively(prop); + } + } + + private static void SetParentsRecursively(Property property) + { + foreach (var childProp in property.Properties) + { + childProp.Parent = property; + childProp.ParentId = property.Id; + SetParentsRecursively(childProp); + } + } + } +} \ No newline at end of file diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index c34fade..22ca84d 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -45,15 +45,29 @@ public partial class MainWindowViewModel : ViewModelBase } [RelayCommand] - private void ImportPoint(Window w) + private async Task ImportPoint(Window w) { - + var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + AllowMultiple = true, + SuggestedStartLocation = + await w.StorageProvider.TryGetFolderFromPathAsync( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) + }); + foreach (var file in files) + { + var url = file.Path.AbsolutePath; + var decoded = HttpUtility.HtmlDecode(url); + var point = DataSerialization.LoadPoint(decoded); + point?.SetPropertyParents(); + Points.Add(new PointViewModel(point ?? new Point())); + } } [RelayCommand] private async Task ExportPoint(Window w) { - var folder = await w.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions() + var folder = await w.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions { AllowMultiple = false, SuggestedStartLocation = @@ -64,9 +78,10 @@ public partial class MainWindowViewModel : ViewModelBase { DataSerialization.SavePoint(point.GetPoint(), Path.Combine(HttpUtility.HtmlDecode(folder[0].Path.AbsolutePath), point.Name + ".json") ); } + } - // Visual properties + // Visual and other properties [ObservableProperty] private bool _isLineVisible; diff --git a/Views/MainWindow.axaml b/Views/MainWindow.axaml index 6642252..bfd2378 100644 --- a/Views/MainWindow.axaml +++ b/Views/MainWindow.axaml @@ -52,7 +52,8 @@ - + diff --git a/obj/Debug/net8.0/Avalonia/resources b/obj/Debug/net8.0/Avalonia/resources index 6c5b15db7413ae43beb551efc6420349a1589776..2ef0e1802924b8f0ed87a01ba05bd8ef54902d88 100644 GIT binary patch delta 105 zcmX^7TV%l>kqxmNjK?O&aVT@n6J%uw=Vf4!p6+YQD$V$H@-hx3#(m8vIoeNhFaj|X z5HkZY%l4BTta@zIMR{3;**tR#@{3BQD@w2`O#kqVg?;)0C05Ppb-b(#CigSSZa=`! H%B%+fC$Axx delta 68 zcmZ4RN96EtkqxmNjG2?;IFuP3CpQ7f8IzZBC^05BpX6vi$-xN3OhC*G#4OuSaX)Bil9sRs}r(O79k9 diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs index 42642ce..244d131 100644 --- a/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs +++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+915c7a7c5ec49dae4fabb6a5def0aa05d90783a6")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f3e0e15f352858b0ee8bba13ece6c0dffa8c8987")] [assembly: System.Reflection.AssemblyProductAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache index c786652..4512602 100644 --- a/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/GazpromApp.AssemblyInfoInputs.cache @@ -1 +1 @@ -21fc2377da7e1819564fca788d76eb9386fb849b5d97c9fa58834904b0020d89 +3913b1f238033a5ab96ca8fd462af0cdbfa6151f322cece9cf7cd65c0266a4e7