private static int CompareByControllerName(IoSystemLevel x, IoSystemLevel y) { if (x == null) { if (y == null) { return(0); } else { return(-1); } } else { if (y == null) // ...and y is null, x is greater. { return(1); } else { // ...and y is not null, compare the // lengths of the two strings. return(x.IoController.HMName.CompareTo(y.IoController.HMName)); //int retval = x.Length.CompareTo(y.Length); } } }
private static string CreateCSVRecord(NetworkDeviceItem netDeviceItem, IoSystemLevel ioSystemLevel) { string deviceName = netDeviceItem.HMName; string ipAddress = netDeviceItem.IpAddress; string addressMask = netDeviceItem.AddressMask; string pnDeviceName = netDeviceItem.PnDeviceName; string interfaceOperatingMode = netDeviceItem.InterfaceOperatingMode; string subnetName = netDeviceItem.PnSubnetName ?? "[Not connected]"; string ioSystemName = ioSystemLevel?.IoSystemName ?? "[Not connected]"; string pnDeviceNumber = netDeviceItem.PnDeviceNumber ?? "[N/A]"; string routerAddress = netDeviceItem.RouterAddress ?? "[Not used]"; bool autoPnName = netDeviceItem.autoGeneratePnName; string record = "" + interfaceOperatingMode + ";" + deviceName + ";" + autoPnName.ToString() + ";" + pnDeviceName + ";" + pnDeviceNumber + ";" + ipAddress + ";" + addressMask + ";" + routerAddress + ";" + subnetName + ";" + ioSystemName; return(record); }
public static async Task <IoSystemLevel> Create(IoSystem iosystem, SubnetLevel subnetLevel) { var ret = new IoSystemLevel(iosystem, subnetLevel); await ret.PopulateIoSystemLvl().ConfigureAwait(false); return(ret); }
private NetworkDeviceItem(DeviceItem di, Node node, NetworkDeviceItemLevel ndil, NetworkDeviceItemWorkMode workMode, SubnetLevel subnetLevel, IoSystemLevel ioSystemLevel) { this.itemLevel = ndil; this.deviceItem = di; this.node = node; this.IoSystemLevel = ioSystemLevel; this.SubnetLevel = subnetLevel; this.workMode = workMode; }
private static int CompareByControllerIpAddress(IoSystemLevel x, IoSystemLevel y) { if (x == null) { if (y == null) { return(0); } else { return(-1); // y is greater. } } else { // If x is not null... if (y == null) // ...and y is null, x is greater. { return(1); } else { // x and y exist but check if they have ip addresses if (String.IsNullOrEmpty(x.IoController.IpAddress)) { if (String.IsNullOrEmpty(y.IoController.IpAddress)) { return(0); } else { return(-1); // y.address is greater. } } else { if (String.IsNullOrEmpty(y.IoController.IpAddress)) { return(1); } else { // they both have ip addresses return(x.IoController.IpAddress.CompareTo(y.IoController.IpAddress)); } } } } }
private DataGridViewRow IoControllerRow(IoSystemLevel ioSystem) { var ioControllerRow = DeviceRowsHelper.InitializeRow(ID.NextID, ioSystem.IoController, ioSystem, deviceTable); var cells = ioControllerRow.Cells; var deviceNameCell = cells[dgv_DeviceName.Index]; DeviceRowsHelper.PadCell(deviceNameCell, 0); DeviceRowsHelper.DisableCell(cells[dgv_PnNumber.Index]); if (!ioSystem.IoController.UseRouter) { DeviceRowsHelper.DisableCell(cells[dgv_RouterAddress.Index]); } return(ioControllerRow); }
private DataGridViewRow IoDeviceRow(NetworkDeviceItem ioDevice, IoSystemLevel ioSystem) { var ioDeviceRow = DeviceRowsHelper.InitializeRow(ID.NextID, ioDevice, ioSystem, deviceTable); var cells = ioDeviceRow.Cells; var deviceNameCell = cells[dgv_DeviceName.Index]; DeviceRowsHelper.PadCell(deviceNameCell, 25); DeviceRowsHelper.DisableCells(cells[dgv_IoSystem.Index], cells[dgv_PnSubnet.Index], cells[dgv_RouterAddress.Index], cells[dgv_Mask.Index]); if (string.IsNullOrEmpty(cells[dgv_IpAddress.Index].Value?.ToString())) // empty in future? { DeviceRowsHelper.DisableCell(cells[dgv_IpAddress.Index]); } return(ioDeviceRow); }
public static async Task <SubnetLevel> Create(Subnet subnet) { var ret = new SubnetLevel(subnet); ret.SubnetLvlDevItems = await ret.FindDevItemsWithoutIoSystem().ConfigureAwait(false); // create subnet builder so it can be multitasked var ioSystemTasks = new List <Task <IoSystemLevel> >(); foreach (IoSystem anyIoSystem in subnet.IoSystems) { // maybe check IoSystem type instead of node type? // should work NetworkInterface controllerNetInterface = (NetworkInterface)anyIoSystem.Parent.Parent; string ioSystemType = controllerNetInterface.GetAttribute("InterfaceType").ToString(); if (!ioSystemType.Equals("Ethernet")) { continue; } ioSystemTasks.Add(IoSystemLevel.Create(anyIoSystem, ret)); } ret.IoSystems.AddRange(await Task.WhenAll(ioSystemTasks).ConfigureAwait(false)); return(ret); }
private static int CompareByControllerIpAddressRev(IoSystemLevel x, IoSystemLevel y) { return(-1 * CompareByControllerIpAddress(x, y)); }
private static int CompareByControllerNameRev(IoSystemLevel x, IoSystemLevel y) { return(-1 * CompareByControllerName(x, y)); }
public static async Task <NetworkDeviceItem> Create(DeviceItem di, NetworkDeviceItemLevel ndil, //ndil will be unnecessary now when ndi references levels NetworkDeviceItemWorkMode workMode, SubnetLevel subnetLevel, IoSystemLevel ioSystemLevel) { NetworkInterface ni = ((IEngineeringServiceProvider)di).GetService <NetworkInterface>(); if (ni == null) { return(null); } Node node = ni.Nodes[0]; // This hack is for distinguishing between HMI and Ethernet Commissioning device. // The proper way would be to find some attribute that differentiates them but I could not find any // You could check for existence of any profinet attribute but GetAttributeInfos is **HEAVY** if (ni.IoConnectors.Count == 0 && ni.IoControllers.Count == 0) { try { node.GetAttribute("PnDeviceNameAutoGeneration"); } catch { return(null); } } string nodeType = node.GetAttribute("NodeType").ToString(); if (!nodeType.Equals("Ethernet")) { return(null); } var ndi = new NetworkDeviceItem(di, node, ndil, workMode, subnetLevel, ioSystemLevel); await ndi.UpdateAllParameters().ConfigureAwait(false); return(ndi); }
public static DataGridViewRow InitializeRow(int Id, NetworkDeviceItem netDeviceItem, IoSystemLevel ioSystemLevel, DataGridView dgvWithExpectedStyle) { DeviceRowsHelper.DeviceByRowID.Add(Id, netDeviceItem); DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dgvWithExpectedStyle); row.SetValues(CreateRecord(Id, netDeviceItem, ioSystemLevel)); return(row); }
private static string[] CreateRecord(int Id, NetworkDeviceItem netDeviceItem, IoSystemLevel ioSystemLevel) { //IoSystemLevel ioSystemLevel_proper = netDeviceItem.IoSystemLevel; // work on that string deviceName = netDeviceItem.HMName; string ipAddress = netDeviceItem.IpAddress ?? ""; string addressMask = netDeviceItem.AddressMask ?? ""; string pnDeviceName = netDeviceItem.PnDeviceName ?? ""; string interfaceOperatingMode = netDeviceItem.InterfaceOperatingMode; string subnetName = netDeviceItem.PnSubnetName ?? "[Not connected]"; string ioSystemName = ioSystemLevel?.IoSystemName ?? "[Not connected]"; string pnDeviceNumber = netDeviceItem.PnDeviceNumber ?? "[N/A]"; string routerAddress = netDeviceItem.RouterAddress ?? "[Not used]"; bool autoPnName = netDeviceItem.autoGeneratePnName; string[] record = new string[] { Id.ToString(), interfaceOperatingMode, deviceName, autoPnName.ToString(), pnDeviceName, pnDeviceNumber, ipAddress, addressMask, routerAddress, subnetName, ioSystemName, }; return(record); }