private static TinyPacket CreateBeatPacket() { var packet = new TinyPacket("Attache", "Beat"); packet.Add("Uptime", (Environment.TickCount / 1000).ToString("0", CultureInfo.InvariantCulture)); var hostEntry = Dns.GetHostEntry(Dns.GetHostName()); var sbIPv4 = new StringBuilder(); foreach (var address in hostEntry.AddressList) { if (address.AddressFamily != AddressFamily.InterNetwork) { continue; } //skip all not IPv4 if (sbIPv4.Length > 0) { sbIPv4.Append(" "); } sbIPv4.Append(address.ToString()); } packet.Add("IPv4", sbIPv4.ToString()); var sbIPv6 = new StringBuilder(); foreach (var address in hostEntry.AddressList) { if ((address.AddressFamily != AddressFamily.InterNetworkV6) || address.IsIPv6LinkLocal) { continue; } //skip all not IPv6 (global) if (sbIPv6.Length > 0) { sbIPv6.Append(" "); } sbIPv6.Append(address.ToString()); } packet.Add("IPv6", sbIPv6.ToString()); var sbIPv6Local = new StringBuilder(); foreach (var address in hostEntry.AddressList) { if ((address.AddressFamily != AddressFamily.InterNetworkV6) || !address.IsIPv6LinkLocal) { continue; } //skip all not IPv6 (link local) if (sbIPv6Local.Length > 0) { sbIPv6Local.Append(" "); } sbIPv6Local.Append(address.ToString()); } packet.Add("IPv6_Local", sbIPv6Local.ToString()); return(packet); }
private static TinyPacket CreateVolumeInfoPacket() { var packet = new TinyPacket("Attache", "VolumeInfo"); foreach (var drive in DriveInfo.GetDrives()) { var volumeLetter = drive.Name.Substring(0, 1); String volumeLabel = ""; try { volumeLabel = drive.VolumeLabel; } catch (IOException ex) { volumeLabel = "{" + ex.Message + "}"; } long volumeSize = -1; try { volumeSize = drive.TotalSize; } catch (IOException) { } long volumeFree = -1; try { volumeFree = drive.AvailableFreeSpace; } catch (IOException) { } String volumeFormat = null; try { volumeFormat = drive.DriveFormat; } catch (IOException) { } packet.Add(volumeLetter, volumeLabel); if (volumeSize >= 0) { packet.Add(volumeLetter + "_Size", volumeSize.ToString("0" + CultureInfo.InvariantCulture)); } if (volumeSize >= 0) { packet.Add(volumeLetter + "_Free", volumeFree.ToString("0" + CultureInfo.InvariantCulture)); } if (volumeFormat != null) { packet.Add(volumeLetter + "_Format", volumeFormat); } } return(packet); }
public void TinyPacket_CannotAddSpecialProperties1() { var packet = new TinyPacket("Example", "Test") { { "A", "1" }, { "B", "2" } }; packet.Add(".X", "X"); }