public override _SubDevice Extend()
            {
                UInt64?Den;

                if (BytesTotalPersec.AsString() != null)
                {
                    Den = BytesTotalPersec.AsUInt64() / 100;

                    if (Den != 0)
                    {
                        UInt64?percentBytesReceived = BytesReceivedPersec.AsString() != null?BytesReceivedPersec.AsUInt64() / Den : null;

                        PercentBytesReceived = new MobProperty(percentBytesReceived);
                        UInt64?percentBytesSent = BytesSentPersec.AsString() != null?BytesSentPersec.AsUInt64() / Den : null;

                        PercentBytesSent = new MobProperty(percentBytesSent);
                    }
                    else
                    {
                        PercentBytesReceived = new MobProperty("0");
                        PercentBytesSent     = new MobProperty("0");
                    }
                }
                else
                {
                    PercentBytesReceived = new MobProperty(null);
                    PercentBytesSent     = new MobProperty(null);
                }

                if (PacketsPersec.AsString() != null)
                {
                    Den = PacketsPersec.AsUInt64() / 100;
                    if (Den != 0)
                    {
                        UInt64?percentPacketsReceived = PacketsReceivedPersec.AsString() != null?PacketsReceivedPersec.AsUInt64() / Den : null;

                        PercentPacketsReceived = new MobProperty(percentPacketsReceived);
                        UInt64?percentPacketsSents = PacketsSentPersec.AsString() != null?PacketsSentPersec.AsUInt64() / Den : null;

                        PercentPacketsSents = new MobProperty(percentPacketsSents);
                    }
                    else
                    {
                        PercentPacketsSents    = new MobProperty("0");
                        PercentPacketsReceived = new MobProperty("0");
                    }
                }
                else
                {
                    PercentPacketsReceived = new MobProperty(null);
                    PercentPacketsSents    = new MobProperty(null);
                }

                var mjx = new WprManagementObjectSearcher("Win32_PerfRawData_Tcpip_NetworkAdapter").First(x => x.GetProperty("Name").AsString().Equals(Name.AsString())) ?? new WprManagementObject();

                TotalBytesReceived = mjx.GetProperty("BytesReceivedPersec");
                TotalBytesSent     = mjx.GetProperty("BytesSentPersec");
                TotalBytes         = mjx.GetProperty("BytesTotalPersec");

                return(this);
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Return passed "Value", "Default" string elsewhere
 /// </summary>
 /// <param name="Value"></param>
 /// <param name="Default"></param>
 /// <returns></returns>
 public static String AsDefaultValue(MobProperty Value, String Default)
 {
     return((Value == null || Value.IsNull) ? Default : Value.AsString());
 }