/// <summary> /// Gets the server credentials. /// </summary> /// <param name="name">The credentials name in the configuration.</param> /// <param name="credentials">The credentials.</param> /// <returns>Returns true if can get; otherwise, false.</returns> public bool TryGetServerCredentials(string name, out ServerCredentials credentials) { if (!m_ServerCredentialsActivators.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out Factory <ServerCredentials> factory)) { credentials = null; return(false); } credentials = factory.GetObject(); return(true); }
/// <summary> /// Gets the callInvoker. /// </summary> /// <param name="name">The callInvoker name in the configuration.</param> /// <param name="callInvoker">The callInvoker.</param> /// <returns>Returns true if can get; otherwise, false.</returns> public bool TryGetCallInvoker(string name, out CallInvoker callInvoker) { if (!m_CallInvokerActivators.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out Factory <CallInvoker> factory)) { callInvoker = null; return(false); } callInvoker = factory.GetObject(); return(true); }
/// <summary> /// Gets the interceptor. /// </summary> /// <param name="name">The interceptor name in the configuration.</param> /// <param name="interceptor">The interceptor.</param> /// <returns>Returns true if can get; otherwise, false.</returns> public bool TryGetInterceptor(string name, out Interceptor interceptor) { if (!m_InterceptorActivators.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out Factory <Interceptor> factory)) { interceptor = null; return(false); } interceptor = factory.GetObject(); return(true); }
/// <summary> /// Gets the serverPort. /// </summary> /// <param name="name">The channel name in the configuration.</param> /// <param name="serverPort">The serverPort.</param> /// <returns>Returns true if can get; otherwise, false.</returns> public bool TryGetServerPort(string name, out ServerPort serverPort) { if (!m_ServerPortActivators.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out Factory <ServerPort> factory)) { serverPort = null; return(false); } serverPort = factory.GetObject(); return(true); }
/// <summary> /// Gets the channel. /// </summary> /// <param name="name">The channel name in the configuration.</param> /// <param name="channel">The channel.</param> /// <returns>Returns true if can get; otherwise, false.</returns> public bool TryGetChannel(string name, out Channel channel) { if (!m_ChannelActivators.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out Factory <Channel> factory)) { channel = null; return(false); } channel = factory.GetObject(); return(true); }
/// <summary> /// Intercept the service. /// </summary> /// <param name="service">The service.</param> /// <param name="context">The context.</param> /// <returns></returns> public ServerServiceDefinition Intercept(ServerServiceDefinition service, RpcConfigurationContext context) { Interceptor[] interceptors = RpcConfigurationUtility.CreateInterceptors(context, Interceptors, ExtraInterceptors); if (interceptors.Length > 0) { return(service.Intercept(interceptors)); } else { return(service); } }
/// <summary> /// Create a <see cref="CallInvoker"/>. /// </summary> /// <param name="channel">The channel.</param> /// <param name="context">The context.</param> /// <returns></returns> public CallInvoker CreateCallInvoker(Channel channel, RpcConfigurationContext context) { Interceptor[] interceptors = RpcConfigurationUtility.CreateInterceptors(context, Interceptors, ExtraInterceptors); if (interceptors.Length > 0) { return(CreateRootCallInvoker(channel, context).Intercept(interceptors)); } else { return(CreateRootCallInvoker(channel, context)); } }
/// <summary> /// Load the specified config. /// </summary> /// <param name="config">The config.</param> private void LoadConfig(RpcConfigurationConfig config) { // channel m_ChannelActivators.Clear(); m_ServerPortActivators.Clear(); foreach (var channelConfig in RpcConfigurationUtility.EnumerateAll(config.Channels)) { if (string.IsNullOrEmpty(channelConfig.Name)) { throw new RpcConfigurationException("The channel name is not set."); } m_ChannelActivators.Add(RpcConfigurationUtility.NormalizeName(channelConfig.Name), new Factory <Channel>(() => CreateChannel(channelConfig, this), DisposeChannel)); m_ServerPortActivators.Add(RpcConfigurationUtility.NormalizeName(channelConfig.Name), new Factory <ServerPort>(() => CreateServerPort(channelConfig, this), DisposeServerPort)); } // credential m_ChannelCredentialsActivators.Clear(); m_ServerCredentialsActivators.Clear(); foreach (var credentialsConfig in RpcConfigurationUtility.EnumerateAll(config.Credentials, config.ExtraCredentials)) { if (string.IsNullOrEmpty(credentialsConfig.Name)) { throw new RpcConfigurationException("The credential name is not set."); } m_ChannelCredentialsActivators.Add(RpcConfigurationUtility.NormalizeName(credentialsConfig.Name), new Factory <ChannelCredentials>(() => CreateChannelCredentials(credentialsConfig, this), null)); m_ServerCredentialsActivators.Add(RpcConfigurationUtility.NormalizeName(credentialsConfig.Name), new Factory <ServerCredentials>(() => CreateServerCredentials(credentialsConfig, this), null)); } // interceptor m_InterceptorActivators.Clear(); foreach (var interceptorConfig in RpcConfigurationUtility.EnumerateAll(config.Interceptors, config.ExtraInterceptors)) { if (interceptorConfig is Interceptors.InterceptorReference) { continue; } if (string.IsNullOrEmpty(interceptorConfig.Name)) { throw new RpcConfigurationException("The interceptor name is not set."); } m_InterceptorActivators.Add(RpcConfigurationUtility.NormalizeName(interceptorConfig.Name), new Factory <Interceptor>(() => CreateInterceptor(interceptorConfig, this), DisposeInterceptor)); } // callInvoker m_CallInvokerActivators.Clear(); foreach (var invokerConfig in RpcConfigurationUtility.EnumerateAll(config.CallInvokers, config.ExtraCallInvokers)) { if (string.IsNullOrEmpty(invokerConfig.Name)) { throw new RpcConfigurationException("The callInvoker name is not set."); } m_CallInvokerActivators.Add(RpcConfigurationUtility.NormalizeName(invokerConfig.Name), new Factory <CallInvoker>(() => CreateCallInvoker(invokerConfig, this), DisposeCallInvoker)); } // service m_ServiceConfigs.Clear(); foreach (var serviceConfig in RpcConfigurationUtility.EnumerateAll(config.Services)) { if (string.IsNullOrEmpty(serviceConfig.Name)) { throw new RpcConfigurationException("The service name is not set."); } m_ServiceConfigs.Add(RpcConfigurationUtility.NormalizeName(serviceConfig.Name), serviceConfig); } }
/// <summary> /// Gets the service config. /// </summary> /// <param name="name">The service name in the configuration.</param> /// <param name="config">The config.</param> /// <returns>Returns true if can get; otherwise, false.</returns> protected bool TryGetServiceConfig(string name, out RpcServiceConfig config) { return(m_ServiceConfigs.TryGetValue(RpcConfigurationUtility.NormalizeName(name), out config)); }