| | | 1 | | using System.Reflection; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Telegram.Internal.Handlers; |
| | | 4 | | |
| | | 5 | | internal delegate ValueTask TelegramHandlerGeneratedInvoker( |
| | | 6 | | IServiceProvider services, |
| | | 7 | | object?[] arguments, |
| | | 8 | | CancellationToken cancellationToken); |
| | | 9 | | |
| | | 10 | | internal sealed class TelegramHandlerDescriptor |
| | | 11 | | { |
| | | 12 | | public TelegramHandlerDescriptor( |
| | | 13 | | Type handlerType, |
| | | 14 | | MethodInfo method, |
| | | 15 | | TelegramRouteDescriptor route, |
| | | 16 | | int registrationOrder, |
| | | 17 | | string? moduleName, |
| | | 18 | | IReadOnlyList<string> states, |
| | | 19 | | IReadOnlyList<TelegramHandlerParameterDescriptor> parameters, |
| | | 20 | | string? sceneName = null, |
| | | 21 | | TelegramAutoAnswerCallbackDescriptor? autoAnswerCallback = null) |
| | 320 | 22 | | : this( |
| | 320 | 23 | | handlerType, |
| | 320 | 24 | | method, |
| | 320 | 25 | | method.Name, |
| | 320 | 26 | | generatedInvoker: null, |
| | 320 | 27 | | route, |
| | 320 | 28 | | registrationOrder, |
| | 320 | 29 | | moduleName, |
| | 320 | 30 | | sceneName, |
| | 320 | 31 | | autoAnswerCallback, |
| | 320 | 32 | | states, |
| | 320 | 33 | | parameters) |
| | | 34 | | { |
| | 320 | 35 | | } |
| | | 36 | | |
| | | 37 | | public TelegramHandlerDescriptor( |
| | | 38 | | Type handlerType, |
| | | 39 | | MethodInfo method, |
| | | 40 | | TelegramHandlerKind kind, |
| | | 41 | | int registrationOrder, |
| | | 42 | | string? moduleName, |
| | | 43 | | string? command, |
| | | 44 | | IReadOnlyList<TelegramTextFilter> textFilters, |
| | | 45 | | IReadOnlyList<string> states, |
| | | 46 | | Type? callbackPayloadType, |
| | | 47 | | IReadOnlyList<TelegramHandlerParameterDescriptor> parameters, |
| | | 48 | | string? sceneName = null, |
| | | 49 | | TelegramAutoAnswerCallbackDescriptor? autoAnswerCallback = null) |
| | 0 | 50 | | : this( |
| | 0 | 51 | | handlerType, |
| | 0 | 52 | | method, |
| | 0 | 53 | | method.Name, |
| | 0 | 54 | | generatedInvoker: null, |
| | 0 | 55 | | new TelegramRouteDescriptor(kind, command, textFilters, callbackPayloadType), |
| | 0 | 56 | | registrationOrder, |
| | 0 | 57 | | moduleName, |
| | 0 | 58 | | sceneName, |
| | 0 | 59 | | autoAnswerCallback, |
| | 0 | 60 | | states, |
| | 0 | 61 | | parameters) |
| | | 62 | | { |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | public TelegramHandlerDescriptor( |
| | | 66 | | Type handlerType, |
| | | 67 | | string methodName, |
| | | 68 | | TelegramHandlerGeneratedInvoker generatedInvoker, |
| | | 69 | | TelegramRouteDescriptor route, |
| | | 70 | | int registrationOrder, |
| | | 71 | | string? moduleName, |
| | | 72 | | IReadOnlyList<string> states, |
| | | 73 | | IReadOnlyList<TelegramHandlerParameterDescriptor> parameters, |
| | | 74 | | string? sceneName = null, |
| | | 75 | | TelegramAutoAnswerCallbackDescriptor? autoAnswerCallback = null) |
| | 832 | 76 | | : this( |
| | 832 | 77 | | handlerType, |
| | 832 | 78 | | method: null, |
| | 832 | 79 | | methodName, |
| | 832 | 80 | | generatedInvoker, |
| | 832 | 81 | | route, |
| | 832 | 82 | | registrationOrder, |
| | 832 | 83 | | moduleName, |
| | 832 | 84 | | sceneName, |
| | 832 | 85 | | autoAnswerCallback, |
| | 832 | 86 | | states, |
| | 832 | 87 | | parameters) |
| | | 88 | | { |
| | 832 | 89 | | } |
| | | 90 | | |
| | | 91 | | public TelegramHandlerDescriptor( |
| | | 92 | | Type handlerType, |
| | | 93 | | string methodName, |
| | | 94 | | TelegramHandlerGeneratedInvoker generatedInvoker, |
| | | 95 | | TelegramHandlerKind kind, |
| | | 96 | | int registrationOrder, |
| | | 97 | | string? moduleName, |
| | | 98 | | string? command, |
| | | 99 | | IReadOnlyList<TelegramTextFilter> textFilters, |
| | | 100 | | IReadOnlyList<string> states, |
| | | 101 | | Type? callbackPayloadType, |
| | | 102 | | IReadOnlyList<TelegramHandlerParameterDescriptor> parameters, |
| | | 103 | | string? sceneName = null, |
| | | 104 | | TelegramAutoAnswerCallbackDescriptor? autoAnswerCallback = null) |
| | 0 | 105 | | : this( |
| | 0 | 106 | | handlerType, |
| | 0 | 107 | | method: null, |
| | 0 | 108 | | methodName, |
| | 0 | 109 | | generatedInvoker, |
| | 0 | 110 | | new TelegramRouteDescriptor(kind, command, textFilters, callbackPayloadType), |
| | 0 | 111 | | registrationOrder, |
| | 0 | 112 | | moduleName, |
| | 0 | 113 | | sceneName, |
| | 0 | 114 | | autoAnswerCallback, |
| | 0 | 115 | | states, |
| | 0 | 116 | | parameters) |
| | | 117 | | { |
| | 0 | 118 | | } |
| | | 119 | | |
| | | 120 | | private TelegramHandlerDescriptor( |
| | | 121 | | Type handlerType, |
| | | 122 | | MethodInfo? method, |
| | | 123 | | string methodName, |
| | | 124 | | TelegramHandlerGeneratedInvoker? generatedInvoker, |
| | | 125 | | TelegramRouteDescriptor route, |
| | | 126 | | int registrationOrder, |
| | | 127 | | string? moduleName, |
| | | 128 | | string? sceneName, |
| | | 129 | | TelegramAutoAnswerCallbackDescriptor? autoAnswerCallback, |
| | | 130 | | IReadOnlyList<string> states, |
| | | 131 | | IReadOnlyList<TelegramHandlerParameterDescriptor> parameters) |
| | | 132 | | { |
| | 1152 | 133 | | ArgumentNullException.ThrowIfNull(handlerType); |
| | 1152 | 134 | | ArgumentException.ThrowIfNullOrWhiteSpace(methodName); |
| | 1152 | 135 | | ArgumentNullException.ThrowIfNull(route); |
| | 1152 | 136 | | ArgumentNullException.ThrowIfNull(states); |
| | 1152 | 137 | | ArgumentNullException.ThrowIfNull(parameters); |
| | | 138 | | |
| | | 139 | | HandlerType = handlerType; |
| | | 140 | | Method = method; |
| | | 141 | | MethodName = methodName; |
| | | 142 | | GeneratedInvoker = generatedInvoker; |
| | | 143 | | RegistrationOrder = registrationOrder; |
| | | 144 | | ModuleName = moduleName; |
| | | 145 | | SceneName = sceneName; |
| | | 146 | | AutoAnswerCallback = autoAnswerCallback; |
| | | 147 | | Route = route; |
| | | 148 | | States = states; |
| | | 149 | | Parameters = parameters; |
| | 1152 | 150 | | } |
| | | 151 | | |
| | | 152 | | public Type HandlerType { get; } |
| | | 153 | | |
| | | 154 | | public MethodInfo? Method { get; } |
| | | 155 | | |
| | | 156 | | public string MethodName { get; } |
| | | 157 | | |
| | | 158 | | public TelegramHandlerGeneratedInvoker? GeneratedInvoker { get; } |
| | | 159 | | |
| | 4379 | 160 | | public TelegramHandlerKind Kind => Route.Kind; |
| | | 161 | | |
| | | 162 | | public int RegistrationOrder { get; } |
| | | 163 | | |
| | | 164 | | public string? ModuleName { get; } |
| | | 165 | | |
| | | 166 | | public string? SceneName { get; } |
| | | 167 | | |
| | | 168 | | public TelegramAutoAnswerCallbackDescriptor? AutoAnswerCallback { get; } |
| | | 169 | | |
| | | 170 | | public TelegramRouteDescriptor Route { get; } |
| | | 171 | | |
| | 1116 | 172 | | public string? Command => Route.Command; |
| | | 173 | | |
| | 0 | 174 | | public IReadOnlyList<TelegramTextFilter> TextFilters => Route.TextFilters; |
| | | 175 | | |
| | | 176 | | public IReadOnlyList<string> States { get; } |
| | | 177 | | |
| | 561 | 178 | | public Type? CallbackPayloadType => Route.CallbackPayloadType; |
| | | 179 | | |
| | | 180 | | public IReadOnlyList<TelegramHandlerParameterDescriptor> Parameters { get; } |
| | | 181 | | } |