public OIMNTFSServer(OIMNTFSPartialScanner scanner, int listentoport = 16383) { eventLog = new EventLog("OIMNTFS Server"); OIMNTFSScanner = scanner; port = listentoport; Thread listener = new Thread(new ThreadStart(acceptConnections)); listener.Start(); eventLog.Write("Server started"); }
protected override void OnStart(string[] args) { eventLog.Buffer("Starting up service <OIMNTFS Service>"); // Update the service state to Start Pending. ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); eventLog.Buffer("SERVICE_START_PENDING"); // Preparation: read AD // todo: offline AD cache this.adCache = new ADCache("LDAP://10.112.128.3/DC=nrwbanki,DC=de"); // Preparation: unmap all network drives string[] drives = Directory.GetLogicalDrives(); NetworkDrive networkDrive = new NetworkDrive(); networkDrive.Persistent = true; networkDrive.SaveCredentials = true; networkDrive.Force = true; foreach (string drive in drives) { try { networkDrive.LocalDrive = drive; networkDrive.UnMapDrive(); eventLog.Buffer("Drive {0} mapping removed (net use {0} /d)", drive); } catch (Exception e) { if (e.HResult != -2147467259) { eventLog.Buffer("unable to unmap {0}", drive); eventLog.Buffer("Exception was: {0}", e.ToString()); } } } eventLog.Buffer("All network drives unmapped."); // Preparation: open database and read information string connectionString; switch (System.Environment.GetEnvironmentVariable("USERDNSDOMAIN")) { case "NRWBANKI.DE": connectionString = "Data Source=10.112.133.87;Initial Catalog=oimntfs;User Id = oimntfsdbo; Password = bbGcmcZlkL8FYnsCN4j4"; eventLog.Buffer("Running in PROD mode."); break; case "NRWBANK.QS": connectionString = "Data Source=10.112.149.4;Initial Catalog=oimntfs;User Id = oimntfsdbo; Password = HbLjSEsgv/9ctvj2pYosOJT7UPVpid3qdJP5RPBVbG8="; eventLog.Buffer("Running in QS mode."); break; case "NRWBANK.DEV": connectionString = "Data Source=10.112.139.4;Initial Catalog=oimntfs;User Id = oimntfsdbo; Password = HbLjSEsgv/9ctvj2pYosOJT7UPVpid3qdJP5RPBVbG8="; eventLog.Buffer("Running in DEV mode."); break; default: eventLog.Buffer("Unknown environment in domain {0}. Exiting.", System.Environment.UserDomainName); eventLog.Flush(); throw (new Exception("Unkown environment.")); } try { scanner = new OIMNTFSPartialScanner(connectionString, this); continuousScanner = new OIMNTFSContinuousScanner(connectionString, this); eventLog.Buffer("Connection created and data read from {0}.", connectionString); continuousScanner.RunWorkerThread(); scanner.RunWorkerThread(); eventLog.Buffer("Worker threads started."); //server = new OIMNTFSServer(scanner, 16383); //eventLog.Buffer("Server started."); // Update the service state to Running. serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); eventLog.Buffer("SERVICE_RUNNING"); // Set up a timer that triggers every minute. Timer timer = new Timer(); timer.Interval = 60000; // 60 seconds timer.Elapsed += new ElapsedEventHandler(this.OnTimer); timer.Start(); eventLog.Flush(); } catch (Exception e) { eventLog.Buffer("Starting scanners failed: {0}", e.Message); eventLog.Buffer(e.StackTrace); eventLog.Flush(); new Exception("Unable to start scanners", e); } }