/// <summary> /// Validates that the correct algorithm will be applied /// </summary> /// <param name="matcher"> /// The Current Instance of the Packet Matcher /// </param> /// <param name="algo"> /// The Desired Algorithm Enumeral /// </param> /// <returns> /// A tuple: /// - Bool declaring whether the correct algorithm is selected /// - The new instance of the packetmatcher /// </returns> public Tuple <bool, PacketMatcher> VerifyMatchingAlgorithm(MatchingAlgorithm algo = MatchingAlgorithm.FIRST) { // initialize the flag bool algorithmWasChanged; // if the algorithm doesn't match or the matcher hasn't been initialized if (Matcher == null || Matcher.Algorithm != algo) { algorithmWasChanged = false; // Check the desired algorithm switch (algo) { // initialize a First-Pair Packet Matcher case MatchingAlgorithm.FIRST_PAIR: algorithmWasChanged = true; Matcher = new FirstPairMatcher(); break; // Determine and initialize a Conservative/Greedy-Heuristic Packet Matcher case MatchingAlgorithm.CONSERVATIVE: case MatchingAlgorithm.GREEDY_HEURISTIC: { algorithmWasChanged = true; string input = ""; bool validInput = false; double tg = 0; do { // Ask user for time gap allowed between Send Packets Tools.TextInput ti = new Tools.TextInput("Enter acceptable send packet time difference[in milliseconds]: "); // Set the form's title ti.Text = "Set Time Difference Threshold"; // show the form to user ti.ShowDialog(); // gather their inputted value input = ti.InputtedText; if (Double.TryParse(input, out tg)) { validInput = true; } // Try to parse the value into a doubleConsole.WriteLine(input); } while (!validInput); Matcher = (algo == MatchingAlgorithm.CONSERVATIVE) ? new ConservativeMatcher(tg) : new GreedyHeuristicPacketMatcher(tg); } break; } } else { algorithmWasChanged = false; } // return the boolean and packet matcher return(Tuple.Create(algorithmWasChanged, matcher)); }
public PacketMatchingFormController() { Matcher = new FirstPairMatcher(); }