diff --git a/src/Elmah.Io.HResults/Facilities/FacilityControlResolver.cs b/src/Elmah.Io.HResults/Facilities/FacilityControlResolver.cs new file mode 100644 index 0000000..8cab371 --- /dev/null +++ b/src/Elmah.Io.HResults/Facilities/FacilityControlResolver.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Elmah.Io.HResults.Facilities +{ + // Sources: + // - https://github.com/tpn/winsdk-10/blob/master/Include/10.0.14393.0/um/OleCtl.h + internal class FacilityControlResolver : FacilityResolverBase + { + public FacilityControlResolver() : base(10, "FACILITY_CONTROL") + { + } + + internal override Code Resolve(bool failure, int code) + { + return code switch + { + 5 => new Code(code, "CTL_E_ILLEGALFUNCTIONCALL"), + 6 => new Code(code, "CTL_E_OVERFLOW"), + 7 => new Code(code, "CTL_E_OUTOFMEMORY"), + 11 => new Code(code, "CTL_E_DIVISIONBYZERO"), + 14 => new Code(code, "CTL_E_OUTOFSTRINGSPACE"), + 28 => new Code(code, "CTL_E_OUTOFSTACKSPACE"), + 52 => new Code(code, "CTL_E_BADFILENAMEORNUMBER"), + 53 => new Code(code, "CTL_E_FILENOTFOUND"), + 54 => new Code(code, "CTL_E_BADFILEMODE"), + 55 => new Code(code, "CTL_E_FILEALREADYOPEN"), + 57 => new Code(code, "CTL_E_DEVICEIOERROR"), + 58 => new Code(code, "CTL_E_FILEALREADYEXISTS"), + 59 => new Code(code, "CTL_E_BADRECORDLENGTH"), + 61 => new Code(code, "CTL_E_DISKFULL"), + 63 => new Code(code, "CTL_E_BADRECORDNUMBER"), + 64 => new Code(code, "CTL_E_BADFILENAME"), + 67 => new Code(code, "CTL_E_TOOMANYFILES"), + 68 => new Code(code, "CTL_E_DEVICEUNAVAILABLE"), + 70 => new Code(code, "CTL_E_PERMISSIONDENIED"), + 71 => new Code(code, "CTL_E_DISKNOTREADY"), + 75 => new Code(code, "CTL_E_PATHFILEACCESSERROR"), + 76 => new Code(code, "CTL_E_PATHNOTFOUND"), + 93 => new Code(code, "CTL_E_INVALIDPATTERNSTRING"), + 94 => new Code(code, "CTL_E_INVALIDUSEOFNULL"), + 321 => new Code(code, "CTL_E_INVALIDFILEFORMAT"), + 380 => new Code(code, "CTL_E_INVALIDPROPERTYVALUE"), + 381 => new Code(code, "CTL_E_INVALIDPROPERTYARRAYINDEX"), + 382 => new Code(code, "CTL_E_SETNOTSUPPORTEDATRUNTIME"), + 383 => new Code(code, "CTL_E_SETNOTSUPPORTED"), + 385 => new Code(code, "CTL_E_NEEDPROPERTYARRAYINDEX"), + 387 => new Code(code, "CTL_E_SETNOTPERMITTED"), + 393 => new Code(code, "CTL_E_GETNOTSUPPORTEDATRUNTIME"), + 394 => new Code(code, "CTL_E_GETNOTSUPPORTED"), + 422 => new Code(code, "CTL_E_PROPERTYNOTFOUND"), + 460 => new Code(code, "CTL_E_INVALIDCLIPBOARDFORMAT"), + 481 => new Code(code, "CTL_E_INVALIDPICTURE"), + 482 => new Code(code, "CTL_E_PRINTERERROR"), + 735 => new Code(code, "CTL_E_CANTSAVEFILETOTEMP"), + 744 => new Code(code, "CTL_E_SEARCHTEXTNOTFOUND"), + 746 => new Code(code, "CTL_E_REPLACEMENTSTOOLONG"), + _ => Unknown(code), + }; + } + } +} diff --git a/src/Elmah.Io.HResults/IntExtensions.cs b/src/Elmah.Io.HResults/IntExtensions.cs index 313521d..c97d651 100644 --- a/src/Elmah.Io.HResults/IntExtensions.cs +++ b/src/Elmah.Io.HResults/IntExtensions.cs @@ -14,7 +14,7 @@ internal static class IntExtensions new FacilityScardResolver(), new FacilitySecurityResolver(), new FacilitySetupapiResolver(), new FacilityStorageResolver(), new FacilityTpmServicesResolver(), new FacilityTpmSoftwareResolver(), new FacilityUrtResolver(), new FacilityUsermodeFilterManagerResolver(), new FacilityWin32Resolver(), - new FacilityWindowsResolver(), + new FacilityWindowsResolver(), new FacilityControlResolver() }; internal static Code ToCode(this int code, bool failure, int facility) @@ -32,7 +32,6 @@ internal static Facility ToFacility(this int facility) return facility switch { - 10 => new Facility(facility, "FACILITY_CONTROL"), 12 => new Facility(facility, "FACILITY_INTERNET"), 14 => new Facility(facility, "FACILITY_MSMQ"), 18 => new Facility(facility, "FACILITY_AAF"), diff --git a/test/Elmah.Io.HResults.Test/HResultTest.cs b/test/Elmah.Io.HResults.Test/HResultTest.cs index 07c07f0..645e177 100644 --- a/test/Elmah.Io.HResults.Test/HResultTest.cs +++ b/test/Elmah.Io.HResults.Test/HResultTest.cs @@ -6,6 +6,16 @@ namespace Elmah.Io.HResults.Test { public class HResultTest { + [TestCase("FACILITY_CONTROL", "CTL_E_ILLEGALFUNCTIONCALL", -2146828283)] + public void CanParseFacility(string expectedFacitliy, string expectedCode, int hresult) + { + var res = HResult.Parse(hresult); + Assert.That(res.Facility.IsMatch); + Assert.That(res.Facility.Name, Is.EqualTo(expectedFacitliy)); + Assert.That(res.Code.IsMatch); + Assert.That(res.Code.Name, Is.EqualTo(expectedCode)); + } + [Test] public void CanParseKnownUrt() {