diff --git a/AISmart.sln b/AISmart.sln index 56f71a6a..14946bfd 100644 --- a/AISmart.sln +++ b/AISmart.sln @@ -95,6 +95,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AISmart.CQRS", "src\AISmart EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AISmart.Rag.Contracts", "src\AISmart.Rag.Contracts\AISmart.Rag.Contracts.csproj", "{3A58DC0A-BA95-48B9-9468-F7892A71F4FA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AISmart.GAgent.Core.Context", "src\AISmart.GAgent.Core.Context\AISmart.GAgent.Core.Context.csproj", "{AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AISmart.GAgent.EventContext", "src\AISmart.GAgent.EventContext\AISmart.GAgent.EventContext.csproj", "{61716D0E-9B1E-47D1-BED6-47D1C034B237}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -269,6 +273,14 @@ Global {3A58DC0A-BA95-48B9-9468-F7892A71F4FA}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A58DC0A-BA95-48B9-9468-F7892A71F4FA}.Release|Any CPU.ActiveCfg = Release|Any CPU {3A58DC0A-BA95-48B9-9468-F7892A71F4FA}.Release|Any CPU.Build.0 = Release|Any CPU + {AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0}.Release|Any CPU.Build.0 = Release|Any CPU + {61716D0E-9B1E-47D1-BED6-47D1C034B237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61716D0E-9B1E-47D1-BED6-47D1C034B237}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61716D0E-9B1E-47D1-BED6-47D1C034B237}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61716D0E-9B1E-47D1-BED6-47D1C034B237}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -316,6 +328,8 @@ Global {89A0820D-CBB0-4061-A939-F30EF486BA93} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} {23A8822F-83B5-4ABA-B05B-BAE9670ACD68} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} {3A58DC0A-BA95-48B9-9468-F7892A71F4FA} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} + {AC8AE7DC-B3D0-4C2D-A905-CB1D0F4F08F0} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} + {61716D0E-9B1E-47D1-BED6-47D1C034B237} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/src/AISmart.Application.Contracts/Agents/EventWrapper.cs b/src/AISmart.Application.Contracts/Agents/EventWrapper.cs index 4b369790..c2a791db 100644 --- a/src/AISmart.Application.Contracts/Agents/EventWrapper.cs +++ b/src/AISmart.Application.Contracts/Agents/EventWrapper.cs @@ -14,13 +14,12 @@ public class EventWrapper : EventWrapperBase [Id(3)] public GrainId? ContextStorageGrainId { get; set; } // Constructor - public EventWrapper(T @event, Guid eventId, GrainId grainId, GrainId? contextStorageGrainId) + public EventWrapper(T @event, Guid eventId, GrainId grainId, GrainId? contextStorageGrainId = null) { Event = @event; EventId = eventId; GrainId = grainId; ContextStorageGrainId = contextStorageGrainId; - } // Optionally, you can add methods or other functionality as needed diff --git a/src/AISmart.Application.Grains/AISmart.Application.Grains.csproj b/src/AISmart.Application.Grains/AISmart.Application.Grains.csproj index 18d9ab0e..ca445a5f 100644 --- a/src/AISmart.Application.Grains/AISmart.Application.Grains.csproj +++ b/src/AISmart.Application.Grains/AISmart.Application.Grains.csproj @@ -20,6 +20,7 @@ + diff --git a/src/AISmart.Application.Grains/Agents/Publisher/PublishingGAgent.cs b/src/AISmart.Application.Grains/Agents/Publisher/PublishingGAgent.cs index 99032cc4..55068377 100644 --- a/src/AISmart.Application.Grains/Agents/Publisher/PublishingGAgent.cs +++ b/src/AISmart.Application.Grains/Agents/Publisher/PublishingGAgent.cs @@ -15,7 +15,7 @@ public class PublishingAgentState : StateBase [StorageProvider(ProviderName = "PubSubStore")] [LogConsistencyProvider(ProviderName = "LogStorage")] -public class PublishingGAgent : GAgentBase, IPublishingGAgent +public class PublishingGAgent : ContextGAgentBase, IPublishingGAgent { public PublishingGAgent(ILogger logger) : base(logger) { diff --git a/src/AISmart.GAgent.Core.Context/AISmart.GAgent.Core.Context.csproj b/src/AISmart.GAgent.Core.Context/AISmart.GAgent.Core.Context.csproj new file mode 100644 index 00000000..90457e67 --- /dev/null +++ b/src/AISmart.GAgent.Core.Context/AISmart.GAgent.Core.Context.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/src/AISmart.GAgent.Core.Context/AISmartGAgentContextConstants.cs b/src/AISmart.GAgent.Core.Context/AISmartGAgentContextConstants.cs new file mode 100644 index 00000000..082df8d3 --- /dev/null +++ b/src/AISmart.GAgent.Core.Context/AISmartGAgentContextConstants.cs @@ -0,0 +1,7 @@ +namespace AISmart.GAgent.Core.Context; + +public class AISmartGAgentContextConstants +{ + public const string ContextStorageGrainSelfTerminateReminderName = "DeleteSelfReminder"; + public static TimeSpan DefaultContextStorageGrainSelfDeleteTime = TimeSpan.FromMinutes(10); +} \ No newline at end of file diff --git a/src/AISmart.GAgent.Core/ContextStorageGrain.cs b/src/AISmart.GAgent.Core.Context/ContextStorageGrain.cs similarity index 88% rename from src/AISmart.GAgent.Core/ContextStorageGrain.cs rename to src/AISmart.GAgent.Core.Context/ContextStorageGrain.cs index 19515984..71473a29 100644 --- a/src/AISmart.GAgent.Core/ContextStorageGrain.cs +++ b/src/AISmart.GAgent.Core.Context/ContextStorageGrain.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace AISmart.GAgent.Core; +namespace AISmart.GAgent.Core.Context; public sealed class ContextStorageState { @@ -85,16 +85,16 @@ public async Task ReceiveReminder(string reminderName, TickStatus status) public async Task ResetSelfTerminateTime(TimeSpan timeSpan) { _reminder = await this.RegisterOrUpdateReminder( - AISmartGAgentConstants.ContextStorageGrainSelfTerminateReminderName, + AISmartGAgentContextConstants.ContextStorageGrainSelfTerminateReminderName, timeSpan, timeSpan); } public override async Task OnActivateAsync(CancellationToken cancellationToken) { _reminder = await this.RegisterOrUpdateReminder( - AISmartGAgentConstants.ContextStorageGrainSelfTerminateReminderName, - AISmartGAgentConstants.DefaultContextStorageGrainSelfDeleteTime, - AISmartGAgentConstants.DefaultContextStorageGrainSelfDeleteTime); + AISmartGAgentContextConstants.ContextStorageGrainSelfTerminateReminderName, + AISmartGAgentContextConstants.DefaultContextStorageGrainSelfDeleteTime, + AISmartGAgentContextConstants.DefaultContextStorageGrainSelfDeleteTime); await base.OnActivateAsync(cancellationToken); } } \ No newline at end of file diff --git a/src/AISmart.GAgent.Core.Context/ContextStorageHelper.cs b/src/AISmart.GAgent.Core.Context/ContextStorageHelper.cs new file mode 100644 index 00000000..3e2e9cb2 --- /dev/null +++ b/src/AISmart.GAgent.Core.Context/ContextStorageHelper.cs @@ -0,0 +1,37 @@ +using AISmart.Agents; + +namespace AISmart.GAgent.Core.Context; + +public class ContextStorageHelper +{ + private readonly IGrainFactory? _grainFactory; + + public ContextStorageHelper(IGrainFactory grainFactory) + { + _grainFactory = grainFactory; + } + + public async Task SetContextAsync(EventWrapperBase item, EventBase eventType) + { + if (_grainFactory == null) + { + return null; + } + + var contextStorageGrainIdValue = item.GetType() + .GetProperty(nameof(EventWrapper.ContextStorageGrainId))? + .GetValue(item); + GrainId? contextStorageGrainId = null; + if (contextStorageGrainIdValue == null) + { + return contextStorageGrainId; + } + + contextStorageGrainId = (GrainId)contextStorageGrainIdValue; + var contextStorageGrain = + _grainFactory.GetGrain(contextStorageGrainId.Value.GetGuidKey()); + var context = await contextStorageGrain.GetContext(); + eventType.SetContext(context); + return contextStorageGrainId; + } +} \ No newline at end of file diff --git a/src/AISmart.GAgent.Core.Context/EventContextExtensions.cs b/src/AISmart.GAgent.Core.Context/EventContextExtensions.cs new file mode 100644 index 00000000..ba5bca5a --- /dev/null +++ b/src/AISmart.GAgent.Core.Context/EventContextExtensions.cs @@ -0,0 +1,56 @@ +namespace AISmart.GAgent.Core.Context; + +public static class EventContextExtensions +{ + public static async Task SetContextAsync(this IEventContext context, string key, object? value) + { + if (context.ContextStorageGrainId != null) + { + var contextStorageGrain = + context.GrainFactory.GetGrain(context.ContextStorageGrainId.Value.GetGuidKey()); + await contextStorageGrain.AddContext(key, value); + } + } + + public static async Task SetContextAsync(this IEventContext context, Dictionary contextData) + { + if (context.ContextStorageGrainId != null) + { + var contextStorageGrain = + context.GrainFactory.GetGrain(context.ContextStorageGrainId.Value.GetGuidKey()); + await contextStorageGrain.AddContext(contextData); + } + } + + public static async Task ResetContextStorageGrainTerminateTimeAsync(this IEventContext context, TimeSpan timeSpan) + { + if (context.ContextStorageGrainId != null) + { + var contextStorageGrain = + context.GrainFactory.GetGrain(context.ContextStorageGrainId.Value.GetGuidKey()); + await contextStorageGrain.ResetSelfTerminateTime(timeSpan); + } + } + + public static async Task> GetContextAsync(this IEventContext context) + { + if (context.ContextStorageGrainId != null) + { + var contextStorageGrain = + context.GrainFactory.GetGrain(context.ContextStorageGrainId.Value.GetGuidKey()); + return await contextStorageGrain.GetContext(); + } + + return new Dictionary(); + } + + public static void SetContextStorageGrainId(this IEventContext context, GrainId? grainId) + { + context.ContextStorageGrainId = grainId; + } + + public static void ClearContext(this IEventContext context) + { + context.ContextStorageGrainId = null; + } +} \ No newline at end of file diff --git a/src/AISmart.GAgent.Core.Context/IEventContext.cs b/src/AISmart.GAgent.Core.Context/IEventContext.cs new file mode 100644 index 00000000..aaf54eb6 --- /dev/null +++ b/src/AISmart.GAgent.Core.Context/IEventContext.cs @@ -0,0 +1,9 @@ +namespace AISmart.GAgent.Core.Context; + +public interface IEventContext +{ + GrainId? ContextStorageGrainId { get; set; } + IGrainFactory GrainFactory { get; } + void SetContextStorageGrainId(GrainId? grainId); + void ClearContext(); +} \ No newline at end of file diff --git a/src/AISmart.GAgent.Core/AISmart.GAgent.Core.csproj b/src/AISmart.GAgent.Core/AISmart.GAgent.Core.csproj index 7a0a03b1..34fd3d75 100644 --- a/src/AISmart.GAgent.Core/AISmart.GAgent.Core.csproj +++ b/src/AISmart.GAgent.Core/AISmart.GAgent.Core.csproj @@ -9,6 +9,7 @@ + diff --git a/src/AISmart.GAgent.Core/AISmartGAgentConstants.cs b/src/AISmart.GAgent.Core/AISmartGAgentConstants.cs index 30049c5e..bb802890 100644 --- a/src/AISmart.GAgent.Core/AISmartGAgentConstants.cs +++ b/src/AISmart.GAgent.Core/AISmartGAgentConstants.cs @@ -6,6 +6,4 @@ public static class AISmartGAgentConstants public const string SubscribersStateName = "Subscribers"; public const string SubscriptionsStateName = "Subscriptions"; public const string PublishersStateName = "Publishers"; - public const string ContextStorageGrainSelfTerminateReminderName = "DeleteSelfReminder"; - public static TimeSpan DefaultContextStorageGrainSelfDeleteTime = TimeSpan.FromMinutes(10); } \ No newline at end of file diff --git a/src/AISmart.GAgent.Core/GAgentBase.Context.cs b/src/AISmart.GAgent.Core/GAgentBase.Context.cs deleted file mode 100644 index e49a0fc2..00000000 --- a/src/AISmart.GAgent.Core/GAgentBase.Context.cs +++ /dev/null @@ -1,60 +0,0 @@ -namespace AISmart.GAgent.Core; - -public abstract partial class GAgentBase -{ - private GrainId? _contextStorageGrainId; - - protected async Task SetContextAsync(string key, object? value) - { - if (_contextStorageGrainId != null) - { - var contextStorageGrain = GrainFactory.GetGrain(_contextStorageGrainId.Value.GetGuidKey()); - await contextStorageGrain.AddContext(key, value); - } - } - - protected async Task SetContextAsync(Dictionary context) - { - if (_contextStorageGrainId != null) - { - var contextStorageGrain = GrainFactory.GetGrain(_contextStorageGrainId.Value.GetGuidKey()); - await contextStorageGrain.AddContext(context); - } - } - - protected async Task ResetContextStorageGrainTerminateTimeAsync(TimeSpan timeSpan) - { - if (_contextStorageGrainId != null) - { - var contextStorageGrain = GrainFactory.GetGrain(_contextStorageGrainId.Value.GetGuidKey()); - await contextStorageGrain.ResetSelfTerminateTime(timeSpan); - } - } - - protected async Task> GetContextAsync() - { - if (_contextStorageGrainId != null) - { - var contextStorageGrain = - GrainFactory.GetGrain(_contextStorageGrainId.Value.GetGuidKey()); - return await contextStorageGrain.GetContext(); - } - - return new Dictionary(); - } - - private void SetContextStorageGrainId(GrainId? grainId) - { - _contextStorageGrainId = grainId; - } - - private GrainId? GetContextStorageGrainId() - { - return _contextStorageGrainId; - } - - private void ClearContext() - { - _contextStorageGrainId = null; - } -} \ No newline at end of file diff --git a/src/AISmart.GAgent.Core/GAgentBase.Observers.cs b/src/AISmart.GAgent.Core/GAgentBase.Observers.cs index 9e31f609..d5ac4143 100644 --- a/src/AISmart.GAgent.Core/GAgentBase.Observers.cs +++ b/src/AISmart.GAgent.Core/GAgentBase.Observers.cs @@ -1,5 +1,6 @@ using System.Reflection; using AISmart.Agents; +using AISmart.GAgent.Core.Context; using Microsoft.Extensions.Logging; namespace AISmart.GAgent.Core; @@ -14,27 +15,26 @@ private Task UpdateObserverList() { var observer = new EventWrapperBaseAsyncObserver(async item => { - var grainId = (GrainId)item.GetType().GetProperty(nameof(EventWrapper.GrainId))?.GetValue(item)!; + var grainId = + (GrainId)item.GetType().GetProperty(nameof(EventWrapper.GrainId))?.GetValue(item)!; if (grainId == this.GetGrainId()) { // Skip the event if it is sent by itself. return; } - var eventId = (Guid)item.GetType().GetProperty(nameof(EventWrapper.EventId))?.GetValue(item)!; + var eventId = (Guid)item.GetType().GetProperty(nameof(EventWrapper.EventId)) + ?.GetValue(item)!; var eventType = item.GetType().GetProperty(nameof(EventWrapper.Event))?.GetValue(item); var parameter = eventHandlerMethod.GetParameters()[0]; - var contextStorageGrainIdValue = item.GetType() - .GetProperty(nameof(EventWrapper.ContextStorageGrainId))? - .GetValue(item); GrainId? contextStorageGrainId = null; - if (contextStorageGrainIdValue != null) + + if (this is IEventContext) { - contextStorageGrainId = (GrainId)contextStorageGrainIdValue; - var contextStorageGrain = GrainFactory.GetGrain(contextStorageGrainId.Value.GetGuidKey()); - var context = await contextStorageGrain.GetContext(); - (eventType! as EventBase)!.SetContext(context); + var contextStorageHelper = new ContextStorageHelper(GrainFactory); + contextStorageGrainId = await contextStorageHelper.SetContextAsync(item, (EventBase)eventType!); + ((IEventContext)this).SetContextStorageGrainId(contextStorageGrainId); } if (parameter.ParameterType == eventType!.GetType()) @@ -61,7 +61,7 @@ await HandleMethodInvocationAsync(eventHandlerMethod, parameter, eventType, even } } - ClearContext(); + (this as IEventContext)?.ClearContext(); }); Observers.Add(observer, new Dictionary()); @@ -104,7 +104,6 @@ private async Task HandleMethodInvocationAsync(MethodInfo method, ParameterInfo { try { - SetContextStorageGrainId(contextStorageGrainId); var result = method.Invoke(this, [eventType]); await (Task)result!; } diff --git a/src/AISmart.GAgent.Core/GAgentBase.cs b/src/AISmart.GAgent.Core/GAgentBase.cs index 3d19c257..c4d5d8a1 100644 --- a/src/AISmart.GAgent.Core/GAgentBase.cs +++ b/src/AISmart.GAgent.Core/GAgentBase.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; using AISmart.Agents; using AISmart.Dapr; +using AISmart.GAgent.Core.Context; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Orleans.EventSourcing; @@ -201,7 +202,8 @@ public Task GetStateAsync() protected async Task PublishAsync(T @event) where T : EventBase { var eventId = Guid.NewGuid(); - var eventWrapper = new EventWrapper(@event, eventId, this.GetGrainId(), GetContextStorageGrainId()); + var eventWrapper = new EventWrapper(@event, eventId, this.GetGrainId(), + (this as IEventContext)?.ContextStorageGrainId); await PublishAsync(eventWrapper); @@ -217,14 +219,17 @@ private async Task PublishAsync(EventWrapper eventWrapper) where T : Event return; } - var eventContext = eventWrapper.Event.GetContext(); - if (!eventContext.IsNullOrEmpty()) + if (this is IEventContext) { - var contextStorageGrain = eventWrapper.ContextStorageGrainId == null - ? GrainFactory.GetGrain(Guid.NewGuid()) - : GrainFactory.GetGrain(eventWrapper.ContextStorageGrainId.Value.GetGuidKey()); - eventWrapper.ContextStorageGrainId = contextStorageGrain.GetGrainId(); - await contextStorageGrain.AddContext(eventContext); + var eventContext = eventWrapper.Event.GetContext(); + if (!eventContext.IsNullOrEmpty()) + { + var contextStorageGrain = eventWrapper.ContextStorageGrainId == null + ? GrainFactory.GetGrain(Guid.NewGuid()) + : GrainFactory.GetGrain(eventWrapper.ContextStorageGrainId.Value.GetGuidKey()); + eventWrapper.ContextStorageGrainId = contextStorageGrain.GetGrainId(); + await contextStorageGrain.AddContext(eventContext); + } } foreach (var publisher in _publishers.State.Select(kp => kp.Value)) diff --git a/src/AISmart.GAgent.EventContext/AISmart.GAgent.EventContext.csproj b/src/AISmart.GAgent.EventContext/AISmart.GAgent.EventContext.csproj new file mode 100644 index 00000000..e6323524 --- /dev/null +++ b/src/AISmart.GAgent.EventContext/AISmart.GAgent.EventContext.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/src/AISmart.GAgent.EventContext/ContextGAgentBase.cs b/src/AISmart.GAgent.EventContext/ContextGAgentBase.cs new file mode 100644 index 00000000..33a8aeb7 --- /dev/null +++ b/src/AISmart.GAgent.EventContext/ContextGAgentBase.cs @@ -0,0 +1,30 @@ +using AISmart.Agents; +using AISmart.GAgent.Core.Context; +using Microsoft.Extensions.Logging; + +namespace AISmart.GAgent.Core; + +[GAgent] +public abstract class ContextGAgentBase : GAgentBase, IEventContext + where TState : StateBase, new() + where TEvent : GEventBase +{ + protected ContextGAgentBase(ILogger logger) : base(logger) + { + } + + public abstract override Task GetDescriptionAsync(); + + public GrainId? ContextStorageGrainId { get; set; } + IGrainFactory IEventContext.GrainFactory => GrainFactory; + + public void SetContextStorageGrainId(GrainId? grainId) + { + ContextStorageGrainId = grainId; + } + + public void ClearContext() + { + ContextStorageGrainId = null; + } +} \ No newline at end of file diff --git a/test/AISmart.GAgents.Tests/AISmart.GAgents.Tests.csproj b/test/AISmart.GAgents.Tests/AISmart.GAgents.Tests.csproj index dc985858..609f00ca 100644 --- a/test/AISmart.GAgents.Tests/AISmart.GAgents.Tests.csproj +++ b/test/AISmart.GAgents.Tests/AISmart.GAgents.Tests.csproj @@ -33,6 +33,7 @@ + diff --git a/test/AISmart.GAgents.Tests/GAgentBase/ContextTests.cs b/test/AISmart.GAgents.Tests/GAgentBase/ContextTests.cs index 7639cea0..8b59e687 100644 --- a/test/AISmart.GAgents.Tests/GAgentBase/ContextTests.cs +++ b/test/AISmart.GAgents.Tests/GAgentBase/ContextTests.cs @@ -1,4 +1,5 @@ using AISmart.GAgent.Core; +using AISmart.GAgent.Core.Context; using AISmart.GAgents.Tests.TestEvents; using AISmart.GAgents.Tests.TestGAgents; using Shouldly; @@ -37,7 +38,7 @@ await publishingGAgent.PublishEventAsync(new ContextTestEvent1 var reminderList = await Silo.ReminderRegistry.GetReminders(contextStorageGrain.GetGrainId()); reminderList.Count.ShouldBe(1); var reminder = (Orleans.TestKit.Reminders.TestReminder)reminderList.First(); - reminder.ReminderName.ShouldBe(AISmartGAgentConstants.ContextStorageGrainSelfTerminateReminderName); + reminder.ReminderName.ShouldBe(AISmartGAgentContextConstants.ContextStorageGrainSelfTerminateReminderName); reminder.DueTime.ShouldBe(TimeSpan.FromMinutes(3)); reminder.Period.ShouldBe(TimeSpan.FromMinutes(3)); } diff --git a/test/AISmart.GAgents.Tests/GAgentTestKitBase.cs b/test/AISmart.GAgents.Tests/GAgentTestKitBase.cs index 0cef7850..7cc1789d 100644 --- a/test/AISmart.GAgents.Tests/GAgentTestKitBase.cs +++ b/test/AISmart.GAgents.Tests/GAgentTestKitBase.cs @@ -3,6 +3,7 @@ using AISmart.Application.Grains.Agents.Group; using AISmart.Application.Grains.Agents.Publisher; using AISmart.GAgent.Core; +using AISmart.GAgent.Core.Context; using AISmart.Sender; using Orleans.TestKit; diff --git a/test/AISmart.GAgents.Tests/TestGAgents/ChatTestGAgent.cs b/test/AISmart.GAgents.Tests/TestGAgents/ChatTestGAgent.cs index 5b5b722c..c8263aab 100644 --- a/test/AISmart.GAgents.Tests/TestGAgents/ChatTestGAgent.cs +++ b/test/AISmart.GAgents.Tests/TestGAgents/ChatTestGAgent.cs @@ -14,7 +14,7 @@ public class ChatTestGAgentState : StateBase } [GAgent] -public class ChatTestGAgent : GAgentBase +public class ChatTestGAgent : ContextGAgentBase { public ChatTestGAgent(ILogger logger) : base(logger) { diff --git a/test/AISmart.GAgents.Tests/TestGAgents/ContextTestGAgents.cs b/test/AISmart.GAgents.Tests/TestGAgents/ContextTestGAgents.cs index 16be3bab..63be48f3 100644 --- a/test/AISmart.GAgents.Tests/TestGAgents/ContextTestGAgents.cs +++ b/test/AISmart.GAgents.Tests/TestGAgents/ContextTestGAgents.cs @@ -1,6 +1,7 @@ using AISmart.Agent.GEvents; using AISmart.Agents; using AISmart.GAgent.Core; +using AISmart.GAgent.Core.Context; using AISmart.GAgents.Tests.TestEvents; using Microsoft.Extensions.Logging.Abstractions; @@ -14,7 +15,7 @@ public class ContextTestGAgentState : StateBase } [GAgent] -public class ContextTestGAgentBase : GAgentBase +public class ContextTestGAgentBase : ContextGAgentBase { public ContextTestGAgentBase() : base(NullLogger.Instance) { @@ -32,8 +33,8 @@ public class ContextTestGAgent1 : ContextTestGAgentBase { public async Task HandleEventAsync(ContextTestEvent1 eventData) { - await SetContextAsync("Set context1", "set context1"); - await ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(1)); + await this.SetContextAsync("Set context1", "set context1"); + await this.ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(1)); if (eventData.TryGetContext("Test1", out var testData) && testData != null) { @@ -58,8 +59,8 @@ public class ContextTestGAgent2 : ContextTestGAgentBase { public async Task HandleEventAsync(ContextTestEvent2 eventData) { - await SetContextAsync("Set context2", "set context2"); - await ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(2)); + await this.SetContextAsync("Set context2", "set context2"); + await this.ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(2)); if (eventData.TryGetContext("Test1", out var testData) && testData != null && eventData.TryGetContext("Test2", out var testData2) @@ -87,8 +88,8 @@ public class ContextTestGAgent3 : ContextTestGAgentBase { public async Task HandleEventAsync(ContextTestEvent3 eventData) { - var getContext = await GetContextAsync(); - await ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(3)); + var getContext = await this.GetContextAsync(); + await this.ResetContextStorageGrainTerminateTimeAsync(TimeSpan.FromMinutes(3)); if (eventData.TryGetContext("Test1", out var testData) && testData != null && eventData.TryGetContext("Test2", out var testData2) diff --git a/test/AISmart.GAgents.Tests/TestGAgents/RelayTestGAgent.cs b/test/AISmart.GAgents.Tests/TestGAgents/RelayTestGAgent.cs index 00ef0960..6b8c404b 100644 --- a/test/AISmart.GAgents.Tests/TestGAgents/RelayTestGAgent.cs +++ b/test/AISmart.GAgents.Tests/TestGAgents/RelayTestGAgent.cs @@ -5,7 +5,7 @@ namespace AISmart.GAgents.Tests.TestGAgents; [GAgent] -public class RelayTestGAgent : GAgentBase +public class RelayTestGAgent : ContextGAgentBase { public RelayTestGAgent(ILogger logger) : base(logger) {