Update Version 2.3
This commit is contained in:
164
BeAUserSync/Program.cs
Normal file
164
BeAUserSync/Program.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security;
|
||||
using Microsoft.VisualBasic;
|
||||
using System.DirectoryServices;
|
||||
using BeAUserSync.AD;
|
||||
using System.DirectoryServices.Protocols;
|
||||
using System.Data;
|
||||
|
||||
|
||||
// Parameter
|
||||
// ADTest - Test von AD-Zugriffen
|
||||
// NoAD - Update E-Mail-Adresse mit TGNummer+@tkb.ch
|
||||
// Normal - Update - E-Mail-Adresse über AD
|
||||
|
||||
namespace BeAUserSync
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private const string CONFIG_ITEM_DIRECTORY = @"ConfigurationItems\";
|
||||
private const string AD_CONFIGURATION_ITEM_NAME = "ActiveDirectory";
|
||||
private static db database = new db();
|
||||
private static db adlog = new db();
|
||||
static string dataselect = "";
|
||||
|
||||
string s = "";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
dataselect = Properties.Settings.Default.Dataselect;
|
||||
if (dataselect != "")
|
||||
{
|
||||
dataselect = "Select top " + dataselect + " Personalnr, TGNummer, EMail from personal where aktiv=1 and isnull(tgnummer,'')<>''";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dataselect = "Select Personalnr, TGNummer, EMail from personal where aktiv = 1 and isnull(tgnummer,'')<>''";
|
||||
}
|
||||
Console.WriteLine(dataselect);
|
||||
|
||||
string arg = "";
|
||||
if (args.Length != 0)
|
||||
{
|
||||
arg = args[0];
|
||||
if (arg != "ADTest" && arg != "NoAD" && arg != "Normal")
|
||||
{
|
||||
Console.WriteLine("Fehlerhafte Argumente - möglich sind:");
|
||||
Console.WriteLine("ADTest - Kommandozeilen-Test für AD-Zugriffe");
|
||||
Console.WriteLine("NoAD - DB-Update ohne AD - Email aus TGNummer und @tkb.ch");
|
||||
Console.WriteLine("Normal - E-Mail-Bezug aus AD");
|
||||
string res = "";
|
||||
res = Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
switch (arg)
|
||||
{
|
||||
case "ADTest":
|
||||
|
||||
SHUAD sad = new SHUAD();
|
||||
if (sad.Connect_to_Server() == true)
|
||||
{
|
||||
Console.WriteLine("Connection OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connection NOK");
|
||||
Console.WriteLine(sad.ErrorMessage);
|
||||
|
||||
}
|
||||
string user = "";
|
||||
Console.WriteLine("UserID:");
|
||||
user = Console.ReadLine();
|
||||
while (user != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine(sad.get_mail_from_user(user));
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("UserID:");
|
||||
user = Console.ReadLine();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
user = "";
|
||||
user = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "NoAD":
|
||||
adlog.Get_Tabeldata_for_Update("Select * from adlog where id=-1");
|
||||
Log_Insert("Start Abgleich");
|
||||
|
||||
database.Get_Tabeldata_for_Update(dataselect);
|
||||
foreach (DataRow dr in database.dsdaten.Tables[0].Rows)
|
||||
{
|
||||
string email = "";
|
||||
email = dr["tgnummer"].ToString() + "@tkb.ch";
|
||||
if (email != "" && email != dr["email"].ToString())
|
||||
{
|
||||
dr["email"] = email;
|
||||
Log_Insert(dr["tgnummer"].ToString() + " - " + email);
|
||||
}
|
||||
}
|
||||
database.Update_Tabeldata();
|
||||
Log_Insert("Ende Abgleich");
|
||||
adlog.Update_Tabeldata();
|
||||
break;
|
||||
default:
|
||||
SHUAD ad = new SHUAD();
|
||||
if (ad.Connect_to_Server() != true)
|
||||
{
|
||||
Console.WriteLine("Connection NOK");
|
||||
return;
|
||||
}
|
||||
adlog.Get_Tabeldata_for_Update("Select * from adlog where id=-1");
|
||||
Log_Insert("Start Abgleich");
|
||||
|
||||
database.Get_Tabeldata_for_Update(dataselect);
|
||||
foreach (DataRow dr in database.dsdaten.Tables[0].Rows)
|
||||
{
|
||||
string email = "";
|
||||
Console.WriteLine(dr["tgnummer"]);
|
||||
email = ad.get_mail_from_user(dr["tgnummer"].ToString());
|
||||
if (email != "" && email != dr["email"].ToString())
|
||||
{
|
||||
dr["email"] = email;
|
||||
Log_Insert(dr["tgnummer"].ToString() + " - " + email);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (email == "")
|
||||
{
|
||||
Log_Insert(dr["tgnummer"].ToString() + " - kein AD-Eintrag");
|
||||
}
|
||||
}
|
||||
}
|
||||
database.Update_Tabeldata();
|
||||
Log_Insert("Ende Abgleich");
|
||||
adlog.Update_Tabeldata();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void Log_Insert(string logentry)
|
||||
{
|
||||
DataRow dr = adlog.dsdaten.Tables[0].NewRow();
|
||||
dr["Eintrag"] = logentry;
|
||||
dr["Zeit"] = DateTime.Now;
|
||||
adlog.dsdaten.Tables[0].Rows.Add(dr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user