Skip to content

Commit

Permalink
Added FACILITY_CONTROL codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jun 26, 2024
1 parent e387224 commit 5bc2985
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
63 changes: 63 additions & 0 deletions src/Elmah.Io.HResults/Facilities/FacilityControlResolver.cs
Original file line number Diff line number Diff line change
@@ -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),
};
}
}
}
3 changes: 1 addition & 2 deletions src/Elmah.Io.HResults/IntExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand Down
10 changes: 10 additions & 0 deletions test/Elmah.Io.HResults.Test/HResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 5bc2985

Please sign in to comment.