using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; using MqttMsgServer.Model; using MqttMsgServer.Tools; using MQTTnet.Protocol; namespace MqttMsgServer.Model { [Table("ReceiveMessageRecords")] public class ReceiveMessageRecord : CreatorEntity { public const int ClientIdMaxLength = 50; //public const int PayloadMaxLength = 5000; public const int ContentTypeMaxLength = 50; public const int TopicMaxLength = 50; [StringLength(ClientIdMaxLength)] public string ClientId { get; set; } //[StringLength(PayloadMaxLength)] public string Payload { get; set; } public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; } public bool Retain { get; set; } [StringLength(ContentTypeMaxLength)] public string ContentType { get; set; } [StringLength(TopicMaxLength)] public string Topic { get; set; } public string InsertSql() { int retain = Retain ? 1 : 0; int qos = QualityOfServiceLevel.ToInt(); return $"insert INTO ReceiveMessageRecords(Id,ClientId,Payload,QualityOfServiceLevel,Retain,ContentType,Topic,CreatorDate,CreatorUserId) values('{Id}','{ClientId}','{Payload}',{qos},{retain},'{ContentType}','{Topic}','{CreatorDate}',{CreatorUserId})"; } public string UpdateSql() { int retain = Retain ? 1 : 0; int qos = QualityOfServiceLevel.ToInt(); return $"update ReceiveMessageRecords set ClientId='{ClientId}',Payload='{Payload}',QualityOfServiceLevel='{qos}',Retain={retain},ContentType='{ContentType}',Topic='{Topic}' where Id='{Id}'"; } public string DeleteSql() { return $"Delete from ReceiveMessageRecords where Id='{Id}'"; } } }