public void Serializable_ArrayNonNullException() { var serializer = new XmlSerializer(typeof(List<SiteStatusIssue>), new Type[] { typeof(SiteStatusIssue) }); Exception exception = null; try { throw new ArgumentException(); } catch (Exception ex) { exception = ex; } var issue2 = new SiteStatusIssue() { FailedTaskDescription = "", Implications = "", ProbableCause = "", Exception = exception }; var result = ""; using (var writer = new StringWriter()) { serializer.Serialize(writer, new List<SiteStatusIssue>() { issue2 }); result = serializer.ToString(); } }
public void Serializable_ArrayNullException() { var serializer = new XmlSerializer(typeof(List<SiteStatusIssue>), new Type[] { typeof(SiteStatusIssue) }); var issue = new SiteStatusIssue() { FailedTaskDescription = "", Implications = "", ProbableCause = "", Exception = null }; var result = ""; using (var writer = new StringWriter()) { serializer.Serialize(writer, new List<SiteStatusIssue>() { issue }); result = serializer.ToString(); } }
/// <summary> /// Checks for whether it was a missing app setting that caused /// the error. If it was it fills in information about it. /// </summary> /// <param name="issue">The issue to fill-in information about if /// this was the cause.</param> /// <returns>Whether a missing app setting is to blame.</returns> private static bool CheckForMissingAppSetting(SiteStatusIssue issue) { bool result = false; if(string.IsNullOrEmpty(ConfigurationManager.AppSettings[VERSION_DIRECTORY_APP_SETTING])) { result = true; issue.ProbableCause = string.Format("The app setting {0} was not found.", VERSION_DIRECTORY_APP_SETTING); } return result; }
/// <summary> /// Checks to see if there was an error during the retrieval of the /// version files from the <c>VersionDirectory</c>. /// </summary> /// <param name="issue">The issue object to contain information /// about the exception.</param> /// <param name="repo">The SiteStatusRepository object that this /// issue occurred in.</param> /// <returns>Whether or not this was the cause of the issue.</returns> private static bool CheckForGetFilesIssue(SiteStatusIssue issue, SiteStatusRepository repo) { bool result = false; try { repo.VersionDirectory.GetFiles(VERSION_FILE_MASK); } catch (ArgumentNullException) { result = true; issue.ProbableCause = "The mask to search for version files in the version directory is null."; } catch(ArgumentException) { result = true; issue.ProbableCause = "The mask to search for version files in the version directory contains invalid characters."; } catch (DirectoryNotFoundException) { result = true; issue.ProbableCause = "The mask specified to search for version files in the version directory is invalid, such as being on an unmapped drive."; } catch (SecurityException) { result = true; issue.ProbableCause = "The mask specified to search for version files in the version directory could not be used due to insufficient permissions."; } catch(Exception) { } return result; }
/// <summary> /// Must be run after the other VersionDirectory checks. /// </summary> /// <param name="issue">The issue object to contain information /// about the exception.</param> /// <param name="repo">The SiteStatusRepository object that this /// issue occurred in.</param> /// <returns>Whether or not it was an exception thrown by the /// constructor of DirectoryInfo or not.</returns> private static bool CheckForDirectoryInfoIssue(SiteStatusIssue issue, SiteStatusRepository repo) { bool result = false; try { var versionDir = repo.VersionDirectory; } catch(ArgumentNullException) { result = true; issue.ProbableCause = "The version directory path is null."; } catch(SecurityException) { result = true; issue.ProbableCause = "The version directory may not be accessed due to insufficient permissions."; } catch(ArgumentException) { result = true; issue.ProbableCause = "The version directory contains invalid characters."; } catch(PathTooLongException) { result = true; issue.ProbableCause = "The version directory path is too long."; } catch (Exception) { } return result; }
/// <summary> /// Checks for whether it was a config file error or not. /// </summary> /// <param name="issue">The issue to fill-in information about if /// this was the cause.</param> /// <returns>Whether if was a config file error or not.</returns> private static bool CheckForConfigFileError(SiteStatusIssue issue) { bool result = false; try { string versionDirectoryRelativePath = ConfigurationManager.AppSettings[VERSION_DIRECTORY_APP_SETTING]; } catch (ConfigurationErrorsException) { result = true; issue.ProbableCause = "The Web.config file could not be read."; } catch(Exception) { } return result; }
public static SiteStatusIssue Get(SiteStatusRepository repo, Exception ex) { var siteStatusIssue = new SiteStatusIssue() { FailedTaskDescription = "The directory with the version files could not be read.", Implications = "The versions for the various components in the site will not be reported.", Exception = ex }; if (CheckForConfigFileError(siteStatusIssue)) { } else if(CheckForMissingAppSetting(siteStatusIssue)) { } else if (CheckForDirectoryInfoIssue(siteStatusIssue, repo)) { } else if(CheckForGetFilesIssue(siteStatusIssue, repo)) { } else { siteStatusIssue.ProbableCause = "Unknown"; } return siteStatusIssue; }
/// <summary> /// Checks for whether it was a config file error or not. /// </summary> /// <param name="issue">The issue to fill-in information about if /// this was the cause.</param> /// <returns>Whether if was a config file error or not.</returns> private static bool CheckForConfigFileError(SiteStatusIssue issue) { bool result = false; try { string StatusConfigurationFileRelativePath = ConfigurationManager.AppSettings[CONFIGURATION_FILE_APP_SETTING]; } catch (ConfigurationErrorsException) { result = true; issue.ProbableCause = "The Web.config file could not be read."; } catch (Exception) { } 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; }
public static SiteStatusIssue Get(FileInfo versionFile, Exception ex) { var result = new SiteStatusIssue() { FailedTaskDescription = FailedTaskDescription(versionFile), Implications = "The component detailed in the file will not be available in the site status report.", ProbableCause = ProbableCause(ex), Exception = ex }; return result; }
public static SiteStatusIssue Get(FileInfo statusConfigurationFile, Exception ex) { var result = new SiteStatusIssue() { FailedTaskDescription = FailedTaskDescription(statusConfigurationFile), Implications = "Services, nor their statii can be reported on.", ProbableCause = ProbableCause(ex), Exception = ex }; return result; }