private Server GetServerClaim() { var servers = new List <Server>(); Server server = null; Logger.LogVerbose("GetServerClaim Called", GetType().Name); try { servers = SqlService.PerformanceServerRepository.ReadAllActive().OrderBy(s => s.LastChecked).ToList(); //Claim the first available server and start working on it foreach (var s in servers) { if (SqlService.ClaimServer(s.ServerId, AgentService.AgentID.ToString())) { server = s; break; } } if (server == null) { Logger.LogVerbose("GetServerClaim Called - Success. No outstanding work to be claimed.", this.GetType().Name); } else { Logger.LogVerbose(string.Format("GetServerClaim Called - Success. Claimed Server: {0} ({1})", server.ServerName, server.ServerId), this.GetType().Name); } } catch (Exception ex) { Logger.LogError(string.Format("GetServerClaim Called - Failure. Details: {0}", ex.Message), this.GetType().Name); } return(server); }