static RecordTypeRegister()
        {
            // FlowKey
            var flowKey = new RecordMemberInfo[]
            {
                new RecordMemberInfo(nameof(FlowKey.ProtocolType), typeof(int), obj => (int)((obj as FlowKey).ProtocolType)),
                new RecordMemberInfo(nameof(FlowKey.SourceIpAddress), typeof(string), obj => (obj as FlowKey).SourceIpAddress.ToString()),
                new RecordMemberInfo(nameof(FlowKey.SourcePort), typeof(ushort), obj => (obj as FlowKey).SourcePort),
                new RecordMemberInfo(nameof(FlowKey.DestinationIpAddress), typeof(string), obj => (obj as FlowKey).DestinationIpAddress.ToString()),
                new RecordMemberInfo(nameof(FlowKey.DestinationPort), typeof(ushort), obj => (obj as FlowKey).DestinationPort)
            };

            RegisterRecordType(typeof(FlowKey), flowKey);
            var ethPacket = new RecordMemberInfo[]
            {
                new RecordMemberInfo(nameof(EthernetPacket.SourceHardwareAddress), typeof(string), obj => (obj as EthernetPacket).SourceHardwareAddress.ToString()),
                new RecordMemberInfo(nameof(EthernetPacket.DestinationHardwareAddress), typeof(string), obj => (obj as EthernetPacket).DestinationHardwareAddress.ToString()),
                new RecordMemberInfo(nameof(EthernetPacket.Type), typeof(int), obj => (int)((obj as EthernetPacket).Type)),
                new RecordMemberInfo(nameof(EthernetPacket.TotalPacketLength), typeof(int), obj => (obj as EthernetPacket).TotalPacketLength),
            };

            RegisterRecordType(typeof(FlowKey), ethPacket);
            // IPPacket
            var ipPacket = new RecordMemberInfo[]
            {
                new RecordMemberInfo(nameof(IPPacket.Version), typeof(int), obj => (obj as IPPacket).Version),
                new RecordMemberInfo(nameof(IPPacket.SourceAddress), typeof(string), obj => (obj as IPPacket).SourceAddress.ToString()),
                new RecordMemberInfo(nameof(IPPacket.DestinationAddress), typeof(string), obj => (obj as IPPacket).DestinationAddress.ToString()),
                new RecordMemberInfo(nameof(IPPacket.TotalPacketLength), typeof(int), obj => (obj as IPPacket).TotalPacketLength),
                new RecordMemberInfo(nameof(IPPacket.Protocol), typeof(int), obj => (int)((obj as IPPacket).Protocol)),
                new RecordMemberInfo(nameof(IPPacket.TimeToLive), typeof(int), obj => (obj as IPPacket).TimeToLive),
            };

            RegisterRecordType(typeof(IPPacket), ipPacket);
        }
Пример #2
0
        /// <summary>
        /// Gets a single column of <see cref="DataFrame"/> including all associated values.
        /// <para/>
        /// As the column can only be primitive type, the method performs necessary conversions.
        /// </summary>
        /// <param name="name">The column name.</param>
        /// <param name="columnType">The column type.</param>
        /// <param name="values">The collection of values that must be of the <paramref name="columnType"/>.</param>
        /// <returns>The new <see cref="DataFrameColumn"/>for the parameters specified.</returns>
        public static DataFrameColumn CreateColumn(RecordMemberInfo member, IEnumerable values)
        {
            var columnType = member.Type;
            var name       = member.Name;

            if (columnType == typeof(bool))
            {
                return(new PrimitiveDataFrameColumn <bool>(name, values.Cast <bool>()));
            }
            else if (columnType == typeof(byte))
            {
                return(new PrimitiveDataFrameColumn <byte>(name, values.Cast <byte>()));
            }
            else if (columnType == typeof(sbyte))
            {
                return(new PrimitiveDataFrameColumn <sbyte>(name, values.Cast <sbyte>()));
            }
            else if (columnType == typeof(short))
            {
                return(new PrimitiveDataFrameColumn <short>(name, values.Cast <short>()));
            }
            else if (columnType == typeof(ushort))
            {
                return(new PrimitiveDataFrameColumn <ushort>(name, values.Cast <ushort>()));
            }
            else if (columnType == typeof(int))
            {
                return(new PrimitiveDataFrameColumn <int>(name, values.Cast <int>()));
            }
            else if (columnType == typeof(uint))
            {
                return(new PrimitiveDataFrameColumn <uint>(name, values.Cast <uint>()));
            }
            else if (columnType == typeof(long))
            {
                return(new PrimitiveDataFrameColumn <long>(name, values.Cast <long>()));
            }
            else if (columnType == typeof(ulong))
            {
                return(new PrimitiveDataFrameColumn <ulong>(name, values.Cast <ulong>()));
            }
            else if (columnType == typeof(IntPtr))
            {
                return(new PrimitiveDataFrameColumn <long>(name, values.Cast <IntPtr>().Select(p => p.ToInt64())));
            }
            else if (columnType == typeof(UIntPtr))
            {
                return(new PrimitiveDataFrameColumn <ulong>(name, values.Cast <UIntPtr>().Select(p => p.ToUInt64())));
            }
            else if (columnType == typeof(char))
            {
                return(new PrimitiveDataFrameColumn <char>(name, values.Cast <char>()));
            }
            else if (columnType == typeof(double))
            {
                return(new PrimitiveDataFrameColumn <double>(name, values.Cast <double>()));
            }
            else if (columnType == typeof(float))
            {
                return(new PrimitiveDataFrameColumn <float>(name, values.Cast <float>()));
            }
            else if (columnType == typeof(DateTime))
            {
                return(new PrimitiveDataFrameColumn <long>(name, values.Cast <DateTime>().Select(d => d.Ticks)));
            }
            else if (columnType == typeof(string))
            {
                return(new StringDataFrameColumn(name, values.Cast <string>()));
            }
            else
            {
                return(new StringDataFrameColumn(name, values.Cast <object>().Select(x => x.ToString())));
            }
        }
Пример #3
0
 public void AddColumn(RecordMemberInfo member, IEnumerable values)
 {
     _columns.Add(CreateColumn(member, values));
 }