Exemplo n.º 1
0
 public static bool ContainsGroup(ContactEntry googleContact, GroupEntry groupEntry)
 {
     foreach (GroupMembership m in googleContact.GroupMembership)
     {
         if (m.HRef == groupEntry.Id.AbsoluteUri)
             return true;
     }
     return false;
 }
Exemplo n.º 2
0
        public static void AddGoogleGroup(ContactEntry googleContact, GroupEntry groupEntry)
        {
            if (ContainsGroup(googleContact, groupEntry))
                return;

            GroupMembership m = new GroupMembership();
            m.HRef = groupEntry.Id.AbsoluteUri;
            googleContact.GroupMembership.Add(m);
        }
Exemplo n.º 3
0
        ///// <summary>
        ///// Syncs groups. googleChanged and outlookChanged are needed because not always
        ///// when a google contact's groups have changed does it become dirty.
        ///// </summary>
        ///// <param name="match"></param>
        ///// <param name="googleChanged"></param>
        ///// <param name="outlookChanged"></param>
        //public void SaveContactGroups(ContactMatch match, out bool googleChanged, out bool outlookChanged)
        //{
        //    // get google groups
        //    Collection<GroupEntry> groups = Utilities.GetGoogleGroups(this, match.GoogleContact);
        //    // get outlook categories
        //    string[] cats = Utilities.GetOutlookGroups(match.OutlookContact);
        //    googleChanged = false;
        //    outlookChanged = false;
        //    if (groups.Count == 0 && cats.Length == 0)
        //        return;
        //    switch (SyncOption)
        //    {
        //        case SyncOption.MergeOutlookWins:
        //            //overwrite google contact
        //            OverwriteGoogleContactGroups(match.GoogleContact, groups, cats);
        //            googleChanged = true;
        //            break;
        //        case SyncOption.MergeGoogleWins:
        //            //overwrite outlook contact
        //            OverwriteOutlookContactGroups(match.OutlookContact, cats, groups);
        //            outlookChanged = true;
        //            break;
        //        case SyncOption.GoogleToOutlookOnly:
        //            //overwrite outlook contact
        //            OverwriteOutlookContactGroups(match.OutlookContact, cats, groups);
        //            outlookChanged = true;
        //            break;
        //        case SyncOption.OutlookToGoogleOnly:
        //            //overwrite google contact
        //            OverwriteGoogleContactGroups(match.GoogleContact, groups, cats);
        //            googleChanged = true;
        //            break;
        //        case SyncOption.MergePrompt:
        //            //TODO: we can not rely on previously chosen option as it may be different for each contact.
        //            if (CResolution == null)
        //            {
        //                //promp for sync option
        //                ConflictResolver r = new ConflictResolver();
        //                CResolution = r.Resolve(match.OutlookContact, match.GoogleContact);
        //            }
        //            switch (CResolution)
        //            {
        //                case ConflictResolution.Cancel:
        //                    break;
        //                case ConflictResolution.OutlookWins:
        //                    //overwrite google contact
        //                    OverwriteGoogleContactGroups(match.GoogleContact, groups, cats);
        //                    //TODO: we don't actually know if groups has changed. if all groups were the same it hasn't changed
        //                    googleChanged = true;
        //                    break;
        //                case ConflictResolution.GoogleWins:
        //                    //overwrite outlook contact
        //                    OverwriteOutlookContactGroups(match.OutlookContact, cats, groups);
        //                    //TODO: we don't actually know if groups has changed. if all groups were the same it hasn't changed
        //                    outlookChanged = true;
        //                    break;
        //                default:
        //                    break;
        //            }
        //            break;
        //    }
        //}
        public GroupEntry SaveGoogleGroup(GroupEntry group)
        {
            //check if this group was not yet inserted on google.
            if (group.Id.Uri == null)
            {
                //insert group.
                Uri feedUri = new Uri(GroupsQuery.CreateGroupsUri("default"));

                try
                {
                    GroupEntry createdEntry = _googleService.Insert(feedUri, group) as GroupEntry;
                    return createdEntry;
                }
                catch (Exception ex)
                {
                    //TODO: save google group xml for diagnistics
                    throw ex;
                }
            }
            else
            {
                try
                {
                    //group already present in google. just update
                    GroupEntry updatedEntry = group.Update() as GroupEntry;
                    return updatedEntry;
                }
                catch (Exception ex)
                {
                    //TODO: save google group xml for diagnistics
                    throw ex;
                }
            }
        }
Exemplo n.º 4
0
 public GroupEntry CreateGroup(string name)
 {
     GroupEntry group = new GroupEntry();
     group.Title.Text = name;
     group.Dirty = true;
     return group;
 }
        /////////////////////////////////////////////////////////////////////////////


        /////////////////////////////////////////////////////////////////////
        /// <summary>runs an basic auth test against the groups feed test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void GroupsSystemTest()
        {
            Tracing.TraceMsg("Entering GroupsSystemTest");

            GroupsQuery query = new GroupsQuery(ContactsQuery.CreateGroupsUri(this.userName + "@googlemail.com"));
            ContactsService service = new ContactsService("unittests");

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }

            GroupsFeed feed = service.Query(query);

            int i = 0; 
            foreach (GroupEntry g in feed.Entries )
            {
               if (g.SystemGroup != null)
               {
                   i++;
               }
            }

            Assert.IsTrue(i==4, "There should be 4 system groups in the groups feed");


            ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("GroupsAuthTest"));

            GroupEntry newGroup = new GroupEntry();
            newGroup.Title.Text = "Private Data";

            GroupEntry insertedGroup = feed.Insert(newGroup);

            GroupEntry g2 = new GroupEntry();
            g2.Title.Text = "Another Private Group";
            GroupEntry insertedGroup2 = feed.Insert(g2);

            // now insert a new contact that belongs to that group
            ContactsQuery q = new ContactsQuery(ContactsQuery.CreateContactsUri(this.userName + "@googlemail.com"));
            ContactsFeed cf = service.Query(q);
            ContactEntry entry = ObjectModelHelper.CreateContactEntry(1);
            GroupMembership member = new GroupMembership();
            member.HRef = insertedGroup.Id.Uri.ToString();
            GroupMembership member2 = new GroupMembership();
            member2.HRef = insertedGroup2.Id.Uri.ToString();

            ContactEntry insertedEntry = cf.Insert(entry);
            // now change the group membership
            insertedEntry.GroupMembership.Add(member);
            insertedEntry.GroupMembership.Add(member2);
            ContactEntry currentEntry = insertedEntry.Update();

            Assert.IsTrue(currentEntry.GroupMembership.Count == 2, "The entry should be in 2 groups");

            currentEntry.GroupMembership.Clear();
            currentEntry = currentEntry.Update();
            // now we should have 2 new groups and one new entry with no groups anymore


            int oldCountGroups = feed.Entries.Count;
            int oldCountContacts = cf.Entries.Count;

            currentEntry.Delete();

            insertedGroup.Delete();
            insertedGroup2.Delete();

            feed = service.Query(query);
            cf = service.Query(q);

            Assert.AreEqual(oldCountContacts, cf.Entries.Count, "Contacts count should be the same");
            Assert.AreEqual(oldCountGroups, feed.Entries.Count, "Groups count should be the same");
        }
Exemplo n.º 6
0
        public static void RemoveGoogleGroup(ContactEntry googleContact, GroupEntry groupEntry)
        {
            if (!ContainsGroup(googleContact, groupEntry))
                return;

            // TODO: broken. removes group membership but does not remove contact
            // from group in the end.

            // look for id
            GroupMembership mem;
            for (int i = 0; i < googleContact.GroupMembership.Count; i++)
            {
                mem = googleContact.GroupMembership[i];
                if (mem.HRef == groupEntry.Id.AbsoluteUri)
                {
                    googleContact.GroupMembership.Remove(mem);
                    return;
                }
            }
            throw new Exception("Did not find group");
        }