/// <summary> /// Returns first connection string /// </summary> /// <returns></returns> private static string ServiceMain() { List <ServiceBase> servicebaseList = new List <ServiceBase>(); ConfigurationManager.RefreshSection("connectionStrings"); EnterpriseModel.Net.LibConfig.Instance.Config = new CooperAtkins.NotificationClient.Generic.DataAccess.EnterpriseModelConfig(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString); OrganizationalUnitList orgUnitList = new OrganizationalUnitList(); ServiceEntity svcEntity = new ServiceEntity(); orgUnitList.Load(null); string firstConnectionString = ""; for (int i = 0; i < orgUnitList.Count; i++) { if (orgUnitList[i].isActive) { string connString = GetConnectionString(orgUnitList[i].DSN); DBName = orgUnitList[i].DBName; oUID = orgUnitList[i].OUID; if (firstConnectionString == "") { DefaultConnectionString = connString; firstConnectionString = connString; firstDBName = orgUnitList[i].DBName; firstOUID = orgUnitList[i].OUID; continue; } Process p = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location, "\"" + connString + " \" " + DBName + " \" " + oUID.ToString() + ""); startInfo.CreateNoWindow = true; p.StartInfo = startInfo; p.Start(); svcEntity.OUID = orgUnitList[i].OUID; svcEntity.PID = p.Id; svcEntity.ExeName = p.ProcessName; svcEntity.TimeStamp = DateTime.Now; using (ServiceEntityContext context = new ServiceEntityContext()) { context.Save(svcEntity); } } else { continue; } } return(firstConnectionString); }
protected override void OnStop() { int pid = Process.GetCurrentProcess().Id; LogBook.Write("Stopping exe's"); LogBook.Write(Process.GetCurrentProcess().ProcessName); LogBook.Write("Master Connection String: " + ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString); foreach (Process pro in Process.GetProcessesByName("CooperAtkins.NotificationClient.Service")) { if (pro.Id != pid) { try { ServiceEntity svcEntity = new ServiceEntity(); svcEntity.PID = pro.Id; svcEntity.ExeName = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString; using (ServiceEntityContext context = new ServiceEntityContext()) { LogBook.Write("Executing update for process id: " + pro.Id.ToString()); context.Save(svcEntity, EnterpriseModel.Net.ObjectAction.Edit); } LogBook.Write("Stopping process: " + pro.Id); pro.Kill(); } catch (Exception ex) { LogBook.Write(ex, "Notification Client Service"); } } } /* Uncommented by 5/9/2012 by Mike R. due to missed comm notification problems * Commented By: Srinivas Rao E * Data: 2/2/02/2012 * Description: Timers runs every 3 seconds, so there is no need to listen from external source. */ if (_udpSocket != null) { try { _udpSocket.Close(); _udpSocket.Dispose(); } catch { } finally { _udpSocket = null; } try { _thdUdpHandler.Abort(); } catch (ThreadAbortException) { } } try { _target.Close(); } catch (Exception ex) { LogBook.Write(ex, "Notification Client Service"); } }