Save last
This commit is contained in:
		
							
								
								
									
										161
									
								
								ApiServer/Parametrs/Analog.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								ApiServer/Parametrs/Analog.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,161 @@
 | 
			
		||||
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;
 | 
			
		||||
using NLog;
 | 
			
		||||
 | 
			
		||||
namespace ApiServer.Parametrs
 | 
			
		||||
{
 | 
			
		||||
  public class AnalogParams
 | 
			
		||||
  {
 | 
			
		||||
    public int Index { get; set; }
 | 
			
		||||
    public bool ShowDefault { get; set; }
 | 
			
		||||
    public bool Skip { get; set; }
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public string Sname { get; set; }
 | 
			
		||||
    public string Metric { get; set; }
 | 
			
		||||
    public double? Min { get; set; }
 | 
			
		||||
    public double? Max { get; set; }
 | 
			
		||||
    public double Mul { get; set; }
 | 
			
		||||
    public int[] Bytes {get;set;}
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ApiServer
 | 
			
		||||
{
 | 
			
		||||
  public static partial class Configuration
 | 
			
		||||
  {
 | 
			
		||||
    private static Logger log = LogManager.GetCurrentClassLogger();
 | 
			
		||||
    public static Dictionary<string,AnalogParams[]> r_analogParams = null;
 | 
			
		||||
    public static AnalogParams[] GetAnalogParams(string name_analog)
 | 
			
		||||
    {
 | 
			
		||||
      log.Info("Ask analog parasm: " + name_analog);
 | 
			
		||||
      if (r_analogParams != null && r_analogParams.ContainsKey(name_analog))
 | 
			
		||||
      {
 | 
			
		||||
        log.Info("Exist: " + name_analog);
 | 
			
		||||
        return r_analogParams[name_analog];
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      var result = new List<AnalogParams>();
 | 
			
		||||
      var list_files = Directory.GetFiles(
 | 
			
		||||
        Path.Combine(
 | 
			
		||||
          Directory.GetCurrentDirectory(),
 | 
			
		||||
          "Config",
 | 
			
		||||
          "Analog"
 | 
			
		||||
          )
 | 
			
		||||
        );
 | 
			
		||||
      foreach (var file in list_files) {
 | 
			
		||||
        log.Info("Try read " + file);
 | 
			
		||||
        var json_conf =
 | 
			
		||||
          JObject.Parse(
 | 
			
		||||
            File.ReadAllText(
 | 
			
		||||
              file
 | 
			
		||||
              )
 | 
			
		||||
            );
 | 
			
		||||
        if (!json_conf.ContainsKey(name_analog))
 | 
			
		||||
          continue;
 | 
			
		||||
 | 
			
		||||
        var analog = json_conf.Value<JObject>(name_analog);
 | 
			
		||||
        if (analog.ContainsKey("struct"))
 | 
			
		||||
        {
 | 
			
		||||
          var struct_arr = analog.Value<JArray>("struct");
 | 
			
		||||
          foreach (JObject struct_el in struct_arr)
 | 
			
		||||
          {
 | 
			
		||||
            var analog_param = GetAnalogParam(struct_el);
 | 
			
		||||
            if (analog_param != null)
 | 
			
		||||
              if (result.Find(x => x.Index == analog_param.Index) == null)
 | 
			
		||||
                result.Add(analog_param);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (analog.ContainsKey("parent"))
 | 
			
		||||
        {
 | 
			
		||||
          var parent_list = analog.Value<JArray>("parent");
 | 
			
		||||
          for(var i = parent_list.Count - 1; i >= 0; i--)
 | 
			
		||||
          {
 | 
			
		||||
            var parent_states = GetAnalogParams(parent_list[i].Value<string>());
 | 
			
		||||
            foreach (var state in parent_states)
 | 
			
		||||
            {
 | 
			
		||||
              if (state != null)
 | 
			
		||||
                if (result.Find(x => x.Index == state.Index) == null)
 | 
			
		||||
                  result.Add(state);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      if (r_analogParams == null)
 | 
			
		||||
        r_analogParams = new Dictionary<string, AnalogParams[]>();
 | 
			
		||||
      if (r_analogParams.ContainsKey(name_analog))
 | 
			
		||||
        r_analogParams[name_analog] = result.ToArray();
 | 
			
		||||
      else
 | 
			
		||||
        r_analogParams.Add(name_analog, result.ToArray());
 | 
			
		||||
      return result.ToArray();
 | 
			
		||||
    }
 | 
			
		||||
    private static AnalogParams GetAnalogParam(JObject data)
 | 
			
		||||
    {
 | 
			
		||||
      if ( data == null || !data.ContainsKey("index"))
 | 
			
		||||
        return null;
 | 
			
		||||
      var index = data.Value<int>("index");
 | 
			
		||||
      var result = new AnalogParams()
 | 
			
		||||
      {
 | 
			
		||||
        Index = index,
 | 
			
		||||
        Name = "Аналог " + index,
 | 
			
		||||
        Sname = "Аналог " + index,
 | 
			
		||||
        Min = null,
 | 
			
		||||
        Max = null,
 | 
			
		||||
        Mul = 1,
 | 
			
		||||
        Metric = "УЕ",
 | 
			
		||||
        Skip = false,
 | 
			
		||||
        ShowDefault = false,
 | 
			
		||||
        Bytes = new int[0]
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      if (data.ContainsKey("skip"))
 | 
			
		||||
      {
 | 
			
		||||
        var skip = data.Value<bool>("skip");
 | 
			
		||||
        if (skip)
 | 
			
		||||
        {
 | 
			
		||||
          result.Skip = true;
 | 
			
		||||
          return result;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (data.ContainsKey("name"))
 | 
			
		||||
        result.Name = data.Value<string>("name");
 | 
			
		||||
      if (data.ContainsKey("s_name"))
 | 
			
		||||
        result.Sname = data.Value<string>("s_name");
 | 
			
		||||
      if (data.ContainsKey("metric"))
 | 
			
		||||
        result.Metric = data.Value<string>("metric");
 | 
			
		||||
      if (data.ContainsKey("min"))
 | 
			
		||||
        result.Min = data.Value<double>("min");
 | 
			
		||||
      if (data.ContainsKey("max"))
 | 
			
		||||
        result.Max = data.Value<double>("max");
 | 
			
		||||
      if (data.ContainsKey("mul"))
 | 
			
		||||
        result.Mul = data.Value<double>("mul");
 | 
			
		||||
      if (data.ContainsKey("show_default"))
 | 
			
		||||
        result.ShowDefault = data.Value<bool>("show_default");
 | 
			
		||||
 | 
			
		||||
      if (data.ContainsKey("bytes"))
 | 
			
		||||
      {
 | 
			
		||||
        var bytes = data.Value<JArray>("bytes");
 | 
			
		||||
        var arr = new List<int>();
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
          for (var i = 0; i < bytes.Count; i++)
 | 
			
		||||
            arr.Add(bytes[i].Value<int>());
 | 
			
		||||
          result.Bytes = arr.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
        catch
 | 
			
		||||
        {
 | 
			
		||||
          result.Bytes = new int[0];
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										142
									
								
								ApiServer/Parametrs/Discret.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								ApiServer/Parametrs/Discret.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,142 @@
 | 
			
		||||
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 DiscretParams
 | 
			
		||||
  {
 | 
			
		||||
    public int Index { get; set; }
 | 
			
		||||
    public bool Skip { get; set; }
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public ByteBit[] Bits {get;set;}
 | 
			
		||||
    public string StateStruct { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
  public class ByteBit
 | 
			
		||||
  {
 | 
			
		||||
    public int ByteIndex { get; set; }
 | 
			
		||||
    public byte BitIndex { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ApiServer
 | 
			
		||||
{
 | 
			
		||||
  public static partial class Configuration
 | 
			
		||||
  {
 | 
			
		||||
    public static DiscretParams[] GetDiscretParams(string name_discret)
 | 
			
		||||
    {
 | 
			
		||||
      var result = new List<DiscretParams>();
 | 
			
		||||
      var list_files = Directory.GetFiles(
 | 
			
		||||
        Path.Combine(
 | 
			
		||||
          Directory.GetCurrentDirectory(),
 | 
			
		||||
          "Config",
 | 
			
		||||
          "Discret"
 | 
			
		||||
          )
 | 
			
		||||
        );
 | 
			
		||||
      foreach (var file in list_files) {
 | 
			
		||||
        var json_conf =
 | 
			
		||||
          JObject.Parse(
 | 
			
		||||
            File.ReadAllText(
 | 
			
		||||
              file
 | 
			
		||||
              )
 | 
			
		||||
            );
 | 
			
		||||
        if (!json_conf.ContainsKey(name_discret))
 | 
			
		||||
          continue;
 | 
			
		||||
 | 
			
		||||
        var discret = json_conf.Value<JObject>(name_discret);
 | 
			
		||||
        if (discret.ContainsKey("struct"))
 | 
			
		||||
        {
 | 
			
		||||
          var struct_arr = discret.Value<JArray>("struct");
 | 
			
		||||
          foreach (JObject struct_el in struct_arr)
 | 
			
		||||
          {
 | 
			
		||||
            var discret_param = GetDiscretParam(struct_el);
 | 
			
		||||
            if (discret_param != null)
 | 
			
		||||
              if (result.Find(x => x.Index == discret_param.Index) == null)
 | 
			
		||||
                result.Add(discret_param);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (discret.ContainsKey("parent"))
 | 
			
		||||
        {
 | 
			
		||||
          var parent_list = discret.Value<JArray>("parent");
 | 
			
		||||
          for(var i = parent_list.Count - 1; i >= 0; i--)
 | 
			
		||||
          {
 | 
			
		||||
            var parent_states = GetDiscretParams(parent_list[i].Value<string>());
 | 
			
		||||
            foreach (var state in parent_states)
 | 
			
		||||
            {
 | 
			
		||||
              if (state != null)
 | 
			
		||||
                if (result.Find(x => x.Index == state.Index) == null)
 | 
			
		||||
                  result.Add(state);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      return result.ToArray();
 | 
			
		||||
    }
 | 
			
		||||
    private static DiscretParams GetDiscretParam(JObject data)
 | 
			
		||||
    {
 | 
			
		||||
      if (
 | 
			
		||||
        data == null ||
 | 
			
		||||
        !data.ContainsKey("index"))
 | 
			
		||||
        return null;
 | 
			
		||||
      if (data.ContainsKey("skip"))
 | 
			
		||||
      {
 | 
			
		||||
        var skip = data.Value<bool>("skip");
 | 
			
		||||
        if (skip)
 | 
			
		||||
        {
 | 
			
		||||
          return new DiscretParams()
 | 
			
		||||
          {
 | 
			
		||||
            Index = data.Value<int>("index"),
 | 
			
		||||
            Skip = true
 | 
			
		||||
          };
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (
 | 
			
		||||
        data == null ||
 | 
			
		||||
        !data.ContainsKey("index") ||
 | 
			
		||||
        !data.ContainsKey("name") ||
 | 
			
		||||
        !data.ContainsKey("state_struct") ||
 | 
			
		||||
        !data.ContainsKey("bits")
 | 
			
		||||
        )
 | 
			
		||||
        return null;
 | 
			
		||||
      var bits = data.Value<JArray>("bits");
 | 
			
		||||
      var arr = new List<ByteBit>();
 | 
			
		||||
      try
 | 
			
		||||
      {
 | 
			
		||||
        for (var i = 0; i < bits.Count; i++)
 | 
			
		||||
        {
 | 
			
		||||
          if (
 | 
			
		||||
            bits[i] == null ||
 | 
			
		||||
            !((JObject)bits[i]).ContainsKey("byte_index") ||
 | 
			
		||||
            !((JObject)bits[i]).ContainsKey("bit_index")
 | 
			
		||||
            )
 | 
			
		||||
            continue;
 | 
			
		||||
          arr.Add(new ByteBit()
 | 
			
		||||
          {
 | 
			
		||||
            ByteIndex = ((JObject)bits[i]).Value<int>("byte_index"),
 | 
			
		||||
            BitIndex = ((JObject)bits[i]).Value<byte>("bit_index")
 | 
			
		||||
          });
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      catch
 | 
			
		||||
      {
 | 
			
		||||
        return null;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return new DiscretParams()
 | 
			
		||||
      {
 | 
			
		||||
        Index = data.Value<int>("index"),
 | 
			
		||||
        Skip = false,
 | 
			
		||||
        Name = data.Value<string>("name"),
 | 
			
		||||
        Bits = arr.ToArray(),
 | 
			
		||||
        StateStruct = data.Value<string>("state_struct")
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								ApiServer/Parametrs/Metrics.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								ApiServer/Parametrs/Metrics.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
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 Metric
 | 
			
		||||
  {
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public bool Log { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ApiServer
 | 
			
		||||
{
 | 
			
		||||
  public static partial class Configuration
 | 
			
		||||
  {
 | 
			
		||||
    public static Metric[] GetMetricsArray()
 | 
			
		||||
    {
 | 
			
		||||
      var result = new List<Metric>();
 | 
			
		||||
      var json_conf =
 | 
			
		||||
        JObject.Parse(
 | 
			
		||||
          File.ReadAllText(
 | 
			
		||||
            Path.Combine(
 | 
			
		||||
              Directory.GetCurrentDirectory(),
 | 
			
		||||
              "Config",
 | 
			
		||||
              "Metrics.json"
 | 
			
		||||
              )
 | 
			
		||||
            )
 | 
			
		||||
          );
 | 
			
		||||
      var list_objects = json_conf.GetEnumerator();
 | 
			
		||||
      while (list_objects.MoveNext())
 | 
			
		||||
      {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
          var name = list_objects.Current.Key;
 | 
			
		||||
          var log = (bool)list_objects.Current.Value;
 | 
			
		||||
          if (result.FindIndex(x => x.Name == name) == -1)
 | 
			
		||||
            result.Add(new Metric()
 | 
			
		||||
            {
 | 
			
		||||
              Name = name,
 | 
			
		||||
              Log = log
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        catch
 | 
			
		||||
        {
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return result.ToArray();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										94
									
								
								ApiServer/Parametrs/Protect.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								ApiServer/Parametrs/Protect.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
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 ProtectState
 | 
			
		||||
  {
 | 
			
		||||
    public byte Index { get; set; }
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public string StateStruct { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ApiServer
 | 
			
		||||
{
 | 
			
		||||
  public static partial class Configuration
 | 
			
		||||
  {
 | 
			
		||||
    public static ProtectState[] GetProtectState(string name_protect)
 | 
			
		||||
    {
 | 
			
		||||
      var result = new List<ProtectState>();
 | 
			
		||||
      var list_files = Directory.GetFiles(
 | 
			
		||||
        Path.Combine(
 | 
			
		||||
          Directory.GetCurrentDirectory(),
 | 
			
		||||
          "Config",
 | 
			
		||||
          "Protect"
 | 
			
		||||
          )
 | 
			
		||||
        );
 | 
			
		||||
      foreach (var file in list_files) {
 | 
			
		||||
        var json_conf =
 | 
			
		||||
          JObject.Parse(
 | 
			
		||||
            File.ReadAllText(
 | 
			
		||||
              file
 | 
			
		||||
              )
 | 
			
		||||
            );
 | 
			
		||||
        if (!json_conf.ContainsKey(name_protect))
 | 
			
		||||
          continue;
 | 
			
		||||
 | 
			
		||||
        var protect = json_conf.Value<JObject>(name_protect);
 | 
			
		||||
        if (protect.ContainsKey("struct"))
 | 
			
		||||
        {
 | 
			
		||||
          var struct_arr = protect.Value<JArray>("struct");
 | 
			
		||||
          foreach (JObject struct_el in struct_arr)
 | 
			
		||||
          {
 | 
			
		||||
            var protect_state = GetProtect(struct_el);
 | 
			
		||||
            if (protect_state != null)
 | 
			
		||||
              if (result.Find(x => x.Index == protect_state.Index) == null)
 | 
			
		||||
                result.Add(protect_state);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (protect.ContainsKey("parent"))
 | 
			
		||||
        {
 | 
			
		||||
          var parent_list = protect.Value<JArray>("parent");
 | 
			
		||||
          for(var i = parent_list.Count - 1; i >= 0; i--)
 | 
			
		||||
          {
 | 
			
		||||
            var parent_states = GetProtectState(parent_list[i].Value<string>());
 | 
			
		||||
            foreach (var state in parent_states)
 | 
			
		||||
            {
 | 
			
		||||
              if (state != null)
 | 
			
		||||
                if (result.Find(x => x.Index == state.Index) == null)
 | 
			
		||||
                  result.Add(state);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      return result.ToArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static ProtectState GetProtect(JObject data)
 | 
			
		||||
    {
 | 
			
		||||
      if (
 | 
			
		||||
        data == null ||
 | 
			
		||||
        !data.ContainsKey("index") ||
 | 
			
		||||
        !data.ContainsKey("name") ||
 | 
			
		||||
        !data.ContainsKey("state_struct")
 | 
			
		||||
        )
 | 
			
		||||
        return null;
 | 
			
		||||
 | 
			
		||||
      return new ProtectState()
 | 
			
		||||
      {
 | 
			
		||||
        Index = data.Value<byte>("index"),
 | 
			
		||||
        Name = data.Value<string>("name"),
 | 
			
		||||
        StateStruct = data.Value<string>("state_struct")
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										105
									
								
								ApiServer/Parametrs/States.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								ApiServer/Parametrs/States.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
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 State
 | 
			
		||||
  {
 | 
			
		||||
    public byte Index { get; set; }
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public string Color { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
  public class StateStruct
 | 
			
		||||
  {
 | 
			
		||||
    public string Name { get; set; }
 | 
			
		||||
    public State[] States { get; set; }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ApiServer
 | 
			
		||||
{
 | 
			
		||||
  public static partial class Configuration
 | 
			
		||||
  {
 | 
			
		||||
    public static StateStruct[] GetStateStructArray()
 | 
			
		||||
    {
 | 
			
		||||
      var result = new List<StateStruct>();
 | 
			
		||||
      var json_conf =
 | 
			
		||||
        JObject.Parse(
 | 
			
		||||
          File.ReadAllText(
 | 
			
		||||
            Path.Combine(
 | 
			
		||||
              Directory.GetCurrentDirectory(),
 | 
			
		||||
              "Config",
 | 
			
		||||
              "StateStruct.json"
 | 
			
		||||
              )
 | 
			
		||||
            )
 | 
			
		||||
          );
 | 
			
		||||
      var list_objects = json_conf.GetEnumerator();
 | 
			
		||||
      while (list_objects.MoveNext())
 | 
			
		||||
      {
 | 
			
		||||
        var sub_res = GetStateStruct(
 | 
			
		||||
          list_objects.Current.Key,
 | 
			
		||||
          (JArray)list_objects.Current.Value
 | 
			
		||||
          );
 | 
			
		||||
        if (sub_res != null)
 | 
			
		||||
          result.Add(sub_res);
 | 
			
		||||
      }
 | 
			
		||||
      return result.ToArray();
 | 
			
		||||
    }
 | 
			
		||||
    public static StateStruct GetStateStruct(string name)
 | 
			
		||||
    {
 | 
			
		||||
      var json_conf =
 | 
			
		||||
        JObject.Parse(
 | 
			
		||||
          File.ReadAllText(
 | 
			
		||||
            Path.Combine(
 | 
			
		||||
              Directory.GetCurrentDirectory(),
 | 
			
		||||
              "Config",
 | 
			
		||||
              "StateStruct.json"
 | 
			
		||||
              )
 | 
			
		||||
            )
 | 
			
		||||
          );
 | 
			
		||||
      if (!json_conf.ContainsKey(name))
 | 
			
		||||
        return null;
 | 
			
		||||
      return GetStateStruct(name, json_conf.Value<JArray>(name));
 | 
			
		||||
    }
 | 
			
		||||
    private static StateStruct GetStateStruct(string name, JArray data)
 | 
			
		||||
    {
 | 
			
		||||
      if (data == null)
 | 
			
		||||
        return null;
 | 
			
		||||
      var result = new StateStruct() { Name = name };
 | 
			
		||||
      var sub_res = new List<State>();
 | 
			
		||||
      foreach (JObject j_state_struct in data)
 | 
			
		||||
      {
 | 
			
		||||
        var state = GetState(j_state_struct);
 | 
			
		||||
        if (state == null)
 | 
			
		||||
          continue;
 | 
			
		||||
        sub_res.Add(state);
 | 
			
		||||
      }
 | 
			
		||||
      result.States = sub_res.ToArray();
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
    private static State GetState(JObject data)
 | 
			
		||||
    {
 | 
			
		||||
      if (
 | 
			
		||||
        data == null ||
 | 
			
		||||
        !data.ContainsKey("index") ||
 | 
			
		||||
        !data.ContainsKey("name") ||
 | 
			
		||||
        !data.ContainsKey("color")
 | 
			
		||||
        )
 | 
			
		||||
        return null;
 | 
			
		||||
 | 
			
		||||
      return new State()
 | 
			
		||||
      {
 | 
			
		||||
        Index = data.Value<byte>("index"),
 | 
			
		||||
        Name = data.Value<string>("name"),
 | 
			
		||||
        Color = data.Value<string>("color")
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										100
									
								
								ApiServer/Parametrs/TechCycle.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								ApiServer/Parametrs/TechCycle.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,100 @@
 | 
			
		||||
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();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user