예제 #1
0
        /// <summary>
        /// 调用分布式服务
        /// </summary>
        /// <param name="node"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public InvokeData Invoke(ServerNode node, InvokeMessage message)
        {
            if (node == null)
            {
                throw new WarningException("Server node can't for empty!");
            }

            //获取本地服务
            IService service = GetLocalService(message);

            if (service == null)
            {
                if (singleton.proxies.ContainsKey(node.Key.ToLower()))
                {
                    service = singleton.proxies[node.Key.ToLower()];
                }
                else
                {
                    if (node.Format == TransferType.Json)
                    {
                        service = new InvokeProxy(node, container);
                    }
                    else
                    {
                        service = new RemoteProxy(node, container);
                    }
                }
            }

            //获取服务内容
            return(GetInvokeData(message, service));
        }
예제 #2
0
        public TOutput Send <TOutput>(InvokeProxy <TOutput> invokeProxy)
        {
            var result = invokeProxy(client);

            client.Close();

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CastleFactory"/> class.
        /// </summary>
        /// <param name="config">The container.</param>
        protected CastleFactory(CastleFactoryConfiguration config)
        {
            this.config    = config;
            this.container = new SimpleServiceContainer(config.Type);

            container.OnLog += (log, type) =>
            {
                if (this.OnLog != null)
                {
                    this.OnLog(log, type);
                }
            };
            container.OnError += error =>
            {
                if (this.OnError != null)
                {
                    this.OnError(error);
                }
            };

            this.proxies = new Dictionary <string, IService>();

            if (config.Nodes.Count > 0)
            {
                foreach (var p in config.Nodes)
                {
                    if (p.Value.MaxPool < 10)
                    {
                        throw new WarningException("Minimum pool size 10!");
                    }
                    if (p.Value.MaxPool > 500)
                    {
                        throw new WarningException("Maximum pool size 500!");
                    }

                    IService proxy = null;
                    if (p.Value.Format == TransferType.Json)
                    {
                        proxy = new InvokeProxy(p.Value, container);
                    }
                    else
                    {
                        proxy = new RemoteProxy(p.Value, container);
                    }

                    this.proxies[p.Key.ToLower()] = proxy;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Create service channel.
        /// </summary>
        /// <param name="node">The node name.</param>
        /// <returns></returns>
        public IServiceInterfaceType GetChannel <IServiceInterfaceType>(ServerNode node)
        {
            if (node == null)
            {
                throw new WarningException("Server node can't for empty!");
            }

            //获取服务节点
            if (resolver != null)
            {
                node = resolver.GetServerNode <IServiceInterfaceType>(node);
            }

            //获取本地服务
            var service = GetLocalService <IServiceInterfaceType>();

            if (service == null)
            {
                IService proxy          = null;
                var      isCacheService = true;
                if (singleton.proxies.ContainsKey(node.Key.ToLower()))
                {
                    proxy = singleton.proxies[node.Key.ToLower()];
                }
                else
                {
                    if (node.Format == TransferType.Json)
                    {
                        proxy = new InvokeProxy(node, container);
                    }
                    else
                    {
                        proxy = new RemoteProxy(node, container);
                    }

                    isCacheService = false;
                }

                service = GetProxyChannel <IServiceInterfaceType>(proxy, isCacheService);
            }

            //返回服务
            return(service);
        }
예제 #5
0
        public static T Proxy <T>()
        {
            var proxy = new InvokeProxy <T>();

            return((T)proxy.GetTransparentProxy());
        }