RouteManager.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using GSG.NET.ObjectBase;
  2. using Newtonsoft.Json.Linq;
  3. using OHV.Common.Model;
  4. using OHV.Common.Shareds;
  5. using OHV.SqliteDAL;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace VehicleControlSystem.Managers
  13. {
  14. public class RouteManager : SingletonBase<RouteManager>, IDisposable
  15. {
  16. SqliteManager sql = null;
  17. public List<segment> Segments = new List<segment>();
  18. public List<point> Points = new List<point>();
  19. public List<equipment> Equipments = new List<equipment>();
  20. public List<obstacles> Obstacles = new List<obstacles>();
  21. private RouteManager( )
  22. {
  23. }
  24. public void Init( SqliteManager sql )
  25. {
  26. this.sql = sql;
  27. this.LoadJson();
  28. }
  29. void LoadJson()
  30. {
  31. var path = sql.ConfigDal.GetK( ConstString.RouteFilePath ).Value;
  32. if ( !System.IO.File.Exists( path ) )
  33. return;
  34. using ( StreamReader r = new StreamReader( path ) )
  35. {
  36. string json = r.ReadToEnd();
  37. var o = JObject.Parse( json );
  38. this.Points = o["points"].ToObject<List<point>>();
  39. this.Segments = o["segments"].ToObject<List<segment>>();
  40. this.Obstacles = o["obstacles"].ToObject<List<obstacles>>();
  41. this.Equipments = o["equipments"].ToObject<List<equipment>>();
  42. }
  43. this.WriteToDB();
  44. }
  45. /// <summary>
  46. /// File 에서 읽어 와서 DB로 넣엇 사용하자 View 에서 같이 사용하기 위해
  47. /// </summary>
  48. void WriteToDB()
  49. {
  50. this.sql.RouteDal.Clean();
  51. this.Points.ForEach( p =>
  52. {
  53. Route route = new Route()
  54. {
  55. ScaleValue = p.barcode,
  56. Name = p.ID.ToString(),
  57. };
  58. sql.RouteDal.Add( route );
  59. } );
  60. }
  61. public void Dispose()
  62. {
  63. }
  64. }
  65. }