当前位置: 首页>>代码示例>>C#>>正文


C# JsonSerializer.Any方法代码示例

本文整理汇总了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;
        }
开发者ID:JanKinable,项目名称:LeanKit.IntegrationService,代码行数:55,代码来源:JiraConnection.cs

示例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();
		}
开发者ID:JanKinable,项目名称:LeanKit.IntegrationService,代码行数:62,代码来源:JiraConnection.cs


注:本文中的JsonSerializer.Any方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。