コード例 #1
0
        public async Task <CMSAccountListModel> GetAccounts(CMSAuthCredentialModel authCredential)
        {
            CMSAccountListModel result = new CMSAccountListModel();
            var response = await _httpProxyService.GetAsync($"/_apis/accounts", authCredential);

            if (!response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation)
            {
                if (response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation)
                {
                    result.Fail($"Code: {response.StatusCode}, Reason: The credentials are not correct");
                    return(result);
                }

                result.Fail($"Code: {response.StatusCode}, Reason: {await response.Content.ReadAsStringAsync()}");
                return(result);
            }

            var accountResult = await response.MapTo <List <CMSVSTSAccountListItemModel> >();

            result.Items = accountResult.Select(x => new CMSAccountListItemModel()
            {
                AccountId = x.AccountId,
                Name      = x.AccountName
            }).ToList();

            return(result);
        }
コード例 #2
0
        private async Task <CMSAccountListModel> GetAccounts(CMSAuthCredentialModel authCredential)
        {
            var list = new CMSAccountListModel()
            {
                Items = new List <CMSAccountListItemModel>()
            };
            var response = await _httpProxyService.GetAsync($"/user", authCredential, Headers);

            var user = await response.MapTo <CMSGitHubUserModel>();

            list.Items.Add(new CMSAccountListItemModel
            {
                AccountId      = user.AccountId,
                Name           = user.UserName,
                Description    = user.UserName,
                IsOrganization = false,
            });

            response = await _httpProxyService.GetAsync($"/user/orgs", authCredential, Headers);

            var teamResult = await response.MapTo <List <CMSGitHubTeamModel> >();

            list.Items.AddRange(teamResult.Select(c => new CMSAccountListItemModel
            {
                AccountId      = c.TeamId,
                Description    = c.DisplayName,
                Name           = c.DisplayName,
                IsOrganization = true
            }));

            return(list);
        }
        public async Task <CMSAccountListModel> GetAccounts(CMSAuthCredentialModel authCredential)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authCredential.AccessToken);
            client.BaseAddress = new Uri(authCredential.Url);

            var response = await client.GetAsync($"/{API_VERSION}/teams?role=admin");

            var teamResult = await response.MapTo <CMSBitBucketTeamListModel>();

            CMSAccountListModel list = new CMSAccountListModel();

            list.Items = teamResult.Teams.Select(c => new CMSAccountListItemModel
            {
                AccountId   = c.TeamId,
                Description = c.DisplayName,
                Name        = c.UserName
            }).ToList();

            return(list);
        }