/// <summary> /// Utility method to return the internal Name of the failure in the BuiltInFailures class /// </summary> /// <param name="failure">the failure to evaluate</param> /// <returns>The String value used to internally represent the BuiltInFailure in Revit</returns> public static String GetBuiltInFailuresInternalName(this FailureDefinitionAccessor failure) { return(builtInFailuresList .Where(x => x.Guid == failure.GetId().Guid) .Select(x => x.Name) .FirstOrDefault()); }
/// <summary> /// Utility method to return the SubCategory (expressed as an inner class in BuiltInFailures) of a failure if it is found in BuiltInFailures /// </summary> /// <param name="failure">The failure to evaluate</param> /// <returns>The SubCategory, or null if the failure was not found in BuiltInFailures</returns> public static String GetBuiltInFailuresSubCategory(this FailureDefinitionAccessor failure) { return(builtInFailuresList .Where(x => x.Guid == failure.GetId().Guid) .Select(x => x.Category) .FirstOrDefault()); //this specifies that if no matching failure was found, null is returned, based on null being the default value for String because it is a reference type }
public AutoFailureHandlingOptions(FailureDefinitionAccessor fda) : this() { FailureGuid = fda.GetId().Guid; BuiltInFailuresInternalName = fda.GetBuiltInFailuresInternalName(); UserDescription = fda.GetDescriptionText(); BuiltInFailuresSubCategory = fda.GetBuiltInFailuresSubCategory(); switch (fda.GetSeverity()) { case FailureSeverity.None: SeverityDescription = "None"; break; case FailureSeverity.Warning: SeverityDescription = "Warning"; break; case FailureSeverity.Error: SeverityDescription = "Error"; break; case FailureSeverity.DocumentCorruption: SeverityDescription = "Document Corruption"; break; default: break; } HasResolutions = fda.HasResolutions(); if (fda.GetSeverity() == FailureSeverity.Warning) { AvailableResolutions = AutoOptionsResolution.WarningResolutions.Concat(fda.GetRevitFailureResolutionOptions()).ToList(); } else if (fda.GetSeverity() == FailureSeverity.Error) { AvailableResolutions = AutoOptionsResolution.ErrorResolutions.Concat(fda.GetRevitFailureResolutionOptions()).ToList(); } else { AvailableResolutions = new List <FailureResolutionOption>(); } HasResolutions = fda.HasResolutions(); FailureResolutionOption noActionRes = AvailableResolutions .Where(x => x is AutoOptionsResolution) .Cast <AutoOptionsResolution>() .Where(x => x.Resolution == ((AutoOptionsResolution)AutoOptionsResolution.NoActionRes).Resolution) .FirstOrDefault(); SelectedResIndex = AvailableResolutions.IndexOf(noActionRes); }
/// <summary> /// Utility method to determine whether a failure is part of Revit's BuiltInFailures /// </summary> /// <param name="failure">The failure to evalutate</param> /// <returns>Whether the Fauilure was found in the API's BuiltInFailures object</returns> public static Boolean IsBuiltInFailure(this FailureDefinitionAccessor failure) { //Contains() wasn't recognizing equal FailureDefintionId values, so I compared values by FailureDefinitionId.Guid instead if (builtInFailuresList.Select(x => x.Guid).Contains(failure.GetId().Guid)) { return(true); } else { return(false); } }