public virtual void AddRecord(DnsResourceRecord record) { switch (record.Type) { case DnsResourceRecordType.CNAME: case DnsResourceRecordType.ANAME: case DnsResourceRecordType.PTR: case DnsResourceRecordType.SOA: throw new InvalidOperationException("Cannot add record: use SetRecords() for " + record.Type.ToString() + " record"); } _entries.AddOrUpdate(record.Type, delegate(DnsResourceRecordType key) { return(new DnsResourceRecord[] { record }); }, delegate(DnsResourceRecordType key, IReadOnlyList <DnsResourceRecord> existingRecords) { foreach (DnsResourceRecord existingRecord in existingRecords) { if (record.Equals(existingRecord.RDATA)) { return(existingRecords); } } List <DnsResourceRecord> updateRecords = new List <DnsResourceRecord>(existingRecords.Count + 1); updateRecords.AddRange(existingRecords); updateRecords.Add(record); return(updateRecords); }); }
DnsRecord Find(DnsRecord record) { DnsRecord[] existingRecords = Client.GetMatchingDnsRecordsByType(record.DomainName, record.RecordType); if (existingRecords.IsNullOrEmpty()) { return(null); } DnsResourceRecord testRecord = record.Deserialize(); foreach (DnsRecord existingRecord in existingRecords) { DnsResourceRecord rr = existingRecord.Deserialize(); if (rr.Equals(testRecord)) { return(existingRecord); } } return(null); }