示例#1
0
        public async Task <IEnumerable <Project> > GetProjectsAsync()
        {
            var taskResponse = await Task.Factory.StartNew(() =>
            {
                var request = new RestRequest("projects/read", Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };
                ProjectResponse response;
                _connection.TryRequest(request, out response);

                if (!response.Success)
                {
                    throw new Exception($"Failed to get projects from API: {string.Join(Environment.NewLine, response.Errors.ToArray())}");
                }

                return(response.Projects.AsEnumerable());
            });

            return(taskResponse);
        }