com.wallstop-studios.dxmessaging 2.0.0-rc11 → 2.0.0-rc13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +63 -63
- package/.github/workflows/npm-publish.yml +66 -0
- package/CHANGELOG.md.meta +7 -7
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +33 -33
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +33 -33
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +33 -33
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +71 -71
- package/Editor/Analyzers.meta +8 -8
- package/Editor/SetupCscRsp.cs +162 -146
- package/Editor/SetupCscRsp.cs.meta +2 -2
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +17 -17
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
- package/Editor.meta +8 -8
- package/LICENSE.md +6 -6
- package/LICENSE.md.meta +7 -7
- package/README.md +387 -363
- package/README.md.meta +7 -7
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +7 -9
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +7 -10
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +7 -10
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +7 -10
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes.meta +2 -2
- package/Runtime/Core/Extensions/MessageExtensions.cs +342 -275
- package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
- package/Runtime/Core/Extensions.meta +8 -8
- package/Runtime/Core/IMessage.cs +12 -12
- package/Runtime/Core/IMessage.cs.meta +11 -11
- package/Runtime/Core/InstanceId.cs +149 -149
- package/Runtime/Core/InstanceId.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageBus.cs +309 -309
- package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessageBus.cs +2243 -2084
- package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +105 -100
- package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
- package/Runtime/Core/MessageBus/RegistrationLog.cs +111 -111
- package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
- package/Runtime/Core/MessageBus.meta +8 -8
- package/Runtime/Core/MessageHandler.cs +2778 -2759
- package/Runtime/Core/MessageHandler.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationHandle.cs +110 -110
- package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationToken.cs +1234 -1234
- package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
- package/Runtime/Core/Messages/IBroadcastMessage.cs +27 -27
- package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/ITargetedMessage.cs +27 -26
- package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/IUntargetedMessage.cs +27 -26
- package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages.meta +8 -8
- package/Runtime/Core/MessagingDebug.cs +70 -71
- package/Runtime/Core/MessagingDebug.cs.meta +11 -11
- package/Runtime/Core.meta +8 -8
- package/Runtime/Unity/MessageAwareComponent.cs +77 -77
- package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
- package/Runtime/Unity/MessagingComponent.cs +99 -99
- package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
- package/Runtime/Unity.meta +8 -8
- package/Runtime/WallstopStudios.DxMessaging.asmdef +15 -15
- package/Runtime.meta +8 -8
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +92 -75
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs.meta +11 -11
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +94 -77
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +94 -77
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +94 -78
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +21 -21
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
- package/SourceGenerators.meta +8 -8
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +373 -310
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs.meta +11 -11
- package/Tests/Runtime/Benchmarks.meta +8 -8
- package/Tests/Runtime/Core/BroadcastTests.cs +899 -899
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +190 -169
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs.meta +11 -11
- package/Tests/Runtime/Core/MessagingTestBase.cs +185 -164
- package/Tests/Runtime/Core/MessagingTestBase.cs.meta +11 -11
- package/Tests/Runtime/Core/NominalTests.cs +1740 -1518
- package/Tests/Runtime/Core/PostProcessorTests.cs +1236 -849
- package/Tests/Runtime/Core/PostProcessorTests.cs.meta +11 -11
- package/Tests/Runtime/Core/RegistrationTests.cs +1266 -995
- package/Tests/Runtime/Core/RegistrationTests.cs.meta +11 -11
- package/Tests/Runtime/Core/TargetedTests.cs +888 -888
- package/Tests/Runtime/Core/TargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Core/UntargetedTests.cs +272 -272
- package/Tests/Runtime/Core/UntargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +9 -9
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +186 -140
- package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +30 -30
- package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +8 -8
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.asmdef +22 -22
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +7 -7
- package/Tests.meta +8 -8
- package/Third Party Notices.md.meta +7 -7
- package/package.json +36 -36
- package/package.json.meta +7 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: a5f6f9d30e8df104dbd3a1bda50cce5f
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: a5f6f9d30e8df104dbd3a1bda50cce5f
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -1,100 +1,105 @@
|
|
|
1
|
-
namespace DxMessaging.Core.MessageBus
|
|
2
|
-
{
|
|
3
|
-
using System;
|
|
4
|
-
using System.Runtime.Serialization;
|
|
5
|
-
|
|
6
|
-
/// <summary>
|
|
7
|
-
/// How the registration was performed.
|
|
8
|
-
/// </summary>
|
|
9
|
-
public enum RegistrationType
|
|
10
|
-
{
|
|
11
|
-
Register,
|
|
12
|
-
Deregister
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/// <summary>
|
|
16
|
-
/// Exact method of MessagingRegistration.
|
|
17
|
-
/// </summary>
|
|
18
|
-
public enum RegistrationMethod
|
|
19
|
-
{
|
|
20
|
-
Targeted,
|
|
21
|
-
Untargeted,
|
|
22
|
-
Broadcast,
|
|
23
|
-
BroadcastWithoutSource,
|
|
24
|
-
TargetedWithoutTargeting,
|
|
25
|
-
GlobalAcceptAll,
|
|
26
|
-
Interceptor,
|
|
27
|
-
UntargetedPostProcessor,
|
|
28
|
-
TargetedPostProcessor,
|
|
29
|
-
BroadcastPostProcessor,
|
|
30
|
-
TargetedWithoutTargetingPostProcessor,
|
|
31
|
-
BroadcastWithoutSourcePostProcessor,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/// <summary>
|
|
35
|
-
/// Holds relevant information about a MessagingRegistration event
|
|
36
|
-
/// </summary>
|
|
37
|
-
[Serializable]
|
|
38
|
-
[DataContract]
|
|
39
|
-
public readonly struct MessagingRegistration
|
|
40
|
-
{
|
|
41
|
-
/// <summary>
|
|
42
|
-
/// Id of the MessageHandler that was registered.
|
|
43
|
-
/// </summary>
|
|
44
|
-
public readonly InstanceId id;
|
|
45
|
-
|
|
46
|
-
/// <summary>
|
|
47
|
-
/// Name of the type of Message that was registered for.
|
|
48
|
-
/// </summary>
|
|
49
|
-
public readonly Type type;
|
|
50
|
-
|
|
51
|
-
/// <summary>
|
|
52
|
-
/// New registration? De-registration?
|
|
53
|
-
/// </summary>
|
|
54
|
-
public readonly RegistrationType registrationType;
|
|
55
|
-
|
|
56
|
-
/// <summary>
|
|
57
|
-
/// Exact method of the registration.
|
|
58
|
-
/// </summary>
|
|
59
|
-
public readonly RegistrationMethod registrationMethod;
|
|
60
|
-
|
|
61
|
-
#if UNITY_2017_1_OR_NEWER
|
|
62
|
-
/// <summary>
|
|
63
|
-
/// Unity time of the registration
|
|
64
|
-
/// </summary>
|
|
65
|
-
public readonly float time;
|
|
66
|
-
#endif
|
|
67
|
-
|
|
68
|
-
/// <summary>
|
|
69
|
-
/// Creates a MessagingRegistration with all of the relevant tidbits filled out.
|
|
70
|
-
/// </summary>
|
|
71
|
-
/// <param name="id">Id of the MessageHandler.</param>
|
|
72
|
-
/// <param name="type">Type of Message.</param>
|
|
73
|
-
/// <param name="registrationType">Register? Deregister?</param>
|
|
74
|
-
/// <param name="registrationMethod">How the Message was chosen to be listened for.</param>
|
|
75
|
-
public MessagingRegistration(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
namespace DxMessaging.Core.MessageBus
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
5
|
+
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// How the registration was performed.
|
|
8
|
+
/// </summary>
|
|
9
|
+
public enum RegistrationType
|
|
10
|
+
{
|
|
11
|
+
Register,
|
|
12
|
+
Deregister,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Exact method of MessagingRegistration.
|
|
17
|
+
/// </summary>
|
|
18
|
+
public enum RegistrationMethod
|
|
19
|
+
{
|
|
20
|
+
Targeted,
|
|
21
|
+
Untargeted,
|
|
22
|
+
Broadcast,
|
|
23
|
+
BroadcastWithoutSource,
|
|
24
|
+
TargetedWithoutTargeting,
|
|
25
|
+
GlobalAcceptAll,
|
|
26
|
+
Interceptor,
|
|
27
|
+
UntargetedPostProcessor,
|
|
28
|
+
TargetedPostProcessor,
|
|
29
|
+
BroadcastPostProcessor,
|
|
30
|
+
TargetedWithoutTargetingPostProcessor,
|
|
31
|
+
BroadcastWithoutSourcePostProcessor,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Holds relevant information about a MessagingRegistration event
|
|
36
|
+
/// </summary>
|
|
37
|
+
[Serializable]
|
|
38
|
+
[DataContract]
|
|
39
|
+
public readonly struct MessagingRegistration
|
|
40
|
+
{
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// Id of the MessageHandler that was registered.
|
|
43
|
+
/// </summary>
|
|
44
|
+
public readonly InstanceId id;
|
|
45
|
+
|
|
46
|
+
/// <summary>
|
|
47
|
+
/// Name of the type of Message that was registered for.
|
|
48
|
+
/// </summary>
|
|
49
|
+
public readonly Type type;
|
|
50
|
+
|
|
51
|
+
/// <summary>
|
|
52
|
+
/// New registration? De-registration?
|
|
53
|
+
/// </summary>
|
|
54
|
+
public readonly RegistrationType registrationType;
|
|
55
|
+
|
|
56
|
+
/// <summary>
|
|
57
|
+
/// Exact method of the registration.
|
|
58
|
+
/// </summary>
|
|
59
|
+
public readonly RegistrationMethod registrationMethod;
|
|
60
|
+
|
|
61
|
+
#if UNITY_2017_1_OR_NEWER
|
|
62
|
+
/// <summary>
|
|
63
|
+
/// Unity time of the registration
|
|
64
|
+
/// </summary>
|
|
65
|
+
public readonly float time;
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
/// <summary>
|
|
69
|
+
/// Creates a MessagingRegistration with all of the relevant tidbits filled out.
|
|
70
|
+
/// </summary>
|
|
71
|
+
/// <param name="id">Id of the MessageHandler.</param>
|
|
72
|
+
/// <param name="type">Type of Message.</param>
|
|
73
|
+
/// <param name="registrationType">Register? Deregister?</param>
|
|
74
|
+
/// <param name="registrationMethod">How the Message was chosen to be listened for.</param>
|
|
75
|
+
public MessagingRegistration(
|
|
76
|
+
InstanceId id,
|
|
77
|
+
Type type,
|
|
78
|
+
RegistrationType registrationType,
|
|
79
|
+
RegistrationMethod registrationMethod
|
|
80
|
+
)
|
|
81
|
+
{
|
|
82
|
+
this.id = id;
|
|
83
|
+
this.type = type;
|
|
84
|
+
this.registrationType = registrationType;
|
|
85
|
+
this.registrationMethod = registrationMethod;
|
|
86
|
+
#if UNITY_2017_1_OR_NEWER
|
|
87
|
+
time = UnityEngine.Time.time;
|
|
88
|
+
#endif
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public override string ToString()
|
|
92
|
+
{
|
|
93
|
+
return new
|
|
94
|
+
{
|
|
95
|
+
#if UNITY_2017_1_OR_NEWER
|
|
96
|
+
time,
|
|
97
|
+
#endif
|
|
98
|
+
id,
|
|
99
|
+
type,
|
|
100
|
+
registrationType,
|
|
101
|
+
registrationMethod,
|
|
102
|
+
}.ToString();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: eee96e56f24970f4eb8be60dadefbefc
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: eee96e56f24970f4eb8be60dadefbefc
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
namespace DxMessaging.Core.MessageBus
|
|
2
|
-
{
|
|
3
|
-
using System;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.Text;
|
|
6
|
-
|
|
7
|
-
/// <summary>
|
|
8
|
-
/// Logs all MessageHandler registrations from the beginning of time.
|
|
9
|
-
/// </summary>
|
|
10
|
-
public sealed class RegistrationLog
|
|
11
|
-
{
|
|
12
|
-
public IReadOnlyList<MessagingRegistration> Registrations => _finalizedRegistrations;
|
|
13
|
-
|
|
14
|
-
private readonly List<MessagingRegistration> _finalizedRegistrations;
|
|
15
|
-
|
|
16
|
-
public bool Enabled
|
|
17
|
-
{
|
|
18
|
-
get => _enabled;
|
|
19
|
-
set => _enabled = value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private bool _enabled;
|
|
23
|
-
|
|
24
|
-
public RegistrationLog(bool enabled = false)
|
|
25
|
-
{
|
|
26
|
-
_enabled = enabled;
|
|
27
|
-
_finalizedRegistrations = new List<MessagingRegistration>();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/// <summary>
|
|
31
|
-
/// Logs a MessagingRegistration.
|
|
32
|
-
/// </summary>
|
|
33
|
-
/// <param name="registration">MessagingRegistration to record.</param>
|
|
34
|
-
public void Log(MessagingRegistration registration)
|
|
35
|
-
{
|
|
36
|
-
if (!_enabled)
|
|
37
|
-
{
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
_finalizedRegistrations.Add(registration);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/// <summary>
|
|
44
|
-
/// Retrieves all registrations for the provided InstanceId.
|
|
45
|
-
/// </summary>
|
|
46
|
-
/// <param name="instanceId">InstanceId to search for.</param>
|
|
47
|
-
/// <returns>All registrations for the provided InstanceId.</returns>
|
|
48
|
-
public IEnumerable<MessagingRegistration> GetRegistrations(InstanceId instanceId)
|
|
49
|
-
{
|
|
50
|
-
foreach (MessagingRegistration registration in _finalizedRegistrations)
|
|
51
|
-
{
|
|
52
|
-
if (registration.id == instanceId)
|
|
53
|
-
{
|
|
54
|
-
yield return registration;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/// <summary>
|
|
60
|
-
/// Pretty-print all of the logged Messaging registrations using the provided print function.
|
|
61
|
-
/// </summary>
|
|
62
|
-
/// <param name="serializer">Serialization function to use. If null, defaults to MessagingRegistration.ToString.</param>
|
|
63
|
-
/// <returns>The string representing all logged MessagingRegistrations.</returns>
|
|
64
|
-
public string ToString(Func<MessagingRegistration, string> serializer)
|
|
65
|
-
{
|
|
66
|
-
if (_finalizedRegistrations.Count == 0)
|
|
67
|
-
{
|
|
68
|
-
return "[]";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
serializer ??= registration => registration.ToString();
|
|
72
|
-
|
|
73
|
-
StringBuilder registrations = new();
|
|
74
|
-
_ = registrations.Append('[');
|
|
75
|
-
for (int i = 0; i < _finalizedRegistrations.Count; ++i)
|
|
76
|
-
{
|
|
77
|
-
if (0 < i)
|
|
78
|
-
{
|
|
79
|
-
_ = registrations.Append(", ");
|
|
80
|
-
}
|
|
81
|
-
MessagingRegistration finalizedRegistration = _finalizedRegistrations[i];
|
|
82
|
-
string prettyFinalizedRegistration = serializer(finalizedRegistration);
|
|
83
|
-
_ = registrations.Append(prettyFinalizedRegistration);
|
|
84
|
-
}
|
|
85
|
-
_ = registrations.Append(']');
|
|
86
|
-
return registrations.ToString();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public override string ToString()
|
|
90
|
-
{
|
|
91
|
-
return ToString(null);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/// <summary>
|
|
95
|
-
/// Removes all MessagingRegistrations that satisfy the provided function, or all registrations if no function is provided.
|
|
96
|
-
/// </summary>
|
|
97
|
-
/// <param name="shouldRemove">Null if all MessagingRegistrations should be removed, or a custom function that returns true for any MessagingRegistration that should be removed.</param>
|
|
98
|
-
/// <returns>Number of MessagingRegistrations removed.</returns>
|
|
99
|
-
public int Clear(Predicate<MessagingRegistration> shouldRemove = null)
|
|
100
|
-
{
|
|
101
|
-
if (shouldRemove == null)
|
|
102
|
-
{
|
|
103
|
-
int currentCount = _finalizedRegistrations.Count;
|
|
104
|
-
_finalizedRegistrations.Clear();
|
|
105
|
-
return currentCount;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return _finalizedRegistrations.RemoveAll(shouldRemove);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
1
|
+
namespace DxMessaging.Core.MessageBus
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Text;
|
|
6
|
+
|
|
7
|
+
/// <summary>
|
|
8
|
+
/// Logs all MessageHandler registrations from the beginning of time.
|
|
9
|
+
/// </summary>
|
|
10
|
+
public sealed class RegistrationLog
|
|
11
|
+
{
|
|
12
|
+
public IReadOnlyList<MessagingRegistration> Registrations => _finalizedRegistrations;
|
|
13
|
+
|
|
14
|
+
private readonly List<MessagingRegistration> _finalizedRegistrations;
|
|
15
|
+
|
|
16
|
+
public bool Enabled
|
|
17
|
+
{
|
|
18
|
+
get => _enabled;
|
|
19
|
+
set => _enabled = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private bool _enabled;
|
|
23
|
+
|
|
24
|
+
public RegistrationLog(bool enabled = false)
|
|
25
|
+
{
|
|
26
|
+
_enabled = enabled;
|
|
27
|
+
_finalizedRegistrations = new List<MessagingRegistration>();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
/// Logs a MessagingRegistration.
|
|
32
|
+
/// </summary>
|
|
33
|
+
/// <param name="registration">MessagingRegistration to record.</param>
|
|
34
|
+
public void Log(MessagingRegistration registration)
|
|
35
|
+
{
|
|
36
|
+
if (!_enabled)
|
|
37
|
+
{
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
_finalizedRegistrations.Add(registration);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// <summary>
|
|
44
|
+
/// Retrieves all registrations for the provided InstanceId.
|
|
45
|
+
/// </summary>
|
|
46
|
+
/// <param name="instanceId">InstanceId to search for.</param>
|
|
47
|
+
/// <returns>All registrations for the provided InstanceId.</returns>
|
|
48
|
+
public IEnumerable<MessagingRegistration> GetRegistrations(InstanceId instanceId)
|
|
49
|
+
{
|
|
50
|
+
foreach (MessagingRegistration registration in _finalizedRegistrations)
|
|
51
|
+
{
|
|
52
|
+
if (registration.id == instanceId)
|
|
53
|
+
{
|
|
54
|
+
yield return registration;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
/// Pretty-print all of the logged Messaging registrations using the provided print function.
|
|
61
|
+
/// </summary>
|
|
62
|
+
/// <param name="serializer">Serialization function to use. If null, defaults to MessagingRegistration.ToString.</param>
|
|
63
|
+
/// <returns>The string representing all logged MessagingRegistrations.</returns>
|
|
64
|
+
public string ToString(Func<MessagingRegistration, string> serializer)
|
|
65
|
+
{
|
|
66
|
+
if (_finalizedRegistrations.Count == 0)
|
|
67
|
+
{
|
|
68
|
+
return "[]";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
serializer ??= registration => registration.ToString();
|
|
72
|
+
|
|
73
|
+
StringBuilder registrations = new();
|
|
74
|
+
_ = registrations.Append('[');
|
|
75
|
+
for (int i = 0; i < _finalizedRegistrations.Count; ++i)
|
|
76
|
+
{
|
|
77
|
+
if (0 < i)
|
|
78
|
+
{
|
|
79
|
+
_ = registrations.Append(", ");
|
|
80
|
+
}
|
|
81
|
+
MessagingRegistration finalizedRegistration = _finalizedRegistrations[i];
|
|
82
|
+
string prettyFinalizedRegistration = serializer(finalizedRegistration);
|
|
83
|
+
_ = registrations.Append(prettyFinalizedRegistration);
|
|
84
|
+
}
|
|
85
|
+
_ = registrations.Append(']');
|
|
86
|
+
return registrations.ToString();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public override string ToString()
|
|
90
|
+
{
|
|
91
|
+
return ToString(null);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// <summary>
|
|
95
|
+
/// Removes all MessagingRegistrations that satisfy the provided function, or all registrations if no function is provided.
|
|
96
|
+
/// </summary>
|
|
97
|
+
/// <param name="shouldRemove">Null if all MessagingRegistrations should be removed, or a custom function that returns true for any MessagingRegistration that should be removed.</param>
|
|
98
|
+
/// <returns>Number of MessagingRegistrations removed.</returns>
|
|
99
|
+
public int Clear(Predicate<MessagingRegistration> shouldRemove = null)
|
|
100
|
+
{
|
|
101
|
+
if (shouldRemove == null)
|
|
102
|
+
{
|
|
103
|
+
int currentCount = _finalizedRegistrations.Count;
|
|
104
|
+
_finalizedRegistrations.Clear();
|
|
105
|
+
return currentCount;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return _finalizedRegistrations.RemoveAll(shouldRemove);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 40f286d82f8049a4cb8c8634b4d869f6
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 40f286d82f8049a4cb8c8634b4d869f6
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid: 83a6c4df135c37d4ebaf87dfd072ebd3
|
|
3
|
-
folderAsset: yes
|
|
4
|
-
DefaultImporter:
|
|
5
|
-
externalObjects: {}
|
|
6
|
-
userData:
|
|
7
|
-
assetBundleName:
|
|
8
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 83a6c4df135c37d4ebaf87dfd072ebd3
|
|
3
|
+
folderAsset: yes
|
|
4
|
+
DefaultImporter:
|
|
5
|
+
externalObjects: {}
|
|
6
|
+
userData:
|
|
7
|
+
assetBundleName:
|
|
8
|
+
assetBundleVariant:
|