LdtpdService() { if (!String.IsNullOrEmpty(ldtpDebugEnv)) debug = true; if (String.IsNullOrEmpty(ldtpPort)) ldtpPort = "4118"; common = new Common(debug); windowList = new WindowList(common); listener = new HttpListener(); listener.Prefixes.Add("http://localhost:" + ldtpPort + "/"); listener.Prefixes.Add("http://+:" + ldtpPort + "/"); // Listen on all possible IP address if (listenAllInterface != null && listenAllInterface.Length > 0) { if (debug) Console.WriteLine("Listening on all interface"); listener.Prefixes.Add("http://*:" + ldtpPort + "/"); } else { // For Windows 8, still you need to add firewall rules // Refer: README.txt if (debug) Console.WriteLine("Listening only on local interface"); } listener.Start(); svc = new Core(windowList, common, debug); }
public ProcessPerformanceCounter(Common common, string processName, int processId) { this.common = common; this.processId = processId; this.processName = processName; GetInstanceName(processId); }
public Utils(WindowList windowList, Common common, bool debug) { this.debug = debug; this.windowList = windowList; this.common = common; backgroundThread = new Thread(new ThreadStart(BackgroundThread)); // Clean up window handles in different thread backgroundThread.Start(); }
public ProcessStats(Common common) { this.common = common; monitorProcess = false; processMonitorThread = null; processList = new ArrayList(); }
public Core(WindowList windowList, Common common, bool debug = false) : base(windowList, common, debug) { ps = new ProcessStats(common); }
static void SingleThreadExec() { bool debug = false; string ldtpDebugEnv = Environment.GetEnvironmentVariable("LDTP_DEBUG"); string ldtpPort = Environment.GetEnvironmentVariable("LDTP_SERVER_PORT"); string listenAllInterface = Environment.GetEnvironmentVariable( "LDTP_LISTEN_ALL_INTERFACE"); if (!String.IsNullOrEmpty(ldtpDebugEnv)) debug = true; if (String.IsNullOrEmpty(ldtpPort)) ldtpPort = "4118"; Common common = new Common(debug); /* // If planning to use Remoting instead of HTTP // use this commented portion of code // NOTE: To have this at work, you need to add your // app under Firewall IDictionary props = new Hashtable(); props["name"] = "LdtpdService"; props["port"] = 4118; HttpChannel channel = new HttpChannel( props, null, new XmlRpcServerFormatterSinkProvider() ); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType( typeof(LdtpdMain), "service.rem", WellKnownObjectMode.Singleton); Console.WriteLine("Press <ENTER> to shutdown"); Console.ReadLine(); /**/ WindowList windowList = new WindowList(common); HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://localhost:" + ldtpPort + "/"); listener.Prefixes.Add("http://+:" + ldtpPort + "/"); // Listen on all possible IP address if (String.IsNullOrEmpty(listenAllInterface)) { if (debug) Console.WriteLine("Listening on all interface"); listener.Prefixes.Add("http://*:" + ldtpPort + "/"); } else { // For Windows 8, still you need to add firewall rules // Refer: README.txt if (debug) Console.WriteLine("Listening only on local interface"); } listener.Start(); XmlRpcListenerService svc = new Core(windowList, common, debug); try { while (true) { GC.Collect(); try { if (debug) Console.WriteLine("Waiting for clients"); HttpListenerContext context = listener.GetContext(); // Don't create LDTP instance here, this creates // new object for every request ! // Moved before creating HttpListenerContext //XmlRpcListenerService svc = new LdtpdMain(); if (debug) Console.WriteLine("Processing request"); svc.ProcessRequest(context); /* // FIXME: If trying to do parallel process // memory usage goes high and never comes back // This is required for startprocessmonitor API Thread parallelProcess = new Thread(delegate() { try { svc.ProcessRequest(context); } finally { context.Response.Close(); context = null; GC.Collect(); } }); parallelProcess.Start(); /* */ context.Response.Close(); context = null; } catch (InvalidOperationException ex) { common.LogMessage(ex); } } } catch (Exception ex) { common.LogMessage(ex); } finally { svc = null; windowList = null; listener.Stop(); } }