Пример #1
0
        /// <summary>
        /// Creates a server channel.
        /// </summary>
        /// <param name="properties">The channel properties.</param>
        /// <param name="provider">The sink provider.</param>
        public IpcServerChannel(IDictionary properties, IServerChannelSinkProvider provider)
        {
            bool impersonate = false;

            if (properties != null)
            {
                foreach (DictionaryEntry e in properties)
                {
                    switch ((string)e.Key)
                    {
                    case "name":
                        channelName = (string)e.Value;
                        break;

                    case "priority":
                        channelPriority = Convert.ToInt32(e.Value);
                        break;

                    case "portName":
                        portName = (string)e.Value;
                        if (!IpcChannelHelper.IsValidPipeName(portName))
                        {
                            throw new ArgumentException("Invalid pipe name.", "portName");
                        }
                        break;

                    case "impersonate":
                        impersonate = Boolean.Parse((string)e.Value);
                        break;
                    }
                }
            }

            if (portName == null)
            {
                portName = Guid.NewGuid().ToString("N");
            }

            serverProvider = provider;

            if (serverProvider == null)
            {
                serverProvider = new BinaryServerFormatterSinkProvider();
            }

            dataStore = new ChannelDataStore(
                new string[] { IpcChannelHelper.SchemeStart + portName }
                );
            PopulateChannelData(dataStore, serverProvider);

            sink = new IpcServerChannelSink(
                ChannelServices.CreateServerChannelSinkChain(serverProvider, this),
                portName,
                impersonate
                );

            StartListening(null);
        }
Пример #2
0
        /// <summary>
        /// Creates a server channel.
        /// </summary>
        /// <param name="properties">The channel properties.</param>
        /// <param name="provider">The sink provider.</param>
        public IpcServerChannel(IDictionary properties, IServerChannelSinkProvider provider)
        {
            bool impersonate = false;

            if (properties != null) 
            {
                foreach (DictionaryEntry e in properties) 
                {
                    switch ((string)e.Key) 
                    {
                        case "name":
                            channelName = (string)e.Value;
                            break;

                        case "priority":
                            channelPriority = Convert.ToInt32(e.Value);
                            break;

                        case "portName":
                            portName = (string)e.Value;
                            if (!IpcChannelHelper.IsValidPipeName(portName))
                                throw new ArgumentException("Invalid pipe name.", "portName");
                            break;

                        case "impersonate":
                            impersonate = Boolean.Parse((string)e.Value);
                            break;
                    }
                }
            }

            if (portName == null) 
            {
                portName = Guid.NewGuid().ToString("N");
            }

            serverProvider = provider;

            if (serverProvider == null) 
            {
                serverProvider = new BinaryServerFormatterSinkProvider();
            }

            dataStore = new ChannelDataStore(
                new string[] {IpcChannelHelper.SchemeStart + portName}
                );
            PopulateChannelData(dataStore, serverProvider);

            sink = new IpcServerChannelSink(
                ChannelServices.CreateServerChannelSinkChain(serverProvider, this),
                portName,
                impersonate
                );

            StartListening(null);
        }