@@ -43,60 +43,54 @@ public IConversationStateService SetState<T>(string name, T value, bool isNeedVe
43
43
var preValue = string . Empty ;
44
44
var currentValue = value . ToString ( ) ;
45
45
var hooks = _services . GetServices < IConversationHook > ( ) ;
46
- var preActiveRounds = - 1 ;
47
- var curActiveRounds = activeRounds > 0 ? activeRounds : - 1 ;
48
46
49
47
if ( ContainsState ( name ) && _states . TryGetValue ( name , out var pair ) )
50
48
{
51
49
var lastNode = pair ? . Values . LastOrDefault ( ) ;
52
- preActiveRounds = lastNode ? . ActiveRounds ?? - 1 ;
53
50
preValue = lastNode ? . Data ?? string . Empty ;
54
51
}
55
52
56
- if ( ! ContainsState ( name ) || preValue != currentValue || ( preValue == currentValue && preActiveRounds > 0 ) )
57
- {
58
- _logger . LogInformation ( $ "[STATE] { name } = { value } ") ;
59
- var routingCtx = _services . GetRequiredService < IRoutingContext > ( ) ;
53
+ _logger . LogInformation ( $ "[STATE] { name } = { value } ") ;
54
+ var routingCtx = _services . GetRequiredService < IRoutingContext > ( ) ;
60
55
61
- if ( ! ContainsState ( name ) || preValue != currentValue )
56
+ if ( ! ContainsState ( name ) || preValue != currentValue )
57
+ {
58
+ foreach ( var hook in hooks )
62
59
{
63
- foreach ( var hook in hooks )
60
+ hook . OnStateChanged ( new StateChangeModel
64
61
{
65
- hook . OnStateChanged ( new StateChangeModel
66
- {
67
- ConversationId = _conversationId ,
68
- MessageId = routingCtx . MessageId ,
69
- Name = name ,
70
- BeforeValue = preValue ,
71
- AfterValue = currentValue
72
- } ) . Wait ( ) ;
73
- }
62
+ ConversationId = _conversationId ,
63
+ MessageId = routingCtx . MessageId ,
64
+ Name = name ,
65
+ BeforeValue = preValue ,
66
+ AfterValue = currentValue
67
+ } ) . Wait ( ) ;
74
68
}
75
-
76
- var newPair = new StateKeyValue
77
- {
78
- Key = name ,
79
- Versioning = isNeedVersion
80
- } ;
69
+ }
81
70
82
- var newValue = new StateValue
83
- {
84
- Data = currentValue ,
85
- MessageId = routingCtx . MessageId ,
86
- Active = true ,
87
- ActiveRounds = curActiveRounds ,
88
- UpdateTime = DateTime . UtcNow ,
89
- } ;
90
-
91
- if ( ! isNeedVersion || ! _states . ContainsKey ( name ) )
92
- {
93
- newPair . Values = new List < StateValue > { newValue } ;
94
- _states [ name ] = newPair ;
95
- }
96
- else
97
- {
98
- _states [ name ] . Values . Add ( newValue ) ;
99
- }
71
+ var newPair = new StateKeyValue
72
+ {
73
+ Key = name ,
74
+ Versioning = isNeedVersion
75
+ } ;
76
+
77
+ var newValue = new StateValue
78
+ {
79
+ Data = currentValue ,
80
+ MessageId = routingCtx . MessageId ,
81
+ Active = true ,
82
+ ActiveRounds = activeRounds > 0 ? activeRounds : - 1 ,
83
+ UpdateTime = DateTime . UtcNow ,
84
+ } ;
85
+
86
+ if ( ! isNeedVersion || ! _states . ContainsKey ( name ) )
87
+ {
88
+ newPair . Values = new List < StateValue > { newValue } ;
89
+ _states [ name ] = newPair ;
90
+ }
91
+ else
92
+ {
93
+ _states [ name ] . Values . Add ( newValue ) ;
100
94
}
101
95
102
96
return this ;
0 commit comments