3using System.Diagnostics.CodeAnalysis;
4using System.Reflection;
5using System.Threading.Tasks;
39 bool IsSpecialArgument;
40 bool IsMetaDataArgument;
44 this.NrSpecialArguments = 0;
50 this.NamedArguments =
new Dictionary<string, int>(StringComparer.InvariantCulture);
52 this.NamedArguments =
new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);
56 IsMetaDataArgument =
false;
63 this.RequestArgument = P.Position;
65 IsSpecialArgument =
true;
68 throw new ArgumentException(
"Only one argument of type HttpRequest is allowed.", nameof(
Method));
74 this.ResponseArgument = P.Position;
76 IsSpecialArgument =
true;
79 throw new ArgumentException(
"Only one argument of type HttpResponse is allowed.", nameof(
Method));
81 else if (P.ParameterType == typeof(Dictionary<string, object?>) &&
86 this.MetaDataArgument = P.Position;
88 IsSpecialArgument =
true;
89 IsMetaDataArgument =
true;
92 throw new ArgumentException(
"Only one meta-data argument is allowed.", nameof(
Method));
98 this.IdArgument = P.Position;
100 IsSpecialArgument =
true;
104 throw new ArgumentException(
"Only one ID argument is allowed.", nameof(
Method));
109 IsSpecialArgument =
false;
113 P.HasDefaultValue, P.HasDefaultValue ? P.DefaultValue :
null,
114 IsMetaDataArgument, IsIdArgument);
119 this.HasReturnValue = Method.ReturnType != typeof(Task) &&
125 this.ReturnValueDocumentation = Array.Empty<KeyValuePair<bool, string>>();
128 this.Name = DocName?.
Name ?? this.
Method.Name;
138 public static KeyValuePair<bool, string>[]
GetDocumentation(ICustomAttributeProvider Object)
145 Documentation.Add(
new KeyValuePair<bool, string>(DocAttribute.IsMarkdown, DocAttribute.Documentation));
254 MissingPrivilege =
null;
264 if (!User.HasPrivilege(Privilege))
266 MissingPrivilege = Privilege;
282 if (!this.
IsAuthorized(User, out
string? MissingPrivilege))
285 User?.UserName ??
string.Empty,
286 MissingPrivilege ??
string.Empty);
301 Dictionary<string, object?>? MetaData,
302 [NotNullWhen(
false)] out
string? Reason,
303 [NotNullWhen(
true)] out
object?[]?
Arguments)
306 int NrParametersSet = 0;
310 foreach (KeyValuePair<string, object?> P
in Parameters)
315 (P.Key ==
this.Arguments[
this.MetaDataArgument.Value].Parameter.Name ||
320 else if (P.Key ==
"_meta")
324 Reason =
"Invalid parameter name: " + P.Key;
330 object? Value = P.Value;
332 Type ExpectedType = ArgumentInfo.
Parameter.ParameterType;
333 Type ParameterType = Value?.GetType() ?? typeof(
object);
337 Dictionary<string, object?>? MetaDataValue = Value as Dictionary<string, object?>;
339 if (Value is
null || !(MetaDataValue is
null))
341 if (MetaDataValue is
null)
342 MetaDataValue = MetaData;
345 foreach (KeyValuePair<string, object?> P2
in MetaData)
347 if (!MetaDataValue.ContainsKey(P2.Key))
348 MetaDataValue[P2.Key] = P2.Value;
352 Value = MetaDataValue;
358 if (ParameterType == ExpectedType)
363 Value is Dictionary<string, object?> Dictionary &&
364 Dictionary.Count == 0)
371 Reason =
"Parameter " + P.Key +
372 " has incorrect type: " + ParameterType.FullName +
373 ", Expected: " + ExpectedType.FullName;
386 !Parameters.ContainsKey(Argument.
Parameter.Name))
396 Reason =
"Missing required parameters.";
424 if (
string.IsNullOrEmpty(ResourceMetaDataUri))
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
static ForbiddenException AccessDenied(string ObjectId, string ActorId)
Returns a ForbiddenException object, and logs a entry in the event log about the event.
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
Represents an HTTP request.
Represets a response of an HTTP client request.
Abstract base class for Web Services based on JSON-RPC v2.0.
Information about an argument in a protected method.
bool IsIdArgument
If the argument represents an ID argument.
bool IsSpecialArgument
If the argument represents a special argument.
ParameterInfo Parameter
Parameter information.
bool IsMetaDataArgument
If the argument represents a meta-data argument.
object? DefaultValue
Default value of argument, if defined.
bool HasDefaultValue
If the argument has a default value.
Information about a protected method.
int NrSpecialArguments
Number of special arguments
ProtectedMethodArgumentInfo[] Arguments
Arguments
bool IsAuthorized(IUser? User, out string? MissingPrivilege)
Checks if a user is authorized to call the method.
int? RequestArgument
Request argument index
int? IdArgument
ID argument index
int? MetaDataArgument
Meta-data argument index
bool IsAuthorized(IUser? User)
Checks if a user is authorized to call the method.
int NrArguments
Number of arguments
MethodInfo Method
Method information.
bool TryBuildRequest(object? Id, Dictionary< string, object?> Parameters, Dictionary< string, object?>? MetaData, [NotNullWhen(false)] out string? Reason, [NotNullWhen(true)] out object?[]? Arguments)
Tries to build a request for the method, based on the provided named parameters.
ProtectedMethod(MethodInfo Method, bool CaseSensitive)
Information about a protected method.
bool HasReturnValue
If the method has a return value.
Dictionary< string, int > NamedArguments
Named arguments
void AssertAuthorized(string ObjectId, IUser? User)
Asserts user is authorized to call the method. If not, a ForbiddenException is thrown.
HttpAuthenticationScheme?[] AuthenticationMechanisms
Authentication mechanisms available to authenticate users, if authentication is required.
int? ResponseArgument
Response argument index
KeyValuePair< bool, string >[] ReturnValueDocumentation
Available documentation for the return value. Value represents documentation text,...
bool RequiresAuthentication
If authentication of the user is required.
string[] RequiredPrivileges
Privileges required by the user that calls the method.
string Name
Name to use in documentation.
static KeyValuePair< bool, string >[] GetDocumentation(ICustomAttributeProvider Object)
Gets available documentation for a member. Value represents documentation text, and Key represents if...
KeyValuePair< bool, string >[] Documentation
Available documentation for the method. Value represents documentation text, and Key represents if th...
void UpdateAuthenticationMechanisms(string? ResourceMetaDataUri)
Updates the authentication mechanisms available to authenticate users that want to access the method.
void UpdateAuthenticationMechanisms()
Updates the authentication mechanisms available to authenticate users that want to access the method.
ProtectedMethod(MethodInfo Method, bool CaseSensitive, string[]? RequiredPrivileges)
Information about a protected method.
A chunked list is a linked list of chunks of objects of type T .
Class managing a script expression.
static bool IsVoid(Type ResultType)
Checks if a result object type is equal to void (i.e. its type equal to System.Threading....
static bool TryConvert(object Value, Type DesiredType, bool AcceptInformationLoss, out object Result)
Tries to convert an object Value to an object of type DesiredType .
static HttpAuthenticationScheme[] GetAuthenticationSchemes()
Gets an array of authentication schemes available to authorize access to a web resource.
Basic interface for a user.