main
1using System;
2using System.Collections.Generic;
3using System.Transactions;
4using Gorilla.Commons.Infrastructure.Logging;
5using gorilla.commons.infrastructure.threading;
6using gorilla.commons.utility;
7using Rhino.Queues;
8using Rhino.Queues.Model;
9
10namespace presentation.windows.common
11{
12 public class RhinoReceiver : Receiver
13 {
14 List<Observer<Message>> observers = new List<Observer<Message>>();
15 IQueue queue;
16 CommandProcessor processor;
17
18 public RhinoReceiver(IQueue queue, CommandProcessor processor)
19 {
20 this.queue = queue;
21 this.processor = processor;
22 }
23
24 public void register(Observer<Message> observer)
25 {
26 observers.Add(observer);
27 }
28
29 public void run()
30 {
31 try
32 {
33 var message = next_message();
34 observers.each(observer => observer(message));
35 }
36 catch (Exception e)
37 {
38 e.add_to_log();
39 }
40 finally
41 {
42 processor.add(this);
43 }
44 }
45
46 Message next_message()
47 {
48 Message message;
49 using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew))
50 {
51 message = queue.Receive();
52 transaction.Complete();
53 }
54 return message;
55 }
56 }
57}