JSON import added
This commit is contained in:
@@ -13,7 +13,8 @@ public static class DataSerialization
|
|||||||
|
|
||||||
private static string LoadData(string path)
|
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)
|
public static void SavePoint(Point point, string path)
|
||||||
@@ -41,7 +42,7 @@ public static class Deserialization
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize<Point>(point) : null;
|
return !string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize<Point>(point) : null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,15 +45,29 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[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]
|
[RelayCommand]
|
||||||
private async Task ExportPoint(Window w)
|
private async Task ExportPoint(Window w)
|
||||||
{
|
{
|
||||||
var folder = await w.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()
|
var folder = await w.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||||
{
|
{
|
||||||
AllowMultiple = false,
|
AllowMultiple = false,
|
||||||
SuggestedStartLocation =
|
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") );
|
DataSerialization.SavePoint(point.GetPoint(), Path.Combine(HttpUtility.HtmlDecode(folder[0].Path.AbsolutePath), point.Name + ".json") );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visual properties
|
// Visual and other properties
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool _isLineVisible;
|
private bool _isLineVisible;
|
||||||
|
|||||||
@@ -52,7 +52,8 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</MenuItem.Header>
|
</MenuItem.Header>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem>
|
<MenuItem Command="{Binding ImportPointCommand}"
|
||||||
|
CommandParameter="{Binding #Window}">
|
||||||
<MenuItem.Header>
|
<MenuItem.Header>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_arrow_import_24_filled (Custom).png"/>
|
<Image Width="24" Height="24" Source="avares://GazpromApp/Assets/ic_fluent_arrow_import_24_filled (Custom).png"/>
|
||||||
|
|||||||
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("GazpromApp")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
21fc2377da7e1819564fca788d76eb9386fb849b5d97c9fa58834904b0020d89
|
3913b1f238033a5ab96ca8fd462af0cdbfa6151f322cece9cf7cd65c0266a4e7
|
||||||
|
|||||||
Reference in New Issue
Block a user