jezell / iserviceoriented

iserviceoriented / IServiceOriented.ServiceBus / Endpoint.cs
100644 210 lines (191 sloc) 5.255 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
 
using System.Runtime.Serialization;
 
namespace IServiceOriented.ServiceBus
{
    /// <summary>
    /// Base class for service bus endpoints.
    /// </summary>
[Serializable]
[DataContract]
    public abstract class Endpoint
    {
        protected Endpoint(Guid id, string name, string configurationName, string address, Type contractType, bool transient, DateTime? expiration) : this(id, name, configurationName, address, contractType)
        {
            Transient = transient;
            Expiration = expiration;
        }
 
        protected Endpoint(Guid id, string name, string configurationName, string address, string contractTypeName, bool transient, DateTime? expiration)
            : this(id, name, configurationName, address, contractTypeName)
        {
            Transient = transient;
            Expiration = expiration;
        }
 
       
        protected Endpoint(Guid id, string name, string configurationName, string address, Type contractType)
        {
            Id = id;
            Name = name;
            ConfigurationName = configurationName;
            Address = address;
            ContractType = contractType;
        }
 
        protected Endpoint(Guid id, string name, string configurationName, string address, string contractTypeName)
        {
            Id = id;
            Name = name;
            ConfigurationName = configurationName;
            Address = address;
            ContractTypeName = contractTypeName;
        }
 
        Guid _endpointId = Guid.NewGuid();
        
        /// <summary>
        /// Gets the unique identifier of the endpoint.
        /// </summary>
[DataMember]
        public Guid Id
        {
            get
            {
                return _endpointId;
            }
            private set
            {
                _endpointId = value;
            }
        }
 
        Type _contractType;
        /// <summary>
        /// Gets the Type of the contract supported by the endpoint.
        /// </summary>
        public Type ContractType
        {
            get
            {
                return _contractType;
            }
            private set
            {
                _contractType = value;
            }
        }
 
        /// <summary>
        /// Gets the name of the contract type supported by the endpoint.
        /// </summary>
[DataMember]
        public string ContractTypeName
        {
            get
            {
                if (_contractType == null)
                {
                    return null;
                }
                else
                {
                    return _contractType.AssemblyQualifiedName;
                }
            }
            private set
            {
                _contractType = Type.GetType(value);
                if (_contractType == null)
                {
                    throw new InvalidOperationException(value + " is an invalid type");
                }
            }
        }
 
        string _address;
        /// <summary>
        /// Gets the address of the endpoint.
        /// </summary>
[DataMember]
        public string Address
        {
            get
            {
                return _address;
            }
            private set
            {
                _address = value;
            }
        }
 
        string _configurationName;
        /// <summary>
        /// Gets the name of the configuration used by the endpoint.
        /// </summary>
[DataMember]
        public string ConfigurationName
        {
            get
            {
                return _configurationName;
            }
            private set
            {
                _configurationName = value;
            }
        }
 
        string _name;
        /// <summary>
        /// Gets the name of this endpoint.
        /// </summary>
[DataMember]
        public string Name
        {
            get
            {
                return _name;
            }
            private set
            {
                _name = value;
            }
        }
 
        bool _transient;
        /// <summary>
        /// Gets a boolean value indicating whether this endpoint is transient (true) or should be persisted (false).
        /// </summary>
[DataMember]
        public bool Transient
        {
            get
            {
                return _transient;
            }
            private set
            {
                _transient = value;
            }
        }
 
        DateTime? _expiration;
 
[DataMember]
        public DateTime? Expiration
        {
            get
            {
                return _expiration;
            }
            private set
            {
                _expiration = value;
            }
        }
 
        public bool IsExpired
        {
            get
            {
                if (_expiration.HasValue)
                {
                    return _expiration.Value < DateTime.Now;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}