|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Watch www.cute-solutions.de
IntroductionOutlooksignature is a simple Windows Console Application which generates Outlook signatures automatically using Information in the Active Directory. It makes it very easy to generate a huge number of signatures. BackgroundThe basic idea behind this application is to use a general signature in Enterprises. I was searching for some Programms with this function but there are only a few very expensive solutions. Configure the application using the OSG.INI[DatabaseParams] SearchFilterpart1= SearchFilterpart2= SearchFilterpart3= SearchFilterpart4= SearchFilterpart5= SearchFilterpart6= Fields=samaccountname,... [SignatureParams] PathSignaturen= SignaturVorlPath= VorlagenDateien=signatur.txt,signatur.rtf,... The key fields "SearchFilterpart1 to SearchFilterpart6" are for registering the LDAP search filter (e.g. (& (ObjectClass=user) (cn=Maier)) for all users called Maier). The finally used search consists of the 6 Parts. Each individual part should not exceed the length of 160 characters. The key field "Fields" defines which user information from the AD is selected. Here the account name MUST stand always in the first place! The name of the key field in the Active Directory should be the same string which schould be replaces in the template (in the AD cn - in the template * ~cn~ *). In the key field "PathSignaturen" is located the path in that the finished generated signatures are stored (this path must already exist). In the field "SignaturVorlPath" is located the path in that the signature templates are. IMPORTANT: each path must be written instead of with \ with \ \. The key field "VorlagenDateien" contains the file names of the templates (separated through , ). These file names must contain the string "signatur" it is replaced by the accountname. Using the codeThe method searchEntry()The most important part in the application is the method This following part initialises the DirectorySearcher. It also reads the filtersring from the osg.ini. public static void searchEntry()
{
DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry();
//read the search filter (osg.ini)
StringBuilder filter = new StringBuilder();
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart1").ToString());
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart2").ToString());
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart3").ToString());
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart4").ToString());
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart5").ToString());
filter.Append(IniFile.a.IniReadValue("DatabaseParams", "SearchFilterpart6").ToString());
Now the filterstring is given ti the DirectorySearcher. And the //give the search filter to the Directory searcher
ds.Filter = filter.ToString();
ds.PropertyNamesOnly = true;
To know which informatioan the DirectorySearcher must load we must load the attributes from the //read attributes
string[] attributes = getAttribute();
for (int i = 0; i < attributes.Length; i++)
{
//adds the fields which schould be reded out of the AD
ds.PropertiesToLoad.Add(attributes[i]);
}
Now the ReferralChasing attribute is turned off and the result of the Directory Searcher is saved in the SearchResultCollection //referenced servers shouldn't be read
ds.ReferralChasing = ReferralChasingOption.None;
//start to search
SearchResultCollection src = ds.FindAll();
//shows the number of entrys
data.global_count = System.Convert.ToInt32(src.Count);
output.log.WriteLine("Es wurden " + data.global_count + " Einträge gefunden");
Console.WriteLine("Es wurden " + data.global_count + " Einträge gefunden");
We now know how much entrys we have fount and so we can initialise the //initalise the global_data array
data.initData(data.global_attribute.Length, data.global_count + 1);
//writes the Attribute names into the [0] row in the array
for (int i = 0; i < data.global_attribute.Length; i++)
{
data.global_data[i, 0] = data.global_attribute[i];
}
//the counter to write the array
data.global_array_counter = 1;
After all it writes the entrys found in the Active Directory into the //for each entry in the SearchResultCollection
try
{
foreach (SearchResult sr in src)
//writes the LDAP entrys into the array
data.globalDataWrite(sr.GetDirectoryEntry());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
output.log.WriteLine(e.Message);
}
src.Dispose();
ds.Dispose();
}
The method signatur(...)An other important method is signatur(string vorlage, string vorlagePath). This generates the signatures using the Templates. public static void signatur(string vorlage, string vorlagePath) { //looks which extention the current templte has string[] typearr = vorlage.Split('.'); string type = typearr[typearr.Length-1]; Now the SreamReader //Streamreader for opening the template
StreamReader tr = new StreamReader(vorlagePath+"file:///">\\"+vorlage,System.Text.Encoding.UTF7);
//a list in which each row of the template is saved
LinkedList<string> list = new LinkedList<string>();
It reads the template file row by row until zhe EndOfStream is reached and saves the rows inside the //reads the lines of the template
while(!tr.EndOfStream)
{
list.AddLast(tr.ReadLine().ToString());
}
// close the stream
tr.Close();
//temporary list
LinkedList<string> temp;
Defining the destination pathes. String Path = vorlagePath;
String Path1 = vorlage;
This part is done for each entry is the //for each entry in data.global_data
for (int i = 1; i < data.global_array_counter; i++)
{
//the path in which the new signature schould be written and replaces the signatur
//by the accountname
Path1 = vorlage;
Path1 = Path1.Replace("signatur", data.global_data[0, i].ToString());
Path = data.PathSignaturen.ToString() + "\\" + Path1;
//StreamWriter th write the signature file
StreamWriter wr = new StreamWriter(Path);
log.WriteLine(Path1 + " wurde erfolgreich erzeugt");
//the list with the rows of the template is copied into the temp list
temp = new LinkedList<string>(list);
And now for each entry in the LinkedList //do while the temp list is empty
while (temp.Count > 0)
{
//define pivot row
String Zeile = temp.First.Value.ToString();
//searches for the fields in the row
for (int p = 0; p < data.global_attribute.Length; p++)
{
try
{
//if there are any (äöüß) in the text code for html and rtf
if (type == "htm")
{
//for html
Zeile = Zeile.Replace("÷", "ö");
Zeile = Zeile.Replace("õ", "ä");
Zeile = Zeile.Replace("³", "ü");
Zeile = Zeile.Replace("Í", "Ö");
Zeile = Zeile.Replace("-", "Ä");
Zeile = Zeile.Replace("_", "Ü");
Zeile = Zeile.Replace("¯", "ß");
}
else if (type == "rtf")
{
//for rtf
Zeile = Zeile.Replace("÷", "file://%27f6/">\\'f6");
Zeile = Zeile.Replace("õ", "file://%27e4/">\\'e4");
Zeile = Zeile.Replace("³", "file://%27fc/">\\'fc");
Zeile = Zeile.Replace("Í", "file://%27d6/">\\'d6");
Zeile = Zeile.Replace("-", "file://%27c4/">\\'c4");
Zeile = Zeile.Replace("_", "file://%27dc/">\\'dc");
Zeile = Zeile.Replace("¯", "file://%27df/">\\'df");
}
//define the string to replace
string reg = "*~" + data.global_data[p, 0].ToString() + "~*";
if (data.global_data[p, i].ToString() == null)
{
}
else
{
//replace it
Zeile = Zeile.Replace(reg, data.global_data[p, i].ToString());
}
}
catch(Exception w)
{
string reg = "*~" + data.global_data[p, 0].ToString() + "~*";
Zeile = Zeile.Replace(reg, "");
}
}
After replacing write the line into the destination file and remove the first entry in the LinkedList //Zeile in Signaturdatei schreiben
wr.WriteLine(Zeile);
//Status Counter inc
data.global_state_counter++;
//remove firs element of the temp list
temp.RemoveFirst();
Close the StreamWriter }
//show status
data.statusFortschritt(data.global_array_counter, data.global_state_counter);
//close filestream of th e signature file
wr.Close();
}
}
To read the other code please download the Download outlooksig_src.zip A possible TemplateAn exemple for a template is:Regards *~title~**~sn~* *~givenname~* *~physicalDeliveryOfficeName~* Liebherr-Hydraulikbagger GmbH *~streetaddress~* *~postalcode~* *~l~* Tel.: *~telephonenumber~* Fax.: *~facsimiletelephonenumber~* E-Mail: *~mail~* All the *~anything~* tags are replaced. These should be named the same way like the attribute in the Active Directory. The application also supports .html and .rtf signatures. Class Diagram
History
|
||||||||||||||||||||||