UIInfoModel..cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using DotNettyFrom.config;
  7. namespace DotNettyFrom.common
  8. {
  9. [Serializable]
  10. public class UIInfoModel
  11. {
  12. public int action = int.MinValue;
  13. public string time = DateTime.Now.ToLongTimeString();
  14. public string info = "";
  15. public string cmd = "";
  16. public int cmdId = int.MinValue;
  17. //1 发送的. 0:接收的, -1.日常信息
  18. public int SendType = SystemConfig.RecType;
  19. public UIInfoModel(string info, string cmd)
  20. {
  21. this.info = info;
  22. this.cmd = cmd;
  23. cmdId = CalcCmdId(cmd);
  24. }
  25. public UIInfoModel(string info)
  26. {
  27. this.info = info;
  28. }
  29. public UIInfoModel setAction(int action)
  30. {
  31. this.action = action;
  32. return this;
  33. }
  34. public UIInfoModel setSendType(int SendType)
  35. {
  36. this.SendType = SendType;
  37. return this;
  38. }
  39. public UIInfoModel setCmd(string cmd)
  40. {
  41. this.cmd = cmd;
  42. cmdId = CalcCmdId(cmd);
  43. return this;
  44. }
  45. public UIInfoModel setInfo(string info)
  46. {
  47. this.info = info;
  48. return this;
  49. }
  50. public override string ToString()
  51. {
  52. string res = time + " - ";
  53. if (!info.Trim().Equals(""))
  54. {
  55. res += this.info;
  56. }
  57. if (!cmd.Trim().Equals(""))
  58. {
  59. try
  60. {
  61. string cmdIdString = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
  62. res += ". cmdId=" + cmdIdString;
  63. cmdId = CalcCmdId(cmd);
  64. }
  65. catch (Exception)
  66. {
  67. }
  68. res += ". cmd=[" + cmd + "]";
  69. }
  70. return res + ".";
  71. }
  72. public int CalcCmdId(string cmd)
  73. {
  74. try
  75. {
  76. string cmdId = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
  77. return int.Parse(cmdId);
  78. }
  79. catch (Exception)
  80. {
  81. }
  82. return int.MinValue;
  83. }
  84. }
  85. }