public void SaveItem(InfoMessage item) { //Todo: handle last application better if (item.MessageType == -10) return; if (_insertInfoMessageItemCommand == null) { _insertInfoMessageItemCommand = new NpgsqlCommand("INSERT INTO log (event_id, description, client_time,route_type, ip, user_name) VALUES " + "(:event_id, :description, :client_time, :route_type, :ip, :user_name)"); _insertInfoMessageItemCommand.Parameters.Add("event_id", NpgsqlDbType.Integer); // 0 _insertInfoMessageItemCommand.Parameters.Add("description", NpgsqlDbType.Text); // 1 _insertInfoMessageItemCommand.Parameters.Add("client_time", NpgsqlDbType.Timestamp); // 2 _insertInfoMessageItemCommand.Parameters.Add("route_type", NpgsqlDbType.Smallint); // 3 _insertInfoMessageItemCommand.Parameters.Add("ip", NpgsqlDbType.Text); // 4 _insertInfoMessageItemCommand.Parameters.Add("user_name", NpgsqlDbType.Text); // 5 _insertInfoMessageItemCommand.Connection = _pgConnect; } // Now, add a value to it and later execute the command as usual. _insertInfoMessageItemCommand.Parameters[0].Value = item.MessageType; _insertInfoMessageItemCommand.Parameters[1].Value = item.Info; _insertInfoMessageItemCommand.Parameters[1].Size = item.Info.Length; _insertInfoMessageItemCommand.Parameters[2].Value = item.Time; _insertInfoMessageItemCommand.Parameters[3].Value = -1; _insertInfoMessageItemCommand.Parameters[4].Value = item.IP; _insertInfoMessageItemCommand.Parameters[4].Size = item.IP.Length; _insertInfoMessageItemCommand.Parameters[5].Value = item.UserName; _insertInfoMessageItemCommand.Parameters[5].Size = item.UserName.Length; _insertInfoMessageItemCommand.ExecuteNonQuery(); }
public static InfoMessage InfoMessageDecoder(byte[] data) { var msg = new InfoMessage(); int bt = 0; msg.MessageType = ReadInt(ref bt, data); msg.Time = ReadDateTime(ref bt, data); msg.IP = ReadString(ref bt, data); msg.UserName = ReadString(ref bt, data); msg.Info = ReadString(ref bt, data); return msg; }
public static InfoMessage InfoMessageDecoder(byte[] data) { var msg = new InfoMessage(); /*int bt = 0; msg.kod = ReadInt(ref bt, data); msg.Time = ReadDateTime(ref bt, data); msg.IP = EncodeString(ref bt, data); msg.UserName = EncodeString(ref bt, data); msg.Info = EncodeString(ref bt, data);*/ return msg; }
public void Log(InfoMessage item) { _infoMessages.Enqueue(item); _newItemEvent.Set(); }