本文整理汇总了C#中StringParser.ParseNextInt32方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.ParseNextInt32方法的具体用法?C# StringParser.ParseNextInt32怎么用?C# StringParser.ParseNextInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.ParseNextInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestParserWithNoEndingSeparatorWithNoSkipEmpty
public void TestParserWithNoEndingSeparatorWithNoSkipEmpty()
{
string buffer = ",,Str|ing,,123";
char separator = ',';
StringParser sp = new StringParser(buffer, separator, false);
sp.MoveNextOrFail();
sp.MoveNextOrFail();
Assert.Equal("Str|ing", sp.MoveAndExtractNext());
Assert.Throws<InvalidDataException>(() => sp.ParseNextInt32());
Assert.Equal(123, sp.ParseNextInt32());
}
示例2: CreateUdpIPv6Statistics
public static UdpStatistics CreateUdpIPv6Statistics()
{
LinuxUdpStatistics stats = new LinuxUdpStatistics();
string fileContents = File.ReadAllText(NetworkFiles.SnmpV6StatsFile);
RowConfigReader reader = new RowConfigReader(fileContents);
stats._inDatagrams = reader.GetNextValueAsInt32("Udp6InDatagrams");
stats._noPorts = reader.GetNextValueAsInt32("Udp6NoPorts");
stats._inErrors = reader.GetNextValueAsInt32("Udp6InErrors");
stats._outDatagrams = reader.GetNextValueAsInt32("Udp6OutDatagrams");
stats._rcvbufErrors = reader.GetNextValueAsInt32("Udp6RcvbufErrors");
stats._sndbufErrors = reader.GetNextValueAsInt32("Udp6SndbufErrors");
stats._inCsumErrors = reader.GetNextValueAsInt32("Udp6InCsumErrors");
// Parse the number of active connections out of /proc/net/sockstat6
string sockstatFile = File.ReadAllText(NetworkFiles.Sockstat6File);
int indexOfUdp = sockstatFile.IndexOf("UDP6:");
int endOfUdpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfUdp + 1);
string udpLineData = sockstatFile.Substring(indexOfUdp, endOfUdpLine - indexOfUdp);
StringParser sockstatParser = new StringParser(udpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "UDP6:"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
stats._udpListeners = sockstatParser.ParseNextInt32();
return stats;
}
示例3: CreateUdpIPv4Statistics
public static UdpStatistics CreateUdpIPv4Statistics()
{
LinuxUdpStatistics stats = new LinuxUdpStatistics();
string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
int firstUdpHeader = fileContents.IndexOf("Udp:");
int secondUdpHeader = fileContents.IndexOf("Udp:", firstUdpHeader + 1);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondUdpHeader);
string tcpData = fileContents.Substring(secondUdpHeader, endOfSecondLine - secondUdpHeader);
StringParser parser = new StringParser(tcpData, ' ');
// NOTE: Need to verify that this order is consistent. Otherwise, we need to parse the first-line header
// to determine the order of information contained in the file.
parser.MoveNextOrFail(); // Skip Udp:
stats._inDatagrams = parser.ParseNextInt32();
stats._noPorts = parser.ParseNextInt32();
stats._inErrors = parser.ParseNextInt32();
stats._outDatagrams = parser.ParseNextInt32();
stats._rcvbufErrors = parser.ParseNextInt32();
stats._sndbufErrors = parser.ParseNextInt32();
stats._inCsumErrors = parser.ParseNextInt32();
// Parse the number of active connections out of /proc/net/sockstat
string sockstatFile = File.ReadAllText(NetworkFiles.SockstatFile);
int indexOfUdp = sockstatFile.IndexOf("UDP:");
int endOfUdpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfUdp + 1);
string udpLineData = sockstatFile.Substring(indexOfUdp, endOfUdpLine - indexOfUdp);
StringParser sockstatParser = new StringParser(udpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "UDP:"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
stats._udpListeners = sockstatParser.ParseNextInt32();
return stats;
}
示例4: TestParserWithNoEndingSeparatorWithSkipEmpty
public void TestParserWithNoEndingSeparatorWithSkipEmpty()
{
string buffer = ",,,Str|ing,,123";
char separator = ',';
StringParser sp = new StringParser(buffer, separator, true);
Assert.Equal("Str|ing", sp.MoveAndExtractNext());
Assert.Equal(123, sp.ParseNextInt32());
}
示例5: ParseNumSocketConnections
private static readonly string[] s_newLineSeparator = new string[] { Environment.NewLine }; // Used for string splitting
internal static int ParseNumSocketConnections(string filePath, string protocolName)
{
// Parse the number of active connections out of /proc/net/sockstat
string sockstatFile = File.ReadAllText(filePath);
int indexOfTcp = sockstatFile.IndexOf(protocolName);
int endOfTcpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfTcp + 1);
string tcpLineData = sockstatFile.Substring(indexOfTcp, endOfTcpLine - indexOfTcp);
StringParser sockstatParser = new StringParser(tcpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "<name>:"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
return sockstatParser.ParseNextInt32();
}
示例6: ParseDefaultTtlFromFile
internal static int ParseDefaultTtlFromFile(string filePath)
{
// snmp6 does not include Default TTL info. Read it from snmp.
string snmp4FileContents = File.ReadAllText(filePath);
int firstIpHeader = snmp4FileContents.IndexOf("Ip:", StringComparison.Ordinal);
int secondIpHeader = snmp4FileContents.IndexOf("Ip:", firstIpHeader + 1, StringComparison.Ordinal);
int endOfSecondLine = snmp4FileContents.IndexOf(Environment.NewLine, secondIpHeader, StringComparison.Ordinal);
string ipData = snmp4FileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
StringParser parser = new StringParser(ipData, ' ');
parser.MoveNextOrFail(); // Skip Ip:
// According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
parser.MoveNextOrFail(); // Skip forwarding
return parser.ParseNextInt32();
}
示例7: ParseNumSocketConnections
private static readonly string[] s_newLineSeparator = new string[] { Environment.NewLine }; // Used for string splitting
internal static int ParseNumSocketConnections(string filePath, string protocolName)
{
if (!File.Exists(filePath))
{
throw new PlatformNotSupportedException(SR.net_InformationUnavailableOnPlatform);
}
// Parse the number of active connections out of /proc/net/sockstat
string sockstatFile = File.ReadAllText(filePath);
int indexOfTcp = sockstatFile.IndexOf(protocolName, StringComparison.Ordinal);
int endOfTcpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfTcp + 1, StringComparison.Ordinal);
string tcpLineData = sockstatFile.Substring(indexOfTcp, endOfTcpLine - indexOfTcp);
StringParser sockstatParser = new StringParser(tcpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "<name>:"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
return sockstatParser.ParseNextInt32();
}
示例8: TestParserMoveWithSkipEmpty
public void TestParserMoveWithSkipEmpty()
{
string buffer = "My,, ,Te,,st,Str|ing,,123,,";
char separator = ',';
StringParser sp = new StringParser(buffer, separator, true);
sp.MoveNextOrFail();
Assert.Equal("My", sp.ExtractCurrent());
Assert.Equal(' ', sp.ParseNextChar());
sp.MoveNextOrFail();
Assert.Equal("Te", sp.ExtractCurrent());
Assert.Equal("st", sp.MoveAndExtractNext());
sp.MoveNextOrFail();
Assert.Equal("Str|ing", sp.ExtractCurrent());
Assert.Equal(123, sp.ParseNextInt32());
Assert.Throws<InvalidDataException>(() => sp.MoveNextOrFail());
sp.MoveNext();
Assert.Equal("", sp.ExtractCurrent());
}
示例9: LinuxTcpStatistics
public LinuxTcpStatistics(bool ipv6)
{
// NOTE: There is no information in the snmp6 file regarding TCP statistics,
// so the statistics are always pulled from /proc/net/snmp.
string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
int firstTcpHeader = fileContents.IndexOf("Tcp:");
int secondTcpHeader = fileContents.IndexOf("Tcp:", firstTcpHeader + 1);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondTcpHeader);
string tcpData = fileContents.Substring(secondTcpHeader, endOfSecondLine - secondTcpHeader);
StringParser parser = new StringParser(tcpData, ' ');
// NOTE: Need to verify that this order is consistent. Otherwise, we need to parse the first-line header
// to determine the order of information contained in the row.
parser.MoveNextOrFail(); // Skip Tcp:
_rtoAlgorithm = parser.ParseNextInt32();
_rtoMin = parser.ParseNextInt32();
_rtoMax = parser.ParseNextInt32();
_maxConn = parser.ParseNextInt32();
_activeOpens = parser.ParseNextInt32();
_passiveOpens = parser.ParseNextInt32();
_attemptFails = parser.ParseNextInt32();
_estabResets = parser.ParseNextInt32();
_currEstab = parser.ParseNextInt32();
_inSegs = parser.ParseNextInt32();
_outSegs = parser.ParseNextInt32();
_retransSegs = parser.ParseNextInt32();
_inErrs = parser.ParseNextInt32();
_outRsts = parser.ParseNextInt32();
_inCsumErrors = parser.ParseNextInt32();
// Parse the number of active connections out of /proc/net/sockstat
string sockstatFile = File.ReadAllText(ipv6 ? NetworkFiles.Sockstat6File : NetworkFiles.SockstatFile);
string tcpLabel = ipv6 ? "TCP6:" : "TCP:";
int indexOfTcp = sockstatFile.IndexOf(tcpLabel);
int endOfTcpLine = sockstatFile.IndexOf(Environment.NewLine, indexOfTcp + 1);
string tcpLineData = sockstatFile.Substring(indexOfTcp, endOfTcpLine - indexOfTcp);
StringParser sockstatParser = new StringParser(tcpLineData, ' ');
sockstatParser.MoveNextOrFail(); // Skip "TCP(6):"
sockstatParser.MoveNextOrFail(); // Skip: "inuse"
_currentConnections = sockstatParser.ParseNextInt32();
}
示例10: CreateIcmpV4Statistics
public static IcmpV4Statistics CreateIcmpV4Statistics()
{
LinuxIcmpV4Statistics stats = new LinuxIcmpV4Statistics();
string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
int firstIpHeader = fileContents.IndexOf("Icmp:");
int secondIpHeader = fileContents.IndexOf("Icmp:", firstIpHeader + 1);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader);
string icmpData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
StringParser parser = new StringParser(icmpData, ' ');
// NOTE: Need to verify that this order is consistent. Otherwise, we need to parse the first-line header
// to determine the order of information contained in the file.
parser.MoveNextOrFail(); // Skip Icmp:
stats._inMsgs = parser.ParseNextInt32();
stats._inErrors = parser.ParseNextInt32();
stats._inCsumErrors = parser.ParseNextInt32();
stats._inDestUnreachs = parser.ParseNextInt32();
stats._inTimeExcds = parser.ParseNextInt32();
stats._inParmProbs = parser.ParseNextInt32();
stats._inSrcQuenchs = parser.ParseNextInt32();
stats._inRedirects = parser.ParseNextInt32();
stats._inEchos = parser.ParseNextInt32();
stats._inEchoReps = parser.ParseNextInt32();
stats._inTimestamps = parser.ParseNextInt32();
stats._inTimeStampReps = parser.ParseNextInt32();
stats._inAddrMasks = parser.ParseNextInt32();
stats._inAddrMaskReps = parser.ParseNextInt32();
stats._outMsgs = parser.ParseNextInt32();
stats._outErrors = parser.ParseNextInt32();
stats._outDestUnreachs = parser.ParseNextInt32();
stats._outTimeExcds = parser.ParseNextInt32();
stats._outParmProbs = parser.ParseNextInt32();
stats._outSrcQuenchs = parser.ParseNextInt32();
stats._outRedirects = parser.ParseNextInt32();
stats._outEchos = parser.ParseNextInt32();
stats._outEchoReps = parser.ParseNextInt32();
stats._outTimestamps = parser.ParseNextInt32();
stats._outTimestampReps = parser.ParseNextInt32();
stats._outAddrMasks = parser.ParseNextInt32();
stats._outAddrMaskReps = parser.ParseNextInt32();
return stats;
}
示例11: ParseUdpv4GlobalStatisticsFromSnmpFile
internal static UdpGlobalStatisticsTable ParseUdpv4GlobalStatisticsFromSnmpFile(string filePath)
{
string fileContents = File.ReadAllText(filePath);
int firstUdpHeader = fileContents.IndexOf("Udp:", StringComparison.Ordinal);
int secondUdpHeader = fileContents.IndexOf("Udp:", firstUdpHeader + 1, StringComparison.Ordinal);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondUdpHeader, StringComparison.Ordinal);
string tcpData = fileContents.Substring(secondUdpHeader, endOfSecondLine - secondUdpHeader);
StringParser parser = new StringParser(tcpData, ' ');
parser.MoveNextOrFail(); // Skip Udp:
return new UdpGlobalStatisticsTable()
{
InDatagrams = parser.ParseNextInt32(),
NoPorts = parser.ParseNextInt32(),
InErrors = parser.ParseNextInt32(),
OutDatagrams = parser.ParseNextInt32(),
RcvbufErrors = parser.ParseNextInt32(),
SndbufErrors = parser.ParseNextInt32(),
InCsumErrors = parser.ParseNextInt32()
};
}
示例12: ParseTcpGlobalStatisticsFromSnmpFile
internal static TcpGlobalStatisticsTable ParseTcpGlobalStatisticsFromSnmpFile(string filePath)
{
// NOTE: There is no information in the snmp6 file regarding TCP statistics,
// so the statistics are always pulled from /proc/net/snmp.
string fileContents = File.ReadAllText(filePath);
int firstTcpHeader = fileContents.IndexOf("Tcp:", StringComparison.Ordinal);
int secondTcpHeader = fileContents.IndexOf("Tcp:", firstTcpHeader + 1, StringComparison.Ordinal);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondTcpHeader, StringComparison.Ordinal);
string tcpData = fileContents.Substring(secondTcpHeader, endOfSecondLine - secondTcpHeader);
StringParser parser = new StringParser(tcpData, ' ');
parser.MoveNextOrFail(); // Skip Tcp:
return new TcpGlobalStatisticsTable()
{
RtoAlgorithm = parser.ParseNextInt32(),
RtoMin = parser.ParseNextInt32(),
RtoMax = parser.ParseNextInt32(),
MaxConn = parser.ParseNextInt32(),
ActiveOpens = parser.ParseNextInt32(),
PassiveOpens = parser.ParseNextInt32(),
AttemptFails = parser.ParseNextInt32(),
EstabResets = parser.ParseNextInt32(),
CurrEstab = parser.ParseNextInt32(),
InSegs = parser.ParseNextInt32(),
OutSegs = parser.ParseNextInt32(),
RetransSegs = parser.ParseNextInt32(),
InErrs = parser.ParseNextInt32(),
OutRsts = parser.ParseNextInt32(),
InCsumErrors = parser.ParseNextInt32()
};
}
示例13: ParseIPv4GlobalStatisticsFromSnmpFile
public static IPGlobalStatisticsTable ParseIPv4GlobalStatisticsFromSnmpFile(string filePath)
{
string fileContents = File.ReadAllText(filePath);
int firstIpHeader = fileContents.IndexOf("Ip:", StringComparison.Ordinal);
int secondIpHeader = fileContents.IndexOf("Ip:", firstIpHeader + 1, StringComparison.Ordinal);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader, StringComparison.Ordinal);
string ipData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
StringParser parser = new StringParser(ipData, ' ');
parser.MoveNextOrFail(); // Skip Ip:
// According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
return new IPGlobalStatisticsTable()
{
Forwarding = parser.MoveAndExtractNext() == "1",
DefaultTtl = parser.ParseNextInt32(),
InReceives = parser.ParseNextInt32(),
InHeaderErrors = parser.ParseNextInt32(),
InAddressErrors = parser.ParseNextInt32(),
ForwardedDatagrams = parser.ParseNextInt32(),
InUnknownProtocols = parser.ParseNextInt32(),
InDiscards = parser.ParseNextInt32(),
InDelivers = parser.ParseNextInt32(),
OutRequests = parser.ParseNextInt32(),
OutDiscards = parser.ParseNextInt32(),
OutNoRoutes = parser.ParseNextInt32(),
ReassemblyTimeout = parser.ParseNextInt32(),
ReassemblyRequireds = parser.ParseNextInt32(),
ReassemblyOKs = parser.ParseNextInt32(),
ReassemblyFails = parser.ParseNextInt32(),
FragmentOKs = parser.ParseNextInt32(),
FragmentFails = parser.ParseNextInt32(),
FragmentCreates = parser.ParseNextInt32(),
};
}
示例14: ParseIcmpv4FromSnmpFile
// Parses ICMP v4 statistics from /proc/net/snmp
public static Icmpv4StatisticsTable ParseIcmpv4FromSnmpFile(string filePath)
{
string fileContents = File.ReadAllText(filePath);
int firstIpHeader = fileContents.IndexOf("Icmp:", StringComparison.Ordinal);
int secondIpHeader = fileContents.IndexOf("Icmp:", firstIpHeader + 1, StringComparison.Ordinal);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader, StringComparison.Ordinal);
string icmpData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
StringParser parser = new StringParser(icmpData, ' ');
parser.MoveNextOrFail(); // Skip Icmp:
return new Icmpv4StatisticsTable()
{
InMsgs = parser.ParseNextInt32(),
InErrors = parser.ParseNextInt32(),
InCsumErrors = parser.ParseNextInt32(),
InDestUnreachs = parser.ParseNextInt32(),
InTimeExcds = parser.ParseNextInt32(),
InParmProbs = parser.ParseNextInt32(),
InSrcQuenchs = parser.ParseNextInt32(),
InRedirects = parser.ParseNextInt32(),
InEchos = parser.ParseNextInt32(),
InEchoReps = parser.ParseNextInt32(),
InTimestamps = parser.ParseNextInt32(),
InTimeStampReps = parser.ParseNextInt32(),
InAddrMasks = parser.ParseNextInt32(),
InAddrMaskReps = parser.ParseNextInt32(),
OutMsgs = parser.ParseNextInt32(),
OutErrors = parser.ParseNextInt32(),
OutDestUnreachs = parser.ParseNextInt32(),
OutTimeExcds = parser.ParseNextInt32(),
OutParmProbs = parser.ParseNextInt32(),
OutSrcQuenchs = parser.ParseNextInt32(),
OutRedirects = parser.ParseNextInt32(),
OutEchos = parser.ParseNextInt32(),
OutEchoReps = parser.ParseNextInt32(),
OutTimestamps = parser.ParseNextInt32(),
OutTimestampReps = parser.ParseNextInt32(),
OutAddrMasks = parser.ParseNextInt32(),
OutAddrMaskReps = parser.ParseNextInt32()
};
}
示例15: ParseStatFile
private static ParsedStat ParseStatFile(string statFilePath)
{
string statFileContents = File.ReadAllText(statFilePath);
var parser = new StringParser(statFileContents, ' ');
var results = default(ParsedStat);
results.pid = parser.ParseNextInt32();
results.comm = parser.ParseRaw(delegate (string str, ref int startIndex, ref int endIndex)
{
if (str[startIndex] == '(')
{
int i;
for (i = endIndex; i < str.Length && str[i - 1] != ')'; i++) ;
if (str[i - 1] == ')')
{
endIndex = i;
return str.Substring(startIndex + 1, i - startIndex - 2);
}
}
throw new InvalidDataException();
});
results.state = parser.ParseNextChar();
parser.MoveNextOrFail(); // ppid
parser.MoveNextOrFail(); // pgrp
results.session = parser.ParseNextInt32();
parser.MoveNextOrFail(); // tty_nr
parser.MoveNextOrFail(); // tpgid
parser.MoveNextOrFail(); // flags
parser.MoveNextOrFail(); // majflt
parser.MoveNextOrFail(); // cmagflt
parser.MoveNextOrFail(); // minflt
parser.MoveNextOrFail(); // cminflt
results.utime = parser.ParseNextUInt64();
results.stime = parser.ParseNextUInt64();
parser.MoveNextOrFail(); // cutime
parser.MoveNextOrFail(); // cstime
parser.MoveNextOrFail(); // priority
results.nice = parser.ParseNextInt64();
parser.MoveNextOrFail(); // num_threads
parser.MoveNextOrFail(); // itrealvalue
results.starttime = parser.ParseNextUInt64();
results.vsize = parser.ParseNextUInt64();
results.rss = parser.ParseNextInt64();
results.rsslim = parser.ParseNextUInt64();
parser.MoveNextOrFail(); // startcode
parser.MoveNextOrFail(); // endcode
results.startstack = parser.ParseNextUInt64();
parser.MoveNextOrFail(); // kstkesp
parser.MoveNextOrFail(); // kstkeip
parser.MoveNextOrFail(); // signal
parser.MoveNextOrFail(); // blocked
parser.MoveNextOrFail(); // sigignore
parser.MoveNextOrFail(); // sigcatch
parser.MoveNextOrFail(); // wchan
parser.MoveNextOrFail(); // nswap
parser.MoveNextOrFail(); // cnswap
parser.MoveNextOrFail(); // exit_signal
parser.MoveNextOrFail(); // processor
parser.MoveNextOrFail(); // rt_priority
parser.MoveNextOrFail(); // policy
parser.MoveNextOrFail(); // delayacct_blkio_ticks
parser.MoveNextOrFail(); // guest_time
parser.MoveNextOrFail(); // cguest_time
return results;
}