Ejemplo n.º 1
0
        private static (ICollection <ReadPlcItemWrapper> Mapping, AGL4.DATA_RW40[] AllAgLinkItems) CreateMappingAndAgLinkItems(ICollection <IPlcItem> plcItems, PlcItemUsageType usageType)
        {
            var mapping = plcItems
                          .Select(plcItem => new ReadPlcItemWrapper(plcItem))
                          .ToArray()
            ;

            // Create all needed AGLink items.
            //! Directly storing the AGLink items in the ReadPlcItemWrapper instance won't work, as AGL4.DATA_RW40 is a struct that would consequently be copied on assignment.
            //! Therefore the ReadPlcItemWrapper only contains the start position and the amount of items in the returned AGLink items array.
            var previousAmount = 0;
            var allAgLinkItems = mapping
                                 .SelectMany
                                 (
                readPlcItemWrapper =>
            {
                var agLinkItems = AgLinkPlc.CreateAgLinkItems(readPlcItemWrapper.PlcItem, usageType).ToArray();

                readPlcItemWrapper.Start  = (previousAmount += agLinkItems.Length) - 1;
                readPlcItemWrapper.Amount = agLinkItems.Length;

                return(agLinkItems);
            }
                                 )
                                 .ToArray()
            ;

            return(mapping, allAgLinkItems);
        }