JSON import added
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user