File: WorkflowControlEndpointElement.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 (186 lines) | stat: -rw-r--r-- 7,737 bytes parent folder | download | duplicates (7)
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
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//----------------------------------------------------------------

namespace System.ServiceModel.Activities.Configuration
{
    using System;
    using System.ServiceModel.Activities;
    using System.ServiceModel.Description;
    using System.Diagnostics.CodeAnalysis;
    using System.Runtime;
    using System.Configuration;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Configuration;
    
    public class WorkflowControlEndpointElement : StandardEndpointElement
    {
        ConfigurationPropertyCollection properties;
        bool shouldLetConfigLoaderOverwriteAddress;

        protected internal override Type EndpointType
        {
            get { return typeof(WorkflowControlEndpoint); }
        }

        [SuppressMessage(FxCop.Category.Configuration, FxCop.Rule.ConfigurationValidatorAttributeRule,
            Justification = "Value will be validated when converted into a Uri.")]
        [ConfigurationProperty(System.ServiceModel.Configuration.ConfigurationStrings.Address, DefaultValue = "")]
        public Uri Address
        {
            get { return (Uri)base[System.ServiceModel.Configuration.ConfigurationStrings.Address]; }
            set { base[System.ServiceModel.Configuration.ConfigurationStrings.Address] = value; }
        }

        [ConfigurationProperty(System.ServiceModel.Configuration.ConfigurationStrings.Binding, DefaultValue = "")]
        [StringValidator(MinLength = 0)]
        public string Binding
        {
            get { return (string)base[System.ServiceModel.Configuration.ConfigurationStrings.Binding]; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    value = string.Empty;
                }
                base[System.ServiceModel.Configuration.ConfigurationStrings.Binding] = value;
            }
        }

        [ConfigurationProperty(System.ServiceModel.Configuration.ConfigurationStrings.BindingConfiguration, DefaultValue = "")]
        [StringValidator(MinLength = 0)]
        public string BindingConfiguration
        {
            get { return (string)base[System.ServiceModel.Configuration.ConfigurationStrings.BindingConfiguration]; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    value = string.Empty;
                }
                base[System.ServiceModel.Configuration.ConfigurationStrings.BindingConfiguration] = value;
            }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                if (this.properties == null)
                {
                    ConfigurationPropertyCollection properties = base.Properties;

                    properties.Add(
                        new ConfigurationProperty(
                        System.ServiceModel.Configuration.ConfigurationStrings.Binding,
                        typeof(string),
                        string.Empty,
                        null,
                        new StringValidator(0, 2147483647, null),
                        ConfigurationPropertyOptions.None));

                    properties.Add(
                        new ConfigurationProperty(
                        System.ServiceModel.Configuration.ConfigurationStrings.BindingConfiguration,
                        typeof(string),
                        string.Empty,
                        null,
                        new StringValidator(0, 2147483647, null),
                        ConfigurationPropertyOptions.None));

                    properties.Add(
                        new ConfigurationProperty(
                        System.ServiceModel.Configuration.ConfigurationStrings.Address,
                        typeof(Uri),
                        string.Empty,
                        null,
                        null,
                        ConfigurationPropertyOptions.None));

                    this.properties = properties;
                }

                return this.properties;
            }
        }

        protected internal override ServiceEndpoint CreateServiceEndpoint(ContractDescription contractDescription)
        {
            WorkflowControlEndpoint result = new WorkflowControlEndpoint();

            if (!string.IsNullOrEmpty(this.Binding))
            {
                Binding binding = ConfigLoader.LookupBinding(this.Binding, this.BindingConfiguration);

                // we need to add validation here
                if (binding == null)
                {
                    throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR.FailedToLoadBindingInControlEndpoint(this.Binding, this.BindingConfiguration, this.Name)));
                }

                result.Binding = binding;
            }

            // This is only for client side
            if (this.shouldLetConfigLoaderOverwriteAddress)
            {
                // ConfigLoader will check for null and overwrite it with the address from ChannelEndpointElement
                result.Address = null;
            }

            return result;
        }

        protected override void OnApplyConfiguration(ServiceEndpoint endpoint, ChannelEndpointElement channelEndpointElement)
        {

        }

        protected override void OnApplyConfiguration(ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)
        {

        }

        protected override void OnInitializeAndValidate(ServiceEndpointElement serviceEndpointElement)
        {
            // Override serviceEndpointElement.Address with this.Address when serviceEndpointElement.Address == null.
            // This condition (serviceEndpointElement.Address == null) should only be true when used with the SqlWorkflowInstanceStoreBehavior.
            // Setting the address here so that ConfigLoader is able to set the EndpointAddress correctly, especially when this.Address is 
            // a relative address and can only be made absolute using the baseAddresses configured on the serviceHost.

            // Server side address inference goes by the following order:
            // 1. ServiceEndpointElement.Address if it is not-null and non-default
            // 2. WorkflowControlEndpointElement.Address
            // 3. Host base address
            
            if (serviceEndpointElement.Address == null ||
                (!HasAddressSetByUser(serviceEndpointElement) && HasAddressSetByUser(this)))
            {
                serviceEndpointElement.Address = this.Address;
            }
        }

        protected override void OnInitializeAndValidate(ChannelEndpointElement channelEndpointElement)
        {
            // Client side address inference goes by the following order:
            // 1. ChannelEndpointElement.Address
            // 2. WorkflowControlEndpointElement.Address
            // 3. Default address from WorkflowControlEndpoint

            if (HasAddressSetByUser(channelEndpointElement))
            {
                this.shouldLetConfigLoaderOverwriteAddress = true;
            }
            else if (HasAddressSetByUser(this))
            {
                channelEndpointElement.Address = this.Address;
                this.shouldLetConfigLoaderOverwriteAddress = true;
            }
        }

        bool HasAddressSetByUser(ConfigurationElement configurationElement)
        {
            return configurationElement.ElementInformation.Properties[System.ServiceModel.Configuration.ConfigurationStrings.Address].ValueOrigin != PropertyValueOrigin.Default;
        }
    }
}