Exemplo n.º 1
0
        public static void AddMessage(WappMessage message)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"INSERT INTO
'Messages' 
(
'jid',
'from_me',
'data',
'timestamp'
)
VALUES (
'" + message.jid + @"',
'" + (message.from_me ? "1" : "0") + @"',
@data,
'" + message.timestamp.ToString() + @"'
)";
                cmd.Parameters.Add(new SQLiteParameter("@data", message.data));
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 2
0
        public static void AddMessage(WappMessage message)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");

            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"INSERT INTO
'Messages' 
(
'jid',
'author',
'from_me',
'data',
'timestamp',
'type',
'preview'
)
VALUES (
'" + message.jid + @"',
'" + message.author + @"',
'" + (message.from_me ? "1" : "0") + @"',
@data,
'" + message.timestamp.ToString() + @"',
'" + message.type + @"',
'" + message.preview + @"'
)";
                cmd.Parameters.Add(new SQLiteParameter("@data", message.data));
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 3
0
        public static WappMessage[] GetAllMessagesForContact(string jid)
        {
            List<WappMessage> messages = new List<WappMessage>();

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd = cnn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Messages where jid = @jid";
                cmd.Parameters.Add(new SQLiteParameter("@jid", jid));
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int id = Int32.Parse(reader["id"].ToString());
                    bool from_me = (Int32.Parse(reader["from_me"].ToString()) == 1 ? true : false);
                    string data = (string)reader["data"];
                    DateTime timestamp = DateTime.Parse(reader["timestamp"].ToString());
                    WappMessage message = new WappMessage(id, data, from_me, jid, timestamp);
                    messages.Add(message);
                }
            }

            return messages.ToArray();
        }
Exemplo n.º 4
0
        public static WappMessage[] GetAllMessagesForContact(string jid)
        {
            List <WappMessage> messages = new List <WappMessage>();

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");

            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd             = cnn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Messages where jid = @jid";
                cmd.Parameters.Add(new SQLiteParameter("@jid", jid));
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int    id     = Int32.Parse(reader["id"].ToString());
                    string author = string.Empty;
                    try
                    {
                        author = (string)reader["author"];
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    bool   from_me = (Int32.Parse(reader["from_me"].ToString()) == 1 ? true : false);
                    string data    = (string)reader["data"];
                    string type;
                    try
                    {
                        type = (string)reader["type"];
                    }catch (Exception)
                    {
                        type = string.Empty;
                    }
                    string preview;
                    try
                    {
                        preview = (string)reader["preview"];
                    }
                    catch (Exception)
                    {
                        preview = string.Empty;
                    }
                    DateTime    timestamp = DateTime.Parse(reader["timestamp"].ToString());
                    WappMessage message   = new WappMessage(id, data, from_me, jid, timestamp, type, preview);
                    if (!String.IsNullOrEmpty(author))
                    {
                        message.author = author;
                    }
                    messages.Add(message);
                }
            }

            return(messages.ToArray());
        }
Exemplo n.º 5
0
        public static WappMessage[] GetAllMessagesForContact(string jid)
        {
            List<WappMessage> messages = new List<WappMessage>();

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd = cnn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Messages where jid = @jid";
                cmd.Parameters.Add(new SQLiteParameter("@jid", jid));
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int id = Int32.Parse(reader["id"].ToString());
                    string author = string.Empty;
                    try
                    {
                        author = (string)reader["author"];
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    bool from_me = (Int32.Parse(reader["from_me"].ToString()) == 1 ? true : false);
                    string data = (string)reader["data"];
                    string type;
                    try
                    {
                        type = (string)reader["type"];
                    }catch(Exception)
                    {
                        type = string.Empty;
                    }
                    string preview;
                    try
                    {
                        preview = (string)reader["preview"];
                    }
                    catch (Exception)
                    {
                        preview = string.Empty;
                    }
                    DateTime timestamp = DateTime.Parse(reader["timestamp"].ToString());
                    WappMessage message = new WappMessage(id, data, from_me, jid, timestamp, type, preview);
                    if (!String.IsNullOrEmpty(author))
                    {
                        message.author = author;
                    }
                    messages.Add(message);
                }
            }

            return messages.ToArray();
        }
Exemplo n.º 6
0
        public ListChat(WappMessage msg, MetroFramework.MetroColorStyle style)
        {
            InitializeComponent();
            this.Style = style;
            this.metroTile1.Style = style;
            this.metroTile1.BackColor = Helper.GetMetroThemeColor(style);
            if (msg.from_me)
            {
                this.Padding = new Padding(50, this.Padding.Top, 4, this.Padding.Bottom);
            }
            if (!String.IsNullOrEmpty(msg.author))
            {
                Contact c = ContactStore.GetContactByJid(msg.author);
                if (c != null)
                {
                    msg.author = c.FullName;
                }
                msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
            }
            if (msg.type == "image")
            {
                if (!string.IsNullOrEmpty(msg.preview))
                {
                    MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
                    Image i = Image.FromStream(ms);
                    this.Height += i.Height;
                    this.Controls.Remove(this.metroTile1);
                    PictureBox pb = new PictureBox();
                    pb.Width = i.Width;
                    pb.Height = i.Height;
                    pb.Image = i;
                    this.Controls.Add(pb);
                }
                
            }
            else
            {
                Font f = MetroFonts.Tile(this.metroTile1.TileTextFontSize, this.metroTile1.TileTextFontWeight);
                int lineHeight = Int32.Parse(Math.Round((decimal)this.metroTile1.CreateGraphics().MeasureString("X", f).Height).ToString());
                SizeF sf = new SizeF();
                sf = this.metroTile1.CreateGraphics().MeasureString(msg.data, f, this.metroTile1.Width);
                this.metroTile1.Text = msg.data;
                int newHeight = (int)Math.Round(decimal.Parse(sf.Height.ToString()));
                int lines = newHeight / f.Height;
                //lines--;

                if (lines > 0)
                {
                    this.Height = (lines * this.Height);
                }
            }
        }
Exemplo n.º 7
0
 public ListChat(WappMessage msg)
 {
     InitializeComponent();
     this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
     if (!msg.from_me)
     {
         this.textBox1.Location = new Point(3, this.textBox1.Location.Y);
     }
     if (!String.IsNullOrEmpty(msg.author))
     {
         Contact c = ContactStore.GetContactByJid(msg.author);
         if (c != null)
         {
             msg.author = c.FullName;
         }
         msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
     }
     if (msg.type == "image")
     {
         if (!string.IsNullOrEmpty(msg.preview))
         {
             MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
             Image i = Image.FromStream(ms);
             this.Height += i.Height;
             this.Controls.Remove(this.textBox1);
             PictureBox pb = new PictureBox();
             pb.Width = i.Width;
             pb.Height = i.Height;
             pb.Image = i;
             this.Controls.Add(pb);
         }
         
     }
     else
     {
         this.textBox1.Text = msg.data;
         Size size = TextRenderer.MeasureText(this.textBox1.Text, this.textBox1.Font, new Size(this.textBox1.Width, int.MaxValue), TextFormatFlags.WordBreak);
         this.Height = size.Height + 15;
     }
 }
Exemplo n.º 8
0
 public void AddMessage(ProtocolTreeNode node)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCallbackNode r = new AddMessageCallbackNode(AddMessage);
         this.Invoke(r, new object[] { node });
     }
     else
     {
         string author = String.Empty;
         WappMessage msg = new WappMessage(node, this.target);
         if (this.IsGroup)
         {
             //extract author
             msg.author = node.GetAttribute("author");
         }
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }
Exemplo n.º 9
0
 private void addChatMessage(WappMessage message)
 {
     ListChat lc = new ListChat(message, this.Style);
     this.flowLayoutPanel1.Controls.Add(lc);
     while (this.flowLayoutPanel1.Controls.Count > MESSAGE_LIMIT)
     {
         this.flowLayoutPanel1.Controls.Remove(this.flowLayoutPanel1.Controls[0]);
     }
 }
Exemplo n.º 10
0
 public void AddMessage(string message)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCallback r = new AddMessageCallback(AddMessage);
         this.Invoke(r, new object[] {message});
     }
     else
     {
         WappMessage msg = new WappMessage(message, this.target);
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }
Exemplo n.º 11
0
 public void AddMessage(ProtocolTreeNode node)
 {
     if (this.listBox1.InvokeRequired)
     {
         AddMessageCallbackNode r = new AddMessageCallbackNode(AddMessage);
         this.Invoke(r, new object[] { node });
     }
     else
     {
         WappMessage msg = new WappMessage(node, this.target);
         this.messages.Add(msg);
         MessageStore.AddMessage(msg);
         this.ScrollToBottom();
     }
 }
Exemplo n.º 12
0
        public static void AddMessage(WappMessage message)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = MessageStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"INSERT INTO
'Messages' 
(
'jid',
'author',
'from_me',
'data',
'timestamp',
'type',
'preview'
)
VALUES (
@jid,
@author,
@from_me,
@data,
@timestamp,
@type,
@preview
)";
                cmd.Parameters.Add(new SQLiteParameter("@jid", message.jid));
                cmd.Parameters.Add(new SQLiteParameter("@author", message.author));
                cmd.Parameters.Add(new SQLiteParameter("@from_me", (message.from_me ? "1" : "0")));
                cmd.Parameters.Add(new SQLiteParameter("@data", message.data));
                cmd.Parameters.Add(new SQLiteParameter("@timestamp", message.timestamp.ToString()));
                cmd.Parameters.Add(new SQLiteParameter("@type", message.type));
                cmd.Parameters.Add(new SQLiteParameter("@preview", message.preview));
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 13
0
 public void AddMessage(string from, string data, bool fromMe)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCustomCallback call = new AddMessageCustomCallback(AddMessage);
         this.Invoke(call, new object[] { from, data, fromMe } );
     }
     else
     {
         WappMessage msg = new WappMessage(from, data, fromMe);
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }