Beispiel #1
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;
                }
            }
            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;
                }
            }
        }
Beispiel #2
0
        static AtomEntryCollection GetGroups()
        {
            var query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"))
            {
                NumberToRetrieve = 1000
            };
            var feed   = service.Query(query);
            var groups = feed.Entries;

            return(groups);
        }
Beispiel #3
0
        private static void findGroup(string groupname)
        {
            GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));

            query.StartDate = new DateTime(2008, 1, 1);
            Feed <Group> feed = cr.Get <Group>(query);

            foreach (Group group in feed.Entries)
            {
                if (group.Title == groupname)
                {
                    HRefMedlem = group.Id;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Send authorized queries to a Request-based library
        /// </summary>
        /// <param name="service"></param>
        static void RunContactsSample(OAuth2Parameters parameters)
        {
            try
            {
                RequestSettings settings = new RequestSettings("Google contacts tutorial", parameters);
                ContactsRequest cr       = new ContactsRequest(settings);

                //ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
                //query.StartDate = new DateTime(2001, 1, 1);
                //Feed<Contact> feed = cr.Get<Contact>(query);
                //foreach (Contact contact in feed.Entries)
                //{
                //    Console.WriteLine(contact.Name.FullName);
                //    //Console.WriteLine("Updated on: " + contact.Updated.ToString());
                //}

                GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
                query.StartDate = new DateTime(2001, 1, 1);
                Feed <Group> feed = cr.Get <Group>(query);

                foreach (Group group in feed.Entries)
                {
                    Console.WriteLine(group.Title);
                    Console.WriteLine("Updated on: " + group.Updated.ToString());
                }

                ////string applicationName = "Test-OAuth2";
                ////GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory("apps", applicationName, parameters);
                ////GroupsService service = new GroupsService(domain, applicationName);
                ////service.RequestFactory = requestFactory;
                ////GroupFeed feed = service.RetrieveAllGroups();
                ////foreach (GroupEntry group in feed.Entries)
                ////{
                ////    Console.WriteLine(group.GroupName);
                ////}

                //Feed<Contact> f = cr.GetContacts();
                //foreach (Contact c in f.Entries)
                //{
                //    Console.WriteLine(c.Name.FullName);
                //}
            }
            catch (Exception a)
            {
                Console.WriteLine("A Google Apps error occurred.");
                Console.WriteLine();
            }
        }
Beispiel #5
0
        public void LoadGoogleGroups()
        {
            GroupsQuery query = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));

            query.NumberToRetrieve = 256;
            query.StartIndex       = 0;
            query.ShowDeleted      = false;

            GroupsFeed feed;

            feed          = _googleService.Query(query);
            _googleGroups = feed.Entries;
            while (feed.Entries.Count == query.NumberToRetrieve)
            {
                query.StartIndex = _googleGroups.Count;
                feed             = _googleService.Query(query);
                foreach (AtomEntry a in feed.Entries)
                {
                    _googleGroups.Add(a);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        ///  returns a feed of Groups for the given user
        /// </summary>
        /// <param name="user">the user for whom to retrieve the feed</param>
        /// <returns>a feed of Groups</returns>
        public Feed <Group> GetGroups(string user)
        {
            GroupsQuery q = PrepareQuery <GroupsQuery>(GroupsQuery.CreateGroupsUri(user));

            return(PrepareFeed <Group>(q));
        }