コード例 #1
0
ファイル: RemoteServiceBase.cs プロジェクト: ewin66/Forge
        protected virtual Channel LookUpChannel()
        {
            Channel channel = ChannelServices.GetChannelById(this.ChannelId);

            if (channel == null)
            {
                // regisztrálás
                BinaryMessageSink   sink  = new BinaryMessageSink(true, 1024);
                List <IMessageSink> sinks = new List <IMessageSink>();
                sinks.Add(sink);

                AddressEndPoint        serverEndPoint = new AddressEndPoint("127.0.0.1", 0);
                List <AddressEndPoint> serverData     = new List <AddressEndPoint>();
                serverData.Add(serverEndPoint);

                TerraGrafNetworkFactory networkFactory = new TerraGrafNetworkFactory();

                DefaultServerStreamFactory serverStreamFactory = new DefaultServerStreamFactory();
                DefaultClientStreamFactory clientStreamFactory = new DefaultClientStreamFactory();

                channel = new TCPChannel(this.ChannelId, sinks, sinks, serverData, networkFactory, serverStreamFactory, clientStreamFactory);
                channel.StartListening();

                ChannelServices.RegisterChannel(channel);
            }

            return(channel);
        }
コード例 #2
0
        private void ValidateConstructorParameters(Type contractInterface, Type realProxyType, String channelId, AddressEndPoint remoteEp)
        {
            if (contractInterface == null)
            {
                ThrowHelper.ThrowArgumentNullException("contractInterface");
            }
            if (realProxyType == null)
            {
                ThrowHelper.ThrowArgumentNullException("realProxyType");
            }
            if (string.IsNullOrEmpty(channelId))
            {
                ThrowHelper.ThrowArgumentNullException("channelId");
            }
            if (!contractInterface.IsAssignableFrom(realProxyType))
            {
                ThrowHelper.ThrowArgumentException("Provided client proxy does not implements the provided contract interface.", "realProxyType");
            }
            if (remoteEp == null)
            {
                ThrowHelper.ThrowArgumentNullException("remoteEp");
            }
            if (!ChannelServices.IsChannelRegistered(channelId))
            {
                throw new ChannelNotFoundException(channelId);
            }

            ContractValidator.ValidateContractIntegrity(contractInterface);
            ImplementationValidator.ValidateProxyIntegration(realProxyType);

            this.mContractInterface = contractInterface;
            this.mRealProxyType     = realProxyType;
            this.mChannel           = ChannelServices.GetChannelById(channelId);
            this.mRemoteEndPoint    = remoteEp;
        }
コード例 #3
0
ファイル: RemoteServiceLocator.cs プロジェクト: ewin66/Forge
        protected virtual Channel LookUpChannel()
        {
            Channel channel = ChannelServices.GetChannelById(this.ChannelId);

            if (channel == null)
            {
                // regisztrálás
                if (LOGGER.IsErrorEnabled)
                {
                    LOGGER.Error(string.Format("{0}, locator cannot find channel with id '{1}'. Create default channel.", LOG_PREFIX, this.ChannelId));
                }
                BinaryMessageSink   sink  = new BinaryMessageSink(true, 1024);
                List <IMessageSink> sinks = new List <IMessageSink>();
                sinks.Add(sink);

                TerraGrafNetworkFactory networkFactory = new TerraGrafNetworkFactory();

                DefaultServerStreamFactory serverStreamFactory = new DefaultServerStreamFactory();
                DefaultClientStreamFactory clientStreamFactory = new DefaultClientStreamFactory();

                channel = new TCPChannel(this.ChannelId, sinks, sinks, networkFactory, serverStreamFactory, clientStreamFactory);

                ChannelServices.RegisterChannel(channel);
            }

            return(channel);
        }
コード例 #4
0
        private void ValidateConstructorParameters(Type contractInterface, Type realProxyType, String channelId)
        {
            if (string.IsNullOrEmpty(channelId))
            {
                ThrowHelper.ThrowArgumentNullException("channelId");
            }
            if (!ChannelServices.IsChannelRegistered(channelId))
            {
                throw new ChannelNotFoundException(channelId);
            }
            Channel c = ChannelServices.GetChannelById(channelId);

            ValidateConstructorParameters(contractInterface, realProxyType, channelId, c.DefaultConnectionData);
        }
コード例 #5
0
        /// <summary>
        /// Get a service factory to create and receive calls from a client.
        /// </summary>
        /// <typeparam name="TServiceContract">The type of the contract.</typeparam>
        /// <param name="channelId">The channel id.</param>
        /// <param name="implementationType">Type of the implementation.</param>
        /// <returns>Service factory</returns>
        /// <exception cref="System.ArgumentNullException">
        /// channelId
        /// or
        /// implementationType
        /// </exception>
        /// <exception cref="ChannelNotFoundException"></exception>
        public static IServiceFactory GetServiceFactory <TServiceContract>(String channelId, Type implementationType) where TServiceContract : IRemoteContract
        {
            if (string.IsNullOrEmpty(channelId))
            {
                throw new ArgumentNullException("channelId");
            }
            if (implementationType == null)
            {
                throw new ArgumentNullException("implementationType");
            }

            Channel channel = ChannelServices.GetChannelById(channelId);

            if (channel == null)
            {
                throw new ChannelNotFoundException(channelId);
            }

            IServiceFactory result = null;

            mFactoryLock.Lock();
            try
            {
                if (mFactories.Count > 0)
                {
                    foreach (ServiceFactory <IRemoteContract> factory in mFactories)
                    {
                        if (factory.ImplementationType.Equals(implementationType) && factory.ServiceContract.Equals(typeof(TServiceContract)) &&
                            factory.Channel.Equals(channel))
                        {
                            result = factory;
                            break;
                        }
                    }
                }
                if (result == null)
                {
                    result = new ServiceFactory <TServiceContract>(channelId, implementationType);
                    mFactories.Add(result);
                }
            }
            finally
            {
                mFactoryLock.Unlock();
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Prevents a default instance of the <see cref="ServiceFactory&lt;TContract&gt;"/> class from being created.
        /// </summary>
        /// <param name="channelId">The channel id.</param>
        /// <param name="implementationType">Type of the implementation.</param>
        private ServiceFactory(String channelId, Type implementationType)
        {
            if (string.IsNullOrEmpty(channelId))
            {
                ThrowHelper.ThrowArgumentNullException("channelId");
            }
            if (implementationType == null)
            {
                ThrowHelper.ThrowArgumentNullException("implementationType");
            }

            if (!ServiceContract.IsAssignableFrom(implementationType))
            {
                throw new ArgumentException("Provided implementation does not implements the contract interface.", "implementationType");
            }

            ContractValidator.ValidateContractIntegrity(ServiceContract);
            ImplementationValidator.ValidateImplementationIntegrity(implementationType);

            this.mChannel = ChannelServices.GetChannelById(channelId);
            if (this.mChannel == null)
            {
                throw new ChannelNotFoundException(channelId);
            }

            this.mImplementationType = implementationType;

            // adatstruktúra adminisztrációja
            // egy factory csak azt adhatja hozzá, ami nincs és csak azt veheti el, ami még nem volt.
            ContractServiceSideDescriptor descriptor = null;
            Dictionary <Type, ContractServiceSideDescriptor> contractDescriptors = ServiceBaseServices.ContractDescriptors;

            lock (contractDescriptors)
            {
                if (contractDescriptors.ContainsKey(ServiceContract))
                {
                    // ismert contract
                    descriptor = contractDescriptors[ServiceContract];
                }
                else
                {
                    // ilyen contract még nincs
                    mControlServiceContract = true;
                    mControlChannel         = true;
                }
            }
            if (descriptor != null)
            {
                lock (descriptor)
                {
                    if (!descriptor.ImplementationPerChannel.ContainsKey(channelId))
                    {
                        mControlChannel = true;
                    }
                    else
                    {
                        if (descriptor.ImplementationPerChannel.ContainsKey(channelId))
                        {
                            // ehhez a csatornához és contracthoz már egy másik implementáció van rendelve
                            Type currentImplType = descriptor.ImplementationPerChannel[channelId];
                            if (!currentImplType.Equals(implementationType))
                            {
                                throw new ArgumentException(String.Format("Unable to register provided implementation type: '{0}'. An other implementation type '{1}' has already definied for channel '{2}' and contract '{3}'.", implementationType.FullName, currentImplType.FullName, channelId, ServiceContract.FullName));
                            }
                        }
                    }
                }
            }
            ChannelServices.UnregisterChannelEvent += new EventHandler <ChannelRegistrationEventArgs>(ChannelUnregisteredEventHandler);
        }