Exemple #1
0
        public static async Task AddSubnetAndUsedDevices(ProjectLevel pl, Subnet subnet, List <Device> usedDevices)
        {
            SubnetLevel subnetlevel = await SubnetLevel.Create(subnet).ConfigureAwait(false);

            pl.Subnets.Add(subnetlevel);
            usedDevices.AddRange(subnetlevel.GetDevices());
        }
Exemple #2
0
 private static int CompareByName(SubnetLevel x, SubnetLevel y)
 {
     if (x == null)
     {
         if (y == null)
         {
             // If x is null and y is null, they're
             // equal.
             return(0);
         }
         else
         {
             // If x is null and y is not null, y
             // is greater.
             return(-1);
         }
     }
     else
     {
         // If x is not null...
         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.SubnetName.CompareTo(y.SubnetName));
         }
     }
 }
        public static async Task <IoSystemLevel> Create(IoSystem iosystem, SubnetLevel subnetLevel)
        {
            var ret = new IoSystemLevel(iosystem, subnetLevel);
            await ret.PopulateIoSystemLvl().ConfigureAwait(false);

            return(ret);
        }
Exemple #4
0
 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;
 }
        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);
        }
Exemple #6
0
 private static int CompareByNameRev(SubnetLevel x, SubnetLevel y)
 {
     return(-1 * CompareByName(x, y));
 }
 private IoSystemLevel(IoSystem iosystem, SubnetLevel subnetLevel)
 {
     this.ioSystem = iosystem;
     IoSystemName  = this.ioSystem.Name;
     SubnetLevel   = subnetLevel;
 }
Exemple #8
0
        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);
        }