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 6c5b15d..2ef0e18 100644 Binary files a/obj/Debug/net8.0/Avalonia/resources and b/obj/Debug/net8.0/Avalonia/resources differ 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