public static Check ( IRestResponse response ) : bool | ||
response | IRestResponse | |
리턴 | bool |
/// <summary> /// Get the list of possible Status Transitions for an Issue /// </summary> /// <param name="IssueKey">Jira Key of the Issue</param> /// <returns></returns> public static List <Transition> GeTransitions(string IssueKey) { var request = new RestRequest("issue/" + IssueKey + "/transitions", Method.GET); request.AddHeader("Content-Type", "application/json"); request.RequestFormat = Arup.RestSharp.DataFormat.Json; var response2 = JiraClient.Client.Execute <IssueTransitions>(request); if (RestCallback.Check(response2) && response2.Data.transitions.Any()) { return(response2.Data.transitions); } return(null); }
void worker_DoWork <T>(object sender, DoWorkEventArgs e) where T : new() { try { var client = JiraClient.Client; if (!usebaseurl) { client = new RestClient(); client.CookieContainer = JiraClient.Client.CookieContainer; string usernameS = MySettings.Get("username"); string passwordS = DataProtector.DecryptData(MySettings.Get("password")); client.Authenticator = new HttpBasicAuthenticator(usernameS, passwordS); } BackgroundWorker worker = (BackgroundWorker)sender; if (requests.Count > 1) { for (var i = 0; i < requests.Count; i++) { worker.ReportProgress((100 * i + 1) / requests.Count(), getProgressString(i + 1)); // HAS TO BE OUT OF THE DISPATCHER! var response = client.Execute <T>(requests[i]); responses.Add(response); if (!RestCallback.Check(response)) { break; } if (i == requests.Count() - 1) { worker.ReportProgress(100, getProgressString(i + 1)); } } } else { var response = client.Execute <T>(requests[0]); responses.Add(response); RestCallback.Check(response); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }
void worker_DoWork <T>(object sender, DoWorkEventArgs e) where T : new() { try { var client = JiraClient.Client; if (!usebaseurl) { client = new RestClient(); client.CookieContainer = JiraClient.Client.CookieContainer; } BackgroundWorker worker = (BackgroundWorker)sender; if (requests.Count > 1) { for (var i = 0; i < requests.Count; i++) { worker.ReportProgress((100 * i + 1) / requests.Count(), getProgressString(i + 1)); // HAS TO BE OUT OF THE DISPATCHER! var response = client.Execute <T>(requests[i]); responses.Add(response); if (!RestCallback.Check(response)) { break; } if (i == requests.Count() - 1) { worker.ReportProgress(100, getProgressString(i + 1)); } } } else { var response = client.Execute <T>(requests[0]); responses.Add(response); RestCallback.Check(response); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }
/// <summary> /// Check if the presented assignee is valid in a project. /// </summary> /// <param name="assigneeName">The (Arup/Jira) account name of the assignee</param> /// <returns></returns> private bool isAssigneeAssignable(string assigneeName, string projectKey) { try { List <User> userlist = new List <User>(); var maxresults = 1000; for (var i = 0; i < 100; i++) { var apicall = "user/assignable/search?project=" + projectKey + "&maxResults=" + maxresults + "&startAt=" + (i * maxresults); var request = new RestRequest(apicall, Method.GET); request.AddHeader("Content-Type", "application/json"); request.RequestFormat = Arup.RestSharp.DataFormat.Json; request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; var response = JiraClient.Client.Execute <List <User> >(request); if (!RestCallback.Check(response) || !response.Data.Any()) { break; } userlist.AddRange(response.Data); if (response.Data.Count < maxresults) { break; } } foreach (User user in userlist) { if (user.name == assigneeName) { return(true); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(false); }
void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; XmlSerializer serializerV = new XmlSerializer(typeof(VisualizationInfo)); for (int i = 0; i < issues.Count(); i++) { try { IssueBCF issue = issues[i]; worker.ReportProgress((100 * i + 1) / issues.Count(), getProgressString(i + 1));// HAS TO BE OUT OF THE DISPATCHER! // check status on each step if (worker.CancellationPending == true) { e.Cancel = true; return; // abort work, if it's cancelled } //CHECK IF ALREADY EXISTING // could use the expression: cf[11600] ~ "aaaa" // = operator not supported string fields = " AND GUID~" + issue.guid.ToString() + "&fields=key,comment"; string query = "search?jql=project=" + projectKey + fields; var request4 = new RestRequest(query, Method.GET); request4.AddHeader("Content-Type", "application/json"); request4.RequestFormat = RestSharp.DataFormat.Json; var response4 = JiraClient.Client.Execute <Issues>(request4); if (!RestCallback.Check(response4)) { break; } //DOESN'T exist already if (!response4.Data.issues.Any()) { string snapshot = Path.Combine(path, issue.guid.ToString(), "snapshot.png"); string viewpoint = Path.Combine(path, issue.guid.ToString(), "viewpoint.bcfv"); string key = ""; //update view - it might be a new issue // Serialize the object, and close the TextWriter Stream writerV = new FileStream(viewpoint, FileMode.Create); serializerV.Serialize(writerV, issue.viewpoint); writerV.Close(); var request = new RestRequest("issue", Method.POST); request.AddHeader("Content-Type", "application/json"); request.RequestFormat = RestSharp.DataFormat.Json; var newissue = new { fields = new Dictionary <string, object>() }; newissue.fields.Add("project", new { key = projectKey }); newissue.fields.Add("summary", (string.IsNullOrWhiteSpace(issue.markup.Topic.Title)) ? "no title" : issue.markup.Topic.Title); newissue.fields.Add("issuetype", new { id = issuesJira[i].fields.issuetype.id }); newissue.fields.Add(MySettings.Get("guidfield"), issue.guid.ToString()); if (issuesJira[i].fields.assignee != null) { newissue.fields.Add("assignee", new { name = issuesJira[i].fields.assignee.name }); } if (issuesJira[i].fields.priority != null) { newissue.fields.Add("priority", new { id = issuesJira[i].fields.priority.id }); } if (issuesJira[i].fields.components != null && issuesJira[i].fields.components.Any()) { newissue.fields.Add("components", issuesJira[i].fields.components); } request.AddBody(newissue); var response = JiraClient.Client.Execute(request); var responseIssue = new Issue(); if (RestCallback.Check(response)) { responseIssue = RestSharp.SimpleJson.DeserializeObject <Issue>(response.Content); key = responseIssue.key;//attach and comment sent to the new issue } else { uploadErrors++; break; } //upload viewpoint and snapshot var request2 = new RestRequest("issue/" + key + "/attachments", Method.POST); request2.AddHeader("X-Atlassian-Token", "nocheck"); request2.RequestFormat = RestSharp.DataFormat.Json; request2.AddFile("file", File.ReadAllBytes(snapshot), "snapshot.png"); request2.AddFile("file", File.ReadAllBytes(viewpoint), "viewpoint.bcfv"); var response2 = JiraClient.Client.Execute(request2); RestCallback.Check(response2); //ADD COMMENTS if (issue.markup.Comment.Any()) { issue.markup.Comment = new System.Collections.ObjectModel.ObservableCollection <CommentBCF>(issue.markup.Comment.Reverse()); foreach (var c in issue.markup.Comment) { var request3 = new RestRequest("issue/" + key + "/comment", Method.POST); request3.AddHeader("Content-Type", "application/json"); request3.RequestFormat = RestSharp.DataFormat.Json; var newcomment = new { body = c.Comment1 }; request3.AddBody(newcomment); var response3 = JiraClient.Client.Execute <Comment2>(request3); if (!RestCallback.Check(response3)) { break; } } } if (i == issues.Count() - 1) { worker.ReportProgress(100, getProgressString(i + 1)); } } else //UPDATE ISSUE { var oldIssue = response4.Data.issues.First(); if (issue.markup.Comment.Any()) { issue.markup.Comment = new System.Collections.ObjectModel.ObservableCollection <CommentBCF>(issue.markup.Comment.Reverse()); foreach (var c in issue.markup.Comment) { string normalized1 = Regex.Replace(c.Comment1, @"\s", ""); if (oldIssue.fields.comment.comments.Any(o => Regex.Replace(o.body, @"\s", "").Equals(normalized1, StringComparison.OrdinalIgnoreCase))) { continue; } var request3 = new RestRequest("issue/" + oldIssue.key + "/comment", Method.POST); request3.AddHeader("Content-Type", "application/json"); request3.RequestFormat = RestSharp.DataFormat.Json; var newcomment = new { body = c.Comment1 }; request3.AddBody(newcomment); var response3 = JiraClient.Client.Execute <Comment2>(request3); if (!RestCallback.Check(response3)) { break; } } } } } // END TRY catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }// END LOOP }
void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; XmlSerializer serializerV = new XmlSerializer(typeof(VisualizationInfo)); int newIssueCounter = 0; int updateIssueCounter = 0; int unchangedIssueCounter = 0; for (int i = 0; i < issues.Count(); i++) { try { Markup issue = issues[i]; worker.ReportProgress((100 * i + 1) / issues.Count(), getProgressString(i + 1));// HAS TO BE OUT OF THE DISPATCHER! // check status on each step if (worker.CancellationPending == true) { e.Cancel = true; return; // abort work, if it's cancelled } //CHECK IF ALREADY EXISTING // could use the expression: cf[11600] ~ "aaaa" // = operator not supported string fields = " AND GUID~" + issue.Topic.Guid + "&fields=key,comment"; string query = "search?jql=project=\"" + projectKey + "\"" + fields; var request4 = new RestRequest(query, Method.GET); request4.AddHeader("Content-Type", "application/json"); request4.RequestFormat = Arup.RestSharp.DataFormat.Json; var response4 = JiraClient.Client.Execute <Issues>(request4); if (!RestCallback.Check(response4)) { break; } //DOESN'T exist already if (!response4.Data.issues.Any()) { //files to be uploaded List <string> filesToBeUploaded = new List <string>(); if (File.Exists(Path.Combine(path, issue.Topic.Guid, "markup.bcf"))) { filesToBeUploaded.Add(Path.Combine(path, issue.Topic.Guid, "markup.bcf")); } issue.Viewpoints.ToList().ForEach(vp => { if (!string.IsNullOrWhiteSpace(vp.Snapshot) && File.Exists(Path.Combine(path, issue.Topic.Guid, vp.Snapshot))) { filesToBeUploaded.Add(Path.Combine(path, issue.Topic.Guid, vp.Snapshot)); } if (!string.IsNullOrWhiteSpace(vp.Viewpoint) && File.Exists(Path.Combine(path, issue.Topic.Guid, vp.Viewpoint))) { filesToBeUploaded.Add(Path.Combine(path, issue.Topic.Guid, vp.Viewpoint)); } }); string key = ""; //update view - it might be a new issue (for direct Jira upload) // Serialize the object, and close the TextWriter string viewpoint = Path.Combine(path, issue.Topic.Guid, "viewpoint.bcfv"); if (!File.Exists(viewpoint)) { Stream writerV = new FileStream(viewpoint, FileMode.Create); serializerV.Serialize(writerV, issue.Viewpoints[0].VisInfo); writerV.Close(); } if (filesToBeUploaded.Find(file => file == viewpoint) == null) { filesToBeUploaded.Add(viewpoint); } var request = new RestRequest("issue", Method.POST); request.AddHeader("Content-Type", "application/json"); request.RequestFormat = Arup.RestSharp.DataFormat.Json; newIssueCounter++; var newissue = new { fields = new Dictionary <string, object>() }; newissue.fields.Add("project", new { key = projectKey }); if (!string.IsNullOrWhiteSpace(issuesJira[i].fields.description)) { newissue.fields.Add("description", issuesJira[i].fields.description); } newissue.fields.Add("summary", (string.IsNullOrWhiteSpace(issue.Topic.Title)) ? "no title" : issue.Topic.Title); newissue.fields.Add("issuetype", new { id = issuesJira[i].fields.issuetype.id }); newissue.fields.Add(MySettings.Get("guidfield"), issue.Topic.Guid); // validate assignee name if present if (issuesJira[i].fields.assignee != null) { if (!string.IsNullOrWhiteSpace(issuesJira[i].fields.assignee.name)) { if (isAssigneeAssignable(issuesJira[i].fields.assignee.name, projectKey)) { newissue.fields.Add("assignee", new { name = issuesJira[i].fields.assignee.name }); } else { newissue.fields.Add("assignee", new { name = issuesJira[i].fields.creator.name }); } } } if (issuesJira[i].fields.priority != null) { newissue.fields.Add("priority", new { id = issuesJira[i].fields.priority.id }); } if (issuesJira[i].fields.components != null && issuesJira[i].fields.components.Any()) { newissue.fields.Add("components", issuesJira[i].fields.components); } if (issuesJira[i].fields.labels != null && issuesJira[i].fields.labels.Any()) { newissue.fields.Add("labels", issuesJira[i].fields.labels); } request.AddBody(newissue); var response = JiraClient.Client.Execute(request); var responseIssue = new Issue(); if (RestCallback.Check(response)) { responseIssue = Arup.RestSharp.SimpleJson.DeserializeObject <Issue>(response.Content); key = responseIssue.key;//attach and comment sent to the new issue } else { uploadErrors++; break; } //upload all viewpoints and snapshots var request2 = new RestRequest("issue/" + key + "/attachments", Method.POST); request2.AddHeader("X-Atlassian-Token", "nocheck"); request2.RequestFormat = Arup.RestSharp.DataFormat.Json; filesToBeUploaded.ForEach(file => request2.AddFile("file", File.ReadAllBytes(file), Path.GetFileName(file))); var response2 = JiraClient.Client.Execute(request2); RestCallback.Check(response2); //ADD COMMENTS if (issue.Comment.Any()) { issue.Comment = new System.Collections.ObjectModel.ObservableCollection <BCF2.Comment>(issue.Comment.Reverse()); foreach (var c in issue.Comment) { var request3 = new RestRequest("issue/" + key + "/comment", Method.POST); request3.AddHeader("Content-Type", "application/json"); request3.RequestFormat = Arup.RestSharp.DataFormat.Json; var newcomment = new { body = c.Comment1 }; request3.AddBody(newcomment); var response3 = JiraClient.Client.Execute <Comment2>(request3); if (!RestCallback.Check(response3)) { break; } } } if (i == issues.Count() - 1) { worker.ReportProgress(100, getProgressString(i + 1)); } } else //UPDATE ISSUE { var oldIssue = response4.Data.issues.First(); if (issue.Comment.Any()) { issue.Comment = new System.Collections.ObjectModel.ObservableCollection <BCF2.Comment>(issue.Comment.Reverse()); int unmodifiedCommentNumber = 0; foreach (var c in issue.Comment) { //clean all metadata annotations string newComment = cleanAnnotationInComment(c.Comment1); string normalized1 = Regex.Replace(newComment, @"\s", ""); if (oldIssue.fields.comment.comments.Any(o => Regex.Replace(cleanAnnotationInComment(o.body), @"\s", "").Equals(normalized1, StringComparison.OrdinalIgnoreCase))) { unmodifiedCommentNumber++; continue; } var request3 = new RestRequest("issue/" + oldIssue.key + "/comment", Method.POST); request3.AddHeader("Content-Type", "application/json"); request3.RequestFormat = Arup.RestSharp.DataFormat.Json; var newcomment = new { body = c.Comment1 }; request3.AddBody(newcomment); var response3 = JiraClient.Client.Execute <Comment2>(request3); //upload viewpoint and snapshot var request5 = new RestRequest("issue/" + oldIssue.key + "/attachments", Method.POST); request5.AddHeader("X-Atlassian-Token", "nocheck"); request5.RequestFormat = Arup.RestSharp.DataFormat.Json; issue.Viewpoints.ToList().ForEach(vp => { if (c.Viewpoint != null) { if (vp.Guid == c.Viewpoint.Guid) { if (File.Exists(Path.Combine(path, issue.Topic.Guid, vp.Snapshot))) { request5.AddFile("file", File.ReadAllBytes(Path.Combine(path, issue.Topic.Guid, vp.Snapshot)), vp.Snapshot); } if (File.Exists(Path.Combine(path, issue.Topic.Guid, vp.Viewpoint))) { request5.AddFile("file", File.ReadAllBytes(Path.Combine(path, issue.Topic.Guid, vp.Viewpoint)), vp.Viewpoint); } } } }); if (request5.Files.Count > 0) { var response5 = JiraClient.Client.Execute(request5); RestCallback.Check(response5); } if (!RestCallback.Check(response3)) { break; } } if (unmodifiedCommentNumber == issue.Comment.Count) { unchangedIssueCounter++; } else { updateIssueCounter++; } } else { unchangedIssueCounter++; } } } // END TRY catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }// END LOOP string msg = string.Format("{0} new issue(s) added, {1} issue(s) updated, and {2} issue(s) unchanged.", newIssueCounter, updateIssueCounter, unchangedIssueCounter); MessageBox.Show(msg, "Success", MessageBoxButton.OK, MessageBoxImage.Information); }