本文整理汇总了C#中StringParser.MoveNextOrFail方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.MoveNextOrFail方法的具体用法?C# StringParser.MoveNextOrFail怎么用?C# StringParser.MoveNextOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringParser
的用法示例。
在下文中一共展示了StringParser.MoveNextOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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();
}
示例4: 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());
}
示例5: 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();
}
示例6: ParseGatewayAddressesFromRouteFile
// /proc/net/route contains some information about gateway addresses,
// and separates the information about by each interface.
internal static List<GatewayIPAddressInformation> ParseGatewayAddressesFromRouteFile(string filePath, string interfaceName)
{
if (!File.Exists(filePath))
{
throw ExceptionHelper.CreateForInformationUnavailable();
}
List<GatewayIPAddressInformation> collection = new List<GatewayIPAddressInformation>();
// Columns are as follows (first-line header):
// Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
string[] fileLines = File.ReadAllLines(filePath);
foreach (string line in fileLines)
{
if (line.StartsWith(interfaceName))
{
StringParser parser = new StringParser(line, '\t', skipEmpty: true);
parser.MoveNext();
parser.MoveNextOrFail();
string gatewayIPHex = parser.MoveAndExtractNext();
long addressValue = Convert.ToInt64(gatewayIPHex, 16);
IPAddress address = new IPAddress(addressValue);
collection.Add(new SimpleGatewayIPAddressInformation(address));
}
}
return collection;
}
示例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: CreateIPv4Statistics
/// <summary>
/// Constructs an IPGlobalStatistics object from the snmp4 stats file.
/// </summary>
public static LinuxIPGlobalStatistics CreateIPv4Statistics()
{
LinuxIPGlobalStatistics stats = new LinuxIPGlobalStatistics();
string fileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
int firstIpHeader = fileContents.IndexOf("Ip:");
int secondIpHeader = fileContents.IndexOf("Ip:", firstIpHeader + 1);
int endOfSecondLine = fileContents.IndexOf(Environment.NewLine, secondIpHeader);
string ipData = fileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
StringParser parser = new StringParser(ipData, ' ');
// 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 Ip:
// According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
stats._forwarding = parser.MoveAndExtractNext() == "1";
stats._defaultTtl = parser.ParseNextInt32();
stats._inReceives = parser.ParseNextInt32();
stats._inHeaderErrors = parser.ParseNextInt32();
stats._inAddressErrors = parser.ParseNextInt32();
stats._forwardedDatagrams = parser.ParseNextInt32();
stats._inUnknownProtocols = parser.ParseNextInt32();
stats._inDiscards = parser.ParseNextInt32();
stats._inDelivers = parser.ParseNextInt32();
stats._outRequests = parser.ParseNextInt32();
stats._outDiscards = parser.ParseNextInt32();
stats._outNoRoutes = parser.ParseNextInt32();
stats._reassemblyTimeout = parser.ParseNextInt32();
stats._reassemblyRequireds = parser.ParseNextInt32();
stats._reassemblyOKs = parser.ParseNextInt32();
stats._reassemblyFails = parser.ParseNextInt32();
stats._fragmentOKs = parser.ParseNextInt32();
stats._fragmentFails = parser.ParseNextInt32();
stats._fragmentCreates = parser.ParseNextInt32();
string routeFile = ReadProcConfigFile(NetworkFiles.Ipv4RouteFile);
stats._numRoutes = CountOccurences(Environment.NewLine, routeFile) - 1; // File includes one-line header
stats._numInterfaces = GetNumInterfaces();
stats._numIPAddresses = GetNumIPAddresses();
return stats;
}
示例12: GetGatewayAddresses
// /proc/net/route contains some information about gateway addresses,
// and seperates the information about by each interface.
public GatewayIPAddressInformationCollection GetGatewayAddresses()
{
GatewayIPAddressInformationCollection collection = new GatewayIPAddressInformationCollection();
// Columns are as follows (first-line header):
// Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
string[] fileLines = File.ReadAllLines(NetworkFiles.Ipv4RouteFile);
foreach (string line in fileLines)
{
if (line.StartsWith(_linuxNetworkInterface.Name))
{
StringParser parser = new StringParser(line, '\t', skipEmpty: true);
parser.MoveNext();
parser.MoveNextOrFail();
string gatewayIPHex = parser.MoveAndExtractNext();
long addressValue = Convert.ToInt64(gatewayIPHex, 16);
IPAddress address = new IPAddress(addressValue);
collection.InternalAdd(new SimpleGatewayIPAddressInformation(address));
}
}
return collection;
}
示例13: ParseTcpConnectionInformationFromLine
// Parsing logic for local and remote addresses and ports, as well as socket state.
internal static TcpConnectionInformation ParseTcpConnectionInformationFromLine(string line)
{
StringParser parser = new StringParser(line, ' ', skipEmpty: true);
parser.MoveNextOrFail(); // skip Index
string localAddressAndPort = parser.MoveAndExtractNext(); // local_address
IPEndPoint localEndPoint = ParseAddressAndPort(localAddressAndPort);
string remoteAddressAndPort = parser.MoveAndExtractNext(); // rem_address
IPEndPoint remoteEndPoint = ParseAddressAndPort(remoteAddressAndPort);
string socketStateHex = parser.MoveAndExtractNext();
int nativeTcpState;
if (!int.TryParse(socketStateHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out nativeTcpState))
{
throw ExceptionHelper.CreateForParseFailure();
}
TcpState tcpState = MapTcpState(nativeTcpState);
return new SimpleTcpConnectionInformation(localEndPoint, remoteEndPoint, tcpState);
}
示例14: 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()
};
}
示例15: 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()
};
}