This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ADWorker.cs
62 lines (53 loc) · 1.78 KB
/
ADWorker.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Hyperfish.ImportExport.AD;
using static Hyperfish.ImportExport.Log;
namespace Hyperfish.ImportExport
{
class AdWorker
{
private readonly ActiveDirectoryClient _ad;
public AdWorker(AdSettings adSettings)
{
_ad = new ActiveDirectoryClient(adSettings);
}
public void ImportPicsToAd(Dictionary<string, ImportExportRecord> peopleToImport)
{
foreach (var upn in peopleToImport.Keys)
{
var upnIdentifier = new UpnIdentifier(upn);
var picture = peopleToImport[upn].PhotoLocation;
if (string.IsNullOrEmpty(picture))
{
// skip
Logger.Info($"Skipping photo import for {upn}, as photo location was invalid");
continue;
}
Stream photoStream;
Logger.Info($"Importing photo for {upn}, {picture}");
try
{
photoStream = File.OpenRead(picture);
}
catch (Exception e)
{
Logger.Error($"Couldn't read photo from disk: {picture}, Message: {e.Message}. Skipping");
continue;
}
try
{
_ad.UpdateAttribute(upnIdentifier, ActiveDirectoryClient.AdPhotoAttribute, photoStream);
}
catch (Exception e)
{
Logger.Error($"Problem updating AD for {upn}: {e.Message}. Skipping");
}
}
}
}
}