public Simulation(SimulationOptions options) { if (options.Topology == null) { throw new ArgumentNullException("Topology cannot be null", nameof(options.Topology)); } if (options.PacketHopCount <= 0) { throw new ArgumentException("Hop count cannot be 0", nameof(options.PacketHopCount)); } if (options.PacketGenerationChance <= 0) { throw new ArgumentException("Packet generation chance cannot be less or equal than 0", nameof(options.PacketGenerationChance)); } if (options.PacketGenerationChance > 1) { throw new ArgumentException("Packet generation chance cannot be greater than 1", nameof(options.PacketGenerationChance)); } if (options.TickInterval <= 0) { throw new ArgumentException("Tick interval cannot be less or equal than 0", nameof(options.TickInterval)); } topology = options.Topology; hopCount = options.PacketHopCount; packetChance = options.PacketGenerationChance; tickInterval = options.TickInterval; }
static void ShowSimulationMenu(SimulationOptions options) { Console.WriteLine("Press enter/return to start the simulation"); Console.ReadLine(); Console.Clear(); Console.WriteLine("Simulation is starting in 3s... Press enter/return to stop the simulation at any time"); Thread.Sleep(2000); Simulation sim = new Simulation(options); sim.Run(); Console.ReadLine(); sim.Stop(); }
static void Main(string[] args) { var cmdOptions = new CmdOptions(); if (CommandLine.Parser.Default.ParseArguments(args, cmdOptions)) // Valid arguments from cmd { var simOptions = new SimulationOptions { Topology = Graph.GetSampleTopology(), PacketGenerationChance = cmdOptions.PacketGenChance, PacketHopCount = cmdOptions.PacketHopCount, TickInterval = cmdOptions.TickInterval }; ShowSimulationMenu(simOptions); } else Console.WriteLine("Invalid arguments supplied"); Console.ReadLine(); }