/******************* * PRIVATE METHODS * *******************/ private void OnTimeEventUpdateGUI(object source, ElapsedEventArgs e) { // Method invoked every _clientTimer milliseconds. // Has to invoke a method to update the timePercentage of the displayed processes. // Update only if the process list is not null if (CurrentSelectedServer != null && TheProcessesList != null) { // For each process in the list, update the timePercentage. foreach (ProcessModel proc in TheProcessesList) { if (proc != null) { // Compute and update the time% proc.TimePercentage = (int)System.Math.Ceiling(100 * (TimeSpanToMilliSeconds(proc.GetElapsedTime()) / TimeSpanToMilliSeconds(CurrentSelectedServer.GetElapsedTime()))); RaisePropertyChanged("TheProcessesList"); } } } }
public void SendCommand() { // Divide the cases: the one with the ServerView and the one with the ApplicationView if (_shouldShowServer) { // The selected view is the one of the servers. // If there is at lest a key in the command if (_keyStrings.Count() != 0) { // If there is a CurrentSelectedServer if (CurrentSelectedServer != null) { // If there is a process selected. if (CurrentSelectedProcess != null) { CurrentSelectedServer.SendCommand(_keyStrings, _currentSelectedProcess.ProcessWindowHandle, _currentSelectedProcess.ProcessId); } else // The CurrentSelectedProcess is null, show the Error Window. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Nessuna finestra selezionata."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } else // The CurrentSelectedServer is null, show the Error Window. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Non è selezionato nessun server."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } else // There is no command to send. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Nessun comando inserito."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } // Clean the textBox in the GUI and clean the list of keys. CancelStringCommand(); } else if (_shouldShowApplication) { // The selected view is the one of the applications. // If there is at lest a key in the command if (_keyStrings.Count() != 0) { // If there is a selected application. if (CurrentSelectedApplication != null) { // If the are selected severs. if (SelectedServersForApplication != null) { // If there is at least a server selected for the selected application. if (SelectedServersForApplication.Count() > 0) { // For each server selected, send the signal to all the applications it runs, that have the same application name of the one selected. foreach (ServerModel server in SelectedServersForApplication) { foreach (ProcessModel process in server.TheProcesses) { // I have to check if the exeName of the process is equal to the selected application. string processExeName = Path.GetFileName(process.ExePath); // returns File.exe if (processExeName.Equals(_currentSelectedApplication.ApplicationName)) { // I have to send the command, since they are the same application server.SendCommand(_keyStrings, process.ProcessWindowHandle, process.ProcessId); } } } CancelStringCommand(); } else // There is no selected server. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Non è selezionato nessun server."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } else // There is no selected server. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Non è selezionato nessun server."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } else // There is no selected application. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Non è selezionata nessuna applicazione."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } else // There is no command to send. { // Open the Error Window Views.ErrorWindowView errView = new Views.ErrorWindowView(); ErrorWindowViewModel errWindViewModel = new ErrorWindowViewModel("Nessun comando inserito."); errWindViewModel.ClosingRequest += errView.Close; errView.DataContext = errWindViewModel; errView.Show(); } } }