/// <summary> /// Resolves a usable <c>IStatusMonitor</c> to determine for use to /// determine if the service is up or down. It does this using the /// supplied factories. /// </summary> /// <param name="service">The service that needs to be evaluated.</param> /// <returns>An <c>IStatusMonitor</c> capable of determining if the /// service status.</returns> public virtual IStatusMonitor ResolveStatusMonitor(Service service) { IStatusMonitor result = null; for (int i = 0; i < factories.Length; i++) { if (factories[i].IsApplicable(service)) { result = factories[i].GetMonitor(service); if(result == null) { if (RecordIssues) siteStatusIssues.Add(FailedToResolveMonitor.Get(service)); } break; } } return result; }
public static SiteStatusIssue Get(Service service) { var result = new SiteStatusIssue() { FailedTaskDescription = string.Format("An IStatusMonitor could not be resolved for the service with name {0}.", service.Name), Implications = string.Format("The status will always be unknown for the service with name {0} and type {1}.", service.Name, service.Type), // This probable cause could be expanded upon, but it cuts across other classes. ProbableCause = "Either a factory is not configured for services of this type, or it is a database service that does not have a known provider.", Exception = null }; return result; }
/// <summary> /// Sets the Status of the given service using the service monitor /// returned from a call to <c>ResolveStatusMonitor</c>. /// </summary> /// <param name="service">The service that needs to be queried.</param> public virtual void ResolveServiceStatus(Service service) { ServiceStatus result = ServiceStatus.Down; var serviceMonitor = ResolveStatusMonitor(service); if (serviceMonitor == null) result = ServiceStatus.Unknown; else { try { result = serviceMonitor.CheckStatus(service); } catch { } } service.Status = result; }