ASCU_ALL/ApiServer/Parametrs/TechCycle.cs
2024-09-22 04:27:05 +05:00

101 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ApiServer.Parametrs;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ApiServer.Parametrs
{
public class TechCycleName
{
public int Index { get; set; }
public string Name { get; set; }
}
public class TechCycleColor
{
public int Index { get; set; }
public string Color { get; set; }
}
}
namespace ApiServer
{
public static partial class Configuration
{
public static TechCycleName[] GetTechCycleNames()
{
var result = new List<TechCycleName>();
var json_conf =
JObject.Parse(
File.ReadAllText(
Path.Combine(
Directory.GetCurrentDirectory(),
"Config",
"TechCycle.json"
)
)
);
if (!json_conf.ContainsKey("tech_cycle_conf"))
return result.ToArray();
var tc_array = json_conf.Value<JArray>("tech_cycle_conf");
foreach(JObject tc in tc_array)
{
int? index = null;
string name = null;
if (tc.ContainsKey("index"))
index = tc.Value<int>("index");
if (tc.ContainsKey("name"))
name = tc.Value<string>("name");
if (!string.IsNullOrEmpty(name) && index.HasValue)
result.Add(
new TechCycleName()
{
Index = index.Value,
Name = name
}
);
}
return result.ToArray();
}
public static TechCycleColor[] GetTechCycleColor()
{
var result = new List<TechCycleColor>();
var json_conf =
JObject.Parse(
File.ReadAllText(
Path.Combine(
Directory.GetCurrentDirectory(),
"Config",
"TechCycle.json"
)
)
);
if (!json_conf.ContainsKey("tech_cycle_conf"))
return result.ToArray();
var tc_array = json_conf.Value<JArray>("tech_cycle_conf");
foreach (JObject tc in tc_array)
{
int? index = null;
string color = null;
if (tc.ContainsKey("index"))
index = tc.Value<int>("index");
if (tc.ContainsKey("color"))
color = tc.Value<string>("color");
if (!string.IsNullOrEmpty(color) && index.HasValue)
result.Add(
new TechCycleColor()
{
Index = index.Value,
Color = color
}
);
}
return result.ToArray();
}
}
}