File: PeerCustomResolverBindingElement.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-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 (177 lines) | stat: -rw-r--r-- 7,115 bytes parent folder | download
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
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.ServiceModel.Channels
{
    using System.ComponentModel;
    using System.ServiceModel;
    using System.ServiceModel.Configuration;
    using System.ServiceModel.Description;
    using System.ServiceModel.Dispatcher;
    using System.ServiceModel.PeerResolvers;

    [ObsoleteAttribute ("PeerChannel feature is obsolete and will be removed in the future.", false)]
    public sealed class PeerCustomResolverBindingElement : PeerResolverBindingElement
    {
        EndpointAddress address;
        Binding binding;
        string bindingSection, bindingConfiguration;
        //this should be PeerCustomResolver?
        PeerResolver resolver;
        ClientCredentials credentials;
        PeerReferralPolicy referralPolicy;

        public PeerCustomResolverBindingElement() { }
        public PeerCustomResolverBindingElement(PeerCustomResolverBindingElement other)
            : base(other)
        {
            this.address = other.address;
            this.bindingConfiguration = other.bindingConfiguration;
            this.bindingSection = other.bindingSection;
            this.binding = other.binding;
            this.resolver = other.resolver;
            this.credentials = other.credentials;
        }

        public PeerCustomResolverBindingElement(PeerCustomResolverSettings settings)
        {
            if (settings != null)
            {
                this.address = settings.Address;
                this.binding = settings.Binding;
                this.resolver = settings.Resolver;
                this.bindingConfiguration = settings.BindingConfiguration;
                this.bindingSection = settings.BindingSection;
            }
        }

        public PeerCustomResolverBindingElement(BindingContext context, PeerCustomResolverSettings settings)
            : this(settings)
        {
            if (context == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));

#pragma warning suppress 56506 // [....], context.BindingParameters is never null
            credentials = context.BindingParameters.Find<ClientCredentials>();
        }
        public override T GetProperty<T>(System.ServiceModel.Channels.BindingContext context)
        {
#pragma warning suppress 56506 // context could be null. Pre-4.0 behaviour, won't fix in Dev10.
            return context.GetInnerProperty<T>();
        }
        public EndpointAddress Address
        {
            get
            {
                return address;
            }
            set
            {
                address = value;
            }
        }

        public Binding Binding
        {
            get
            {
                return binding;
            }
            set
            {
                binding = value;
            }
        }

        public override PeerReferralPolicy ReferralPolicy
        {
            get
            {
                return referralPolicy;
            }
            set
            {
                if (!PeerReferralPolicyHelper.IsDefined(value))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("value", (int)value, typeof(PeerReferralPolicy)));
                }
                referralPolicy = value;
            }
        }

        public override BindingElement Clone()
        {
            return new PeerCustomResolverBindingElement(this);
        }

        public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
        {
            if (context == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));

#pragma warning suppress 56506 // [....], context.BindingParameters is never null
            context.BindingParameters.Add(this);
            credentials = context.BindingParameters.Find<ClientCredentials>();
            return context.BuildInnerChannelFactory<TChannel>();
        }

        public override bool CanBuildChannelFactory<TChannel>(BindingContext context)
        {
            if (context == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
#pragma warning suppress 56506 // [....], context.BindingParameters is never null
            this.credentials = context.BindingParameters.Find<ClientCredentials>();
            context.BindingParameters.Add(this);
            return context.CanBuildInnerChannelFactory<TChannel>();
        }

        public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
        {
            if (context == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));

#pragma warning suppress 56506 // [....], context.BindingParameters is never null
            context.BindingParameters.Add(this);
            this.credentials = context.BindingParameters.Find<ClientCredentials>();
            return context.BuildInnerChannelListener<TChannel>();
        }

        public override bool CanBuildChannelListener<TChannel>(BindingContext context)
        {
            if (context == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("context"));
#pragma warning suppress 56506 // [....], context.BindingParameters is never null
            this.credentials = context.BindingParameters.Find<ClientCredentials>();
            context.BindingParameters.Add(this);
            return context.CanBuildInnerChannelListener<TChannel>();
        }

        public override PeerResolver CreatePeerResolver()
        {
            if (resolver == null)
            {
                if (address == null || ((binding == null) && (String.IsNullOrEmpty(this.bindingSection) || String.IsNullOrEmpty(this.bindingConfiguration))))
                    PeerExceptionHelper.ThrowArgument_InsufficientResolverSettings();
                if (binding == null)
                {
                    this.binding = ConfigLoader.LookupBinding(this.bindingSection, this.bindingConfiguration);
                    if (binding == null)
                        PeerExceptionHelper.ThrowArgument_InsufficientResolverSettings();
                }
                resolver = new PeerDefaultCustomResolverClient();
            }
            if (resolver != null)
            {
                resolver.Initialize(address, binding, credentials, this.referralPolicy);
                if (resolver is PeerDefaultCustomResolverClient)
                {
                    (resolver as PeerDefaultCustomResolverClient).BindingName = this.bindingSection;
                    (resolver as PeerDefaultCustomResolverClient).BindingConfigurationName = this.bindingConfiguration;
                }
            }
            return resolver;
        }
    }
}