jezell / iserviceoriented

iserviceoriented / IServiceOriented.ServiceBus / ListenerEndpoint.cs
100644 78 lines (68 sloc) 2.869 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
 
namespace IServiceOriented.ServiceBus
{
    /// <summary>
    /// Represents a listener endpoint.
    /// </summary>
[DataContract]
    public sealed class ListenerEndpoint : Endpoint
    {
        public ListenerEndpoint(string name, string configurationName, string address, Type contractType, Listener listener)
            : this(Guid.NewGuid(), name, configurationName, address, contractType, listener, false, null)
        {
        }
 
        public ListenerEndpoint(Guid id, string name, string configurationName, string address, Type contractType, Listener listener) : this(id, name, configurationName, address, contractType, listener, false, null)
        {
            
        }
 
        public ListenerEndpoint(Guid id, string name, string configurationName, string address, Type contractType, Listener listener, bool transient, DateTime? expiration)
            : base(id, name, configurationName, address, contractType, transient, expiration)
        {
            Listener = listener;
        }
 
        public ListenerEndpoint(string name, string configurationName, string address, string contractTypeName, Listener listener)
            : this(Guid.NewGuid(), name, configurationName, address, contractTypeName, listener, false, null)
        {
        }
 
        public ListenerEndpoint(Guid id, string name, string configurationName, string address, string contractTypeName, Listener listener)
            : this(id, name, configurationName, address, contractTypeName, listener, false, null)
        {
 
        }
 
        public ListenerEndpoint(Guid id, string name, string configurationName, string address, string contractTypeName, Listener listener, bool transient, DateTime? expiration)
            : base(id, name, configurationName, address, contractTypeName, transient, expiration)
        {
            Listener = listener;
        }
 
        Listener _listener;
        /// <summary>
        /// The listener used by this endpoint
        /// </summary>
        /// <remarks>
        /// Listeners cannot be shared by multiple endpoints.
        /// </remarks>
[DataMember]
        public Listener Listener
        {
            get
            {
                return _listener;
            }
            private set
            {
                if (value != null && value.Endpoint != null)
                {
                    throw new InvalidOperationException("Endpoint is attached to another listener");
                }
                if (_listener != null)
                {
                    _listener.Endpoint = null;
                }
                _listener = value;
                if(value != null) value.Endpoint = this;
            }
        }
    }
}