Ejemplo n.º 1
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)
            {
                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();
        }
Ejemplo n.º 2
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 exe)
            {
                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();
        }