Пример #1
0
        public void OnResponse(IResponse response, HttpResponseMessage responseMessage)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                ServiceResponseException exception =
                    new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase}");

                var error = responseMessage.Content.ReadAsStringAsync().Result;

                if (responseMessage.Content.Headers.ContentType != null && responseMessage.Content.Headers.ContentType.MediaType == HttpMediaType.APPLICATION_JSON)
                {
                    exception.Error = JsonConvert.DeserializeObject <Error>(error);
                }
                else
                {
                    exception.Error = new Error()
                    {
                        CodeDescription = responseMessage.StatusCode.ToString(),
                        Message         = error
                    };
                }

                throw exception;
            }
        }
Пример #2
0
 internal static void AppendServiceResponseExceptionDetail(ServiceResponseException srex, StringBuilder details)
 {
     if (srex != null)
     {
         AppendServiceResponse(srex.Response, details);
     }
 }
Пример #3
0
        public void OnResponse(IResponse response, HttpResponseMessage responseMessage)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                HttpHeaders responseHeaders = responseMessage.Headers;

                IEnumerable <string> globalTransactionId;
                string globalTransactionIdString = "";
                if (responseHeaders.TryGetValues("x-global-transaction-id", out globalTransactionId))
                {
                    globalTransactionIdString = string.Join(", ", globalTransactionId);
                }

                ServiceResponseException exception =
                    new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase} | x-global-transaction-id: {globalTransactionIdString} | error: {responseMessage.Content.ReadAsStringAsync().Result}");

                var error = responseMessage.Content.ReadAsStringAsync().Result;

                if (responseMessage.Content.Headers?.ContentType?.MediaType == HttpMediaType.APPLICATION_JSON)
                {
                    exception.Error = JsonConvert.DeserializeObject <IBMError>(error);
                }
                else
                {
                    exception.Error = new IBMError()
                    {
                        CodeDescription = responseMessage.StatusCode.ToString(),
                        Message         = error
                    };
                }

                throw exception;
            }
        }
Пример #4
0
        public static DialogResult ShowServiceExceptionMsgBox(ServiceResponseException srex, bool offerRetry, MessageBoxIcon icon)
        {
            StringBuilder message = new StringBuilder();

            AppendServiceResponseExceptionDetail(srex, message);

            // If there were bad properties in the request, display Yes/No options
            // and offer to retry the request.
            if (offerRetry && (srex.Response.ErrorProperties.Count > 0))
            {
                message.AppendLine();
                message.AppendLine("Do you want to retry the request without the offending property?");
                return(MessageBox.Show(
                           message.ToString(),
                           FormatDialogCaption(string.Empty, icon),
                           MessageBoxButtons.YesNo,
                           icon,
                           MessageBoxDefaultButton.Button1));
            }
            else
            {
                return(MessageBox.Show(
                           message.ToString(),
                           FormatDialogCaption(string.Empty, icon),
                           MessageBoxButtons.OK,
                           icon,
                           MessageBoxDefaultButton.Button1));
            }
        }
        private Folder GetOrCreateFolderCore(string folderName, FolderId parentFolder, Func <Folder> creator)
        {
            SearchFilter       filter             = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName);
            FolderView         view               = new FolderView(1);
            FindFoldersResults findFoldersResults = this.InvokeServiceCall <FindFoldersResults>(() => this.Service.FindFolders(parentFolder, filter, view));

            if (findFoldersResults.Folders.Count == 0)
            {
                Folder folder = creator();
                folder.DisplayName = folderName;
                try
                {
                    this.InvokeServiceCall(delegate()
                    {
                        folder.Save(parentFolder);
                    });
                }
                catch (DataSourceOperationException ex)
                {
                    ServiceResponseException ex2 = ex.InnerException as ServiceResponseException;
                    if (ex2 == null || ex2.ErrorCode != 107)
                    {
                        throw;
                    }
                }
                findFoldersResults = this.InvokeServiceCall <FindFoldersResults>(() => this.Service.FindFolders(parentFolder, filter, view));
            }
            return(findFoldersResults.Folders[0]);
        }
 private static void CheckForAccessDenied(IRoom room, ServiceResponseException ex)
 {
     if (ex.ErrorCode == ServiceError.ErrorFolderNotFound || ex.ErrorCode == ServiceError.ErrorNonExistentMailbox || ex.ErrorCode == ServiceError.ErrorAccessDenied)
     {
         __log.DebugFormat("Access denied ({0}) getting appointments for {1}/{2}", ex.ErrorCode, room.RoomAddress, room.Id);
         throw new AccessDeniedException("Folder/mailbox not found or access denied", ex);
     }
 }
Пример #7
0
        public void OnResponse(IResponse response, HttpResponseMessage responseMessage)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                ServiceResponseException exception =
                    new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase}");

                exception.Error = responseMessage.Content.ReadAsAsync <Error>().Result;

                throw exception;
            }
        }
Пример #8
0
        public void OnResponse(IResponse response, HttpResponseMessage responseMessage)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                ServiceResponseException exception =
                    new ServiceResponseException(response, responseMessage, $"The API query failed with status code {responseMessage.StatusCode}: {responseMessage.ReasonPhrase}");

                var jsonError = responseMessage.Content.ReadAsStringAsync().Result;

                exception.Error = JsonConvert.DeserializeObject <Error>(jsonError);

                throw exception;
            }
        }
Пример #9
0
        public void UpdateResults(IEnumerable <FanoutParameters> parameters, SearchMailboxesInputs input, SearchMailboxesResponse response, Exception exception)
        {
            Recorder.Trace(4L, TraceType.InfoTrace, new object[]
            {
                "SearchMailboxesResults.UpdateResults Parameters:",
                parameters,
                "Input:",
                input,
                "Response:",
                response,
                "Exception:",
                exception
            });
            this.AddSources(from t in parameters
                            select t.Source);
            using (WebServiceMailboxSearchGroup webServiceMailboxSearchGroup = new WebServiceMailboxSearchGroup(parameters.First <FanoutParameters>().GroupId, new WebServiceMailboxSearchGroup.FindMailboxInfoHandler(this.FindMailboxInfo), input.Criteria, input.PagingInfo, input.CallerInfo))
            {
                if (exception == null && (response.SearchResult == null || response.Result == 2))
                {
                    exception = new ServiceResponseException(response);
                }
                if (exception != null)
                {
                    using (IEnumerator <SearchSource> enumerator = this.Sources.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            SearchSource searchSource = enumerator.Current;
                            if (searchSource.MailboxInfo != null)
                            {
                                webServiceMailboxSearchGroup.MergeMailboxResult(searchSource.MailboxInfo, exception);
                            }
                        }
                        goto IL_10D;
                    }
                }
                if (response.SearchResult != null)
                {
                    webServiceMailboxSearchGroup.MergeSearchResults(response.SearchResult);
                }
IL_10D:
                this.SearchResult = webServiceMailboxSearchGroup.GetResultAggregator();
            }
        }