public override bool UpdateHostname(string hostname, string ipAddress)
{
try
{
if (HasIpAddresssChanged(hostname, ipAddress) == false) return true; // No change, no need to update
if (IsValidIpAddress(ipAddress) == false)
{
logger.Error(string.Format("Invalid IP Address provided: {0}", ipAddress));
return false;
}
var request = CreateUpdateHostnameRequest(hostname, ipAddress);
using(var response = request.GetResponse())
{
string responseBody = string.Empty;
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
responseBody = streamReader.ReadToEnd();
logger.Info(string.Format("DNS-O-Matic update response for hostname {0}: {1}", hostname, responseBody));
var regex = new Regex(@"\w+");
var match = regex.Match(responseBody);
var statusCode = match.Success ? UpdateStatusCodeConverter.GetUpdateStatusCode(match.Value) : UpdateStatusCode.Unknown;
UpdateStatusCodes[hostname] = statusCode;
if (statusCode == UpdateStatusCode.Good || statusCode == UpdateStatusCode.NoChange)
{
LastUpdateIpAddresses[hostname] = ipAddress;
return true;
}
return false;
}
}
}
catch (Exception ex)
{
logger.Error(ex);
return false;
}
}