static void Main() { ServiceBusConfig serviceBusConfig = InitServiceBusConfig(); ManagementHelper helper = new ManagementHelper(serviceBusConfig.ConnectionString); bool done = false; do { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Please enter your command:"); Console.Write(">> "); Console.ForegroundColor = ConsoleColor.Gray; string commandLine = Console.ReadLine(); string[] commands = commandLine.Split(' '); try { if (string.IsNullOrWhiteSpace(commands[0]) || string.Compare("exit", commands[0], true) == 0) { done = true; return; } switch (commands[0].ToLower()) { case "createqueue": case "cq": if (commands.Length > 1) { helper.CreateQueueAsync(commands[1]).Wait(); } else { PrintWarning("Queue path missing after command name"); } break; case "deletequeue": case "dq": if (commands.Length > 1) { helper.DeleteQueueAsync(commands[1]).Wait(); } else { PrintWarning("Queue path missing after command name"); } break; case "listqueues": case "lq": helper.ListQueuesAsync().Wait(); break; case "getqueue": case "gq": if (commands.Length > 1) { helper.GetQueueAsync(commands[1]).Wait(); } else { PrintWarning("Queue path missing after command name"); } break; case "createtopic": case "ct": if (commands.Length > 1) { helper.CreateTopicAsync(commands[1]).Wait(); } else { PrintWarning("Topic path missing after command name"); } break; case "CreateSubscriptionAsync": case "cs": if (commands.Length > 2) { helper.CreateSubscriptionAsync(commands[1], commands[2]).Wait(); } else { PrintWarning("Topic/Subscription path missing after command name"); } break; case "lts": helper.ListTopicsAndSubscriptionsAsync().Wait(); break; default: PrintWarning("Invalid command, Please try again"); break; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } while (!done); }
static void Main(string[] args) { // Console.WriteLine("Hello World!"); ManagementHelper helper = new ManagementHelper(serviceBusConnectionString); bool done = false; do { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(">"); string CommandLine = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Magenta; string[] Commands = CommandLine.Split(' '); try { if (Commands.Length > 0) { switch (Commands[0]) { case "Createqueue": case "cq": if (Commands.Length > 1) { helper.CreateQueueAsync(Commands[1]).Wait(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Queue path not specified"); } break; case "listQueue": case "lq": helper.ListQueuesAsync().Wait(); break; case "getQueue": case "gq": if (Commands.Length > 1) { helper.GetQueueAsync(Commands[1]).Wait(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Quepath is not given"); } break; case "DeleteQueue": case "dq": if (Commands.Length > 1) { helper.DeleteQueueAsync(Commands[1]).Wait(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Queue path name not given to delete"); } break; case "CreateTopic": case "ct": if (Commands.Length > 1) { helper.CreateTopicAsync(Commands[1]).Wait(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Topic path is not given"); } break; case "CreateSubscription": case "cs": if (Commands.Length > 2) { helper.CreateSubscriptionAsync(Commands[1], Commands[2]).Wait(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Topic path and subscription name are not given"); } break; case "listTopics": case "lt": helper.ListTopicsAndSubscription().Wait(); break; case "exit": done = true; break; default: break; } } } catch (Exception ex) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); } } while (!done); }