コード例 #1
0
ファイル: RestCallback.cs プロジェクト: woweh/issue-tracker
        public static bool Check(IRestResponse response)
        {
            try
            {
                if (null == response)
                {
                    string error = "Please check your connection.";
                    MessageBox.Show(error, "Unknown error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }



                if (response.StatusCode != System.Net.HttpStatusCode.OK &&
                    response.StatusCode != System.Net.HttpStatusCode.Created &&
                    response.StatusCode != System.Net.HttpStatusCode.NoContent &&
                    response != null)
                {
                    object ve;
                    if (Arup.RestSharp.SimpleJson.TryDeserializeObject(response.Content, out ve))
                    {
                        ErrorMsg validationErrorResponse = Arup.RestSharp.SimpleJson.DeserializeObject <ErrorMsg>(response.Content);
                        string   error = "";
                        if (validationErrorResponse.errorMessages.Any())
                        {
                            foreach (var str in validationErrorResponse.errorMessages)
                            {
                                error += str + "\n";
                            }
                        }
                        error += (null != validationErrorResponse.errors && validationErrorResponse.errors.ToString().Replace(" ", "") != "{}") ? validationErrorResponse.errors.ToString() : "";

                        if (error.Contains("customfield"))  // when there's no custom field on Jira
                        {
                            MessageBox.Show("The custom GUID field required by Arup Issue Tracker is missing. For a Next-gen Project on Jira Cloud, please make sure you have a Text Field called GUID for all Issue Types. For a Classic Project, please ask your Jira administrators to check that the GUID field is part of the field configuration and visible on the Create/Edit screens for all issue types in this project.",
                                            response.StatusDescription, MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        else if (error.Contains("Comment body can not be empty"))
                        {
                            // ignore this error because Solibri generates blank BCF comments
                        }
                        else  // other unsuccessful reponses
                        {
                            MessageBox.Show(error, response.StatusDescription, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        string error = response.StatusDescription;
                        if (string.IsNullOrWhiteSpace(error))
                        {
                            error = "Please check your connection.";
                        }
                        MessageBox.Show(error, string.Format("{0}: {1}", response.StatusCode, response.StatusDescription), MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    return(false);
                }
            }
            catch (Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }

            return(true);
        }