-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (51 loc) · 1.97 KB
/
Program.cs
File metadata and controls
57 lines (51 loc) · 1.97 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.DirectoryServices;
using System.Threading;
namespace ldapload
{
class Program
{
static string ldapurl = ConfigurationManager.AppSettings["ldapurl"];
static string login = ConfigurationManager.AppSettings["login"];
static string kode = ConfigurationManager.AppSettings["kode"];
static int antalrequests = int.Parse(ConfigurationManager.AppSettings["antalrequests"]);
static double antalsekunder = double.Parse(ConfigurationManager.AppSettings["antalsekunder"]);
static void Main(string[] args)
{
Console.WriteLine("version {0}", typeof(Program).Assembly.GetName().Version);
for(var counter = 0;counter<antalrequests;counter++) {
testQuery(counter + 1);
if (counter < antalrequests - 1)
{
Thread.Sleep(Convert.ToInt32(antalsekunder * 1000 / antalrequests));
}
}
}
static void testQuery(int counter)
{
try
{
using (var de = new DirectoryEntry(ldapurl, login, kode, AuthenticationTypes.Secure))
using (var deSearch = new DirectorySearcher(de, string.Format("(&(objectClass=user) (cn={0}))", login)))
{
deSearch.FindOne();
//hvis man er nået hertil uden exception er login gået godt.
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Ok. ({0})", counter);
Console.ResetColor();
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
Console.ResetColor();
}
}
}
}