public ContactEntry Add(ContactEntry c, string domain)
 {
     using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
     {
         return(ApiExtensions.InvokeWithRateLimit(() => connection.Item.Insert($"https://www.google.com/m8/feeds/contacts/{domain}/full", c), this.serviceName));
     }
 }
 public ContactEntry Update(ContactEntry c)
 {
     using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
     {
         return(ApiExtensions.InvokeWithRateLimit(() => connection.Item.Update(c), this.serviceName));
     }
 }
 public void Delete(ContactEntry c)
 {
     using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
     {
         ApiExtensions.InvokeWithRateLimit(() => connection.Item.Delete(c), this.serviceName);
     }
 }
 public ContactEntry GetContact(string id)
 {
     using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
     {
         return(ApiExtensions.InvokeWithRateLimit(() => (ContactEntry)connection.Item.Get(id), this.serviceName));
     }
 }
 public void Delete(string id)
 {
     using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
     {
         ContactEntry e = ApiExtensions.InvokeWithRateLimit(() => (ContactEntry)connection.Item.Get(id), this.serviceName);
         this.Delete(e);
     }
 }
Example #6
0
        private void ProcessMemberResponse <T>(string id, T item, bool ignoreExistingMember, bool ignoreMissingMember, RequestError error, HttpResponseMessage message, Dictionary <string, ClientServiceRequest <T> > requestsToRetry, ClientServiceRequest <T> request, List <string> failedMembers, List <Exception> failures)
        {
            string memberKey;
            string memberRole = string.Empty;

            Member member = item as Member;

            if (member == null)
            {
                memberKey = item as string ?? "unknown";
            }
            else
            {
                memberKey  = member.Email ?? member.Id;
                memberRole = member.Role;
            }

            string requestType = request.GetType().Name;

            if (error == null)
            {
                Trace.WriteLine($"{requestType}: Success: Member: {memberKey}, Role: {memberRole}, Group: {id}");
                return;
            }

            string errorString = $"{error}\nFailed {requestType}: {memberKey}\nGroup: {id}";

            Trace.WriteLine($"{requestType}: Failed: Member: {memberKey}, Role: {memberRole}, Group: {id}\n{error}");

            if (ignoreExistingMember && this.IsExistingMemberError(message.StatusCode, errorString))
            {
                return;
            }

            if (ignoreMissingMember && this.IsMissingMemberError(message.StatusCode, errorString))
            {
                return;
            }

            if (ApiExtensions.IsRetryableError(message.StatusCode, errorString))
            {
                Trace.WriteLine($"Queuing {requestType} of {memberKey} from group {id} for backoff/retry");
                requestsToRetry.Add(memberKey, request);
                return;
            }

            GoogleApiException ex = new GoogleApiException("admin", errorString);

            ex.HttpStatusCode = message.StatusCode;
            failedMembers.Add(memberKey);
            failures.Add(ex);
        }
Example #7
0
        private void ProcessStudentResponse <T>(string id, string studentKey, bool ignoreExistingStudent, bool ignoreMissingStudent, RequestError error, HttpResponseMessage message, Dictionary <string, ClientServiceRequest <T> > requestsToRetry, ClientServiceRequest <T> request, List <string> failedStudents, List <Exception> failures)
        {
            string requestType = request.GetType().Name;

            if (error == null)
            {
                Trace.WriteLine($"{requestType}: Success: Student: {studentKey}, Course: {id}");
                return;
            }

            string errorString = $"{error}\nFailed {requestType}: {studentKey}\nCourse: {id}";

            Trace.WriteLine($"{requestType}: Failed: Student: {studentKey}, Course: {id}\n{error}");

            if (ignoreExistingStudent && this.IsExistingStudentError(message.StatusCode, errorString))
            {
                return;
            }

            if (ignoreMissingStudent && this.IsMissingStudentError(message.StatusCode, errorString))
            {
                return;
            }

            if (ApiExtensions.IsRetryableError(message.StatusCode, errorString))
            {
                Trace.WriteLine($"Queuing {requestType} of student {studentKey} from course {id} for backoff/retry");
                requestsToRetry.Add(studentKey, request);
                return;
            }

            GoogleApiException ex = new GoogleApiException("admin", errorString)
            {
                HttpStatusCode = message.StatusCode
            };

            failedStudents.Add(studentKey);
            failures.Add(ex);
        }
        public IEnumerable <ContactEntry> GetContacts(string domain)
        {
            using (PoolItem <ContactsService> connection = this.contactsServicePool.Take())
            {
                string uri = ContactsQuery.CreateContactsUri(domain);

                do
                {
                    ContactsQuery request = new ContactsQuery(uri)
                    {
                        NumberToRetrieve = 1000
                    };

                    ContactsFeed result = ApiExtensions.InvokeWithRateLimit(() => connection.Item.Query(request), this.serviceName);

                    foreach (ContactEntry entry in result.Entries.OfType <ContactEntry>())
                    {
                        yield return(entry);
                    }

                    uri = result.NextChunk;
                } while (uri != null);
            }
        }