File: RoutingSection.cs

package info (click to toggle)
mono 4.6.2.7+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (115 lines) | stat: -rw-r--r-- 4,566 bytes parent folder | download | duplicates (6)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace System.ServiceModel.Routing.Configuration
{
	static class RoutingConfigurationExtension
	{
		public static ServiceEndpoint CreateEndpoint (this ChannelEndpointElement el)
		{
			// depends on System.ServiceModel internals (by InternalVisibleTo).
			// FIXME: is IRequestReplyRouter okay for every case?
			return new ServiceEndpoint (ContractDescription.GetContract (typeof (IRequestReplyRouter)), ConfigUtil.CreateBinding (el.Binding, el.BindingConfiguration), new EndpointAddress (el.Address));
		}

		public static MessageFilter CreateFilter (this FilterElement el, RoutingSection sec)
		{
			switch (el.FilterType) {
			case FilterType.Action:
				return new ActionMessageFilter (el.FilterData);
			case FilterType.EndpointAddress:
				return new EndpointAddressMessageFilter (new EndpointAddress (el.FilterData), false);
			case FilterType.PrefixEndpointAddress:
				return new PrefixEndpointAddressMessageFilter (new EndpointAddress (el.FilterData), false);
			case FilterType.And:
				var fe1 = (FilterElement) sec.Filters [el.Filter1];
				var fe2 = (FilterElement) sec.Filters [el.Filter2];
				return new StrictAndMessageFilter (fe1.CreateFilter (sec), fe2.CreateFilter (sec));
			case FilterType.Custom:
				return (MessageFilter) Activator.CreateInstance (Type.GetType (el.CustomType));
			case FilterType.EndpointName:
				return new EndpointNameMessageFilter (el.FilterData);
			case FilterType.MatchAll:
				return new MatchAllMessageFilter ();
			case FilterType.XPath:
				return new XPathMessageFilter (el.FilterData);
			default:
				throw new ArgumentOutOfRangeException ("FilterType");
			}
		}
	}

	public class RoutingSection : ConfigurationSection
	{
		static ServiceEndpoint CreateServiceEndpoint (string name)
		{
			// FIXME: might be service endpoints.
			var endpoints = ConfigUtil.ClientSection.Endpoints;
			foreach (ChannelEndpointElement ep in endpoints)
				if (ep.Name == name)
					return ep.CreateEndpoint ();
			throw new KeyNotFoundException (String.Format ("client endpoint '{0}' not found", name));
		}

		[MonoTODO]
		public static MessageFilterTable<IEnumerable<ServiceEndpoint>> CreateFilterTable (string name)
		{
			var sec = (RoutingSection) ConfigurationManager.GetSection ("system.serviceModel/routing");

			var table = new MessageFilterTable<IEnumerable<ServiceEndpoint>> ();
			var ftec = (FilterTableEntryCollection) sec.FilterTables [name];
			foreach (FilterTableEntryElement fte in ftec) {
				var filterElement = (FilterElement) sec.Filters [fte.FilterName];
				MessageFilter filter = filterElement.CreateFilter (sec);
				table.Add (filter, new List<ServiceEndpoint> (), fte.Priority);
				var list = (List<ServiceEndpoint>) table [filter];
				list.Add (CreateServiceEndpoint (fte.EndpointName));
				var bec = (BackupEndpointCollection) sec.BackupLists [fte.BackupList];
				if (bec != null)
					foreach (BackupEndpointElement bee in bec)
						list.Add (CreateServiceEndpoint (bee.EndpointName));
			}
			return table;
		}

		public RoutingSection ()
		{
			//BackupLists = new BackupListCollection ();
			//Filters = new FilterElementCollection ();
			//FilterTables = new FilterTableCollection ();
			//NamespaceTable = new NamespaceElementCollection ();
		}

		[ConfigurationProperty ("backupLists", Options = ConfigurationPropertyOptions.None)]
		public BackupListCollection BackupLists {
			get { return (BackupListCollection) base ["backupLists"]; }
			private set { base ["backupLists"] = value; }
		}

		[ConfigurationProperty ("filters", Options = ConfigurationPropertyOptions.None)]
		public FilterElementCollection Filters {
			get { return (FilterElementCollection) base ["filters"]; }
			private set { base ["filters"] = value; }
		}

		[ConfigurationProperty ("filterTables", Options = ConfigurationPropertyOptions.None)]
		public FilterTableCollection FilterTables {
			get { return (FilterTableCollection) base ["filterTables"]; }
			private set { base ["filterTables"] = value; }
		}

		[ConfigurationProperty ("namespaceTable", Options = ConfigurationPropertyOptions.None)]
		public NamespaceElementCollection NamespaceTable {
			get { return (NamespaceElementCollection) base ["namespaceTable"]; }
			private set { base ["namespaceTable"] = value; }
		}
	}
}