@@ -21,8 +21,8 @@ public void Publish(ICommand command)
2121
2222 using ( var context = new QueueDbContext ( QueueBaseName ) )
2323 {
24- context . Messages . Add ( new MessageModel ( ) {
25- Status = MessageStatus . Pending ,
24+ context . Messages . Add ( new CommandEnvelopeModel ( ) {
25+ Status = CommandEnvelopeStatus . Pending ,
2626 IsCompressed = UseCompression ,
2727 CommandClassName = command . GetType ( ) . FullName ,
2828 CommandAssemblyName = command . GetType ( ) . Assembly . GetName ( ) . Name + ".dll" ,
@@ -35,7 +35,7 @@ public void Publish(ICommand command)
3535 public bool Consume ( )
3636 {
3737
38- IMessage message ;
38+ ICommandEnvelope commandEnvelope ;
3939 using ( var conn = new SqlConnection ( ) )
4040 {
4141 conn . Open ( ) ;
@@ -48,10 +48,10 @@ public bool Consume()
4848 context . Database . UseTransaction ( transaction ) ;
4949 var messageModel = context . Messages
5050 . OrderBy ( x => x . QueuedAt )
51- . FirstOrDefault ( x => x . Status == MessageStatus . Pending && x . QueueName == QueueName ) ;
52- messageModel . Status = MessageStatus . InProgress ;
51+ . FirstOrDefault ( x => x . Status == CommandEnvelopeStatus . Pending && x . QueueName == QueueName ) ;
52+ messageModel . Status = CommandEnvelopeStatus . InProgress ;
5353 context . SaveChanges ( ) ;
54- message = messageModel ;
54+ commandEnvelope = messageModel ;
5555 }
5656
5757 transaction . Commit ( ) ;
@@ -66,7 +66,7 @@ public bool Consume()
6666
6767 try
6868 {
69- Queue . ExtractCommandInstanceFromMessage ( message ) . Run ( ) ;
69+ Queue . ExtractCommandInstanceFromMessageAndRun ( commandEnvelope ) ;
7070 }
7171 catch ( Exception exception )
7272 {
@@ -80,18 +80,18 @@ public bool Consume()
8080 using ( var context = new QueueDbContext ( conn , false , QueueBaseName ) )
8181 {
8282 context . Database . UseTransaction ( transaction ) ;
83- var messageModel = context . Messages . FirstOrDefault ( x => x . Id == message . Id ) ;
84- messageModel . Status = MessageStatus . Failed ;
83+ var messageModel = context . Messages . FirstOrDefault ( x => x . Id == commandEnvelope . Id ) ;
84+ messageModel . Status = CommandEnvelopeStatus . Failed ;
8585 context . SaveChanges ( ) ;
86- message = messageModel ;
86+ commandEnvelope = messageModel ;
8787 }
8888
8989 transaction . Commit ( ) ;
9090 }
9191 catch ( Exception dbException )
9292 {
9393 transaction . Rollback ( ) ;
94- throw new CommandFailedException ( "Failed to set queue message from in-progress to failed." , dbException ) ;
94+ throw new CommandFailedException ( "Failed to set queue commandEnvelope from in-progress to failed." , dbException ) ;
9595 }
9696 }
9797 }
@@ -110,42 +110,42 @@ public bool Consume()
110110 using ( var context = new QueueDbContext ( conn , false , QueueBaseName ) )
111111 {
112112 context . Database . UseTransaction ( transaction ) ;
113- var messageModel = context . Messages . FirstOrDefault ( x => x . Id == message . Id ) ;
114- messageModel . Status = MessageStatus . Completed ;
113+ var messageModel = context . Messages . FirstOrDefault ( x => x . Id == commandEnvelope . Id ) ;
114+ messageModel . Status = CommandEnvelopeStatus . Completed ;
115115 context . SaveChanges ( ) ;
116- message = messageModel ;
116+ commandEnvelope = messageModel ;
117117 }
118118 transaction . Commit ( ) ;
119119 }
120120 catch ( Exception dbException )
121121 {
122122 transaction . Rollback ( ) ;
123- throw new CommandFailedException ( "Failed to set queue message from in-progress to completed." , dbException ) ;
123+ throw new CommandFailedException ( "Failed to set queue commandEnvelope from in-progress to completed." , dbException ) ;
124124 }
125125 }
126126 }
127127 }
128128 catch ( Exception exception )
129129 {
130- throw new CommandFailedException ( $ "Failed to remove completed message from queue", exception ) ;
130+ throw new CommandFailedException ( $ "Failed to remove completed commandEnvelope from queue", exception ) ;
131131 }
132132
133133 return true ;
134134 }
135135
136136 public long GetPendingQueueLength ( )
137137 {
138- return GetQueueLength ( MessageStatus . Pending ) ;
138+ return GetQueueLength ( CommandEnvelopeStatus . Pending ) ;
139139 }
140140
141141 public long GetInProgressQueueLength ( )
142142 {
143- return GetQueueLength ( MessageStatus . InProgress ) ;
143+ return GetQueueLength ( CommandEnvelopeStatus . InProgress ) ;
144144 }
145145
146146 public long GetFailedQueueLength ( )
147147 {
148- return GetQueueLength ( MessageStatus . Failed ) ;
148+ return GetQueueLength ( CommandEnvelopeStatus . Failed ) ;
149149 }
150150
151151 public long GetQueueLength ( string status )
@@ -158,19 +158,19 @@ public long GetQueueLength(string status)
158158
159159 public bool ClearPendingQueue ( )
160160 {
161- ClearQueue ( MessageStatus . Pending ) ;
161+ ClearQueue ( CommandEnvelopeStatus . Pending ) ;
162162 return true ;
163163 }
164164
165165 public bool ClearInProgressQueue ( )
166166 {
167- ClearQueue ( MessageStatus . InProgress ) ;
167+ ClearQueue ( CommandEnvelopeStatus . InProgress ) ;
168168 return true ;
169169 }
170170
171171 public bool ClearFailedQueue ( )
172172 {
173- ClearQueue ( MessageStatus . Failed ) ;
173+ ClearQueue ( CommandEnvelopeStatus . Failed ) ;
174174 return true ;
175175 }
176176
@@ -198,10 +198,10 @@ public void RepublishFailedMessages()
198198 {
199199 context . Database . UseTransaction ( transaction ) ;
200200 var messageModels = context . Messages
201- . Where ( x => x . QueueName == QueueName && x . Status == MessageStatus . Pending )
201+ . Where ( x => x . QueueName == QueueName && x . Status == CommandEnvelopeStatus . Pending )
202202 . OrderBy ( x => x . QueuedAt ) ;
203203 foreach ( var messageModel in messageModels )
204- messageModel . Status = MessageStatus . InProgress ;
204+ messageModel . Status = CommandEnvelopeStatus . InProgress ;
205205 context . SaveChanges ( ) ;
206206 }
207207
@@ -216,30 +216,30 @@ public void RepublishFailedMessages()
216216 }
217217 }
218218
219- public List < IMessage > PeekPendingMessages ( long from , long to )
219+ public List < ICommandEnvelope > PeekPendingMessages ( long from , long to )
220220 {
221- return GetMessages ( MessageStatus . Pending , from , to ) ;
221+ return GetMessages ( CommandEnvelopeStatus . Pending , from , to ) ;
222222 }
223223
224- public List < IMessage > PeekInProgressMessages ( long from , long to )
224+ public List < ICommandEnvelope > PeekInProgressMessages ( long from , long to )
225225 {
226- return GetMessages ( MessageStatus . InProgress , from , to ) ;
226+ return GetMessages ( CommandEnvelopeStatus . InProgress , from , to ) ;
227227 }
228228
229- public List < IMessage > PeekFailedMessages ( long from , long to )
229+ public List < ICommandEnvelope > PeekFailedMessages ( long from , long to )
230230 {
231- return GetMessages ( MessageStatus . Failed , from , to ) ;
231+ return GetMessages ( CommandEnvelopeStatus . Failed , from , to ) ;
232232 }
233233
234- public List < IMessage > GetMessages ( string status , long from , long to )
234+ public List < ICommandEnvelope > GetMessages ( string status , long from , long to )
235235 {
236236 using ( var context = new QueueDbContext ( QueueBaseName ) )
237237 {
238238 return context . Messages
239239 . Where ( x => x . QueueName == QueueName && x . Status == status )
240240 . Skip ( Convert . ToInt32 ( from ) )
241241 . Take ( Convert . ToInt32 ( to - from ) )
242- . Select ( x => x as IMessage )
242+ . Select ( x => x as ICommandEnvelope )
243243 . ToList ( ) ;
244244 }
245245 }
0 commit comments