Пример #1
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);
        }
Пример #2
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);
        }