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