@@ -31,6 +31,8 @@ public static IntegrationManager Instance
3131
3232 private readonly List < MessageInfo > _publishedMessages ;
3333 private readonly List < MessageInfo > _subscribedMessages ;
34+ private readonly List < CommandInfo > _sentCommands ;
35+ private readonly List < CommandInfo > _receivedCommands ;
3436
3537 private IntegrationManager ( IApplication application )
3638 {
@@ -65,6 +67,31 @@ private IntegrationManager(IApplication application)
6567 . Select ( sub => new MessageInfo ( app . Id , app . Name , sub . Message , sub . Handler ) ) )
6668 . Distinct ( )
6769 . ToList ( ) ;
70+
71+ // Collect sent commands
72+ _sentCommands = applications
73+ . Where ( app => app . Modules . Any ( x => x . ModuleId == awsSqsModule ) )
74+ . SelectMany ( app => application . MetadataManager
75+ . GetExplicitlySentIntegrationCommandModels ( app . Id )
76+ . Select ( command => new CommandInfo ( app . Id , app . Name , command , null ) ) )
77+ . Distinct ( )
78+ . ToList ( ) ;
79+
80+ // Collect received commands
81+ _receivedCommands = applications
82+ . Where ( app => app . Modules . Any ( x => x . ModuleId == awsSqsModule ) )
83+ . SelectMany ( app => application . MetadataManager
84+ . Services ( app . Id )
85+ . GetIntegrationEventHandlerModels ( )
86+ . SelectMany ( handler => handler . IntegrationCommandSubscriptions ( )
87+ . Select ( sub => new
88+ {
89+ Command = sub . Element . AsIntegrationCommandModel ( ) ,
90+ Handler = handler
91+ } ) )
92+ . Select ( sub => new CommandInfo ( app . Id , app . Name , sub . Command , sub . Handler ) ) )
93+ . Distinct ( )
94+ . ToList ( ) ;
6895 }
6996
7097 public IReadOnlyList < SqsMessage > GetPublishedSqsMessages ( string applicationId )
@@ -92,18 +119,51 @@ public IReadOnlyList<SqsMessage> GetSubscribedSqsMessages(string applicationId)
92119 . ToList ( ) ;
93120 }
94121
122+ public IReadOnlyList < SqsCommand > GetPublishedSqsCommands ( string applicationId )
123+ {
124+ return _sentCommands
125+ . Where ( p => p . ApplicationId == applicationId )
126+ . Select ( s => new SqsCommand (
127+ s . ApplicationId ,
128+ s . ApplicationName ,
129+ s . Command ,
130+ SqsMethodType . Publish ) )
131+ . ToList ( ) ;
132+ }
133+
134+ public IReadOnlyList < SqsCommand > GetSubscribedSqsCommands ( string applicationId )
135+ {
136+ return _receivedCommands
137+ . Where ( p => p . ApplicationId == applicationId )
138+ . DistinctBy ( s => s . Command . Id )
139+ . Select ( s => new SqsCommand (
140+ s . ApplicationId ,
141+ s . ApplicationName ,
142+ s . Command ,
143+ SqsMethodType . Subscribe ) )
144+ . ToList ( ) ;
145+ }
146+
95147 public IReadOnlyList < SqsItemBase > GetAggregatedPublishedSqsItems ( string applicationId )
96148 {
97- return GetPublishedSqsMessages ( applicationId )
149+ var messages = GetPublishedSqsMessages ( applicationId )
98150 . Cast < SqsItemBase > ( )
99151 . ToList ( ) ;
152+ var commands = GetPublishedSqsCommands ( applicationId )
153+ . Cast < SqsItemBase > ( )
154+ . ToList ( ) ;
155+ return messages . Concat ( commands ) . ToList ( ) ;
100156 }
101157
102158 public IReadOnlyList < SqsItemBase > GetAggregatedSubscribedSqsItems ( string applicationId )
103159 {
104- return GetSubscribedSqsMessages ( applicationId )
160+ var messages = GetSubscribedSqsMessages ( applicationId )
105161 . Cast < SqsItemBase > ( )
106162 . ToList ( ) ;
163+ var commands = GetSubscribedSqsCommands ( applicationId )
164+ . Cast < SqsItemBase > ( )
165+ . ToList ( ) ;
166+ return messages . Concat ( commands ) . ToList ( ) ;
107167 }
108168
109169 public IReadOnlyList < SqsItemBase > GetAggregatedSqsItems ( string applicationId )
@@ -117,7 +177,7 @@ public IReadOnlyList<SqsItemBase> GetAggregatedSqsItems(string applicationId)
117177
118178 public IReadOnlyList < Subscription < SqsItemBase > > GetAggregatedSqsSubscriptions ( string applicationId )
119179 {
120- return _subscribedMessages
180+ var messageSubscriptions = _subscribedMessages
121181 . Where ( message => message . ApplicationId == applicationId )
122182 . Select ( message => new Subscription < SqsItemBase > (
123183 message . EventHandlerModel ! ,
@@ -127,6 +187,19 @@ public IReadOnlyList<Subscription<SqsItemBase>> GetAggregatedSqsSubscriptions(st
127187 message . Message ,
128188 SqsMethodType . Subscribe ) ) )
129189 . ToList ( ) ;
190+
191+ var commandSubscriptions = _receivedCommands
192+ . Where ( command => command . ApplicationId == applicationId )
193+ . Select ( command => new Subscription < SqsItemBase > (
194+ command . EventHandlerModel ! ,
195+ new SqsCommand (
196+ applicationId ,
197+ command . ApplicationName ,
198+ command . Command ,
199+ SqsMethodType . Subscribe ) ) )
200+ . ToList ( ) ;
201+
202+ return messageSubscriptions . Concat ( commandSubscriptions ) . ToList ( ) ;
130203 }
131204
132205 public record Subscription < TSubscriptionItem > (
@@ -138,4 +211,10 @@ private record MessageInfo(
138211 string ApplicationName ,
139212 MessageModel Message ,
140213 IntegrationEventHandlerModel ? EventHandlerModel ) ;
214+
215+ private record CommandInfo (
216+ string ApplicationId ,
217+ string ApplicationName ,
218+ IntegrationCommandModel Command ,
219+ IntegrationEventHandlerModel ? EventHandlerModel ) ;
141220}
0 commit comments