/*
* Copyright 2004-2006 Luke Quinane and Daniel Frampton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using NDns.Message;
namespace NDns.Message.Records{
/// <summary>
/// A DNS record.
/// </summary>
public abstract class Record
{
/// <summary>
/// The type of this record.
/// </summary>
protected QType type;
/// <summary>
/// The time to live for this record (in seconds).
/// </summary>
protected uint recordTTL;
/// <summary>
/// The time this record was created.
/// </summary>
protected DateTime creationTime;
/// <summary>
/// Creates a new DNS record.
/// </summary>
protected Record()
{
this.creationTime = DateTime.Now;
}
/// <summary>
/// Returns the type for this record.
/// </summary>
public QType Type
{
get
{
return this.type;
}
}
/// <summary>
/// The data associated with this record as a user readable string.
/// </summary>
public abstract string Data {
get;
}
/// <summary>
/// Gets and sets the time to live for this record (in seconds).
/// </summary>
public uint TTL
{
get
{
TimeSpan ttl = new TimeSpan(0, 0, (int) this.recordTTL);
TimeSpan elapsed = new TimeSpan(DateTime.Now.Subtract(this.creationTime).Ticks);
uint delta = (uint) ttl.Subtract(elapsed).TotalSeconds;
return delta;
}
set
{
this.recordTTL = value;
this.creationTime = DateTime.Now;
}
}
}
}
|