Example #1
0
        public void TestGooglePhoto()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            Assert.IsTrue(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg"));

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            //save contact to google.
            sync.SaveGoogleContact(match);
            googleContact = null;

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            Image pic   = Utilities.CropImageGoogleFormat(Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg"));
            bool  saved = Utilities.SaveGooglePhoto(sync, match.GoogleContact, pic);

            Assert.IsTrue(saved);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            Image image = Utilities.GetGooglePhoto(sync, match.GoogleContact);

            Assert.IsNotNull(image);

            //delete test contacts
            match.Delete();
        }
Example #2
0
        public void TestSync()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            //save contact to google.
            sync.SaveGoogleContact(match);
            googleContact = null;

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            Outlook.ContactItem recreatedOutlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            ContactSync.MergeContacts(match.GoogleContact, recreatedOutlookContact);

            // match recreatedOutlookContact with outlookContact
            Assert.AreEqual(outlookContact.FullName, recreatedOutlookContact.FullName);
            Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);
            Assert.AreEqual(outlookContact.Email1Address, recreatedOutlookContact.Email1Address);
            Assert.AreEqual(outlookContact.Email2Address, recreatedOutlookContact.Email2Address);
            Assert.AreEqual(outlookContact.Email3Address, recreatedOutlookContact.Email3Address);
            Assert.AreEqual(outlookContact.PrimaryTelephoneNumber, recreatedOutlookContact.PrimaryTelephoneNumber);
            Assert.AreEqual(outlookContact.HomeAddress, recreatedOutlookContact.HomeAddress);

            //delete test contacts
            match.Delete();
        }
Example #3
0
        public void TestMassSyncToGoogle()
        {
            // NEED TO DELETE CONTACTS MANUALY

            int c = 300;

            string[]            names  = new string[c];
            string[]            emails = new string[c];
            Outlook.ContactItem outlookContact;
            ContactMatch        match;

            for (int i = 0; i < c; i++)
            {
                names[i]  = "TEST name" + i;
                emails[i] = "email" + i + "@domain.com";
            }

            // count existing google contacts
            int excount = sync.GoogleContacts.Count;

            DateTime start = DateTime.Now;

            Console.WriteLine("Started mass sync to google of " + c + " contacts");

            for (int i = 0; i < c; i++)
            {
                outlookContact               = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
                outlookContact.FullName      = names[i];
                outlookContact.FileAs        = names[i];
                outlookContact.Email1Address = emails[i];
                outlookContact.Save();

                ContactEntry googleContact = new ContactEntry();
                ContactSync.UpdateContact(outlookContact, googleContact);
                match = new ContactMatch(outlookContact, googleContact);

                //save contact to google.
                sync.SaveGoogleContact(match);
            }

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // all contacts should be synced
            Assert.AreEqual(c, sync.Contacts.Count - excount);

            DateTime end  = DateTime.Now;
            TimeSpan time = end - start;

            Console.WriteLine("Synced " + c + " contacts to google in " + time.TotalSeconds + " s ("
                              + ((float)time.TotalSeconds / (float)c) + " s per contact)");

            // received: Synced 50 contacts to google in 30.137 s (0.60274 s per contact)
        }
Example #4
0
        public void TestExtendedProps()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            sync.SaveGoogleContact(match);

            // read contact from google
            googleContact = null;
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            foreach (ContactMatch m in sync.Contacts)
            {
                if (m.GoogleContact.Title.Text == name)
                {
                    googleContact = m.GoogleContact;
                    break;
                }
            }

            // get extended prop
            Assert.AreEqual(ContactPropertiesUtils.GetOutlookId(outlookContact), ContactPropertiesUtils.GetGoogleOutlookContactId(sync.SyncProfile, googleContact));

            //delete test contacts
            match.Delete();
        }
Example #5
0
        public void TestCreatingGoogeAccountThatFailed3()
        {
            Outlook.ContactItem outlookContact = sync.OutlookContacts.Find(
                string.Format("[FirstName]='{0}' AND [LastName]='{1}'",
                              ConfigurationManager.AppSettings["Test.FirstName"],
                              ConfigurationManager.AppSettings["Test.LastName"])) as Outlook.ContactItem;

            ContactMatch match = FindMatch(outlookContact);

            Assert.IsNotNull(match);
            Assert.IsNull(match.GoogleContact);

            ContactEntry googleContact = new ContactEntry();

            //ContactSync.UpdateContact(outlookContact, googleContact);

            googleContact.Title.Text = outlookContact.FileAs;

            if (googleContact.Title.Text == null)
            {
                googleContact.Title.Text = outlookContact.FullName;
            }

            if (googleContact.Title.Text == null)
            {
                googleContact.Title.Text = outlookContact.CompanyName;
            }

            //SetEmails(outlookContact, googleContact);

            ContactSync.SetPhoneNumbers(outlookContact, googleContact);

            //SetAddresses(outlookContact, googleContact);

            //SetCompanies(outlookContact, googleContact);

            //SetIMs(outlookContact, googleContact);

            //googleContact.Content.Content = outlookContact.Body;

            Uri          feedUri      = new Uri(ContactsQuery.CreateContactsUri("default"));
            ContactEntry createdEntry = (ContactEntry)sync.GoogleService.Insert(feedUri, googleContact);

            ContactPropertiesUtils.SetOutlookGoogleContactId(sync, match.OutlookContact, createdEntry);
            match.GoogleContact = createdEntry;
            match.OutlookContact.Save();
        }
Example #6
0
        public void TestUpdatingGoogeAccountThatFailed()
        {
            Outlook.ContactItem outlookContact = sync.OutlookContacts.Find(
                string.Format("[FirstName]='{0}' AND [LastName]='{1}'",
                              ConfigurationManager.AppSettings["Test.FirstName"],
                              ConfigurationManager.AppSettings["Test.LastName"])) as Outlook.ContactItem;

            ContactMatch match = FindMatch(outlookContact);

            Assert.IsNotNull(match);
            Assert.IsNotNull(match.GoogleContact);

            ContactEntry googleContact = match.GoogleContact;

            ContactSync.UpdateContact(outlookContact, googleContact);

            googleContact.Title.Text = outlookContact.FileAs;

            if (googleContact.Title.Text == null)
            {
                googleContact.Title.Text = outlookContact.FullName;
            }

            if (googleContact.Title.Text == null)
            {
                googleContact.Title.Text = outlookContact.CompanyName;
            }

            ContactSync.SetEmails(outlookContact, googleContact);

            ContactSync.SetPhoneNumbers(outlookContact, googleContact);

            //SetAddresses(outlookContact, googleContact);

            //SetCompanies(outlookContact, googleContact);

            //SetIMs(outlookContact, googleContact);

            //googleContact.Content.Content = outlookContact.Body;

            ContactEntry updatedEntry = googleContact.Update() as ContactEntry;

            ContactPropertiesUtils.SetOutlookGoogleContactId(sync, match.OutlookContact, updatedEntry);
            match.GoogleContact = updatedEntry;
            match.OutlookContact.Save();
        }
Example #7
0
        private async void LoadDummyData()
        {
            // Add a simple contact (this will be "improved" when we have somethign real).
            var finder = new InSpireContactFinder();
            var me     = await finder.FindContactAsync(new Uri("http://inspirehep.net/record/983968?ln=en"));

            People.Add(new ContactViewModel(me.First()));
            var david = await finder.FindContactAsync(new Uri("http://inspirehep.net/record/1024481?ln=en"));

            People.Add(new ContactViewModel(david.First()));
            var daniel = await finder.FindContactAsync(new Uri("http://inspirehep.net/record/1020448?ln=en"));

            People.Add(new ContactViewModel(daniel.First()));

            await ContactSync.SyncContactList(new[] { me.First(), david.First(), daniel.First() });

            await ContactSync.SyncContactList(new[] { me.First(), david.First(), daniel.First() });
        }
Example #8
0
        public static void SyncWaContacts(string username, string password)
        {
            Contact[]     contacts = ContactStore.GetAllContacts();
            List <string> input    = new List <string>();

            foreach (Contact c in contacts)
            {
                input.Add(c.jid.Split('@').First());
            }
            ContactSync s = new ContactSync(username, password);

            try
            {
                ContactSyncResult[] res = s.Sync(input.ToArray());

                if (res != null)
                {
                    foreach (ContactSyncResult r in res)
                    {
                        if (r.w == 1)
                        {
                            string  jid = r.n + "@s.whatsapp.net";
                            Contact con = ContactStore.GetContactByJid(jid);
                            if (con != null && con.status != r.s)
                            {
                                //update status if changed
                                con.status = r.s;
                                ContactStore.UpdateStatus(con);
                            }
                        }
                        else
                        {
                            //delete
                            Contact con = ContactStore.GetContactByJid(r.n + "@s.whatsapp.net");
                            if (con != null)
                            {
                                ContactStore.DeleteContact(con);
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }
Example #9
0
        public void TestResetMatches()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string groupName = "A_TEST_GROUP";
            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            //save contact to google.
            sync.SaveContact(match);

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // delete outlook contact
            match.OutlookContact.Delete();
            match.OutlookContact = null;

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // reset matches
            sync.ResetMatch(match);

            // load same contact match
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // google contact should still be present
            Assert.IsNotNull(match.GoogleContact);

            //delete test contacts
            match.Delete();

            // create new contact to sync
            outlookContact                        = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            // same test for delete google contact...
            googleContact = new ContactEntry();
            ContactSync.UpdateContact(outlookContact, googleContact);
            match = new ContactMatch(outlookContact, googleContact);

            //save contact to google.
            sync.SaveContact(match);

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // delete google contact
            match.GoogleContact.Delete();
            match.GoogleContact = null;

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // reset matches
            sync.ResetMatch(match);

            // load same contact match
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // google contact should still be present
            Assert.IsNotNull(match.OutlookContact);

            //delete test contacts
            match.Delete();
        }
Example #10
0
        public void TestSyncDeletedOutlookGroup()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string groupName = "A_TEST_GROUP";
            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Categories             = groupName;
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            //save contact to google.
            sync.SaveContact(match);

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // delete group from outlook
            Utilities.RemoveOutlookGroup(match.OutlookContact, groupName);

            sync.SyncOption = SyncOption.OutlookToGoogleOnly;

            //save contact to google.
            sync.SaveContact(match);

            //load the same contact from google.
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            match = sync.ContactByProperty(name, email);

            // google and outlook should now have no category
            Assert.AreEqual(null, match.OutlookContact.Categories);
            Assert.AreEqual(0, Utilities.GetGoogleGroups(sync, match.GoogleContact).Count);

            //delete test contacts
            match.Delete();

            // delete test group
            GroupEntry group = sync.GetGoogleGroupByName(groupName);

            group.Delete();
        }
Example #11
0
        public void TestSyncDeletedOulook()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            string timestamp = DateTime.Now.Ticks.ToString();
            string name      = "AN OUTLOOK TEST CONTACT";
            string email     = "*****@*****.**";

            name = name.Replace(" ", "_");

            // delete previously failed test contacts
            DeleteExistingTestContacts(name, email);

            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // create new contact to sync
            Outlook.ContactItem outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            outlookContact.FullName               = name;
            outlookContact.FileAs                 = name;
            outlookContact.Email1Address          = email;
            outlookContact.Email2Address          = email.Replace("00", "01");
            outlookContact.Email3Address          = email.Replace("00", "02");
            outlookContact.HomeAddress            = "10 Parades";
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.Save();

            ContactEntry googleContact = new ContactEntry();

            ContactSync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(outlookContact, googleContact);

            //save contacts
            sync.SaveContact(match);

            // delete outlook contact
            outlookContact.Delete();

            // sync
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            // find match
            match = null;
            foreach (ContactMatch m in sync.Contacts)
            {
                if (m.GoogleContact.Title.Text == name)
                {
                    match = m;
                    break;
                }
            }

            // delete
            sync.SaveContact(match);

            // sync
            sync.Load();
            ContactsMatcher.SyncContacts(sync);

            // check if google contact still exists
            googleContact = null;
            foreach (ContactMatch m in sync.Contacts)
            {
                if (m.GoogleContact.Title.Text == name)
                {
                    googleContact = m.GoogleContact;
                    break;
                }
            }
            Assert.IsNull(googleContact);
        }
 partial void DeleteContactSync(ContactSync instance);
 partial void UpdateContactSync(ContactSync instance);
 partial void InsertContactSync(ContactSync instance);