ReceiveMessageRecord.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using MqttMsgServer.Model;
  9. using MqttMsgServer.Tools;
  10. using MQTTnet.Protocol;
  11. namespace MqttMsgServer.Model
  12. {
  13. [Table("ReceiveMessageRecords")]
  14. public class ReceiveMessageRecord : CreatorEntity<string>
  15. {
  16. public const int ClientIdMaxLength = 50;
  17. //public const int PayloadMaxLength = 5000;
  18. public const int ContentTypeMaxLength = 50;
  19. public const int TopicMaxLength = 50;
  20. [StringLength(ClientIdMaxLength)]
  21. public string ClientId { get; set; }
  22. //[StringLength(PayloadMaxLength)]
  23. public string Payload { get; set; }
  24. public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }
  25. public bool Retain { get; set; }
  26. [StringLength(ContentTypeMaxLength)]
  27. public string ContentType { get; set; }
  28. [StringLength(TopicMaxLength)]
  29. public string Topic { get; set; }
  30. public string InsertSql()
  31. {
  32. int retain = Retain ? 1 : 0;
  33. int qos = QualityOfServiceLevel.ToInt();
  34. return
  35. $"insert INTO ReceiveMessageRecords(Id,ClientId,Payload,QualityOfServiceLevel,Retain,ContentType,Topic,CreatorDate,CreatorUserId) values('{Id}','{ClientId}','{Payload}',{qos},{retain},'{ContentType}','{Topic}','{CreatorDate}',{CreatorUserId})";
  36. }
  37. public string UpdateSql()
  38. {
  39. int retain = Retain ? 1 : 0;
  40. int qos = QualityOfServiceLevel.ToInt();
  41. return
  42. $"update ReceiveMessageRecords set ClientId='{ClientId}',Payload='{Payload}',QualityOfServiceLevel='{qos}',Retain={retain},ContentType='{ContentType}',Topic='{Topic}' where Id='{Id}'";
  43. }
  44. public string DeleteSql()
  45. {
  46. return $"Delete from ReceiveMessageRecords where Id='{Id}'";
  47. }
  48. }
  49. }