/// <summary> /// 插入数据 /// </summary> /// <param name="channelName">通道名称</param> /// <param name="message">待插入消息</param> /// <returns>是否成功</returns> public Boolean InsertMessageData(String channelName, ReceiveObject message) { lock (queueLock) { Boolean result = true; if (this.lastInsertTime.ContainsKey(message.ReceiveID.ToString()) == false) { this.lastInsertTime[message.ReceiveID.ToString()] = DateTime.MinValue; } if (DateTime.Now < lastInsertTime[message.ReceiveID.ToString()].AddMilliseconds(100)) { result = false; } else { if (this.isDisposed == false) { messageQueue.Enqueue(new MessageModel() { Message = message, ChannelName = channelName, }); } if ((messageQueue.Count > 100) || this.isDisposed) { var tempBuffer = messageQueue; messageQueue = new Queue <MessageModel>(); foreach (var item in tempBuffer) { var sql = ConstDefine.InsertData; SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@FrameType", item.Message.FrameType), new SQLiteParameter("@ReceiveID", item.Message.ReceiveID), new SQLiteParameter("@TimeStamp", item.Message.TimeStamp), new SQLiteParameter("@Length", item.Message.Length), new SQLiteParameter("@data1", item.Message.ReceiveData[0]), new SQLiteParameter("@data2", item.Message.ReceiveData[1]), new SQLiteParameter("@data3", item.Message.ReceiveData[2]), new SQLiteParameter("@data4", item.Message.ReceiveData[3]), new SQLiteParameter("@data5", item.Message.ReceiveData[4]), new SQLiteParameter("@data6", item.Message.ReceiveData[5]), new SQLiteParameter("@data7", item.Message.ReceiveData[6]), new SQLiteParameter("@data8", item.Message.ReceiveData[7]), new SQLiteParameter("@IsSelfSend", item.Message.IsSelfSend), new SQLiteParameter("@ChannelName", item.ChannelName) }; var effectLines = SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql, parameters); if (effectLines < 0) { result = false; } } tempBuffer.Clear(); } } return(result); } }
/// <summary> /// 删除全部记录 /// </summary> /// <returns>返回受影响行数</returns> public Int32 DeleteAllRecord() { Int32 result = 0; var sql = ConstDefine.DeleteAllRecord; result = SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql); return(result); }
/// <summary> /// 创建表 /// </summary> private void CreateTable() { var sql = ConstDefine.CreateTable; SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql); }
/// <summary> /// 删除表 /// </summary> public void DeleteTable() { var sql = ConstDefine.DeleteTable; SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql); }