ServiceConfig.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Shaker.Model;
  2. using ShakerService.ViewModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Http.Headers;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace ShakerService
  10. {
  11. internal class ServiceConfigModel : BaseModel
  12. {
  13. public string Name = "振动台";
  14. public string SN = "SN123456";
  15. public int Port = 5555;
  16. public int AnalogCount = 11;
  17. public int ValveCount = 4;
  18. public int AccelerationCount = 2;
  19. public override object Clone()
  20. {
  21. return this.CloneBase();
  22. }
  23. }
  24. internal class ServiceConfigViewModel:BaseServiceViewModel<ServiceConfigModel>
  25. {
  26. public string Name => Model.Name;
  27. public string SN => Model.SN;
  28. public int Port => Model.Port;
  29. public int AnalogCount => Model.AnalogCount;
  30. public int ValveCount => Model.ValveCount;
  31. public int AccelerationCount => Model.AccelerationCount;
  32. private ServiceConfigViewModel()
  33. {
  34. Communication.Instance.DbConnection.CreateTable<ServiceConfigModel>();
  35. var config = Communication.Instance.DbConnection.Query<ServiceConfigModel>($"select * from {nameof(ServiceConfigModel)}")?.FirstOrDefault() ?? new ServiceConfigModel();
  36. UpModel(config);
  37. Communication.Instance.DbConnection.DeleteAll<ServiceConfigModel>();
  38. Communication.Instance.DbConnection.Insert(config, nameof(ServiceConfigModel));
  39. }
  40. static ServiceConfigViewModel()
  41. {
  42. }
  43. public static ServiceConfigViewModel Instance { get; } = new ServiceConfigViewModel();
  44. }
  45. }