public ClientController( IActionCenter actionCenter, IDisplayMonitor displayMonitor, IExplorerShell explorerShell, IHashAlgorithm hashAlgorithm, ILogger logger, IMessageBox messageBox, IOperationSequence operations, IProcessMonitor processMonitor, IRuntimeProxy runtime, Action shutdown, ITaskbar taskbar, ITerminationActivator terminationActivator, IText text, IUserInterfaceFactory uiFactory, IWindowMonitor windowMonitor) { this.actionCenter = actionCenter; this.displayMonitor = displayMonitor; this.explorerShell = explorerShell; this.hashAlgorithm = hashAlgorithm; this.logger = logger; this.messageBox = messageBox; this.operations = operations; this.processMonitor = processMonitor; this.runtime = runtime; this.shutdown = shutdown; this.taskbar = taskbar; this.terminationActivator = terminationActivator; this.text = text; this.uiFactory = uiFactory; this.windowMonitor = windowMonitor; }
public void WhenFirstProcessIsRunningAndThenStoppedShouldUpdateTheProcessStatus() { //Arrange Process demoProcess1 = Process.Start(_process1FilePath); //Act IProcessMonitor pMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); pMonitor.RefreshInformation(); //Assert Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong"); Assert.AreEqual(1, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong"); Assert.AreEqual(1, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong"); Assert.AreEqual(ProcessState.Running, pMonitor.GetProcessInformation().First().State, "ProcessState1 assertion is wrong"); Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State, "ProcessState2 assertion is wrong"); //Act demoProcess1.Kill(); pMonitor.RefreshInformation(); //Assert Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong"); Assert.AreEqual(2, pMonitor.NbOfNotRunningProcesses, "NbOfNotRunningProcesses assertion is wrong"); Assert.AreEqual(0, pMonitor.NbOfRunningProcesses, "NbOfRunningProcesses assertion is wrong"); Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().First().State, "ProcessState1 assertion is wrong"); Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State, "ProcessState2 assertion is wrong"); }
public ServerLifecycleManager(StartupConfiguration startupConfiguration) { SetApplicationDirectory(); _writer = startupConfiguration.Writer; _serverEnvironmentPreparer = startupConfiguration.ServerEnvironmentPreparer; _startUpDirectory = startupConfiguration.Directory; _startupResourceCatalogFactory = startupConfiguration.ResourceCatalogFactory; _ipcClient = startupConfiguration.IpcClient; _assemblyLoader = startupConfiguration.AssemblyLoader; _pulseLogger = new PulseLogger(60000).Start(); _pulseTracker = new PulseTracker(TimeSpan.FromDays(1).TotalMilliseconds).Start(); _serverEnvironmentPreparer.PrepareEnvironment(); _startWebServer = startupConfiguration.StartWebServer; _webServerConfiguration = startupConfiguration.WebServerConfiguration; _loggingProcessMonitor = startupConfiguration.LoggingServiceMonitor; _loggingProcessMonitor.OnProcessDied += (e) => _writer.WriteLine("logging service exited"); _queueProcessMonitor = startupConfiguration.QueueWorkerMonitor; _queueProcessMonitor.OnProcessDied += (config) => _writer.WriteLine($"queue process died: {config.Name}({config.Id})"); _webSocketPool = startupConfiguration.WebSocketPool; SecurityIdentityFactory.Set(startupConfiguration.SecurityIdentityFactory); }
public AiTester(Settings settings, IMapGenerator mapGenerator, IGameVisualizer gameVisualizer, IProcessMonitor monitor, IAiFactory aiFactory, IGameFactory gameFactory) { this.settings = settings; this.mapGenerator = mapGenerator; this.gameVisualizer = gameVisualizer; this.monitor = monitor; this.aiFactory = aiFactory; this.gameFactory = gameFactory; }
public ProcessLock( IProcessMonitor monitor, string lockKey ) { _monitor = monitor; _lockKey = lockKey; _monitor.Enter(lockKey); }
public JsonResult GetProcessStatus() { //Instantiate and refresh information regarding the 3 processes (Notepad, Wordpad and Paint). The //information is taken from the Web.config file IProcessMonitor processMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); IList <BasicProcessInformation> statusOfProcesses = processMonitor.GetProcessInformation(); return(Json(statusOfProcesses, JsonRequestBehavior.AllowGet)); }
/// <summary> /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close /// Notepad in order to see how the program responds to your changes. We print the output on the console. /// </summary> static void Main() { System.Console.WriteLine("PMonitor Example - Console"); IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); while (true) { pm.RefreshInformation(); BasicProcessInformation bpi = pm.GetProcessInformation().Single(); System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString()); Thread.Sleep(3000); } }
public void TheConstructorShouldInstantiateMonitorCorrectly() { //Act IProcessMonitor pMonitor = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); //Assert Assert.AreEqual(2, pMonitor.NbOfProcesses, "NbOfProcesses assertion is wrong"); Assert.AreEqual("PMonitor.DemoProcess1", pMonitor.GetProcessInformation().First().ProcessName, "ProcessName1 assertion is wrong"); Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().First().State, "ProcessState1 assertion is wrong"); Assert.AreEqual("PMonitor.DemoProcess2", pMonitor.GetProcessInformation().Last().ProcessName, "ProcessName2 assertion is wrong"); Assert.AreEqual(ProcessState.NotRunning, pMonitor.GetProcessInformation().Last().State, "ProcessState2 assertion is wrong"); }
public void Stop() { if (!Running) { throw new InvalidOperationException("Server not running"); } ISLogger.Write("Stopping server"); foreach (ConnectedClient client in clientMan?.AllClients) { clientMan.RemoveClient(client); client.Dispose(); } tcpListener?.Stop(); if (inputMan.Running) { inputMan?.Stop(); } inputMan = null; if (curMonitor.Running) { curMonitor?.Stop(); } curMonitor = null; if (procMonitor.Monitoring) { procMonitor?.StopMonitoring(); } procMonitor = null; tcpListener = null; Running = false; ServerStopped?.Invoke(this, null); }
/// <summary> /// On Windows, interrogate the status of the Notepad process every 3 seconds. You can open and close /// Notepad in order to see how the program responds to your changes. We print the output on the console. /// </summary> static void Main() { System.Console.WriteLine("PMonitor BoehmTrader - Console"); IProcessMonitor pm = ProcessMonitorFactory.BuildDefaultOSProcessMonitor(); while (true) { pm.RefreshInformation(); BasicProcessInformation bpi = pm.GetProcessInformation().Single(); if (numMonitoring % 10 == 0) { System.Console.WriteLine("{0} Process {1} is {2}", DateTime.Now.ToString(CultureInfo.InvariantCulture), bpi.FriendlyName, bpi.State.ToString()); } if (bpi.State == ProcessState.NotRunning) { StartProcess(); } Thread.Sleep(500); numMonitoring++; } }
public ProcessMonitorOperation(ILogger logger, IProcessMonitor processMonitor, Settings settings) { this.logger = logger; this.processMonitor = processMonitor; this.settings = settings; }
/// <summary> /// Application startup /// </summary> public void AppStartup(object sender, StartupEventArgs e) { // We save this so that if we perform an upgrade of settings, // we still treat this startup as a first-time run of the application bool firstTimeUse = GW2PAO.Properties.Settings.Default.FirstTimeRun; // Update settings if neccessary if (GW2PAO.Properties.Settings.Default.UpgradeRequired) { GW2PAO.Properties.Settings.Default.Upgrade(); GW2PAO.Properties.Settings.Default.UpgradeRequired = false; GW2PAO.Properties.Settings.Default.FirstTimeRun = firstTimeUse; GW2PAO.Properties.Settings.Default.Save(); } #if DEBUG // Enable logging if running in debug LogManager.GlobalThreshold = NLog.LogLevel.Trace; #else // Set up logging configuration if (!GW2PAO.Properties.Settings.Default.IsLoggingEnabled) { LogManager.GlobalThreshold = NLog.LogLevel.Fatal; } #endif // Disable the debug assert windows that pop-up from NLog System.Diagnostics.Trace.Listeners.OfType <System.Diagnostics.DefaultTraceListener>().First().AssertUiEnabled = false; // Log application information var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(executingAssembly.Location); logger.Info("Application starting - " + executingAssembly.GetName().Name + " - " + executingAssembly.GetName().Version + " - " + fvi.FileVersion + " - " + fvi.ProductVersion); // Initialize the last chance exception handlers logger.Debug("Registering last chance exception handlers"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; #if !NO_BROWSER // Initialize the WebCore for the web browser logger.Debug("Initializing Awesomium WebCore"); if (!WebCore.IsInitialized) { WebCore.Initialize(new WebConfig() { HomeURL = "http://wiki.guildwars2.com/".ToUri(), }); } #endif // Create dummy window so that the only way to exit the app is by using the tray icon Window dummyWindow = new Window() { WindowStyle = System.Windows.WindowStyle.None, AllowsTransparency = true, Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent), ShowInTaskbar = false, Title = "GW2 Personal Assistant Overlay" }; dummyWindow.Show(); GW2PAO.Views.OverlayWindow.OwnerWindow = dummyWindow; // Create the tray icon logger.Debug("Creating tray icon"); TaskbarIcon = (TaskbarIcon)this.FindResource("TrayIcon"); TrayIconVm = new TrayIconViewModel(); TaskbarIcon.DataContext = TrayIconVm; TaskbarIcon.ContextMenu.DataContext = TrayIconVm; TaskbarIcon.ContextMenu.ItemsSource = TrayIconVm.MenuItems; App.TrayIcon = new ApplicationTrayIcon(TaskbarIcon); logger.Debug("Tray icon created"); // Initialize the application controller AppController = new ApplicationController(); // Initialize the process monitor ProcessMonitor = new ProcessMonitor(AppController.SystemService); GW2PAO.Views.OverlayWindow.ProcessMonitor = ProcessMonitor; // Initialize the OverlayMenuIcon ApplicationOverlayMenuIcon = new OverlayMenuIcon(TrayIconVm); // Set up the menu items logger.Debug("Initializing menu items"); if (TrayIconVm != null) { foreach (var item in AppController.GetMenuItems()) { TrayIconVm.MenuItems.Add(item); } TrayIconVm.MenuItems.Add(null); // Null is treated as a seperator var settingsMenu = new MenuItemViewModel("Settings", null); settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Non-Interactive Windows", null, true, () => { return(GW2PAO.Properties.Settings.Default.IsClickthroughEnabled); }, (enabled) => { GW2PAO.Properties.Settings.Default.IsClickthroughEnabled = enabled; GW2PAO.Properties.Settings.Default.Save(); }, GW2PAO.Properties.Settings.Default, "IsClickthroughEnabled")); settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Sticky Windows", null, true, () => { return(GW2PAO.Properties.Settings.Default.AreWindowsSticky); }, (enabled) => { GW2PAO.Properties.Settings.Default.AreWindowsSticky = enabled; GW2PAO.Properties.Settings.Default.Save(); }, GW2PAO.Properties.Settings.Default, "AreWindowsSticky")); settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Overlay Menu Icon", null, true, () => { return(ApplicationOverlayMenuIcon.IsVisible); }, (show) => { ApplicationOverlayMenuIcon.IsVisible = show; }, ApplicationOverlayMenuIcon, "IsVisible")); settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Check for Updates at Startup", null, true, () => { return(GW2PAO.Properties.Settings.Default.CheckForUpdates); }, (enabled) => { GW2PAO.Properties.Settings.Default.CheckForUpdates = enabled; GW2PAO.Properties.Settings.Default.Save(); }, GW2PAO.Properties.Settings.Default, "CheckForUpdates")); TrayIconVm.MenuItems.Add(settingsMenu); TrayIconVm.MenuItems.Add(new MenuItemViewModel("About", () => new GW2PAO.Views.AboutView().Show())); TrayIconVm.MenuItems.Add(new MenuItemViewModel("Exit", this.ExitAndCleanup)); } logger.Info("Program startup complete"); // Reopen windows based on user settings AppController.ReopenWindowsFromSettings(); GW2PAO.Properties.Settings.Default.FirstTimeRun = false; GW2PAO.Properties.Settings.Default.Save(); // Perform a check for new updates if (GW2PAO.Properties.Settings.Default.CheckForUpdates) { UpdateChecker.CheckForUpdateAndNotify(); } }
public void Start(int port) { if (Running) { throw new InvalidOperationException("Server already running"); } try { Process.GetCurrentProcess().PriorityClass = ServerBasePriority; }catch (Exception ex) { ISLogger.Write("Cannot set process priority to {0}: {1}", ServerBasePriority, ex.Message); } ConnectedClient.LocalHost = new ConnectedClient(true); ISLogger.Write("Starting server..."); ServerPort = port; clientMan = new ClientManager(ServerDefaultMaxClients); clientMan.AddClient(ConnectedClient.LocalHost); tcpListener = new ClientListener(); tcpListener.ClientConnected += TcpListener_ClientConnected; tcpListener.Start(port); SetConsoleText("Current client: localhost"); //We need to determine which OS is being used OSHelper.Os os = OSHelper.GetOsVersion(); switch (os.System) { case OSHelper.Platform.Windows: { inputMan = new WindowsInputManager(); curMonitor = new WindowsCursorMonitor(); outManager = new WindowsOutputManager(); procMonitor = new WindowsProcessMonitor(); break; } default: throw new NotImplementedException(); } inputMan.Start(); curMonitor.Start(); curMonitor.EdgeHit += LocalHost_EdgeHit; procMonitor.StartMonitoring(); procMonitor.ProcessEnteredFullscreen += ProcMonitor_ProcessEnteredFullscreen; procMonitor.ProcessExitedFullscreen += ProcMonitor_ProcessExitedFullscreen; Running = true; inputMan.InputReceived += InputMan_InputReceived; inputMan.ClientHotkeyPressed += InputMan_ClientHotkeyPressed; inputMan.FunctionHotkeyPressed += InputMan_FunctionHotkeyPressed; inputMan.ClipboardTextCopied += InputMan_ClipboardTextCopied; LoadHotkeySettings(); }
internal void BuildObjectGraph(Action shutdown) { ValidateCommandLineArguments(); configuration = new ClientConfiguration(); logger = new Logger(); nativeMethods = new NativeMethods(); systemInfo = new SystemInfo(); InitializeLogging(); InitializeText(); actionCenter = BuildActionCenter(); messageBox = BuildMessageBox(); processMonitor = new ProcessMonitor(new ModuleLogger(logger, nameof(ProcessMonitor)), nativeMethods); uiFactory = BuildUserInterfaceFactory(); runtimeProxy = new RuntimeProxy(runtimeHostUri, new ProxyObjectFactory(), new ModuleLogger(logger, nameof(RuntimeProxy)), Interlocutor.Client); taskbar = BuildTaskbar(); terminationActivator = new TerminationActivator(new ModuleLogger(logger, nameof(TerminationActivator))); windowMonitor = new WindowMonitor(new ModuleLogger(logger, nameof(WindowMonitor)), nativeMethods); var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, nameof(DisplayMonitor)), nativeMethods, systemInfo); var explorerShell = new ExplorerShell(new ModuleLogger(logger, nameof(ExplorerShell)), nativeMethods); var hashAlgorithm = new HashAlgorithm(); var operations = new Queue <IOperation>(); operations.Enqueue(new I18nOperation(logger, text, textResource)); operations.Enqueue(new RuntimeConnectionOperation(logger, runtimeProxy, authenticationToken)); operations.Enqueue(new ConfigurationOperation(configuration, logger, runtimeProxy)); operations.Enqueue(new DelegateOperation(UpdateAppConfig)); operations.Enqueue(new LazyInitializationOperation(BuildClientHostOperation)); operations.Enqueue(new LazyInitializationOperation(BuildClientHostDisconnectionOperation)); operations.Enqueue(new LazyInitializationOperation(BuildKeyboardInterceptorOperation)); operations.Enqueue(new LazyInitializationOperation(BuildMouseInterceptorOperation)); operations.Enqueue(new LazyInitializationOperation(BuildWindowMonitorOperation)); operations.Enqueue(new LazyInitializationOperation(BuildProcessMonitorOperation)); operations.Enqueue(new DisplayMonitorOperation(displayMonitor, logger, taskbar)); operations.Enqueue(new LazyInitializationOperation(BuildShellOperation)); operations.Enqueue(new LazyInitializationOperation(BuildBrowserOperation)); operations.Enqueue(new ClipboardOperation(logger, nativeMethods)); operations.Enqueue(new DelegateOperation(UpdateClientControllerDependencies)); var sequence = new OperationSequence(logger, operations); ClientController = new ClientController( actionCenter, displayMonitor, explorerShell, hashAlgorithm, logger, messageBox, sequence, processMonitor, runtimeProxy, shutdown, taskbar, terminationActivator, text, uiFactory, windowMonitor); }
public AccountViewModel(IProcessMonitor processMonitor) { this.processMonitor = processMonitor; }
public Ai(string exePath, IProcessMonitor monitor) { this.exePath = exePath; this.monitor = monitor; }
public AiFactory(IProcessMonitor monitor) { this.monitor = monitor; }