电子药箱通讯服务端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

7 месяцев назад
6 месяцев назад
7 месяцев назад
6 месяцев назад
7 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http.Headers;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Rdh.SocketServer.Client.Models
  8. {
  9. public abstract class BaseEleMedKitProtocol
  10. {
  11. public virtual string? Command { get; set; }
  12. /// <summary>
  13. /// 获取或设置数据的最小行数
  14. /// </summary>
  15. public virtual int MinLines { get; set; } = 1;
  16. public virtual string AddLineContent(string? line)
  17. {
  18. return line == null
  19. ? string.Empty
  20. : EleMedKitProtocolFlags.LineStart + line + EleMedKitProtocolFlags.LineEnd;
  21. }
  22. public virtual string AddBlockContent(string? content)
  23. {
  24. return content == null
  25. ? string.Empty
  26. : EleMedKitProtocolFlags.BlockSpiltor + content;
  27. }
  28. public virtual string AddList<T>(IEnumerable<T>? list)
  29. {
  30. if (list == null || list.Count() == 0)
  31. {
  32. return string.Empty;
  33. }
  34. StringBuilder builder = new StringBuilder();
  35. if (typeof(T) == typeof(string))
  36. {
  37. foreach (T t in list)
  38. {
  39. builder.Append(t as string);
  40. }
  41. }
  42. else
  43. {
  44. foreach (T t in list)
  45. {
  46. builder.Append(t.ToString());
  47. }
  48. }
  49. return builder.ToString();
  50. }
  51. public abstract string GetContent();
  52. /// <summary>
  53. /// 检验数据行并进行解析
  54. /// </summary>
  55. /// <param name="lines"></param>
  56. /// <returns>是否检验成功</returns>
  57. public virtual bool ParseContent(string[] lines)
  58. {
  59. if (lines == null || lines.Length < 1)
  60. {
  61. return false;
  62. }
  63. Command = lines[0];
  64. return true;
  65. }
  66. public override string ToString()
  67. {
  68. return EleMedKitProtocolFlags.Start + GetContent() + EleMedKitProtocolFlags.End;
  69. }
  70. }
  71. }