JSON import added

This commit is contained in:
retr0volkov
2025-07-10 11:29:19 +03:00 Unverified
parent fe8bfe7ef0
commit 7a34fc2dbb
7 changed files with 60 additions and 9 deletions
+3 -2
View File
@@ -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>(point) : null;
return !string.IsNullOrEmpty(point) ? JsonSerializer.Deserialize<Point>(point) : null;
}
catch
{
+34
View File
@@ -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);
}
}
}
}