2016-04-15 63 views
0

我正在使用下面的代碼來獲取所有GitHub Enterprise用戶的列表,然後我試圖暫停AD中的這些用戶。 Suspend函數可以工作,但User.Suspended屬性總是返回false。User.Suspended總是在octokit.net中返回false

var searhRequest = new SearchUsersRequest("type:user&page="+pageNumber+"&page_size=100"); 
       githubUsers = await client.Search.SearchUsers(searhRequest); 

client.User.Administration.Suspend(userId); 

回答

0

是的,我認爲這個問題是,我們試圖將返回值轉換爲一個用戶時,最終,這是做幕後的調用不返回數據。作爲一種解決方法,我剛剛調用了get用戶方法,以便在我收集原始結果後獲取用戶。

大概可以做的更好,但這裏是我現在所擁有的

Task<SearchUsersResult> task; 
List<User> users = new List<User>(); 
int page = 1; 

do 
{ 
    task = github.Search.SearchUsers(new SearchUsersRequest("type:user&repos:>=0") { Page = page, PerPage = 500 }); 
    task.Wait(); 

    users.AddRange(task.Result.Items.ToList<User>()); 
    page++; 
} 
while (users.Count < task.Result.TotalCount); 

// Get all users by login (this calls the api once for every user you have) 
var tasks = users.Select(u => github.User.Get(u.Login)); 

// Get all unsuspended users 
var activeUsers = Task.WhenAll<User>(tasks).Result.Where<User>(u => !u.Suspended).ToList(); 

注意,在電話中不包括「isSuspended」數據的結果(從我的本地企業例如使用拉小提琴手,然後消毒)

{"login":"User1" 
"id":45 
"avatar_url":"http://github.com/avatars/u/45?" 
"gravatar_id":"" 
"url":"http://github.com/api/v3/users/User1" 
"html_url":"http://github.com/User1" 
"followers_url":"http://github.com/api/v3/users/User1/followers" 
"following_url":"http://github.com/api/v3/users/User1/following{/other_user}" 
"gists_url":"http://github.com/api/v3/users/User1/gists{/gist_id}" 
"starred_url":"http://github.com/api/v3/users/User1/starred{/owner}{/repo}" 
"subscriptions_url":"http://github.com/api/v3/users/User1/subscriptions" 
"organizations_url":"http://github.com/api/v3/users/User1/orgs" 
"repos_url":"http://github.com/api/v3/users/User1/repos" 
"events_url":"http://github.com/api/v3/users/User1/events{/privacy}" 
"received_events_url":"http://github.com/api/v3/users/User1/received_events" 
"type":"User" 
"site_admin":false 
"ldap_dn":"CN=User1 
OU=CompanyDEVUsers 
OU=Users 
OU=Company 
DC=Company 
DC=com" 
"score":1.0}