public void SendMessage(Message message) { string data = SerializeMessage(message); byte[] bytes = Encoding.UTF8.GetBytes(data + '\n'); client.Send(bytes); }
public override int CreateMessage(Message m) { int messageID = -1; try { OracleCommand command = CreateCommand("insertar_Mensaje"); OracleParameter[] parameters = new OracleParameter[] { new OracleParameter("id_mensajeV", OracleDbType.Int32) { Direction = ParameterDirection.Output }, new OracleParameter("id_usuario_emisorV", OracleDbType.Int32) { Value = m.Sender }, new OracleParameter("id_grupo", OracleDbType.Int32) { Value = m.Conversation }, new OracleParameter("mensajeV", OracleDbType.Varchar2) { Value = m.Content }, new OracleParameter("fechaV", OracleDbType.Date) { Value = m.Date }, new OracleParameter("tipoV", OracleDbType.Varchar2) { Value = m.Type } }; command.Parameters.AddRange(parameters); _connection.Open(); command.ExecuteReader(); messageID = (Int32) parameters[0].Value; } catch (Exception e) { throw e; } finally { _connection.Close(); } return messageID; }
private string SerializeMessage(Message message) { stream = new MemoryStream(); messageSerializer.WriteObject(stream, message); stream.Position = 0; StreamReader reader = new StreamReader(stream); return reader.ReadToEnd(); }
public abstract int CreateMessage(Message m);
protected Message GetCurrentMessage(DbDataReader reader) { int colID = reader.GetOrdinal("id_mensaje"); int colSender = reader.GetOrdinal("id_usuario_emisor"); int colConversation = reader.GetOrdinal("id_grupo"); int colContent = reader.GetOrdinal("mensaje"); int colDate = reader.GetOrdinal("fecha"); int colType = reader.GetOrdinal("tipo"); Message message = new Message(); if (!reader.IsDBNull(colID)) { message.ID = reader.GetInt32(colID); } if (!reader.IsDBNull(colSender)) { message.Sender = reader.GetInt32(colSender); } if (!reader.IsDBNull(colConversation)) { message.Conversation = reader.GetInt32(colConversation); } if (!reader.IsDBNull(colContent)) { message.Content = reader.GetString(colContent); } if (!reader.IsDBNull(colDate)) { message.Date = reader.GetDateTime(colDate); } if (!reader.IsDBNull(colType)) { message.Type = reader.GetString(colType); } return message; }
public Message[] GetConversationMessages(Conversation conversation) { Message[] conversations = new Message[0]; CheckConnection(); try { conversations = _activeDB.GetConversationMessages(conversation); } catch (Exception e) { Console.WriteLine("[EXCEPTION GetConversationMesages] Message={0}", e.Message); } return conversations; }
public int CreateMessage(Message m) { int messageID = -1; CheckConnection(); try { messageID = _activeDB.CreateMessage(m); } catch (Exception e) { Console.WriteLine("[EXCEPTION CreateMessage] Message={0}", e.Message); } return messageID; }