private void ConnectSniffer_OnClick(object sender, RoutedEventArgs e) { if (sender == connectSniffer) { if (connectSniffer.IsChecked) { // can only attach sniffer to receiver if receiver object exists if (audysseyMultEQAvr == null) { // create receiver instance audysseyMultEQAvr = new AudysseyMultEQAvr(); // create adapter to interface MultEQAvr properties as if they were MultEQApp properties audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr); // data Binding to adapter if ((tabControl.SelectedIndex == 0) && (audysseyMultEQApp == null)) { this.DataContext = audysseyMultEQAvrAdapter; } if (tabControl.SelectedIndex == 1) { this.DataContext = audysseyMultEQAvr; } } // sniffer must be elevated to capture raw packets if (!IsElevated()) { // we cannot create the sniffer... connectSniffer.IsChecked = false; // but we can ask the user to elevate the program! RunAsAdmin(); } else { // onyl create sniffer if it not already exists if (audysseyMultEQTcpSniffer == null) { // create sniffer attached to receiver audysseyMultEQTcpSniffer = new AudysseyMultEQTcpSniffer(audysseyMultEQAvr, cmbInterfaceHost.SelectedItem.ToString(), cmbInterfaceClient.SelectedItem.ToString()); } } } else { if (audysseyMultEQTcpSniffer != null) { audysseyMultEQTcpSniffer = null; // if not interested in receiver then close connection and delete objects if (connectReceiver.IsChecked == false) { this.DataContext = null; audysseyMultEQAvrAdapter = null; audysseyMultEQAvr = null; } // immediately clean up the object GC.Collect(); GC.WaitForPendingFinalizers(); } } } }
private void ParseFileToAudysseyMultEQAvr(string FileName) { if (File.Exists(FileName)) { string Serialized = File.ReadAllText(FileName); audysseyMultEQAvr = JsonConvert.DeserializeObject <AudysseyMultEQAvr>(Serialized, new JsonSerializerSettings { }); if (audysseyMultEQAvrAdapter == null) { audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr); } } }
private void ConnectReceiver_OnClick(object sender, RoutedEventArgs e) { if (sender == connectReceiver) { if (connectReceiver.IsChecked) { if (string.IsNullOrEmpty(cmbInterfaceClient.Text)) { System.Windows.MessageBox.Show("Please enter receiver IP address."); } else { // if there is no Tcp client if (audysseyMultEQAvrTcp == null) { // create receiver instance if (audysseyMultEQAvr == null) { audysseyMultEQAvr = new AudysseyMultEQAvr(); } // create receiver tcp instance audysseyMultEQAvrTcp = new AudysseyMultEQAvrTcp(audysseyMultEQAvr, cmbInterfaceClient.Text); // create adapter to interface MultEQAvr properties as if they were MultEQApp properties if (audysseyMultEQAvrAdapter == null) { audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr); } // data Binding to adapter if ((tabControl.SelectedIndex == 0) && (audysseyMultEQApp == null)) { this.DataContext = audysseyMultEQAvrAdapter; } if (tabControl.SelectedIndex == 1) { this.DataContext = audysseyMultEQAvr; } } audysseyMultEQAvrTcp.Connect(); // attach sniffer if (connectSniffer.IsChecked) { // sniffer must be elevated to capture raw packets if (!IsElevated()) { // we cannot create the sniffer... connectSniffer.IsChecked = false; // but we can ask the user to elevate the program! RunAsAdmin(); } else { if (audysseyMultEQTcpSniffer == null) { audysseyMultEQTcpSniffer = new AudysseyMultEQTcpSniffer(audysseyMultEQAvr, cmbInterfaceHost.SelectedItem.ToString(), cmbInterfaceClient.SelectedItem.ToString()); } } } } } else { audysseyMultEQAvrAdapter = null; audysseyMultEQAvrTcp = null; audysseyMultEQAvr = null; // immediately clean up the object GC.Collect(); GC.WaitForPendingFinalizers(); this.DataContext = null; } } }