GetUpdateStatusCode() public static method

Takes the update status code string that is returned from DNS-O-Matic and converts it into its proper enum value.
public static GetUpdateStatusCode ( string nativeUpdateStatusCode ) : UpdateStatusCode
nativeUpdateStatusCode string
return UpdateStatusCode
Example #1
0
        /// <summary>
        /// Updates the specified hostname via DNS-O-Matic to the IP Address that is given.
        /// </summary>
        /// <param name="hostname">The hostname to update.</param>
        /// <param name="ipAddress">The IP address to use.</param>
        /// <returns>True if the update was successful or there was no change in the IP Address.</returns>
        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);
            }
        }