public DeviceConnectView() { InitializeComponent(); var searcher = DeviceSearcher.GetSearcher(); searcher.Search(); devicesList.ItemsSource = new ObservableCollection <Model.Device>(searcher.Devices); if (connection != null) { devicesList.IsEnabled = false; } }
private void btnSearch_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; grid.Rows.Clear(); List <ParkDevice> devices = DeviceSearcher.EnumAllParkDevices(); if (devices != null && devices.Count > 0) { foreach (ParkDevice device in devices) { int row = grid.Rows.Add(); grid.Rows[row].Tag = device; Ralid.Park.Hardware.DeviceInfo deviceInfo; if (device.GetDeviceInfo(out deviceInfo)) { grid.Rows[row].Cells["colSerialNum"].Value = deviceInfo.StrSerialNum; } grid.Rows[row].Cells["colIP"].Value = device.LANInfo.IPAddress; grid.Rows[row].Cells["colMAC"].Value = device.LANInfo.MACAddress; } } this.Cursor = Cursors.Arrow; }
private void ImportExcelData() { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Excel Files | *.xlsx";; if (openFileDialog.ShowDialog() == true) { IList <DeviceExcelData> deviceExcelDatas = ExcelPackageExporter.ImportDeviceExcelStream(openFileDialog.FileName); int currentCount = 0; int maxCount = 100; foreach (var excelData in deviceExcelDatas) { DeviceModel item = this.Devices.Where(x => x.PhysicalAddress.ToUpper() == excelData.PhysicalAddress.ToUpper()).SingleOrDefault(); if (item == null) { continue; } NetworkAddress networkAddress = new NetworkAddress() { AddressingType = Boolean2ChineseConverter.GetBoolean(excelData.DHCP) ? Howell.Industry.NetworkAddressingType.Dynamic : Howell.Industry.NetworkAddressingType.Static, HttpPort = item.NetworkDeviceInformation.HttpPort, IPAddress = item.NetworkDeviceInformation.NetworkInterface.IPAddress, Port = item.NetworkDeviceInformation.Port, }; if (excelData.Port > 0 && excelData.Port <= 65535) { networkAddress.Port = excelData.Port; } if (String.IsNullOrEmpty(excelData.IPAddress) == false && excelData.IPAddress != "0.0.0.0") { networkAddress.IPAddress.IPv4Address.Address = excelData.IPAddress; } if (String.IsNullOrEmpty(excelData.SubnetMask) == false && excelData.SubnetMask != "0.0.0.0") { networkAddress.IPAddress.IPv4Address.Subnetmask = excelData.SubnetMask; } if (String.IsNullOrEmpty(excelData.Gateway) == false && excelData.Gateway != "0.0.0.0") { networkAddress.IPAddress.IPv4Address.DefaultGateway = excelData.Gateway; } if (String.IsNullOrEmpty(excelData.Password) == false) { item.Password = excelData.Password; } if (String.IsNullOrEmpty(excelData.Username) == false) { item.Username = excelData.Username; } if (FactoryType == "Howell8000") { //必须使用原始的MAC地址,区分大小写 DeviceSearcher.SetNetworkAddress(item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress, excelData.Password, networkAddress); } else { DeviceSearcher.SetNetworkAddress(networkAddress.IPAddress.IPv4Address.Address, networkAddress.IPAddress.IPv4Address.Subnetmask, networkAddress.IPAddress.IPv4Address.DefaultGateway, networkAddress.Port, item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress); } item.IPAddress = networkAddress.IPAddress.IPv4Address.Address; item.SubnetMask = networkAddress.IPAddress.IPv4Address.Subnetmask; item.Gateway = networkAddress.IPAddress.IPv4Address.DefaultGateway; item.Port = networkAddress.Port; item.DHCP = (networkAddress.AddressingType == Howell.Industry.NetworkAddressingType.Dynamic); } System.Threading.Thread.Sleep(2000); foreach (var excelData in deviceExcelDatas) { DeviceModel item = this.Devices.Where(x => x.PhysicalAddress.ToUpper() == excelData.PhysicalAddress.ToUpper()).SingleOrDefault(); if (item == null) { continue; } do { if (currentCount < maxCount) { Interlocked.Increment(ref currentCount); Task task = Task.Run(() => { try { NetworkDeviceHelper.SetOSDName(item, excelData.Name); item.Name = excelData.Name; item.SettingSucceed = true; } catch (Exception ex) { item.SettingSucceed = false; Helper.Logger.Error(String.Format("SetOSDName error, DeviceIP:{0}", item.IPAddress), ex); } }) .ContinueWith(x => { Interlocked.Decrement(ref currentCount); }); break; } System.Threading.Thread.Sleep(100); } while (true); } while (currentCount > 0) { System.Threading.Thread.Sleep(100); } this.ShowMessageAsync("导入数据完成", null); } } catch (Exception ex) { Helper.Logger.Error("导入数据失败", ex); this.ShowMessageAsync("导入数据失败", ex.Message); } }
private void SetDeviceIP() { try { //批量修改IP地址 if (DeviceIPSetting.No == "N/A") { ValidationResult result = DeviceIPSetting.Validate(); if (result.IsValid == false) { this.ShowMessageAsync("参数错误", result.ErrorContent.ToString()); return; } UInt32 ipAddress = System.Net.IPAddress.Parse(DeviceIPSetting.IPAddress).ToUInt32(); DeviceModel[] deviceModels = this.Devices.Where(x => x.IsSelected).ToArray(); foreach (var item in deviceModels) { NetworkAddress networkAddress = new NetworkAddress() { AddressingType = DeviceIPSetting.DHCP ? Howell.Industry.NetworkAddressingType.Dynamic : Howell.Industry.NetworkAddressingType.Static, HttpPort = item.NetworkDeviceInformation.HttpPort, IPAddress = item.NetworkDeviceInformation.NetworkInterface.IPAddress, Port = DeviceIPSetting.Port, }; if (ipAddress != 0) { //ipAddress = ipAddress.GetAddressBytes(); networkAddress.IPAddress.IPv4Address.Address = ipAddress.ToIPAddress().ToString(); ++ipAddress; } if (DeviceIPSetting.SubnetMask != "0.0.0.0") { networkAddress.IPAddress.IPv4Address.Subnetmask = DeviceIPSetting.SubnetMask; } if (DeviceIPSetting.Gateway != "0.0.0.0") { networkAddress.IPAddress.IPv4Address.DefaultGateway = DeviceIPSetting.Gateway; } if (FactoryType == "Howell8000") { //必须使用原始的MAC地址,区分大小写 DeviceSearcher.SetNetworkAddress(item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress, DeviceIPSetting.Password, networkAddress); } else { DeviceSearcher.SetNetworkAddress(networkAddress.IPAddress.IPv4Address.Address, networkAddress.IPAddress.IPv4Address.Subnetmask, networkAddress.IPAddress.IPv4Address.DefaultGateway, networkAddress.Port, item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress); } item.IPAddress = networkAddress.IPAddress.IPv4Address.Address; item.SubnetMask = networkAddress.IPAddress.IPv4Address.Subnetmask; item.Gateway = networkAddress.IPAddress.IPv4Address.DefaultGateway; item.Port = networkAddress.Port; item.DHCP = (networkAddress.AddressingType == Howell.Industry.NetworkAddressingType.Dynamic); } this.ShowMessageAsync("修改IP地址成功", null).ContinueWith(x => { //成功后,关闭悬浮窗口 ThreadStart threadStart = () => { ToggleFlyout(0); }; Application.Current.Dispatcher.BeginInvoke(threadStart); }); return; } else { DeviceModel item = this.Devices.Where(x => x.IsSelected).FirstOrDefault(); if (item == null) { this.ShowMessageAsync("没有任何选中项", null); return; } ValidationResult result = DeviceIPSetting.Validate(); if (result.IsValid == false) { this.ShowMessageAsync("参数错误", result.ErrorContent.ToString()); return; } NetworkAddress networkAddress = new NetworkAddress() { AddressingType = DeviceIPSetting.DHCP ? Howell.Industry.NetworkAddressingType.Dynamic : Howell.Industry.NetworkAddressingType.Static, HttpPort = item.NetworkDeviceInformation.HttpPort, IPAddress = item.NetworkDeviceInformation.NetworkInterface.IPAddress, Port = DeviceIPSetting.Port, }; networkAddress.IPAddress.IPv4Address.Address = DeviceIPSetting.IPAddress; networkAddress.IPAddress.IPv4Address.DefaultGateway = DeviceIPSetting.Gateway; networkAddress.IPAddress.IPv4Address.Subnetmask = DeviceIPSetting.SubnetMask; if (FactoryType == "Howell8000") { //必须使用原始的MAC地址,区分大小写 DeviceSearcher.SetNetworkAddress(item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress, DeviceIPSetting.Password, networkAddress); } else { DeviceSearcher.SetNetworkAddress(networkAddress.IPAddress.IPv4Address.Address, networkAddress.IPAddress.IPv4Address.Subnetmask, networkAddress.IPAddress.IPv4Address.DefaultGateway, networkAddress.Port, item.NetworkDeviceInformation.NetworkInterface.PhyscialAddress); } item.IPAddress = networkAddress.IPAddress.IPv4Address.Address; item.SubnetMask = networkAddress.IPAddress.IPv4Address.Subnetmask; item.Gateway = networkAddress.IPAddress.IPv4Address.DefaultGateway; item.Port = networkAddress.Port; item.DHCP = (networkAddress.AddressingType == Howell.Industry.NetworkAddressingType.Dynamic); if (DeviceIPSetting.OSDNameEnabled) { NetworkDeviceHelper.SetOSDName(item, DeviceIPSetting.OSDName); item.Name = DeviceIPSetting.OSDName; } this.ShowMessageAsync("修改IP地址成功", null).ContinueWith(x => { //成功后,关闭悬浮窗口 ThreadStart threadStart = () => { ToggleFlyout(0); }; Application.Current.Dispatcher.BeginInvoke(threadStart); }); } } catch (Exception ex) { Helper.Logger.Error(String.Format("设置IP地址失败, No:{0},IP:{1}", DeviceIPSetting.No, DeviceIPSetting.IPAddress), ex); this.ShowMessageAsync("修改IP失败", ex.Message); } }