예제 #1
0
 public void SendMessage(Message message)
 {
     string data = SerializeMessage(message);
     byte[] bytes = Encoding.UTF8.GetBytes(data + '\n');
     client.Send(bytes);
 }
예제 #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;
        }
예제 #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();
 }
예제 #4
0
파일: Database.cs 프로젝트: jags9415/chat
 public abstract int CreateMessage(Message m);
예제 #5
0
파일: Database.cs 프로젝트: jags9415/chat
        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;
        }
예제 #6
0
파일: DataAccess.cs 프로젝트: jags9415/chat
 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;
 }
예제 #7
0
파일: DataAccess.cs 프로젝트: jags9415/chat
 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;
 }