本文整理汇总了C#中JsonSerializer.Any方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.Any方法的具体用法?C# JsonSerializer.Any怎么用?C# JsonSerializer.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.Any方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjects
public List<Project> GetProjects()
{
var issueTypes = new List<Type>();
var projects = new List<Project>();
try
{
"Getting a list of issue types from JIRA".Debug();
//https://yoursite.atlassian.net/rest/api/2/issuetype
var issueTypeRequest = new RestRequest("/rest/api/2/issuetype", Method.GET);
var issueTypeResponse = _restClient.Execute(issueTypeRequest);
if (issueTypeResponse.StatusCode == HttpStatusCode.OK)
{
"JIRA issue types retrieved. Deserializing results.".Debug();
var jiraIssueTypes =
new JsonSerializer<List<IssueType>>().DeserializeFromString(issueTypeResponse.Content);
if (jiraIssueTypes != null && jiraIssueTypes.Any())
{
issueTypes.AddRange(jiraIssueTypes.Select(jiraIssueType => new Type(jiraIssueType.Name)));
}
}
"Getting projects from JIRA".Debug();
//https://yoursite.atlassian.net/rest/api/2/project
var request = new RestRequest("/rest/api/2/project", Method.GET);
var jiraResp = _restClient.Execute(request);
if (jiraResp.StatusCode != HttpStatusCode.OK)
{
string.Format("Failed to get projects from JIRA. {0}: {1}", jiraResp.StatusCode, jiraResp.ErrorMessage ?? string.Empty).Warn();
//var serializer = new JsonSerializer<ErrorMessage>();
//var errorMessage = serializer.DeserializeFromString(jiraResp.Content);
return projects;
}
"JIRA projects retrieved. Deserializing results.".Debug();
var resp = new JsonSerializer<List<JiraProject>>().DeserializeFromString(jiraResp.Content);
if (resp != null && resp.Any())
{
projects.AddRange(
resp.Select(
jiraProject =>
new Project(jiraProject.Key, jiraProject.Name, issueTypes,
GetProjectStates(jiraProject.Key))));
}
}
catch (Exception ex)
{
"Error getting JIRA projects.".Error(ex);
}
return projects;
}
示例2: GetProjectStates
private List<State> GetProjectStates(string projectKey)
{
"Getting JIRA project states.".Debug();
var states = new SortedList<string, State>();
try
{
//https://yoursite.atlassian.net/rest/api/2/project/{key}/statuses
var request = new RestRequest(string.Format("/rest/api/2/project/{0}/statuses", projectKey), Method.GET);
var response = _restClient.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{
"Retrieved project states, deserializing.".Debug();
var jiraIssueTypes = new JsonSerializer<List<IssueType>>().DeserializeFromString(response.Content);
if (jiraIssueTypes != null && jiraIssueTypes.Any())
{
foreach (var jiraIssueType in jiraIssueTypes)
{
if (jiraIssueType.Statuses != null && jiraIssueType.Statuses.Any())
{
foreach (var jiraState in jiraIssueType.Statuses)
{
if (!states.ContainsKey(jiraState.Name))
states.Add(jiraState.Name, new State(jiraState.Name));
}
}
}
}
}
else
{
"First attempt to retrieve states failed. Retrying with JIRA 5.x API.".Debug();
// JIRA 5.x has one list of statuses for all projects
// http://example.com:8080/jira/rest/api/2/status
request = new RestRequest("/rest/api/2/status", Method.GET);
response = _restClient.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{
"Retrieved project states, deserializing.".Debug();
var jiraStates = new JsonSerializer<List<Status>>().DeserializeFromString(response.Content);
if (jiraStates != null && jiraStates.Any())
{
foreach (var jiraStatus in jiraStates)
{
if (!states.ContainsKey(jiraStatus.Name))
states.Add(jiraStatus.Name, new State(jiraStatus.Name));
}
}
}
}
}
catch (Exception ex)
{
"Error getting JIRA project states.".Error(ex);
}
return states.Values.ToList();
}