public void getAllProxyAddresses()
{
var db = new UMTDataContext();
PrincipalContext AD = new PrincipalContext(ContextType.Domain, this.MailDomain);
UserPrincipal u = new UserPrincipal(AD);
PrincipalSearcher search = new PrincipalSearcher(u);
List<string> emailAddresses = new List<string>();
Console.WriteLine("Huidige collectie aan het verwijderen.");
db.ExecuteCommand("truncate table ProxyAddress");
db.SubmitChanges();
Console.WriteLine("Alle proxy addressen aan het verzamelen.. dit duurt wel even.");
foreach (UserPrincipal result in search.FindAll())
{
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "headquarters");
UserPrincipal user = UserPrincipal.FindByIdentity(domainContext, result.SamAccountName);
// Add the "mail" entry
emailAddresses.Add(user.EmailAddress);
// Add the "proxyaddresses" entries.
System.DirectoryServices.PropertyCollection properties = ((DirectoryEntry)user.GetUnderlyingObject()).Properties;
foreach (object property in properties["proxyaddresses"])
{
emailAddresses.Add(property.ToString());
}
}
Console.WriteLine("Alle proxy addressen zijn verzameld. Nu in de database inserten.");
search.Dispose();
foreach (var e in emailAddresses)
{
var mail = new ProxyAddress();
mail.Mail = e;
db.ProxyAddresses.InsertOnSubmit(mail);
}
db.SubmitChanges();
Console.WriteLine("{0} proxyadressen toegevoegd", db.ProxyAddresses.Count());
Console.WriteLine("Klaar met deze bevalling.");
}