File: OperationInfo.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (308 lines) | stat: -rw-r--r-- 10,585 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.Workflow.Activities
{
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Diagnostics.CodeAnalysis;
    using System.Net.Security;
    using System.Reflection;
    using System.ServiceModel;
    using System.Workflow.Activities.Design;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Compiler;

    [Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
    public sealed class OperationInfo : OperationInfoBase
    {
        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
        internal static readonly DependencyProperty ContractNameProperty =
            DependencyProperty.Register("ContractName",
            typeof(string), typeof(OperationInfo),
            new PropertyMetadata(null, DependencyPropertyOptions.Metadata));

        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
        internal static readonly DependencyProperty IsOneWayProperty =
            DependencyProperty.Register("IsOneWay",
            typeof(bool), typeof(OperationInfo),
            new PropertyMetadata(false, DependencyPropertyOptions.Metadata));

        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
        internal static readonly DependencyProperty ParametersProperty =
            DependencyProperty.Register("Parameters",
            typeof(OperationParameterInfoCollection), typeof(OperationInfo),
            new PropertyMetadata(null, DependencyPropertyOptions.Metadata | DependencyPropertyOptions.ReadOnly,
            new Attribute[] {
                new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)
            }
            ));

        [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
        internal static readonly DependencyProperty ProtectionLevelProperty =
            DependencyProperty.Register("ProtectionLevel",
            typeof(ProtectionLevel?), typeof(OperationInfo),
            new PropertyMetadata(null, DependencyPropertyOptions.Metadata));

        public OperationInfo()
        {
            this.SetReadOnlyPropertyValue(OperationInfo.ParametersProperty,
                new OperationParameterInfoCollection(this));
        }

        public string ContractName
        {
            get
            {
                return (string) this.GetValue(OperationInfo.ContractNameProperty);
            }
            set
            {
                this.SetValue(OperationInfo.ContractNameProperty, value);
            }
        }

        [DefaultValue(false)]
        public bool HasProtectionLevel
        {
            get
            {
                return (this.ProtectionLevel != null);
            }
        }

        [DefaultValue(false)]
        public bool IsOneWay
        {
            get
            {
                return (bool) this.GetValue(OperationInfo.IsOneWayProperty);
            }
            set
            {
                this.SetValue(OperationInfo.IsOneWayProperty, value);
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public OperationParameterInfoCollection Parameters
        {
            get
            {
                return (OperationParameterInfoCollection) this.GetValue(OperationInfo.ParametersProperty);
            }
        }

        [DefaultValue(null)]
        public ProtectionLevel? ProtectionLevel
        {
            get
            {
                return (ProtectionLevel?) this.GetValue(OperationInfo.ProtectionLevelProperty);
            }
            set
            {
                this.SetValue(OperationInfo.ProtectionLevelProperty, value);
            }
        }

        public override OperationInfoBase Clone()
        {
            OperationInfo clonedOperation = (OperationInfo) base.Clone();
            clonedOperation.ContractName = this.ContractName;
            clonedOperation.IsOneWay = this.IsOneWay;
            if (this.HasProtectionLevel)
            {
                clonedOperation.ProtectionLevel = this.ProtectionLevel;
            }

            foreach (OperationParameterInfo parameter in this.Parameters)
            {
                clonedOperation.Parameters.Add(parameter.Clone());
            }

            return clonedOperation;
        }

        public override bool Equals(object obj)
        {
            if (!base.Equals(obj))
            {
                return false;
            }

            OperationInfo operationInfo = obj as OperationInfo;
            if (operationInfo == null)
            {
                return false;
            }
            if (String.Compare(operationInfo.ContractName, this.ContractName, StringComparison.Ordinal) != 0)
            {
                return false;
            }
            if (operationInfo.IsOneWay != this.IsOneWay)
            {
                return false;
            }
            if (operationInfo.HasProtectionLevel != this.HasProtectionLevel)
            {
                return false;
            }
            if (operationInfo.ProtectionLevel != this.ProtectionLevel)
            {
                return false;
            }

            if (operationInfo.Parameters.Count != this.Parameters.Count)
            {
                return false;
            }

            foreach (OperationParameterInfo parameter in operationInfo.Parameters)
            {
                OperationParameterInfo correspondingParameter = this.Parameters[parameter.Name];
                if (correspondingParameter == null)
                {
                    return false;
                }

                if (!parameter.Equals(correspondingParameter))
                {
                    return false;
                }
            }

            return true;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            string returnValue = string.Empty;
            if (!string.IsNullOrEmpty(this.Name))
            {
                returnValue = this.Name;

                if (!string.IsNullOrEmpty(this.ContractName))
                {
                    returnValue = this.ContractName + "." + returnValue;
                }
            }

            return returnValue;
        }

        protected internal override string GetContractFullName(IServiceProvider provider)
        {
            return this.ContractName;
        }

        protected internal override Type GetContractType(IServiceProvider provider)
        {
            Type contractType = DynamicContractTypeBuilder.GetContractType(this, this.ParentDependencyObject as ReceiveActivity);
            if (contractType == null && !this.IsReadOnly)
            {
                Activity owner = this.ParentDependencyObject as Activity;
                if (owner != null)
                {
                    owner.RootActivity.RemoveProperty(DynamicContractTypeBuilder.DynamicContractTypesProperty);
                }

                contractType = DynamicContractTypeBuilder.GetContractType(this, this.ParentDependencyObject as ReceiveActivity);
            }
            return contractType;
        }

        internal protected override bool GetIsOneWay(IServiceProvider provider)
        {
            return this.IsOneWay;
        }

        internal protected override MethodInfo GetMethodInfo(IServiceProvider provider)
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                return null;
            }

            MethodInfo methodInfo = null;
            if (this.IsReadOnly)
            {
                if (this.UserData.Contains(OperationInfoBase.MethodInfoProperty))
                {
                    methodInfo = this.UserData[OperationInfoBase.MethodInfoProperty] as MethodInfo;
                }

                if (methodInfo != null)
                {
                    return methodInfo;
                }
            }

            methodInfo = InternalGetMethodInfo(provider);
            if (methodInfo == null && !this.IsReadOnly)
            {
                Activity owner = this.ParentDependencyObject as Activity;
                if (owner != null)
                {
                    owner.RootActivity.RemoveProperty(DynamicContractTypeBuilder.DynamicContractTypesProperty);
                }
                methodInfo = InternalGetMethodInfo(provider);
            }

            if (this.IsReadOnly)
            {
                this.UserData[OperationInfoBase.MethodInfoProperty] = methodInfo;
            }

            return methodInfo;
        }

        internal protected override OperationParameterInfoCollection GetParameters(IServiceProvider provider)
        {
            return this.Parameters;
        }

        internal void ResetProtectionLevel()
        {
            this.ProtectionLevel = null;
        }

        MethodInfo InternalGetMethodInfo(IServiceProvider provider)
        {
            Type type = this.GetContractType(provider);
            if (type != null)
            {
                foreach (MethodInfo methodInfo in type.GetMethods())
                {
                    object[] operationContractAttribs =
                        methodInfo.GetCustomAttributes(typeof(OperationContractAttribute), true);

                    if (operationContractAttribs != null && operationContractAttribs.Length > 0)
                    {
                        string operationName =
                            ((OperationContractAttribute) operationContractAttribs[0]).Name;

                        if (string.IsNullOrEmpty(operationName) &&
                            string.Compare(methodInfo.Name, this.Name, StringComparison.Ordinal) == 0)
                        {
                            return methodInfo;
                        }
                        else if (string.Compare(operationName, this.Name, StringComparison.Ordinal) == 0)
                        {
                            return methodInfo;
                        }
                    }
                }
            }

            return null;
        }
    }
}