AddInIpcChannel.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Hosting / AddInIpcChannel.cs / 1305376 / AddInIpcChannel.cs

                            using System; 
using System.Collections;
using System.Text;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels; 
using System.Runtime.Remoting.Messaging;
using System.Security; 
using System.Security.Permissions; 

namespace System.AddIn.Hosting 
{
    //This class exists only to do two security asserts, allowing us to use remoting with partial-trust app domains in external processes.
    internal class AddInIpcChannel : IpcChannel
    { 
        ///
        /// 
        /// 
        [System.Security.SecurityCritical]
        public AddInIpcChannel(IDictionary props, IClientChannelSinkProvider client, IServerChannelSinkProvider server) 
            : base(props, new AddInBinaryClientFormaterSinkProvider(client), new AddInBinaryServerFormaterSinkProvider(server))
        {
        }
    } 

    internal class AddInBinaryServerFormaterSinkProvider : IServerChannelSinkProvider 
    { 
        internal IServerChannelSinkProvider _sinkProvider;
 
        public AddInBinaryServerFormaterSinkProvider(IServerChannelSinkProvider sink)
        {
            _sinkProvider = sink;
        } 

        #region IServerChannelSinkProvider Members 
 
        ///
        /// 
        ///
        [System.Security.SecurityCritical]
        public IServerChannelSink CreateSink(IChannelReceiver channel)
        { 
            return new AddInBinaryServerSink(_sinkProvider.CreateSink(channel));
        } 
 
        ///
        /// 
        ///
        [System.Security.SecurityCritical]
        public void GetChannelData(IChannelDataStore channelData)
        { 
            _sinkProvider.GetChannelData(channelData);
        } 
 
        public IServerChannelSinkProvider Next
        { 
            ///
            ///
            ///
            [System.Security.SecurityCritical] 
            get
            { 
                return _sinkProvider.Next; 
            }
            /// 
            ///
            ///
            [System.Security.SecurityCritical]
            set 
            {
                _sinkProvider.Next = value; 
            } 
        }
 
        #endregion
    }

    internal class AddInBinaryServerSink : IServerChannelSink 
    {
        #region IServerChannelSink Members 
 
        private IServerChannelSink _sink;
 
        public AddInBinaryServerSink(IServerChannelSink sink)
        {
            _sink = sink;
        } 

        /// 
        /// 
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
        {
             _sink.AsyncProcessResponse(sinkStack, state, msg, headers, stream);
        } 

        /// 
        /// 
        ///
        [System.Security.SecurityCritical] 
        public System.IO.Stream GetResponseStream(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers)
        {
            return _sink.GetResponseStream(sinkStack, state, msg, headers);
        } 

        public IServerChannelSink NextChannelSink 
        { 
            ///
            /// 
            ///
            [System.Security.SecurityCritical]
            get { return _sink.NextChannelSink; }
        } 

        /// 
        /// 
        ///
        /// 
        [System.Security.SecurityCritical]
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
        {
            new System.Security.Permissions.SecurityPermission(SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode).Assert(); 
            return _sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);
        } 
 
        #endregion
 
        #region IChannelSinkBase Members

        public IDictionary Properties
        { 
            ///
            /// 
            /// 
            [System.Security.SecurityCritical]
            get { return _sink.Properties; } 
        }

        #endregion
    } 

 
 
    internal class AddInBinaryClientFormaterSinkProvider : IClientChannelSinkProvider
    { 
        IClientChannelSinkProvider _provider;

        public AddInBinaryClientFormaterSinkProvider(IClientChannelSinkProvider provider)
        { 
            _provider = provider;
        } 
 
        #region IClientChannelSinkProvider Members
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public IClientChannelSink CreateSink(IChannelSender channel, string url, object remoteChannelData)
        { 
            return new AddInBinaryClientFormaterSink(_provider.CreateSink(channel, url, remoteChannelData)); 
        }
 
        public IClientChannelSinkProvider Next
        {
            ///
            /// 
            ///
            [System.Security.SecurityCritical] 
            get 
            {
                return _provider.Next; 
            }
            ///
            ///
            /// 
            [System.Security.SecurityCritical]
            set 
            { 
                _provider.Next = value;
            } 
        }

        #endregion
    } 

    internal class AddInBinaryClientFormaterSink : IClientChannelSink, IMessageSink 
    { 
        IClientChannelSink _sink;
        IMessageSink _mSink; 

        public AddInBinaryClientFormaterSink(IClientChannelSink sink)
        {
            _sink = sink; 
            _mSink = (IMessageSink)sink;
        } 
 
        #region IClientChannelSink Members
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
        { 
             _sink.AsyncProcessRequest(sinkStack, msg, headers, stream); 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, System.IO.Stream stream)
        { 
             _sink.AsyncProcessResponse(sinkStack, state, headers, stream); 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public System.IO.Stream GetRequestStream(IMessage msg, ITransportHeaders headers)
        { 
            return _sink.GetRequestStream(msg, headers); 
        }
 
        public IClientChannelSink NextChannelSink
        {
            ///
            /// 
            ///
            [System.Security.SecurityCritical] 
            get { return _sink.NextChannelSink; } 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
        { 
            _sink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders,out responseStream); 
        }
 
        #endregion

        #region IChannelSinkBase Members
 
        public IDictionary Properties
        { 
            /// 
            ///
            /// 
            [System.Security.SecurityCritical]
            get { return _sink.Properties; }
        }
 
        #endregion
 
        #region IMessageSink Members 

        /// 
        ///
        ///
        [System.Security.SecurityCritical]
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) 
        {
            return _mSink.AsyncProcessMessage(msg, replySink); 
        } 

        public IMessageSink NextSink 
        {
            ///
            ///
            /// 
            [System.Security.SecurityCritical]
            get { return _mSink.NextSink; } 
        } 

        /// 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public IMessage SyncProcessMessage(IMessage msg)
        { 
            new System.Security.Permissions.SecurityPermission(SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode).Assert(); 
            return _mSink.SyncProcessMessage(msg);
        } 

        #endregion
    }
} 


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System; 
using System.Collections;
using System.Text;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels; 
using System.Runtime.Remoting.Messaging;
using System.Security; 
using System.Security.Permissions; 

namespace System.AddIn.Hosting 
{
    //This class exists only to do two security asserts, allowing us to use remoting with partial-trust app domains in external processes.
    internal class AddInIpcChannel : IpcChannel
    { 
        ///
        /// 
        /// 
        [System.Security.SecurityCritical]
        public AddInIpcChannel(IDictionary props, IClientChannelSinkProvider client, IServerChannelSinkProvider server) 
            : base(props, new AddInBinaryClientFormaterSinkProvider(client), new AddInBinaryServerFormaterSinkProvider(server))
        {
        }
    } 

    internal class AddInBinaryServerFormaterSinkProvider : IServerChannelSinkProvider 
    { 
        internal IServerChannelSinkProvider _sinkProvider;
 
        public AddInBinaryServerFormaterSinkProvider(IServerChannelSinkProvider sink)
        {
            _sinkProvider = sink;
        } 

        #region IServerChannelSinkProvider Members 
 
        ///
        /// 
        ///
        [System.Security.SecurityCritical]
        public IServerChannelSink CreateSink(IChannelReceiver channel)
        { 
            return new AddInBinaryServerSink(_sinkProvider.CreateSink(channel));
        } 
 
        ///
        /// 
        ///
        [System.Security.SecurityCritical]
        public void GetChannelData(IChannelDataStore channelData)
        { 
            _sinkProvider.GetChannelData(channelData);
        } 
 
        public IServerChannelSinkProvider Next
        { 
            ///
            ///
            ///
            [System.Security.SecurityCritical] 
            get
            { 
                return _sinkProvider.Next; 
            }
            /// 
            ///
            ///
            [System.Security.SecurityCritical]
            set 
            {
                _sinkProvider.Next = value; 
            } 
        }
 
        #endregion
    }

    internal class AddInBinaryServerSink : IServerChannelSink 
    {
        #region IServerChannelSink Members 
 
        private IServerChannelSink _sink;
 
        public AddInBinaryServerSink(IServerChannelSink sink)
        {
            _sink = sink;
        } 

        /// 
        /// 
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessResponse(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
        {
             _sink.AsyncProcessResponse(sinkStack, state, msg, headers, stream);
        } 

        /// 
        /// 
        ///
        [System.Security.SecurityCritical] 
        public System.IO.Stream GetResponseStream(IServerResponseChannelSinkStack sinkStack, object state, IMessage msg, ITransportHeaders headers)
        {
            return _sink.GetResponseStream(sinkStack, state, msg, headers);
        } 

        public IServerChannelSink NextChannelSink 
        { 
            ///
            /// 
            ///
            [System.Security.SecurityCritical]
            get { return _sink.NextChannelSink; }
        } 

        /// 
        /// 
        ///
        /// 
        [System.Security.SecurityCritical]
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
        {
            new System.Security.Permissions.SecurityPermission(SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode).Assert(); 
            return _sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);
        } 
 
        #endregion
 
        #region IChannelSinkBase Members

        public IDictionary Properties
        { 
            ///
            /// 
            /// 
            [System.Security.SecurityCritical]
            get { return _sink.Properties; } 
        }

        #endregion
    } 

 
 
    internal class AddInBinaryClientFormaterSinkProvider : IClientChannelSinkProvider
    { 
        IClientChannelSinkProvider _provider;

        public AddInBinaryClientFormaterSinkProvider(IClientChannelSinkProvider provider)
        { 
            _provider = provider;
        } 
 
        #region IClientChannelSinkProvider Members
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public IClientChannelSink CreateSink(IChannelSender channel, string url, object remoteChannelData)
        { 
            return new AddInBinaryClientFormaterSink(_provider.CreateSink(channel, url, remoteChannelData)); 
        }
 
        public IClientChannelSinkProvider Next
        {
            ///
            /// 
            ///
            [System.Security.SecurityCritical] 
            get 
            {
                return _provider.Next; 
            }
            ///
            ///
            /// 
            [System.Security.SecurityCritical]
            set 
            { 
                _provider.Next = value;
            } 
        }

        #endregion
    } 

    internal class AddInBinaryClientFormaterSink : IClientChannelSink, IMessageSink 
    { 
        IClientChannelSink _sink;
        IMessageSink _mSink; 

        public AddInBinaryClientFormaterSink(IClientChannelSink sink)
        {
            _sink = sink; 
            _mSink = (IMessageSink)sink;
        } 
 
        #region IClientChannelSink Members
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders headers, System.IO.Stream stream)
        { 
             _sink.AsyncProcessRequest(sinkStack, msg, headers, stream); 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state, ITransportHeaders headers, System.IO.Stream stream)
        { 
             _sink.AsyncProcessResponse(sinkStack, state, headers, stream); 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public System.IO.Stream GetRequestStream(IMessage msg, ITransportHeaders headers)
        { 
            return _sink.GetRequestStream(msg, headers); 
        }
 
        public IClientChannelSink NextChannelSink
        {
            ///
            /// 
            ///
            [System.Security.SecurityCritical] 
            get { return _sink.NextChannelSink; } 
        }
 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)
        { 
            _sink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders,out responseStream); 
        }
 
        #endregion

        #region IChannelSinkBase Members
 
        public IDictionary Properties
        { 
            /// 
            ///
            /// 
            [System.Security.SecurityCritical]
            get { return _sink.Properties; }
        }
 
        #endregion
 
        #region IMessageSink Members 

        /// 
        ///
        ///
        [System.Security.SecurityCritical]
        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) 
        {
            return _mSink.AsyncProcessMessage(msg, replySink); 
        } 

        public IMessageSink NextSink 
        {
            ///
            ///
            /// 
            [System.Security.SecurityCritical]
            get { return _mSink.NextSink; } 
        } 

        /// 
        ///
        ///
        ///
        [System.Security.SecurityCritical] 
        public IMessage SyncProcessMessage(IMessage msg)
        { 
            new System.Security.Permissions.SecurityPermission(SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode).Assert(); 
            return _mSink.SyncProcessMessage(msg);
        } 

        #endregion
    }
} 


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK