jezell / iserviceoriented

This URL has Read+Write access

iserviceoriented / IServiceOriented.ServiceBus / ActionMessageFilter.cs
100644 57 lines (48 sloc) 1.552 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
 
namespace IServiceOriented.ServiceBus
{
[Serializable]
[DataContract]
    public class ActionMessageFilter : MessageFilter
    {
        public ActionMessageFilter(string[] actions)
        {
            _actions = new HashSet<string>(actions);
        }
[DataMember(Name="Actions")]
        HashSet<string> _actions;
 
        public ReadOnlyCollection<string> Actions
        {
            get
            {
                return new ReadOnlyCollection<string>(_actions.ToList());
            }
        }
 
        public override bool Include(PublishRequest request)
        {
            return _actions.Contains("*") || _actions.Contains(request.Action);
        }
 
        public static ActionMessageFilter Create(ContractDescription description)
        {
            List<string> actions = new List<string>();
 
            foreach (OperationDescription od in description.Operations)
            {
                foreach (MessageDescription md in od.Messages)
                {
                   actions.Add(md.Action);
                }
 
                foreach (FaultDescription fd in od.Faults)
                {
                   actions.Add(fd.Action);
                }
            }
 
            return new ActionMessageFilter(actions.Distinct().ToArray());
        }
    }
}