コード例 #1
0
ファイル: AuthZone.cs プロジェクト: piccobit/DnsServer
        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);
            });
        }
コード例 #2
0
        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);
        }