Beispiel #1
0
        public virtual bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData record)
        {
            if (_entries.TryGetValue(type, out IReadOnlyList <DnsResourceRecord> existingRecords))
            {
                if (existingRecords.Count == 1)
                {
                    if (record.Equals(existingRecords[0].RDATA))
                    {
                        return(_entries.TryRemove(type, out _));
                    }
                }
                else
                {
                    List <DnsResourceRecord> updateRecords = new List <DnsResourceRecord>(existingRecords.Count);

                    for (int i = 0; i < existingRecords.Count; i++)
                    {
                        if (!record.Equals(existingRecords[i].RDATA))
                        {
                            updateRecords.Add(existingRecords[i]);
                        }
                    }

                    return(_entries.TryUpdate(type, updateRecords, existingRecords));
                }
            }

            return(false);
        }
Beispiel #2
0
        protected bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData rdata, out DnsResourceRecord deletedRecord)
        {
            if (_entries.TryGetValue(type, out IReadOnlyList <DnsResourceRecord> existingRecords))
            {
                if (existingRecords.Count == 1)
                {
                    if (rdata.Equals(existingRecords[0].RDATA))
                    {
                        if (_entries.TryRemove(type, out IReadOnlyList <DnsResourceRecord> removedRecords))
                        {
                            deletedRecord = removedRecords[0];
                            return(true);
                        }
                    }
                }
                else
                {
                    deletedRecord = null;
                    List <DnsResourceRecord> updatedRecords = new List <DnsResourceRecord>(existingRecords.Count);

                    foreach (DnsResourceRecord existingRecord in existingRecords)
                    {
                        if ((deletedRecord is null) && rdata.Equals(existingRecord.RDATA))
                        {
                            deletedRecord = existingRecord;
                        }
                        else
                        {
                            updatedRecords.Add(existingRecord);
                        }
                    }