Exemplo n.º 1
0
 public void SendMessage(Message message)
 {
     string data = SerializeMessage(message);
     byte[] bytes = Encoding.UTF8.GetBytes(data + '\n');
     client.Send(bytes);
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 private string SerializeMessage(Message message)
 {
     stream = new MemoryStream();
     messageSerializer.WriteObject(stream, message);
     stream.Position = 0;
     StreamReader reader = new StreamReader(stream);
     return reader.ReadToEnd();
 }
Exemplo n.º 4
0
 public abstract int CreateMessage(Message m);
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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;
 }