-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserStats.cs
75 lines (63 loc) · 2.72 KB
/
UserStats.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Graph.Models;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Kiota.Abstractions;
namespace appsvc_fnc_dev_userstats
{
class UserStats
{
public async Task<List<usersData>> UserStatsDataAsync(ILogger log)
{
log.LogInformation("UserStatsDataAsync received a request.");
List<usersData> userList = new List<usersData>();
try {
IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();
var exceptionUsersArray = config["exceptionUsersArray"];
Auth auth = new Auth();
var graphAPIAuth = auth.graphAuth(log);
// Create a bucket to hold the users
List<User> users = new List<User>();
// Get the first page
var usersPage = await graphAPIAuth.Users.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string[] { "id, createdDateTime, mail" };
});
// Add the first page of results to the user list
users.AddRange(usersPage.Value);
// Fetch each page and add those results to the list
while (usersPage.OdataNextLink != null)
{
var nextPageRequestInformation = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = usersPage.OdataNextLink
};
usersPage = await graphAPIAuth.RequestAdapter.SendAsync(nextPageRequestInformation, (parseNode) => new UserCollectionResponse());
users.AddRange(usersPage.Value);
}
foreach (var user in users)
{
if (exceptionUsersArray.Contains(user.Id) == false)
{
userList.Add(new usersData()
{
Id = user.Id,
creationDate = user.CreatedDateTime,
mail = user.Mail
});
}
}
}
catch (System.Exception e) {
log.LogError("!! Exception !!");
log.LogError(e.Message);
log.LogError("!! StackTrace !!");
log.LogError(e.StackTrace);
}
log.LogInformation("UserStatsDataAsync processed a request.");
return userList;
}
}
}