public static Contact GetContactByJid(string jid)
        {
            Contact contact;

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd = cnn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Contacts where jid = @jid";
                cmd.Parameters.Add(new SQLiteParameter("@jid", jid));
                DbDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    int id = Int32.Parse(reader["id"].ToString());
                    string status = reader["status"].ToString();
                    string nickname = reader["nickname"].ToString();
                    string given_name = reader["given_name"].ToString();
                    string family_name = reader["family_name"].ToString();
                    contact = new Contact(id, jid, status, nickname, given_name, family_name);
                    return contact;
                }
                else
                {
                    return null;
                    //contact = new Contact(-1, jid, "", "", "", "");
                    //AddContact(contact);
                    //return contact;
                }
            }
        }
Beispiel #2
0
 public ListContact(string jid, MetroFramework.MetroColorStyle style)
 {
     this.Style = style;
     InitializeComponent();
     int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
     this.Width -= vertScrollWidth;
     this.BackColor = Helper.GetMetroThemeColor(style);
     this.contact = ContactStore.GetContactByJid(jid);
     if (this.contact != null)
     {
         this.lblName.Text = this.contact.FullName;
         string imgpath = ChatWindow.getCacheImagePath(jid);
         if (File.Exists(imgpath))
         {
             try
             {
                 Image i = Image.FromFile(imgpath);
                 Bitmap b = new Bitmap(i, new Size(48, 48));
                 this.pictureBox1.Image = b;
                 i.Dispose();
             }
             catch (Exception e)
             {
                 throw e;
             }
         }
     }
 }
Beispiel #3
0
        public ChatWindow(string target, bool stealFocus, bool onTop)
        {
            this.stealFocus = stealFocus;
            this.onTop = onTop;
            this.TopMost = onTop;
            if (stealFocus)
            {
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.WindowState = FormWindowState.Minimized;
            }
            if(target.Contains("-"))
                this.IsGroup = true;
            this.target = target;
            InitializeComponent();

            try
            {
                string path = Directory.GetCurrentDirectory() + "\\notify.wav";
                path = new System.IO.FileInfo(path).FullName;
                this.sp = new SoundPlayer(path);
                this.sp.Load();
            }
            catch (Exception e)
            {
                this.sp = null;
            }

            Contact con = ContactStore.GetContactByJid(target);

            if (con == null)
            {
                con = new Contact(-1, target, "", "", "", "");
                ContactStore.AddContact(con);
            }

            this.lblNick.Text = con.nickname;
            this.lblUserStatus.Text = con.status;
            this.SetUnavailable();

            if (this.IsGroup)
                this.ProcessGroupChat();
            else
                this.ProcessChat();

            WappMessage[] oldmessages = MessageStore.GetAllMessagesForContact(target);
            this.messages.AddRange(oldmessages);

            this.limitMessages();
            //this.redraw();
        }
Beispiel #4
0
        protected void ExecuteImport()
        {
            //start sync
            ContactsService GContactService = new ContactsService("Contact Infomation");
            GContactService.setUserCredentials(email, password);

            ContactsQuery query = new ContactsQuery(ContactsQuery.
            CreateContactsUri("default"));
            ContactsFeed feed = null;

            try
            {
                feed = GContactService.Query(query);
            }
            catch (Exception)
            {
                this.setLabelText("Invalid email or password", Color.Red);
                return;
            }

            //start
            this.showProgressBar(feed.TotalResults);
            this.setLabelText("Importing...", Color.Black);

            int progress = 0;
            int startIndex = 0;
            while (feed.Entries.Count > 0)
            {
                startIndex += feed.ItemsPerPage;
                query.StartIndex = startIndex;
                PhoneNumbers.PhoneNumberUtil util = PhoneNumbers.PhoneNumberUtil.GetInstance();
                foreach (ContactEntry entry in feed.Entries)
                {
                    this.setProgress(progress);
                    progress++;

                    if (entry.Phonenumbers.Count > 0)
                    {
                        foreach (PhoneNumber number in entry.Phonenumbers)
                        {
                            string numb = string.Empty;
                            try
                            {
                                PhoneNumbers.PhoneNumber num = util.Parse(number.Value, "NL");
                                numb = num.CountryCode.ToString() + num.NationalNumber.ToString();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Exception was thrown: " + ex.Message);
                                continue;
                            }
                            if (!ContactStore.numberExists(numb + "@s.whatsapp.net"))
                            {
                                Contact contact = new Contact(0, numb + "@s.whatsapp.net", "", "", entry.Name.GivenName, entry.Name.FamilyName);
                                ContactStore.AddContact(contact);
                            }
                        }
                    }
                }
                feed = GContactService.Query(query);
            }

            //done!
            this.doExit();
        }
        public static void DeleteContact(Contact contact)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"DELETE
FROM
'Contacts' 
WHERE jid = @gjid";
                cmd.Parameters.Add(new SQLiteParameter("@gjid", contact.jid));
                cmd.ExecuteNonQuery();
            }
        }
        public static void UpdateNickname(Contact contact)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"UPDATE
'Contacts' 
SET
nickname = @nickname
WHERE jid = @gjid";
                cmd.Parameters.Add(new SQLiteParameter("@nickname", contact.nickname));
                cmd.Parameters.Add(new SQLiteParameter("@gjid", contact.jid));
                cmd.ExecuteNonQuery();
            }
        }
        public static void AddContact(Contact contact)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"INSERT INTO
'Contacts' 
(
'jid',
'status',
'nickname',
'given_name',
'family_name'
)
VALUES (
@jid,
@status,
@nickname,
@given_name,
@family_name
)";
                cmd.Parameters.Add(new SQLiteParameter("@jid", contact.jid));
                cmd.Parameters.Add(new SQLiteParameter("@status", contact.status));
                cmd.Parameters.Add(new SQLiteParameter("@nickname", contact.nickname));
                cmd.Parameters.Add(new SQLiteParameter("@given_name", contact.given_name));
                cmd.Parameters.Add(new SQLiteParameter("@family_name", contact.family_name));
                cmd.ExecuteNonQuery();
            }
        }
        public static Contact[] GetAllContacts()
        {
            List<Contact> contacts = new List<Contact>();

            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd = cnn.CreateCommand();
                cmd.CommandText = "SELECT * FROM Contacts order by given_name asc";
                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int id = Int32.Parse(reader["id"].ToString());
                    string jid = reader["jid"].ToString();
                    string status = reader["status"].ToString();
                    string nickname = reader["nickname"].ToString();
                    string given_name = reader["given_name"].ToString();
                    string family_name = reader["family_name"].ToString();
                    Contact contact = new Contact(id, jid, status, nickname, given_name, family_name);
                    contacts.Add(contact);
                }
            }

            return contacts.ToArray();
        }
Beispiel #9
0
        public ChatWindow(string target, bool stealFocus)
        {
            this.stealFocus = stealFocus;
            if (stealFocus)
            {
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.WindowState = FormWindowState.Minimized;
            }
            if(target.Contains("-"))
                this.IsGroup = true;
            this.target = target;
            InitializeComponent();

            Contact con = ContactStore.GetContactByJid(target);

            if (con == null)
            {
                con = new Contact(-1, target, "", "", "", "");
                ContactStore.AddContact(con);
            }

            this.lblNick.Text = con.nickname;
            this.lblUserStatus.Text = con.status;

            listBox1.DataSource = messages;

            if (this.IsGroup)
                this.ProcessGroupChat();
            else
                this.ProcessChat();

            WappMessage[] oldmessages = MessageStore.GetAllMessagesForContact(target);
            foreach (WappMessage msg in oldmessages)
            {
                this.messages.Add(msg);
            }
        }
Beispiel #10
0
        public static void AddContact(Contact contact)
        {
            DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
            using (DbConnection cnn = fact.CreateConnection())
            {
                cnn.ConnectionString = ContactStore.ConnectionString;
                cnn.Open();
                DbCommand cmd = cnn.CreateCommand();
                cmd.CommandText = @"INSERT INTO
'Contacts' 
(
'jid',
'status',
'nickname',
'given_name',
'family_name'
)
VALUES (
'" + contact.jid + @"',
'" + contact.status + @"',
'" + contact.nickname + @"',
'" + contact.given_name + @"',
'" + contact.family_name + @"'
)";
                cmd.ExecuteNonQuery();
            }
        }