PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.ServiceModel.Internal/Microsoft/ServiceModel/Activation/AspNetEnvironment.cs

#
C# | 66 lines | 50 code | 8 blank | 8 comment | 6 complexity | 01887987575682f245072553e8ad89db MD5 | raw file
 1// <copyright>
 2// Copyright (c) Microsoft Corporation.  All rights reserved.
 3// </copyright>
 4
 5namespace Microsoft.ServiceModel.Activation
 6{
 7    using System.Configuration;
 8    using System.Diagnostics.CodeAnalysis;
 9    using System.ServiceModel.Channels;
10    using Microsoft.Server.Common;
11
12    internal class AspNetEnvironment
13    {
14        public const string HostingMessagePropertyName = "webhost";
15        
16        private const string HostingMessagePropertyTypeName = "System.ServiceModel.Activation.HostingMessageProperty";
17        private static AspNetEnvironment current;
18        private static object thisLock = new object();
19
20        public static AspNetEnvironment Current
21        {
22            get
23            {
24                if (current == null)
25                {
26                    lock (thisLock)
27                    {
28                        if (current == null)
29                        {
30                            current = new AspNetEnvironment();
31                        }
32                    }
33                }
34
35                return current;
36            }
37        }
38
39        // ALTERED_FOR_PORT:
40        // The GetHostingProperty() code below is an altered implementation from the System.ServiceModel.Activation.HostedAspNetEnvironment class.
41        // The original implementation casts the hostingProperty to type System.ServiceModel.Activation.HostingMessageProperty.  However,
42        //  this class is internal sealed, therefore we simply check the type name.
43        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This is existing public API")]
44        public object GetHostingProperty(Message message)
45        {
46            object hostingProperty;
47            if (message.Properties.TryGetValue(HostingMessagePropertyName, out hostingProperty))
48            {
49                string hostingPropertyName = hostingProperty.GetType().FullName;
50                if (string.Equals(hostingPropertyName, HostingMessagePropertyTypeName, System.StringComparison.Ordinal))
51                {
52                    return hostingProperty;
53                }
54            }
55
56            return null;
57        }
58
59        // TODO: CSDMAIN 205599 -- verify this approach works under IIS
60        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This is existing public API")]
61        public object GetConfigurationSection(string sectionPath)
62        {
63            return ConfigurationManager.GetSection(sectionPath);
64        }
65    }
66}