Skip to content

AD – Enumerate domains in the current forest

Enumerate domains in the current forest

public static ArrayList EnumerateDomains()
{
    ArrayList alDomains = new ArrayList();
    Forest currentForest = Forest.GetCurrentForest();
    DomainCollection myDomains = currentForest.Domains;

    foreach (Domain objDomain in myDomains)
    {
        alDomains.Add(objDomain.Name);
    }
    return alDomains;
}
Advertisements

just another line in the file Getting list of (sub-)domains from Active Directory with C#

http://www.janus-net.de/2005/11/18/getting-list-of-sub-domains-from-active-directory-with-c/

split comma 2

publicstaticIEnumerable<string>SplitCSV(string csvString){var sb =newStringBuilder();
    bool quoted =false;foreach(char c in csvString){if(quoted){if(c =='"')
                quoted =false;else
                sb.Append(c);}else{if(c =='"'){
                quoted =true;}elseif(c ==','){
                yield return sb.ToString();
                sb.Length=0;}else{
                sb.Append(c);}}}if(quoted)thrownewArgumentException("csvString","Unterminated quotation mark.");

    yield return sb.ToString();}

Split Comma

[Test]
        public void StringTest()
        {
            const string input = @"""Peter"",""Pan"",,""Hello, is it ok"",";
            var strings = Split(input);
            Assert.That(strings[0], Is.EqualTo("Peter"));
            Assert.That(strings[1], Is.EqualTo("Pan"));
            Assert.That(strings[2], Is.EqualTo(""));
            Assert.That(strings[3], Is.EqualTo("Hello, is it ok"));
            }

        protected virtual string[] Split(string value)
        {
            var regex = new Regex("(?:^|,)(\\\"(?:[^\\\"]+|\\\"\\\")*\\\"|[^,]*)");
            var collection = regex.Matches(value);
            var items = new string[collection.Count];
            var i = 0;
            foreach (Match match in collection)
            {
                items[i++] = match.Groups[0].Value.Trim('"').Trim(',').Trim('"').Trim();
            }
            return items;
        }

windows service in C#

http://www.aspdotnet-suresh.com/2011/06/creating-windows-service-in-c-or.html

http://stackoverflow.com/questions/12885013/windows-service-with-timer

First approach with Windows Service is not easy..

Lot of time ago, i have written a c# service.

This is the logic of the Service class (tested, works fine):

namespace MyServiceApp
{
    public class MyService : ServiceBase
    {
        private System.Timers.Timer timer;

        protected override void OnStart(string[] args)
        {
            this.timer = new System.Timers.Timer(30000D);  // 30000 milliseconds = 30 seconds
            this.timer.AutoReset = true;
            this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
            this.timer.Start();
        }

        protected override void OnStop()
        {
            this.timer.Stop();
            this.timer = null;
        }

        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MyServiceApp.ServiceWork.Main(); // my separate static method for do work
        }

        public MyService()
        {
            this.ServiceName = "MyService";
        }

        // service entry point
        static void Main()
        {
            System.ServiceProcess.ServiceBase.Run(new MyService());
        }
    }
}

I recommend to write your real service work in a separate static method (why not, in a console application…just add reference to it), for simplify debugging and cleaning service code.

Make sure the interval is enough, and write in log ONLY in OnStart and OnStop overrides.

Hope this help!

 

 

SQL Server Mail : Database Mail & SQL Mail

Database Mail is new in 2005 with some new features.

http://www.codeproject.com/Articles/29060/SQL-SERVER-2008-Configure-Database-Mail-Send-Email

 

Fit a Flash SWF File to Any Screen Size

http://www.webdeveloper.com/forum/showthread.php?263386-Fit-a-Flash-SWF-File-to-Any-Screen-Size

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>untitled document</title>

<style>
html,body {
    height:100%;
    margin:0;
 }
#swf-holder {
    height:100%;
 }
#swf-holder object {
    display:block;
    width:100%;
    height:100%;
 }
</style>

</head>
<body>

<div id="swf-holder">

</div>

</body>
</html>