/// <summary> /// Acts as a Factory which reads QType from Immutable IResource param to return concrete type which implements IResource. /// </summary> /// <param name="data"></param> /// <param name="position"></param> /// <param name="resource"></param> /// <returns></returns> private static IResource ReadAnswer(ref byte[] data, int position, IResource resource) { switch (resource.Type) { case QType.TXT: return(TxtRecord.Parse(data, position, resource)); case QType.MX: return(MxRecord.Parse(data, position, resource)); case QType.A: return(ARecord.Parse(data, position, resource)); case QType.SOA: return(SoaRecord.Parse(data, position, resource)); case QType.NS: return(NsRecord.Parse(data, position, resource)); case QType.CNAME: return(CNameRecord.Parse(data, position, resource)); } return(null); //TODO: Thrown Exception Here }
internal SoaRecordSetData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, string etag, IDictionary <string, string> metadata, long?ttl, string fqdn, string provisioningState, WritableSubResource targetResource, SoaRecord soaRecord) : base(id, name, resourceType, systemData) { Etag = etag; Metadata = metadata; TTL = ttl; Fqdn = fqdn; ProvisioningState = provisioningState; TargetResource = targetResource; SoaRecord = soaRecord; }
internal virtual void AssertEquality(SoaRecord expected, SoaRecord actual) { Assert.AreEqual(expected.MName, actual.MName, "Should be equal"); Assert.AreEqual(expected.RName, actual.RName, "Should be equal"); Assert.AreEqual(expected.Serial, actual.Serial, "Should be equal"); Assert.AreEqual(expected.Refresh, actual.Refresh, "Should be equal"); Assert.AreEqual(expected.Retry, actual.Retry, "Should be equal"); Assert.AreEqual(expected.Expire, actual.Expire, "Should be equal"); Assert.AreEqual(expected.Minimum, actual.Minimum, "Should be equal"); }
internal RecordSetData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, string etag, IDictionary <string, string> metadata, long?ttl, string fqdn, string provisioningState, WritableSubResource targetResource, IList <ARecord> aRecords, IList <AaaaRecord> aaaaRecords, IList <MxRecord> mxRecords, IList <NsRecord> nsRecords, IList <PtrRecord> ptrRecords, IList <SrvRecord> srvRecords, IList <TxtRecord> txtRecords, CnameRecord cnameRecord, SoaRecord soaRecord, IList <CaaRecord> caaRecords) : base(id, name, resourceType, systemData) { Etag = etag; Metadata = metadata; TTL = ttl; Fqdn = fqdn; ProvisioningState = provisioningState; TargetResource = targetResource; ARecords = aRecords; AaaaRecords = aaaaRecords; MxRecords = mxRecords; NsRecords = nsRecords; PtrRecords = ptrRecords; SrvRecords = srvRecords; TxtRecords = txtRecords; CnameRecord = cnameRecord; SoaRecord = soaRecord; CaaRecords = caaRecords; }
public static bool AreEqual(SoaRecord first, SoaRecord second) { if (first == null && second == null) { return(true); } else if (first == null || second == null) { return(false); } return(first.Email == second.Email && first.ExpireTime == second.ExpireTime && first.Host == second.Host && first.MinimumTtl == second.MinimumTtl && first.RefreshTime == second.RefreshTime && first.RetryTime == second.RetryTime && first.SerialNumber == second.SerialNumber); }
public static bool AreSoaRecordSetsEquivalent(SoaRecord subject, SoaRecord expected) { if (subject == null) { return(expected == null); } else if (expected == null) { return(false); } return(subject.Email == expected.Email && subject.ExpireTime == expected.ExpireTime && subject.Host == expected.Host && subject.MinimumTtl == expected.MinimumTtl && subject.RefreshTime == expected.RefreshTime && subject.RetryTime == expected.RetryTime && subject.SerialNumber == expected.SerialNumber); }
internal static RecordSetData DeserializeRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <IList <ARecord> > aRecords = default; Optional <IList <AaaaRecord> > aaaaRecords = default; Optional <IList <MxRecord> > mxRecords = default; Optional <IList <NsRecord> > nsRecords = default; Optional <IList <PtrRecord> > ptrRecords = default; Optional <IList <SrvRecord> > srvRecords = default; Optional <IList <TxtRecord> > txtRecords = default; Optional <CnameRecord> cnameRecord = default; Optional <SoaRecord> soaRecord = default; Optional <IList <CaaRecord> > caaRecords = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("ARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <ARecord> array = new List <ARecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(ARecord.DeserializeARecord(item)); } aRecords = array; continue; } if (property0.NameEquals("AAAARecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <AaaaRecord> array = new List <AaaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(AaaaRecord.DeserializeAaaaRecord(item)); } aaaaRecords = array; continue; } if (property0.NameEquals("MXRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <MxRecord> array = new List <MxRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(MxRecord.DeserializeMxRecord(item)); } mxRecords = array; continue; } if (property0.NameEquals("NSRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <NsRecord> array = new List <NsRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(NsRecord.DeserializeNsRecord(item)); } nsRecords = array; continue; } if (property0.NameEquals("PTRRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <PtrRecord> array = new List <PtrRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(PtrRecord.DeserializePtrRecord(item)); } ptrRecords = array; continue; } if (property0.NameEquals("SRVRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <SrvRecord> array = new List <SrvRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(SrvRecord.DeserializeSrvRecord(item)); } srvRecords = array; continue; } if (property0.NameEquals("TXTRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <TxtRecord> array = new List <TxtRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(TxtRecord.DeserializeTxtRecord(item)); } txtRecords = array; continue; } if (property0.NameEquals("CNAMERecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cnameRecord = CnameRecord.DeserializeCnameRecord(property0.Value); continue; } if (property0.NameEquals("SOARecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } soaRecord = SoaRecord.DeserializeSoaRecord(property0.Value); continue; } if (property0.NameEquals("caaRecords")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <CaaRecord> array = new List <CaaRecord>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(CaaRecord.DeserializeCaaRecord(item)); } caaRecords = array; continue; } } continue; } } return(new RecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, Optional.ToList(aRecords), Optional.ToList(aaaaRecords), Optional.ToList(mxRecords), Optional.ToList(nsRecords), Optional.ToList(ptrRecords), Optional.ToList(srvRecords), Optional.ToList(txtRecords), cnameRecord.Value, soaRecord.Value, Optional.ToList(caaRecords))); }
static string ParseRecord(IDnsQueryResponse dnsQueryResponse, bool isA = false, bool isMx = false) { string output = ""; string value = ""; string ttl = ""; string mxp = ""; foreach (DnsResourceRecord record in dnsQueryResponse.Answers) { switch (record.RecordType) { case ResourceRecordType.MX: { MxRecord mxRecord = record as MxRecord; if (mxRecord != null) { value += mxRecord.Exchange + "\n"; ttl += mxRecord.InitialTimeToLive + "\n"; mxp += mxRecord.Preference + "\n"; // output += $"{mxRecord.Exchange} | TTL {mxRecord.InitialTimeToLive}\n"; } break; } case ResourceRecordType.SOA: { SoaRecord soaRecord = record as SoaRecord; if (soaRecord != null) { value += soaRecord.ToString() + "\n"; ttl += soaRecord.Minimum + "\n"; // output += $"SOA TTL {soaRecord.Minimum}\n"; } break; } case ResourceRecordType.NS: { NsRecord nsRecord = record as NsRecord; if (nsRecord != null) { value += nsRecord.NSDName + "\n"; ttl += nsRecord.InitialTimeToLive + "\n"; // output += $"{nsRecord.NSDName} | TTL {nsRecord.InitialTimeToLive}\n"; } break; } case ResourceRecordType.A: { ARecord nsRecord = record as ARecord; if (nsRecord != null) { return($"{nsRecord.InitialTimeToLive}"); } return("No record"); } case ResourceRecordType.TXT: { TxtRecord txtRecord = record as TxtRecord; if (txtRecord != null) { foreach (string txt in txtRecord.Text) { value += "\"\"" + txt + "\"\"\n"; ttl += txtRecord.InitialTimeToLive + "\n"; // output += $"\"{txt}\" | TTL {txtRecord.InitialTimeToLive}\n"; } } break; } } } if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(ttl)) { if (string.IsNullOrEmpty(mxp)) { output = $"\"{value.Trim()}\",\"{ttl.Trim()}\""; } else { output = $"\"{value.Trim()}\",\"{mxp.Trim()}\",\"{ttl.Trim()}\""; } } else { if (isA) { output = "No record"; } else if (isMx) { output = "No record,No record,No record"; } else { output = "No record,No record"; } } if (string.IsNullOrEmpty(output)) { return("No record\n"); } return(output); }
internal static SoaRecordSetData DeserializeSoaRecordSetData(JsonElement element) { Optional <string> etag = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <IDictionary <string, string> > metadata = default; Optional <long> ttl = default; Optional <string> fqdn = default; Optional <string> provisioningState = default; Optional <WritableSubResource> targetResource = default; Optional <SoaRecord> soaRecord = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { etag = property.Value.GetString(); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, property1.Value.GetString()); } metadata = dictionary; continue; } if (property0.NameEquals("TTL")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } ttl = property0.Value.GetInt64(); continue; } if (property0.NameEquals("fqdn")) { fqdn = property0.Value.GetString(); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("targetResource")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } targetResource = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("SOARecord")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } soaRecord = SoaRecord.DeserializeSoaRecord(property0.Value); continue; } } continue; } } return(new SoaRecordSetData(id, name, type, systemData, etag.Value, Optional.ToDictionary(metadata), Optional.ToNullable(ttl), fqdn.Value, provisioningState.Value, targetResource, soaRecord.Value)); }