private void Window_Loaded(object sender, RoutedEventArgs e) { this.Title = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " - " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; IPHostEntry host; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily.ToString() == "InterNetwork") { if (ip.AddressFamily == AddressFamily.InterNetwork) { comboBoxIp.Items.Add(ip.ToString()); } } } commands = new ConcurrentDictionary<string, string[]>(); meitrackTcpManager = new MeitrackTcpManager(); meitrackTcpManager.Event += MeitrackTcpManager_Event; meitrackTcpManager.DataReceived += MeitrackTcpManager_DataReceived; meitrackTcpManager.BufferOut = commands; tqatCommandTcpManager = new TqatCommandTcpManager(); tqatCommandTcpManager.Event += TqatCommandTcpManager_Event; ; tqatCommandTcpManager.DataReceived += TqatCommandTcpManager_DataReceived; }
private void initializedTcpManagers () { tcpManagers = new ConcurrentDictionary<long, TcpManager>(); StringCollection servers = Settings.Default.Servers; Int32 id = 0; foreach (string server in servers) { string[] attributes = server.Split(','); string[] device = attributes[0].Split('|'); id++; if (device[0] == "Meitrack") { if (device[1] == "Mvt100") { MeitrackTcpManager meitrackMvt100 = new MeitrackTcpManager(); meitrackMvt100.Id = id; meitrackMvt100.Device = new Device { Company = "Meitrack", Name = "Mvt100" }; meitrackMvt100.IpAddress = attributes[1]; meitrackMvt100.Port = Int32.Parse(attributes[2]); meitrackMvt100.IsEnabled = attributes[3] == "0" ? false : true; listViewTcpManagersSetup.Items.Add(meitrackMvt100); } if (device[1] == "T1") { MeitrackTcpManager meitractTcpManagerT1 = new MeitrackTcpManager(); meitractTcpManagerT1.Id = id; meitractTcpManagerT1.Device = new Device { Company = "Meitrack", Name = "T1" }; meitractTcpManagerT1.IpAddress = attributes[1]; meitractTcpManagerT1.Port = Int32.Parse(attributes[2]); meitractTcpManagerT1.IsEnabled = attributes[3] == "0" ? false : true; listViewTcpManagersSetup.Items.Add(meitractTcpManagerT1); } } else if (device[0] == "Teltonika") { if (device[1] == "FM1100") { TeltonikaTcpManager teltonikaTcpManager = new TeltonikaTcpManager(); teltonikaTcpManager.Id = id; teltonikaTcpManager.Device = new Device { Company = "Teltonika", Name = "FM1100" }; teltonikaTcpManager.IpAddress = attributes[1]; teltonikaTcpManager.Port = Int32.Parse(attributes[2]); teltonikaTcpManager.IsEnabled = attributes[3] == "0" ? false : true; listViewTcpManagersSetup.Items.Add(teltonikaTcpManager); } } else if (device[0] == "Ats") { if (device[1] == "Command") { TqatCommandTcpManager tqatCommandTcpManager = new TqatCommandTcpManager(); tqatCommandTcpManager.Id = id; tqatCommandTcpManager.Device = new Device { Company = "Ats", Name = "Command" }; tqatCommandTcpManager.IpAddress = attributes[1]; tqatCommandTcpManager.Port = Int32.Parse(attributes[2]); tqatCommandTcpManager.IsEnabled = attributes[3] == "0" ? false : true; listViewTcpManagersSetup.Items.Add(tqatCommandTcpManager); } } } }
private void buttonAdd_Click (object sender, RoutedEventArgs e) { //validation var company = ((ComboBoxItem)comboBoxCompany.SelectedItem).Content; var device = (String)(comboBoxDevice.SelectedItem); var ip = ((String)comboBoxIp.SelectedItem); var port = ((String)textBoxPort.Text); var isEnabled = checkBoxEnabled.IsChecked; if (String.IsNullOrEmpty((String)company)) { MessageBox.Show("Company is Empty", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(device)) { MessageBox.Show("Device is Empty", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(ip)) { MessageBox.Show("Ip is Empty", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (String.IsNullOrEmpty(port)) { MessageBox.Show("Port is Empty", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } TcpManager tcpManager = null; if ((String)company == "Meitrack") { tcpManager = new MeitrackTcpManager() { Device = new Device() { Company = (String)company, Name = (String)device }, IpAddress = (String)ip, Port = Int32.Parse((String)port), IsEnabled = (bool)isEnabled }; } else if ((String)company == "Ats") { if ((String)device == "Command") { tcpManager = new TqatCommandTcpManager() { Device = new Device() { Company = (String)company, Name = (String)device }, IpAddress = (String)ip, Port = Int32.Parse((String)port), IsEnabled = (bool)isEnabled }; } } else if ((String)company == "Teltonika") { if ((String)device == "FM1100") { tcpManager = new TqatCommandTcpManager() { Device = new Device() { Company = (String)company, Name = (String)device }, IpAddress = (String)ip, Port = Int32.Parse((String)port), IsEnabled = (bool)isEnabled }; } } this.Tag = tcpManager; this.Close(); }