-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (60 loc) · 2.24 KB
/
Program.cs
File metadata and controls
69 lines (60 loc) · 2.24 KB
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
using System;
using Microsoft.Graph;
using Microsoft.Identity.Client;
using Microsoft.Graph.Auth;
using CommandLine;
using System.Linq;
namespace updatealluserphoto
{
class Program
{
public class Options
{
[Option('i', "applicationId")]
public string ApplicationId { get; set; }
[Option('s', "clientSecret")]
public string ClientSecret { get; set; }
[Option('t', "tenantId")]
public string TenantId { get; set; }
[Option('d', "directory")]
public string Directory { get; set; }
}
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args).WithParsed(o =>
{
var appId = o.ApplicationId;
var secret = o.ClientSecret;
var tenantId = o.TenantId;
var directory = o.Directory;
if (!System.IO.Directory.Exists(directory))
{
Console.WriteLine("Directory is not exist, please check and try again");
return;
}
var app = ConfidentialClientApplicationBuilder.Create(appId)
.WithClientSecret(secret)
.WithTenantId(tenantId)
.Build();
var authProvider = new ClientCredentialProvider(app);
var client = new GraphServiceClient(authProvider);
var files = new System.IO.DirectoryInfo(directory).GetFiles("*.jpg").Where(x => x.Length <= 4 * 1024 *1024);
foreach (var file in files)
{
var user = System.IO.Path.GetFileNameWithoutExtension(file.Name);
using (var stream = System.IO.File.OpenRead(file.FullName))
{
client.Users[user].Photo.Content.Request().PutAsync(stream).Wait();
stream.Close();
}
Console.WriteLine("Done - {0}", user);
}
})
.WithNotParsed(Error =>
{
Console.WriteLine("Please check the args...");
});
Console.ReadKey();
}
}
}