Esempio n. 1
0
        private void DeleteExistingTestContacts(string name, string email)
        {
            sync.Load();
            ContactsMatcher.SyncContacts(sync);
            ContactMatch match = sync.ContactByProperty(name, email);

            try
            {
                while (match != null)
                {
                    if (match.GoogleContact != null)
                    {
                        match.GoogleContact.Delete();
                    }
                    if (match.OutlookContact != null)
                    {
                        match.OutlookContact.Delete();
                    }

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

            Outlook.ContactItem prevOutlookContact = sync.OutlookContacts.Find("[Email1Address] = '" + email + "'") as Outlook.ContactItem;
            if (prevOutlookContact != null)
            {
                prevOutlookContact.Delete();
            }
        }
        public DeleteResolution ResolveDelete(OutlookContactInfo outlookContact)
        {
            string name = ContactMatch.GetName(outlookContact);

            _form.Text = "Google Contact deleted";
            _form.messageLabel.Text =
                "Google Contact \"" + name +
                "\" doesn't exist anymore. Do you want to delete it also on Outlook side?";

            _form.OutlookItemTextBox.Text = string.Empty;
            _form.GoogleItemTextBox.Text  = string.Empty;
            Outlook.ContactItem item = outlookContact.GetOriginalItemFromOutlook();
            try
            {
                _form.OutlookItemTextBox.Text = ContactMatch.GetSummary(item);
            }
            finally
            {
                if (item != null)
                {
                    Marshal.ReleaseComObject(item);
                    item = null;
                }
            }

            _form.keepOutlook.Text = "Keep Outlook";
            _form.keepGoogle.Text  = "Delete Outlook";
            _form.skip.Enabled     = false;

            return(ResolveDeletedGoogle());
        }
Esempio n. 3
0
 private void GoogleComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (GoogleComboBox.SelectedItem != null)
     {
         GoogleItemTextBox.Text = ContactMatch.GetSummary((Google.Contacts.Contact)GoogleComboBox.SelectedItem);
     }
 }
Esempio n. 4
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();
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        private static int Compare(ContactMatch x1, ContactMatch x2)
        {
            int result = x2.Match.CompareTo(x1.Match);

            if (result == 0)
            {
                result = x1.Total.CompareTo(x2.Total);
            }
            return(result);
        }
Esempio n. 7
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)
        }
Esempio n. 8
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();
        }
Esempio n. 9
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();
        }
Esempio n. 10
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();
        }
Esempio n. 11
0
        public ConflictResolution Resolve(ContactMatch match, bool isNewMatch)
        {
            string name = match.ToString();

            if (isNewMatch)
            {
                _form.messageLabel.Text =
                    "This is the first time these Outlook and Google Contacts \"" + name +
                    "\" are synced. Choose which you would like to keep.";
                _form.skip.Text = "Keep both";
            }
            else
            {
                _form.messageLabel.Text =
                    "Both the Outlook Contact and the Google Contact \"" + name +
                    "\" have been changed. Choose which you would like to keep.";
            }

            _form.OutlookItemTextBox.Text = string.Empty;
            _form.GoogleItemTextBox.Text  = string.Empty;
            if (match.OutlookContact != null)
            {
                Microsoft.Office.Interop.Outlook.ContactItem item = match.OutlookContact.GetOriginalItemFromOutlook();
                try
                {
                    _form.OutlookItemTextBox.Text = ContactMatch.GetSummary(item);
                }
                finally
                {
                    if (item != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
                        item = null;
                    }
                }
            }

            if (match.GoogleContact != null)
            {
                _form.GoogleItemTextBox.Text = ContactMatch.GetSummary(match.GoogleContact);
            }


            return(Resolve());
        }
Esempio n. 12
0
        private static Contact FindContact(Dictionary <string, Contact> phonebook, List <string> items)
        {
            var candidates = new List <ContactMatch>();

            foreach (var contact in phonebook.Values)
            {
                if (contact.Confirmed)
                {
                    continue;
                }

                ContactMatch mtch = new ContactMatch {
                    Contact = contact
                };

                foreach (var phone in contact.Phones)
                {
                    mtch.Total += phone.Length;
                    foreach (var number in items)
                    {
                        if (number.Replace(" ", "").EndsWith(phone))
                        {
                            mtch.Match += phone.Length;
                            break;
                        }
                    }
                }

                if (mtch.Match > 0)
                {
                    candidates.Add(mtch);
                }
            }

            if (candidates.Count == 0)
            {
                return(null);
            }
            else if (candidates.Count > 1)
            {
                candidates.Sort(Compare);
            }

            return(candidates[0].Contact);
        }
Esempio n. 13
0
        public DeleteResolution ResolveDelete(Contact googleContact)
        {
            string name = ContactMatch.GetName(googleContact);

            _form.Text = "Outlook Contact deleted";
            _form.messageLabel.Text =
                "Outlook Contact \"" + name +
                "\" doesn't exist anymore. Do you want to delete it also on Google side?";

            _form.OutlookItemTextBox.Text = string.Empty;
            _form.GoogleItemTextBox.Text  = string.Empty;
            _form.GoogleItemTextBox.Text  = ContactMatch.GetSummary(googleContact);

            _form.keepOutlook.Text = "Keep Google";
            _form.keepGoogle.Text  = "Delete Google";
            _form.skip.Enabled     = false;

            return(ResolveDeletedOutlook());
        }
Esempio n. 14
0
        public ConflictResolution ResolveDuplicate(OutlookContactInfo outlookContact, List <Contact> googleContacts, out Contact googleContact)
        {
            string name = ContactMatch.GetName(outlookContact);

            _form.messageLabel.Text =
                "There are multiple Google Contacts (" + googleContacts.Count + ") matching unique properties for Outlook Contact \"" + name +
                "\". Please choose from the combobox below the Google Contact you would like to match with Outlook and if you want to keep the Google or Outlook properties of the selected contact.";


            _form.OutlookItemTextBox.Text = string.Empty;
            _form.GoogleItemTextBox.Text  = string.Empty;

            Microsoft.Office.Interop.Outlook.ContactItem item = outlookContact.GetOriginalItemFromOutlook();
            try
            {
                _form.OutlookItemTextBox.Text = ContactMatch.GetSummary(item);
            }
            finally
            {
                if (item != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
                    item = null;
                }
            }



            _form.GoogleComboBox.DataSource = googleContacts;
            _form.GoogleComboBox.Visible    = true;
            _form.AllCheckBox.Visible       = false;
            _form.skip.Text = "Keep both";


            ConflictResolution res = Resolve();

            googleContact = _form.GoogleComboBox.SelectedItem as Contact;

            return(res);
        }
Esempio n. 15
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();
        }
Esempio n. 16
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();
        }
Esempio n. 17
0
        public void SaveGoogleContact(ContactMatch match)
        {
            //check if this contact was not yet inserted on google.
            if (match.GoogleContact.Id.Uri == null)
            {
                //insert contact.
                Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));

                try
                {
                    ContactPropertiesUtils.SetGoogleOutlookContactId(SyncProfile, match.GoogleContact, match.OutlookContact);

                    ContactEntry createdEntry = (ContactEntry)_googleService.Insert(feedUri, match.GoogleContact);
                    match.GoogleContact = createdEntry;

                    ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
                    match.OutlookContact.Save();
                }
                catch (Exception ex)
                {
                    MemoryStream ms = new MemoryStream();
                    match.GoogleContact.SaveToXml(ms);

                    StreamReader sr = new StreamReader(ms);

                    ms.Seek(0, SeekOrigin.Begin);
                    Debug.WriteLine(String.Format("Error saving google contact: {0}", ex.Message));
                    Debug.WriteLine(sr.ReadToEnd());
                    //TODO: save google contact xml for diagnistics
                    throw;
                }
            }
            else
            {
                try
                {
                    //contact already present in google. just update
                    ContactPropertiesUtils.SetGoogleOutlookContactId(SyncProfile, match.GoogleContact, match.OutlookContact);

                    //TODO: this will fail if original contact had an empty name or rpimary email address.
                    ContactEntry updatedEntry = match.GoogleContact.Update() as ContactEntry;
                    match.GoogleContact = updatedEntry;

                    ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
                    match.OutlookContact.Save();
                }
                catch (Exception ex)
                {
                    //TODO: save google contact xml for diagnistics
                    throw ex;
                }
            }
        }
Esempio n. 18
0
        public void TestGooglePhoto()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

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

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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();

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

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

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

            MatchContacts(sync);
            match = sync.ContactByProperty(name, email);
            ContactsMatcher.SyncContact(match, sync);

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

            DeleteTestContacts(match);
        }
Esempio n. 19
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 = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
                outlookContact.FullName = names[i];
                outlookContact.FileAs = names[i];
                outlookContact.Email1Address = emails[i];
                outlookContact.Save();

                Contact googleContact = new Contact();
                ContactSync.UpdateContact(outlookContact, googleContact, sync.UseFileAs);
                match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

            MatchContacts(sync);
            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)
        }
Esempio n. 20
0
        public void SaveContact(ContactMatch match)
        {
            if (match.GoogleContact != null && match.OutlookContact != null)
            {
                //bool googleChanged, outlookChanged;
                //SaveContactGroups(match, out googleChanged, out outlookChanged);

                if (match.GoogleContact.IsDirty() || !match.OutlookContact.Saved)
                    _syncedCount++;

                if (match.GoogleContact.IsDirty())// || googleChanged)
                {
                    //google contact was modified. save.
                    SaveGoogleContact(match);
                    if (Logger != null)
                        Logger.Log("Saved Google contact: \"" + match.GoogleContact.Title.Text + "\"", EventType.Information);
                }

                if (!match.OutlookContact.Saved)// || outlookChanged)
                {
                    match.OutlookContact.Save();
                    ContactPropertiesUtils.SetGoogleOutlookContactId(SyncProfile, match.GoogleContact, match.OutlookContact);

                    ContactEntry updatedEntry = match.GoogleContact.Update() as ContactEntry;
                    match.GoogleContact = updatedEntry;

                    ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
                    match.OutlookContact.Save();
                    if (Logger != null)
                        Logger.Log("Saved Outlook contact: \"" + match.OutlookContact.FileAs + "\"", EventType.Information);

                    //TODO: this will cause the google contact to be updated on next run because Outlook's contact will be marked as saved later that Google's contact.
                }

                // save photos
                SaveContactPhotos(match);
            }
            else if (match.GoogleContact == null && match.OutlookContact != null)
            {
                if (ContactPropertiesUtils.GetOutlookGoogleContactId(this, match.OutlookContact) != null && _syncDelete)
                {
                    _deletedCount++;
                    string name = match.OutlookContact.FileAs;
                    // peer google contact was deleted, delete outlook contact
                    match.OutlookContact.Delete();
                    if (Logger != null)
                        Logger.Log("Deleted Outlook contact: \"" + name + "\"", EventType.Information);
                }
            }
            else if (match.GoogleContact != null && match.OutlookContact == null)
            {
                if (ContactPropertiesUtils.GetGoogleOutlookContactId(SyncProfile, match.GoogleContact) != null && _syncDelete)
                {
                    _deletedCount++;
                    // peer outlook contact was deleted, delete google contact
                    match.GoogleContact.Delete();
                    if (Logger != null)
                        Logger.Log("Deleted Google contact: \"" + match.GoogleContact.Title.Text + "\"", EventType.Information);
                }
            }
            else
            {
                //TODO: ignore for now: throw new ArgumentNullException("To save contacts both ContactMatch peers must be present.");
                if (Logger != null)
                    Logger.Log("Both Google and Outlook contact: \"" + match.GoogleContact.Title.Text + "\" have been changed! Not implemented yet.", EventType.Warning);
            }
        }
Esempio n. 21
0
        public void TestSyncGroups()
        {
            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);

            // google contatc should now have the same group
            Assert.AreEqual(sync.GetGoogleGroupByName(groupName), Utilities.GetGoogleGroups(sync, match.GoogleContact)[0]);

            // delete outlook contact
            match.OutlookContact.Delete();
            outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            ContactSync.UpdateContact(match.GoogleContact, outlookContact);
            match = new ContactMatch(outlookContact, match.GoogleContact);
            match.OutlookContact.Save();

            sync.SyncOption = SyncOption.MergeGoogleWins;

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

            // outlook contact should now have the same group
            Assert.AreEqual(groupName, match.OutlookContact.Categories);

            //delete test contacts
            match.Delete();

            // delete test group
            GroupEntry group = sync.GetGoogleGroupByName(groupName);
            group.Delete();
        }
Esempio n. 22
0
        public void TestSyncDeletedGoogleGroup()
        {
            //ToDo: Check for eache SyncOption and SyncDelete combination
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.SyncDelete = true;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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();

            //Outlook contact should now have a group
            Assert.AreEqual(groupName, outlookContact.Categories);

            //Sync Groups first
            MatchContacts(sync);
            ContactsMatcher.SyncGroups(sync);

            //Create now Google Contact and assing new Group
            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

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

            // google contact should now have the same group
            System.Collections.ObjectModel.Collection<Group> googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleContact);
            Group group = sync.GetGoogleGroupByName(groupName);

            Assert.AreEqual(2, googleGroups.Count);
            Assert.Contains(group, googleGroups);
            Assert.Contains(sync.GetGoogleGroupByName(Synchronizer.myContactsGroup), googleGroups);

            // delete group from google
            Utilities.RemoveGoogleGroup(match.GoogleContact, group);

            googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleContact);
            Assert.AreEqual(1, googleGroups.Count);
            Assert.Contains(sync.GetGoogleGroupByName(Synchronizer.myContactsGroup), googleGroups);

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

            sync.SyncOption = SyncOption.GoogleToOutlookOnly;

            //Sync Groups first
            MatchContacts(sync);
            ContactsMatcher.SyncGroups(sync);

            //sync and save contact to outlook.
            match = sync.ContactByProperty(name, email);
            sync.UpdateContact(match.GoogleContact, outlookContact);
            sync.SaveContact(match);

            // google and outlook should now have no category except for the System Group: My Contacts
            googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleContact);
            Assert.AreEqual(1, googleGroups.Count);
            Assert.AreEqual(null, outlookContact.Categories);
            Assert.Contains(sync.GetGoogleGroupByName(Synchronizer.myContactsGroup), googleGroups);

            DeleteTestContacts(match);

            // delete test group
            if (group != null)
                sync.ContactsRequest.Delete(group);
        }
Esempio n. 23
0
        public void TestSync_EmailOnly()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            outlookContact.FileAs = email;
            outlookContact.Email1Address = email;

            outlookContact.Save();

            Assert.IsNull(outlookContact.FullName);
            Assert.IsNull(outlookContact.CompanyName);

            sync.SyncOption = SyncOption.OutlookToGoogleOnly;

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

            sync.SyncOption = SyncOption.GoogleToOutlookOnly;
            //load the same contact from google.
            MatchContacts(sync);
            match = sync.ContactByProperty(email, email);
            //ContactsMatcher.SyncContact(match, sync);

            Outlook.ContactItem recreatedOutlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            ContactSync.UpdateContact(match.GoogleContact, recreatedOutlookContact, sync.UseFileAs);

            // match recreatedOutlookContact with outlookContact
            Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);

            Assert.AreEqual(outlookContact.Email1Address, recreatedOutlookContact.Email1Address);

            Assert.IsNull(recreatedOutlookContact.FullName);
            Assert.IsNull(outlookContact.CompanyName);

            DeleteTestContacts(match);
            recreatedOutlookContact.Delete();
        }
Esempio n. 24
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();
        }
Esempio n. 25
0
        public void TestSyncPhoto()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

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

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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";
            Utilities.SetOutlookPhoto(outlookContact, AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg");
            outlookContact.Save();

            // outlook contact should now have a photo
            Assert.IsNotNull(Utilities.GetOutlookPhoto(outlookContact));

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

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

            // google contact should now have a photo
            Assert.IsNotNull(Utilities.GetGooglePhoto(sync, match.GoogleContact));

            // delete outlook contact
            outlookContact.Delete();

            // recreate outlook contact
            outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);

            // outlook contact should now have no photo
            Assert.IsNull(Utilities.GetOutlookPhoto(outlookContact));

            sync.UpdateContact(match.GoogleContact, outlookContact);
            match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), match.GoogleContact);
            //match.OutlookContact.Save();

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

            // outlook contact should now have a photo
            Assert.IsNotNull(Utilities.GetOutlookPhoto(outlookContact));

            Thread.Sleep(5000);
            DeleteTestContacts();
        }
Esempio n. 26
0
        public void TestSyncGroups()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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();

            //Outlook contact should now have a group
            Assert.AreEqual(groupName, outlookContact.Categories);

            //Sync Groups first
            MatchContacts(sync);
            ContactsMatcher.SyncGroups(sync);

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

            //sync and save contact to google.
            ContactsMatcher.SyncContact(match, sync);
            sync.SaveContact(match);

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

            // google contact should now have the same group
            System.Collections.ObjectModel.Collection<Group> googleGroups = Utilities.GetGoogleGroups(sync, match.GoogleContact);
            Assert.AreEqual(2, googleGroups.Count);
            Assert.Contains(sync.GetGoogleGroupByName(groupName), googleGroups);
            Assert.Contains(sync.GetGoogleGroupByName(Synchronizer.myContactsGroup), googleGroups);

            // delete outlook contact
            outlookContact.Delete();
            outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            sync.UpdateContact(match.GoogleContact, outlookContact);
            match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), match.GoogleContact);
            outlookContact.Save();

            sync.SyncOption = SyncOption.MergeGoogleWins;

            //sync and save contact to outlook
            ContactsMatcher.SyncContact(match, sync);
            sync.SaveContact(match);

            //load the same contact from outlook
            MatchContacts(sync);
            match = sync.ContactByProperty(name, email);
            ContactsMatcher.SyncContact(match, sync);

            Assert.AreEqual(groupName, outlookContact.Categories);

            DeleteTestContacts(match);

            // delete test group
            Group group = sync.GetGoogleGroupByName(groupName);
            if (group != null)
                sync.ContactsRequest.Delete(group);
        }
Esempio n. 27
0
        public void TestSyncDeletedOulook()
        {
            //ToDo: Check for eache SyncOption and SyncDelete combination
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.SyncDelete = true;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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();

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

            //save contacts
            sync.SaveContact(match);

            // delete outlook contact
            outlookContact.Delete();

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

            Assert.IsNotNull(match);

            // delete
            sync.SaveContact(match);

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

            // check if google contact still exists
            googleContact = null;
            match = sync.ContactByProperty(name, email);
            //foreach (ContactMatch m in sync.Contacts)
            //{
            //    if (m.GoogleContact.Title == name)
            //    {
            //        googleContact = m.GoogleContact;
            //        break;
            //    }
            //}
            Assert.IsNull(match);
        }
Esempio n. 28
0
        public void Sync()
        {
            lock (_syncRoot)
            {
                try
                {
                    if (string.IsNullOrEmpty(SyncProfile))
                    {
                        Logger.Log("Must set a sync profile. This should be different on each user/computer you sync on.", EventType.Error);
                        return;
                    }

                    LogSyncParams();

                    SyncedCount = 0;
                    appointmentsSynchronizer.SyncedCount = 0;
                    contactsSynchronizer.SyncedCount     = 0;
                    DeletedCount = 0;
                    appointmentsSynchronizer.DeletedCount = 0;
                    contactsSynchronizer.DeletedCount     = 0;
                    ErrorCount = 0;
                    appointmentsSynchronizer.ErrorCount = 0;
                    contactsSynchronizer.ErrorCount     = 0;
                    SkippedCount = 0;
                    appointmentsSynchronizer.SkippedCount = 0;
                    contactsSynchronizer.SkippedCount     = 0;
                    SkippedCountNotMatches = 0;
                    appointmentsSynchronizer.SkippedCountNotMatches = 0;
                    contactsSynchronizer.SkippedCountNotMatches     = 0;
                    ConflictResolution      = ConflictResolution.Cancel;
                    DeleteGoogleResolution  = DeleteResolution.Cancel;
                    DeleteOutlookResolution = DeleteResolution.Cancel;

                    if (SyncContacts)
                    {
                        contactsSynchronizer.MatchContacts();
                    }

                    if (SyncAppointments)
                    {
                        appointmentsSynchronizer.SetTimeZone();
                        appointmentsSynchronizer.MatchAppointments();
                    }

                    if (SyncContacts)
                    {
                        if (contactsSynchronizer.Contacts == null)
                        {
                            return;
                        }

                        TotalCount = contactsSynchronizer.Contacts.Count + SkippedCountNotMatches + appointmentsSynchronizer.SkippedCountNotMatches + contactsSynchronizer.SkippedCountNotMatches;

                        //Resolve Google duplicates from matches to be synced
                        contactsSynchronizer.ResolveDuplicateContacts(contactsSynchronizer.GoogleContactDuplicates);

                        //Remove Outlook duplicates from matches to be synced
                        if (contactsSynchronizer.OutlookContactDuplicates != null)
                        {
                            for (int i = contactsSynchronizer.OutlookContactDuplicates.Count - 1; i >= 0; i--)
                            {
                                ContactMatch match = contactsSynchronizer.OutlookContactDuplicates[i];
                                if (contactsSynchronizer.Contacts.Contains(match))
                                {
                                    //ToDo: If there has been a resolution for a duplicate above, there is still skipped increased, check how to distinguish
                                    SkippedCount++;
                                    contactsSynchronizer.Contacts.Remove(match);
                                }
                            }
                        }

                        Logger.Log("Syncing groups...", EventType.Information);
                        ContactsMatcher.SyncGroups(contactsSynchronizer);

                        Logger.Log("Syncing contacts...", EventType.Information);
                        ContactsMatcher.SyncContacts(contactsSynchronizer);

                        contactsSynchronizer.SaveContacts(contactsSynchronizer.Contacts);
                    }

                    if (SyncAppointments)
                    {
                        if (appointmentsSynchronizer.Appointments == null)
                        {
                            return;
                        }

                        TotalCount += appointmentsSynchronizer.Appointments.Count + SkippedCountNotMatches + appointmentsSynchronizer.SkippedCountNotMatches + contactsSynchronizer.SkippedCountNotMatches;

                        Logger.Log("Syncing appointments...", EventType.Information);
                        AppointmentsMatcher.SyncAppointments(appointmentsSynchronizer);

                        appointmentsSynchronizer.DeleteAppointments();
                    }
                }
                finally
                {
                    if (contactsSynchronizer.OutlookContacts != null)
                    {
                        Marshal.ReleaseComObject(contactsSynchronizer.OutlookContacts);
                        contactsSynchronizer.OutlookContacts = null;
                    }
                    if (appointmentsSynchronizer.OutlookAppointments != null)
                    {
                        Marshal.ReleaseComObject(appointmentsSynchronizer.OutlookAppointments);
                        appointmentsSynchronizer.OutlookAppointments = null;
                    }
                    contactsSynchronizer.GoogleContacts           = null;
                    appointmentsSynchronizer.GoogleAppointments   = null;
                    contactsSynchronizer.OutlookContactDuplicates = null;
                    contactsSynchronizer.GoogleContactDuplicates  = null;
                    contactsSynchronizer.GoogleGroups             = null;
                    contactsSynchronizer.Contacts         = null;
                    appointmentsSynchronizer.Appointments = null;
                }
            }
        }
Esempio n. 29
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);
        }
Esempio n. 30
0
        public void TestSyncPhoto()
        {
            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";
            Utilities.SetOutlookPhoto(outlookContact, AppDomain.CurrentDomain.BaseDirectory + "\\SamplePic.jpg");
            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);

            // google contact should now have a photo
            Assert.IsNotNull(Utilities.GetGooglePhoto(sync, match.GoogleContact));

            // delete outlook contact
            match.OutlookContact.Delete();
            outlookContact = sync.OutlookApplication.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
            ContactSync.UpdateContact(match.GoogleContact, outlookContact);
            match = new ContactMatch(outlookContact, match.GoogleContact);
            match.OutlookContact.Save();

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

            // outlook contact should now have a photo
            Assert.IsNotNull(Utilities.GetOutlookPhoto(match.OutlookContact));

            //delete test contacts
            match.Delete();
        }
Esempio n. 31
0
        public void TestResetMatches()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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; //Group is not relevant here
            outlookContact.Save();

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

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

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

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

            Assert.IsNull(match.OutlookContact);

            // reset matches
            sync.ResetMatch(match.GoogleContact);
            //Not, because NULL: sync.ResetMatch(match.OutlookContact.GetOriginalItemFromOutlook(sync));

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

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

            DeleteTestContacts();

            // create new contact to sync
            outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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 Contact();
            sync.UpdateContact(outlookContact, googleContact);
            match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

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

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

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

            Assert.IsNull(match.GoogleContact);

            // reset matches
            //Not, because null: sync.ResetMatch(match.GoogleContact);
            sync.ResetMatch(match.OutlookContact.GetOriginalItemFromOutlook());

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

            // Outlook contact should still be present and GoogleContact should be filled
            Assert.IsNotNull(match.OutlookContact);
            Assert.IsNotNull(match.GoogleContact);

            outlookContact.Delete();
        }
Esempio n. 32
0
 private void DeleteTestContacts(ContactMatch match)
 {
     if (match != null)
     {
         DeleteTestContact(match.GoogleContact);
         DeleteTestContact(match.OutlookContact);
     }
 }
Esempio n. 33
0
        public void TestSync_UseFullName()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.UseFileAs = false;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            outlookContact.FullName = name;
            outlookContact.FileAs = "SaveAs";

            outlookContact.Save();

            Assert.AreNotEqual(outlookContact.FullName, outlookContact.FileAs);

            sync.SyncOption = SyncOption.OutlookToGoogleOnly;

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

            sync.SyncOption = SyncOption.GoogleToOutlookOnly;
            //load the same contact from google.
            MatchContacts(sync);
            match = sync.ContactByProperty(name, email);
            //ContactsMatcher.SyncContact(match, sync);

            Outlook.ContactItem recreatedOutlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            ContactSync.UpdateContact(match.GoogleContact, recreatedOutlookContact, sync.UseFileAs);

            // match recreatedOutlookContact with outlookContact
            Assert.AreEqual(match.GoogleContact.Name.FullName, OutlookContactInfo.GetTitleFirstLastAndSuffix(recreatedOutlookContact).Trim().Replace("  ", " "));
            Assert.AreNotEqual(outlookContact.FileAs, match.GoogleContact.Title);
            Assert.AreNotEqual(outlookContact.FileAs, match.GoogleContact.Name.FullName);
            Assert.AreNotEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);

            recreatedOutlookContact.FileAs = "SaveAs";
            Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);
            ContactSync.UpdateContact(match.GoogleContact, recreatedOutlookContact, sync.UseFileAs);
            Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);

            DeleteTestContacts(match);
            recreatedOutlookContact.Delete();
        }
Esempio n. 34
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();
        }
Esempio n. 35
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);
        }
Esempio n. 36
0
 public void ResetMatch(ContactMatch match)
 {
     if (match.GoogleContact != null)
     {
         ContactPropertiesUtils.ResetGoogleOutlookContactId(SyncProfile, match.GoogleContact);
         SaveGoogleContact(match.GoogleContact);
     }
     if (match.OutlookContact != null)
     {
         ContactPropertiesUtils.ResetOutlookGoogleContactId(this, match.OutlookContact);
         match.OutlookContact.Save();
     }
 }
Esempio n. 37
0
        public void TestSync_Unstructured()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            outlookContact.FileAs = name;

            outlookContact.HomeAddress = "10 Parades";

            outlookContact.BusinessAddress = "11 Parades";

            outlookContact.OtherAddress = "12 Parades";

            outlookContact.IMAddress = "  "; //Test empty IMAddress

            outlookContact.Email2Address = "  "; //Test empty Email Address

            outlookContact.FullName = name;

            outlookContact.Save();

            sync.SyncOption = SyncOption.OutlookToGoogleOnly;

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

            sync.SyncOption = SyncOption.GoogleToOutlookOnly;
            //load the same contact from google.
            MatchContacts(sync);
            match = sync.ContactByProperty(name, email);
            //ContactsMatcher.SyncContact(match, sync);

            Outlook.ContactItem recreatedOutlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            ContactSync.UpdateContact(match.GoogleContact, recreatedOutlookContact, sync.UseFileAs);

            // match recreatedOutlookContact with outlookContact
            Assert.AreEqual(outlookContact.FileAs, recreatedOutlookContact.FileAs);

            Assert.AreEqual(outlookContact.HomeAddress, recreatedOutlookContact.HomeAddress);
            Assert.AreEqual(outlookContact.BusinessAddress, recreatedOutlookContact.BusinessAddress);
            Assert.AreEqual(outlookContact.OtherAddress, recreatedOutlookContact.OtherAddress);

            Assert.AreEqual(outlookContact.FullName, recreatedOutlookContact.FullName);

            DeleteTestContacts(match);
            recreatedOutlookContact.Delete();
        }
Esempio n. 38
0
        public void SaveContactPhotos(ContactMatch match)
        {
            bool hasGooglePhoto = Utilities.HasPhoto(match.GoogleContact);
            bool hasOutlookPhoto = Utilities.HasPhoto(match.OutlookContact);

            if (!hasGooglePhoto && !hasOutlookPhoto)
                return;
            else if (hasGooglePhoto && !hasOutlookPhoto)
            {
                // add google photo to outlook
                Image googlePhoto = Utilities.GetGooglePhoto(this, match.GoogleContact);
                Utilities.SetOutlookPhoto(match.OutlookContact, googlePhoto);
                match.OutlookContact.Save();

                googlePhoto.Dispose();
            }
            else if (!hasGooglePhoto && hasOutlookPhoto)
            {
                // add outlook photo to google
                Image outlookPhoto = Utilities.GetOutlookPhoto(match.OutlookContact);
                outlookPhoto = Utilities.CropImageGoogleFormat(outlookPhoto);
                bool saved = Utilities.SaveGooglePhoto(this, match.GoogleContact, outlookPhoto);
                if (!saved)
                    throw new Exception("Could not save");

                outlookPhoto.Dispose();
            }
            else
            {
                // TODO: if both contacts have photos and one is updated, the
                // other will not be updated.
            }

            //Utilities.DeleteTempPhoto();
        }
Esempio n. 39
0
        public void TestSync_Structured()
        {
            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            outlookContact.FileAs = name;
            outlookContact.Email1Address = email;
            outlookContact.Email2Address = email.Replace("00", "01");
            outlookContact.Email3Address = email.Replace("00", "02");

            //outlookContact.HomeAddress = "10 Parades";
            outlookContact.HomeAddressStreet = "Street";
            outlookContact.HomeAddressCity = "City";
            outlookContact.HomeAddressPostalCode = "1234";
            outlookContact.HomeAddressCountry = "Country";
            outlookContact.HomeAddressPostOfficeBox = "PO1";
            outlookContact.HomeAddressState = "State1";

            //outlookContact.BusinessAddress = "11 Parades"
            outlookContact.BusinessAddressStreet = "Street2";
            outlookContact.BusinessAddressCity = "City2";
            outlookContact.BusinessAddressPostalCode = "5678";
            outlookContact.BusinessAddressCountry = "Country2";
            outlookContact.BusinessAddressPostOfficeBox = "PO2";
            outlookContact.BusinessAddressState = "State2";

            ///outlookContact.OtherAddress = "12 Parades";
            outlookContact.OtherAddressStreet = "Street3";
            outlookContact.OtherAddressCity = "City3";
            outlookContact.OtherAddressPostalCode = "8012";
            outlookContact.OtherAddressCountry = "Country3";
            outlookContact.OtherAddressPostOfficeBox = "PO3";
            outlookContact.OtherAddressState = "State3";

            #region phones
            //First delete the destination phone numbers
            outlookContact.PrimaryTelephoneNumber = "123";
            outlookContact.HomeTelephoneNumber = "456";
            outlookContact.Home2TelephoneNumber = "4567";
            outlookContact.BusinessTelephoneNumber = "45678";
            outlookContact.Business2TelephoneNumber = "456789";
            outlookContact.MobileTelephoneNumber = "123";
            outlookContact.BusinessFaxNumber = "1234";
            outlookContact.HomeFaxNumber = "12345";
            outlookContact.PagerNumber = "123456";
            //outlookContact.RadioTelephoneNumber = "1234567";
            outlookContact.OtherTelephoneNumber = "12345678";
            outlookContact.CarTelephoneNumber = "123456789";
            outlookContact.AssistantTelephoneNumber = "987";
            #endregion phones

            #region Name
            outlookContact.Title = "Title";
            outlookContact.FirstName = "Firstname";
            outlookContact.MiddleName = "Middlename";
            outlookContact.LastName = "Lastname";
            outlookContact.Suffix = "Suffix";
            //outlookContact.FullName = name; //The Outlook fullName is automatically set, so don't assign it from Google
            #endregion Name

            outlookContact.Birthday = new DateTime(1999,1,1);

            outlookContact.NickName = "Nickname";
            outlookContact.OfficeLocation = "Location";
            outlookContact.Initials = "IN";
            outlookContact.Language = "German";

            //outlookContact.Companies = "Company";
            outlookContact.CompanyName = "CompanyName";
            outlookContact.JobTitle = "Position";
            outlookContact.Department = "Department";

            outlookContact.IMAddress = "IMs";
            outlookContact.Anniversary = new DateTime(2000,1,1);
            outlookContact.Children = "Children";
            outlookContact.Spouse = "Spouse";
            outlookContact.AssistantName = "Assi";
            outlookContact.ManagerName = "Chef";
            outlookContact.WebPage = "http://www.test.de";
            outlookContact.Body = "<sn>Content & other stuff</sn>\r\n<![CDATA[  \r\n...\r\n&stuff in CDATA < >\r\n  ]]>";
            outlookContact.Save();

            sync.SyncOption = SyncOption.OutlookToGoogleOnly;

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

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

            sync.SyncOption = SyncOption.GoogleToOutlookOnly;
            //load the same contact from google.
            MatchContacts(sync);
            match = sync.ContactByProperty(name, email);
            //ContactsMatcher.SyncContact(match, sync);

            Outlook.ContactItem recreatedOutlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            ContactSync.UpdateContact(match.GoogleContact, recreatedOutlookContact, sync.UseFileAs);

            // match recreatedOutlookContact with outlookContact
            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.HomeTelephoneNumber, recreatedOutlookContact.HomeTelephoneNumber);
            Assert.AreEqual(outlookContact.Home2TelephoneNumber, recreatedOutlookContact.Home2TelephoneNumber);
            Assert.AreEqual(outlookContact.BusinessTelephoneNumber, recreatedOutlookContact.BusinessTelephoneNumber);
            Assert.AreEqual(outlookContact.Business2TelephoneNumber, recreatedOutlookContact.Business2TelephoneNumber);
            Assert.AreEqual(outlookContact.MobileTelephoneNumber, recreatedOutlookContact.MobileTelephoneNumber);
            Assert.AreEqual(outlookContact.BusinessFaxNumber, recreatedOutlookContact.BusinessFaxNumber);
            Assert.AreEqual(outlookContact.HomeFaxNumber, recreatedOutlookContact.HomeFaxNumber);
            Assert.AreEqual(outlookContact.PagerNumber, recreatedOutlookContact.PagerNumber);
            //Assert.AreEqual(outlookContact.RadioTelephoneNumber, recreatedOutlookContact.RadioTelephoneNumber);
            Assert.AreEqual(outlookContact.OtherTelephoneNumber, recreatedOutlookContact.OtherTelephoneNumber);
            Assert.AreEqual(outlookContact.CarTelephoneNumber, recreatedOutlookContact.CarTelephoneNumber);
            Assert.AreEqual(outlookContact.AssistantTelephoneNumber, recreatedOutlookContact.AssistantTelephoneNumber);

            Assert.AreEqual(outlookContact.HomeAddressStreet, recreatedOutlookContact.HomeAddressStreet);
            Assert.AreEqual(outlookContact.HomeAddressCity, recreatedOutlookContact.HomeAddressCity);
            Assert.AreEqual(outlookContact.HomeAddressCountry, recreatedOutlookContact.HomeAddressCountry);
            Assert.AreEqual(outlookContact.HomeAddressPostalCode, recreatedOutlookContact.HomeAddressPostalCode);
            Assert.AreEqual(outlookContact.HomeAddressPostOfficeBox, recreatedOutlookContact.HomeAddressPostOfficeBox);
            Assert.AreEqual(outlookContact.HomeAddressState, recreatedOutlookContact.HomeAddressState);

            Assert.AreEqual(outlookContact.BusinessAddressStreet, recreatedOutlookContact.BusinessAddressStreet);
            Assert.AreEqual(outlookContact.BusinessAddressCity, recreatedOutlookContact.BusinessAddressCity);
            Assert.AreEqual(outlookContact.BusinessAddressCountry, recreatedOutlookContact.BusinessAddressCountry);
            Assert.AreEqual(outlookContact.BusinessAddressPostalCode, recreatedOutlookContact.BusinessAddressPostalCode);
            Assert.AreEqual(outlookContact.BusinessAddressPostOfficeBox, recreatedOutlookContact.BusinessAddressPostOfficeBox);
            Assert.AreEqual(outlookContact.BusinessAddressState, recreatedOutlookContact.BusinessAddressState);

            Assert.AreEqual(outlookContact.OtherAddressStreet, recreatedOutlookContact.OtherAddressStreet);
            Assert.AreEqual(outlookContact.OtherAddressCity, recreatedOutlookContact.OtherAddressCity);
            Assert.AreEqual(outlookContact.OtherAddressCountry, recreatedOutlookContact.OtherAddressCountry);
            Assert.AreEqual(outlookContact.OtherAddressPostalCode, recreatedOutlookContact.OtherAddressPostalCode);
            Assert.AreEqual(outlookContact.OtherAddressPostOfficeBox, recreatedOutlookContact.OtherAddressPostOfficeBox);
            Assert.AreEqual(outlookContact.OtherAddressState, recreatedOutlookContact.OtherAddressState);

            Assert.AreEqual(outlookContact.FullName, recreatedOutlookContact.FullName);
            Assert.AreEqual(outlookContact.MiddleName, recreatedOutlookContact.MiddleName);
            Assert.AreEqual(outlookContact.LastName, recreatedOutlookContact.LastName);
            Assert.AreEqual(outlookContact.FirstName, recreatedOutlookContact.FirstName);
            Assert.AreEqual(outlookContact.Title, recreatedOutlookContact.Title);
            Assert.AreEqual(outlookContact.Suffix, recreatedOutlookContact.Suffix);

            Assert.AreEqual(outlookContact.Birthday, recreatedOutlookContact.Birthday);

            Assert.AreEqual(outlookContact.NickName, recreatedOutlookContact.NickName);
            Assert.AreEqual(outlookContact.OfficeLocation, recreatedOutlookContact.OfficeLocation);
            Assert.AreEqual(outlookContact.Initials, recreatedOutlookContact.Initials);
            Assert.AreEqual(outlookContact.Language, recreatedOutlookContact.Language);

            Assert.AreEqual(outlookContact.IMAddress, recreatedOutlookContact.IMAddress);
            Assert.AreEqual(outlookContact.Anniversary, recreatedOutlookContact.Anniversary);
            Assert.AreEqual(outlookContact.Children, recreatedOutlookContact.Children);
            Assert.AreEqual(outlookContact.Spouse, recreatedOutlookContact.Spouse);
            Assert.AreEqual(outlookContact.ManagerName, recreatedOutlookContact.ManagerName);
            Assert.AreEqual(outlookContact.AssistantName, recreatedOutlookContact.AssistantName);

            Assert.AreEqual(outlookContact.WebPage, recreatedOutlookContact.WebPage);
            Assert.AreEqual(outlookContact.Body, recreatedOutlookContact.Body);

            //Assert.AreEqual(outlookContact.Companies, recreatedOutlookContact.Companies);
            Assert.AreEqual(outlookContact.CompanyName, recreatedOutlookContact.CompanyName);
            Assert.AreEqual(outlookContact.JobTitle, recreatedOutlookContact.JobTitle);
            Assert.AreEqual(outlookContact.Department, recreatedOutlookContact.Department);

            DeleteTestContacts(match);
            recreatedOutlookContact.Delete();

            //Also delete the birthday/anniversary entries in Outlook calendar
            Logger.Log("Deleting Outlook calendar TEST entries (birthday, anniversary) ...", EventType.Information);

            try
            {   Outlook.NameSpace outlookNamespace = Synchronizer.OutlookApplication.GetNamespace("mapi");
                Outlook.MAPIFolder calendarFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.Items outlookCalendarItems = calendarFolder.Items;
                for (int i = outlookCalendarItems.Count ; i > 0; i--)
                {
                    Outlook.AppointmentItem item = outlookCalendarItems[i] as Outlook.AppointmentItem;
                    if (item.Subject.Contains(name))
                    {
                        string subject = item.Subject;
                        item.Delete();
                        Logger.Log("Deleted Outlook calendar TEST entry: " + subject, EventType.Information);
                    }

                }
            }
            catch (System.Exception ex)
            {
                Logger.Log("Could not delete Outlook calendar TEST entries: " + ex.Message, EventType.Information);
            }
        }
Esempio n. 40
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();
        }
Esempio n. 41
0
        public void TestExtendedProps()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.UseFileAs = true;

            // create new contact to sync
            Outlook.ContactItem outlookContact = Synchronizer.CreateOutlookContactItem(Synchronizer.SyncContactsFolder);
            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();

            Contact googleContact = new Contact();
            sync.UpdateContact(outlookContact, googleContact);
            ContactMatch match = new ContactMatch(new OutlookContactInfo(outlookContact, sync), googleContact);

            sync.SaveGoogleContact(match);

            Assert.AreEqual(name, match.GoogleContact.Title);

            // read contact from google
            googleContact = null;
            MatchContacts(sync);
            ContactsMatcher.SyncContacts(sync);

            match = sync.ContactByProperty(name, email);
            //foreach (ContactMatch m in sync.Contacts)
            //{
            //    if (m.GoogleContact != null && (m.GoogleContact.Title == name || m.GoogleContact.Name.FullName == name))
            //    {
            //        googleContact = m.GoogleContact;
            //        break;
            //    }
            //}

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

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

            DeleteTestContacts(match);
        }