static void Main(string[] args) { IDisposable responseDispose = null; bool showHelp = false; char[] splitChar = { '=' }; CommandRequest commandRequest = new CommandRequest(); commandRequest.EventType = new Guid("C8EDEB22-7E4A-4441-B7B4-419DDB856321"); commandRequest.EventIdForResponse = Guid.NewGuid(); commandRequest.CorrelationID = Guid.NewGuid(); commandRequest.Command = string.Empty; if (args.Length == 0) { showHelp = true; } else { commandRequest.Command = args[0].ToLower(); for (int i = 1; i < args.Length; i++) { if (args[i].StartsWith("/") == true) { string option = args[i].Split(splitChar)[0].ToLower(); switch (option) { case "/eventtype": try { commandRequest.EventType = new Guid(args[i].Split(splitChar)[1]); } catch { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Bad 'EventType' parameter"); Console.ForegroundColor = currColor; return; } break; case "/target": try { commandRequest.TargetMachineFilter = args[i].Split(splitChar)[1]; } catch { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Bad 'Target' parameter"); Console.ForegroundColor = currColor; return; } break; case "/role": try { commandRequest.TargetRoleFilter = args[i].Split(splitChar)[1]; } catch { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Bad 'Role' parameter"); Console.ForegroundColor = currColor; return; } break; default: showHelp = true; break; } } else { commandRequest.Arguments.Add(args[i]); } } } try { responseObservable = new WspEventObservable(commandRequest.EventIdForResponse, false); } catch (PubSubQueueDoesNotExistException) { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: the WspEventRouter service is not running"); Console.ForegroundColor = currColor; return; } responseDispose = responseObservable.Subscribe(new ResponseObservable()); WspEventPublish eventPush = new WspEventPublish(); switch (commandRequest.Command) { case "wsp_processcommands": if (commandRequest.Arguments.Count == 0) { commandRequest.Arguments.Add("true"); } else { if (commandRequest.Arguments.Count > 1 || (string.Compare((string)commandRequest.Arguments[0], "true", true) != 0 && string.Compare((string)commandRequest.Arguments[0], "false", true) != 0)) { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Invalid arguments"); Console.ForegroundColor = currColor; responseDispose.Dispose(); return; } } break; case "wsp_getdeviceinfo": case "wsp_getprocessinfo": case "wsp_getserviceinfo": case "wsp_getnetworkinfo": case "wsp_getdriveinfo": case "wsp_geteventloginfo": case "wsp_getwspassemblyinfo": case "wsp_getsysteminfo": if (commandRequest.Arguments.Count > 0) { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Invalid arguments"); Console.ForegroundColor = currColor; responseDispose.Dispose(); return; } break; case "wsp_getperformancecounters": case "wsp_getfileversioninfo": case "wsp_getregistrykeys": if (commandRequest.Arguments.Count == 0) { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: Argument list is empty"); Console.ForegroundColor = currColor; responseDispose.Dispose(); return; } break; default: showHelp = true; break; } if (showHelp == true) { ConsoleColor currColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.Write("\nCommand Format:\n\n"); Console.Write("\tWspCommand <cmd> [argsIn] [/target=<regex filter>] [/role=<Wsp Role>] [/eventtype=<Guid>]\n\n\n"); Console.Write("\tCommands:\n\n"); Console.Write("\t\tWsp_GetDeviceInfo\n"); Console.Write("\t\tWsp_GetDriveInfo\n"); Console.Write("\t\tWsp_GetEventLogInfo\n"); Console.Write("\t\tWsp_GetFileVersionInfo <argsIn>\n"); Console.Write("\t\tWsp_GetNetworkInfo\n"); Console.Write("\t\tWsp_GetPerformanceCounters <argsIn>\n"); Console.Write("\t\tWsp_GetProcessInfo\n"); Console.Write("\t\tWsp_GetRegistryKeys <argsIn>\n"); Console.Write("\t\tWsp_GetServiceInfo\n"); Console.Write("\t\tWsp_GetSystemInfo\n"); Console.Write("\t\tWsp_GetWspAssemblyInfo\n"); Console.ForegroundColor = currColor; responseDispose.Dispose(); return; } eventPush.OnNext(new WspEvent(commandRequest.EventType, null, commandRequest.Serialize())); Console.WriteLine(); ConsoleColor c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("---- Press any key to end ----"); Console.ForegroundColor = c; Console.ReadKey(); responseDispose.Dispose(); return; }