static void Main(string[] args) { #region Constants string PROCESS_ID = Process.GetCurrentProcess().Id.ToString(); const string COUNTER_NAME = "WPC Data Request Generator"; const string COUNTER_HELP = "WPC Data Request Generator is used to monitor the number of seconds each request took until it got back from the WPC framework service."; #endregion #region Validate arguments count // Check number of arguments if (args.Length != 4) { Console.WriteLine("Usage: WBXEventGenerator.exe [test number] [iterations] [threads] [delay]\n"); Console.WriteLine("\ttest number: the test number to run"); Console.WriteLine("\titeration: the number of times to perform the operations\n\t\tin each thread"); Console.WriteLine("\tthreads number: the number of threads that will execute\n\t\tthe operations simultaneously"); Console.WriteLine("\tdelay: number of milliseconds to wait between each operations"); return; } #endregion #region Initialize local variables int testNumber; int delayTime; int iterationsCount; #endregion #region Validations // Check the test number if (!int.TryParse(args[0], out testNumber)) { Console.WriteLine("Invalid test number " + args[0]); return; } // Check the iterations count if (!int.TryParse(args[1], out iterationsCount)) { Console.WriteLine("Invalid iterations count number " + args[1]); return; } else { if (iterationsCount < 1) { Console.WriteLine("Iterations count number should be at least 1"); return; } } // Check the threads count number if (!int.TryParse(args[2], out _threadsCount)) { Console.WriteLine("Invalid thread count number " + args[2]); return; } else { if (_threadsCount < 1) { Console.WriteLine("Threads number should be at least 1"); return; } } // Check delay time if (!int.TryParse(args[3], out delayTime)) { Console.WriteLine("Invalid delay number " + args[3]); return; } #endregion #region Create and open the agent configuration service _serviceClient = new WPCFrameworkServiceClient(); try { _serviceClient.Open(); } catch (Exception ex) { Console.Out.Write( "Open WPC Framework Service failed with exception: " + ex ); return; } #endregion #region Create performance counters // Delete the WhiteOPS category PerformanceMonitorHelper.deleteCategory( PerformanceMonitorHelper.WBX_CATEGORY_NAME ); string counterInstanceName = COUNTER_NAME + " " + PROCESS_ID; _counters = new PerformanceCounter[_threadsCount]; for (int i = 0; i < _threadsCount; i++) { _counters[i] = createCounter( COUNTER_NAME, COUNTER_HELP, counterInstanceName + ", thread " + i.ToString() ); } #endregion #region Create the stream writers _streamWriters = new StreamWriter[_threadsCount]; for (int i = 0; i < _threadsCount; i++) { _streamWriters[i] = openFile( counterInstanceName + "_thread_" + i.ToString() ); } #endregion /////////////////////////////////////////////////////// /// Before starting to handle the events, pause the /// process and wait for the user to to hit any key to /// continue. This is done is order to let the user /// create a new Performance Counter Log. /////////////////////////////////////////////////////// // Show the user the counter instance name Console.WriteLine( "New performance counters were created, the counter instance name is:\n{0}", counterInstanceName ); Console.WriteLine("Press any key to process tests..."); Console.ReadKey(true); Console.WriteLine( "\nProcessing operations of test {0}, please wait...\n", testNumber ); string agentUID = null; _runTestCase runTestDelegate = null; switch (testNumber) { case 1: agentUID = AD_UID; break; case 2: agentUID = EPO_UID; break; case 3: agentUID = CP_UID; break; default: Console.WriteLine( "Test number {0} does not exist.", testNumber ); return; } runTestDelegate = new _runTestCase(runReqeusts); if (runTestDelegate != null) { // For each counter begin a new thread for (int i = 0; i < _threadsCount; i++) { runTestDelegate.BeginInvoke( agentUID, CLIENT_IP, USER_NAME, _counters[i], _streamWriters[i], iterationsCount, delayTime, null, null ); } } // Wait for all threads to finished. while (_numberOfThreadsFinished != _threadsCount) { Thread.Sleep(1000); } #region Remove the counter instances and close data collector files if (_counters != null) { Console.WriteLine("\nPress any key to terminate performance instance counters..."); Console.ReadKey(true); foreach (PerformanceCounter counter in _counters) { counter.RemoveInstance(); } foreach (StreamWriter sw in _streamWriters) { sw.Close(); } } #endregion Console.WriteLine("Process Finished"); }