You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
source.AppendLine(" var services = new global::System.Collections.Generic.Dictionary<string, global::Lagrange.Core.Internal.Services.IService>();");
126
-
source.AppendLine(" var servicesEventType = new global::System.Collections.Generic.Dictionary<global::System.Type, (global::Lagrange.Core.Internal.Services.ServiceAttribute Attribute, global::Lagrange.Core.Internal.Services.IService Instance)>();");
126
+
source.AppendLine(" var services = new global::System.Collections.Generic.Dictionary<string, global::Lagrange.Core.Services.IService>();");
127
+
source.AppendLine(" var servicesEventType = new global::System.Collections.Generic.Dictionary<global::System.Type, (global::Lagrange.Core.Services.ServiceAttribute Attribute, global::Lagrange.Core.Services.IService Instance)>();");
source.AppendLine(" if (servicesEventType.ContainsKey(eventType))");
141
142
source.AppendLine(" {");
142
-
source.AppendLine(" throw new global::System.InvalidOperationException($\"Multiple services for event type: {eventType}\");");
143
+
source.AppendLine(" throw new global::Lagrange.Core.Exceptions.ServiceRegistrationException($\"Multiple protocol services are registered for event type '{eventType}'.\");");
source.AppendLine(" if (!services.TryGetValue(attribute.Command, out service))");
183
+
source.AppendLine(" if (service is null)");
183
184
source.AppendLine(" {");
185
+
source.AppendLine(" if (services.ContainsKey(attribute.Command))");
186
+
source.AppendLine(" {");
187
+
source.AppendLine(" throw new global::Lagrange.Core.Exceptions.ServiceRegistrationException($\"Multiple protocol services are registered for command '{attribute.Command}'.\");");
188
+
source.AppendLine(" }");
189
+
source.AppendLine();
184
190
source.Append(" service = new ").Append(service.ServiceType).AppendLine("();");
thrownewLagrangeException($"The event type is not the same as the expected type. Expected: {typeof(T)}, Actual: {resolved.GetType()}");
34
+
varresult=resolvedasT??thrownewLagrangeException($"The event type is not the same as the expected type. Expected: {typeof(T)}, Actual: {resolved.GetType()}");
35
+
awaitHandleIncomingEvent(result);
36
+
returnresult;
45
37
}
46
38
catch(Exceptione)when(eis not LagrangeException)
47
39
{
@@ -112,7 +104,7 @@ public async Task HandleServerPacket(BotSsoPacket packet)
112
104
}
113
105
catch(ServiceNotFoundExceptione)
114
106
{
115
-
_context.LogDebug(Tag,"Service not found for command: {0}",e,e.Command);
107
+
_context.LogDebug(Tag,"Service not found for command: {0}",e.Command);
varattribute=serviceType.GetCustomAttribute<ServiceAttribute>(false)??thrownewServiceRegistrationException($"Custom protocol service {serviceType} must have {nameof(ServiceAttribute)}.");
88
+
if(string.IsNullOrWhiteSpace(attribute.Command))thrownewServiceRegistrationException($"Custom protocol service {serviceType} must specify a non-empty command.");
if(!services.TryAdd(attribute.Command,service))thrownewServiceRegistrationException($"Multiple protocol services are registered for command '{attribute.Command}'.");
if(servicesEventType.ContainsKey(eventType))thrownewServiceRegistrationException($"Multiple protocol services are registered for event type '{eventType}'.");
if(!typeof(ProtocolEvent).IsAssignableFrom(subscription.EventType))thrownewServiceRegistrationException($"Event type '{subscription.EventType}' on {serviceType} must derive from {nameof(ProtocolEvent)}.");
116
+
if(subscription.Protocols==Protocols.None)thrownewServiceRegistrationException($"Event subscription '{subscription.EventType}' on {serviceType} must specify at least one protocol.");
117
+
if(!eventTypes.Add(subscription.EventType))thrownewServiceRegistrationException($"Custom protocol service {serviceType} registers event type '{subscription.EventType}' more than once.");
0 commit comments