PageRenderTime 78ms CodeModel.GetById 73ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/ExpressInteropBinding/Microsoft.ServiceModel.Interop/Metro/Configuration/MetroBindingElement.cs

#
C# | 112 lines | 62 code | 17 blank | 33 comment | 1 complexity | 8c301545777775eae8827dbd3693d8ff MD5 | raw file
  1// <copyright file="MetroBindingElement.cs" company="Microsoft Corporation">
  2// Copyright (c) Microsoft Corporation.  All rights reserved.
  3// </copyright>
  4
  5namespace Microsoft.ServiceModel.Interop.Metro.Configuration
  6{
  7    using System;
  8    using System.Configuration;
  9    using System.ServiceModel.Channels;
 10    using Microsoft.ServiceModel.Interop.Configuration;
 11
 12    /// <summary>
 13    /// Binding element implementation for Metro
 14    /// </summary>
 15    public class MetroBindingElement : InteropBindingElement
 16    {
 17        private const string SecurityProperty = "security";
 18        private const string ReliableSessionProperty = "reliableSession";
 19
 20        /// <summary>
 21        /// Initializes a new instance of the MetroBindingElement class
 22        /// </summary>
 23        /// <param name="configurationName">Binding configuration name</param>
 24        public MetroBindingElement(string configurationName) :
 25            base(configurationName)
 26        {
 27        }
 28
 29        /// <summary>
 30        /// Initializes a new instance of the MetroBindingElement class
 31        /// </summary>
 32        public MetroBindingElement()
 33            : this(null)
 34        {
 35        }
 36        
 37        /// <summary>
 38        /// Gets the Security binding element
 39        /// </summary>
 40        [ConfigurationProperty(SecurityProperty)]
 41        public MetroSecurityElement Security
 42        {
 43            get { return (MetroSecurityElement)base[SecurityProperty]; }
 44        }
 45
 46        /// <summary>
 47        /// Gets the reliable session binding element
 48        /// </summary>
 49        [ConfigurationProperty(ReliableSessionProperty)]
 50        public MetroReliableSessionElement ReliableSession
 51        {
 52            get { return (MetroReliableSessionElement)base[ReliableSessionProperty]; }
 53        }
 54
 55        /// <summary>
 56        /// Gets all the available configuration properties
 57        /// </summary>
 58        protected override ConfigurationPropertyCollection Properties
 59        {
 60            get
 61            {
 62                ConfigurationPropertyCollection properties = base.Properties;
 63                properties.Add(new ConfigurationProperty(SecurityProperty, typeof(MetroSecurityElement)));
 64                properties.Add(new ConfigurationProperty(ReliableSessionProperty, typeof(MetroReliableSessionElement)));
 65
 66                return properties;
 67            }
 68        }
 69
 70        /// <summary>
 71        /// Gets the binding element implementation type
 72        /// </summary>
 73        protected override Type BindingElementType
 74        {
 75            get { return typeof(MetroBinding); }
 76        }
 77
 78        /// <summary>
 79        /// Initializes this configuration element from an existing binding instance 
 80        /// </summary>
 81        /// <param name="binding">Binding instance</param>
 82        protected override void InitializeFrom(Binding binding)
 83        {
 84            base.InitializeFrom(binding);
 85
 86            MetroBinding metroBinding = (MetroBinding)binding;
 87
 88            this.ReliableSession.InitializeFrom(metroBinding.ReliableSession);
 89            this.Security.InitializeFrom(metroBinding.Security);
 90        }
 91
 92        /// <summary>
 93        /// Applies this configuration element to an existing binding instance
 94        /// </summary>
 95        /// <param name="binding">Binding instance</param>
 96        protected override void OnApplyConfiguration(Binding binding)
 97        {
 98            base.OnApplyConfiguration(binding);
 99
100            MetroBinding metroBinding = (MetroBinding)binding;
101
102            this.ReliableSession.ApplyConfiguration(metroBinding.ReliableSession);
103            this.Security.ApplyConfiguration(metroBinding.Security);
104
105            if (this.ReliableSession.Enabled)
106            {
107                metroBinding.Security.EstablishSecurityContext = true;
108            }
109        }
110    }
111}
112