Exemplo n.º 1
0
        /// <summary>
        /// 生成客户端C#代码文件
        /// 另外此方法名不宜调整
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="spaceName"></param>
        /// <param name="types"></param>
        public static void Generate(string folder, string spaceName, params Type[] types)
        {
            RPCMapping.Regists(types);

            GenerateProxy(spaceName);

            var filePath = Path.Combine(folder, "RPCServiceProxy.cs");

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(_proxyStr);

            if (_serviceStrs != null && _serviceStrs.Count > 0)
            {
                foreach (var serviceStr in _serviceStrs)
                {
                    sb.AppendLine(serviceStr);
                }
            }

            if (_modelStrs != null && _modelStrs.Count > 0)
            {
                foreach (var entry in _modelStrs)
                {
                    sb.AppendLine(entry.Value);
                }
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            File.WriteAllText(filePath, sb.ToString(), Encoding.UTF8);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 启动服务
        /// </summary>
        public void Start()
        {
            if (!_started)
            {
                _RServer.Start();

                RPCMapping.Regists(_serviceTypes);

                _started = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// RPC服务提供者
        /// </summary>
        /// <param name="serviceTypes"></param>
        /// <param name="port"></param>
        public ServiceProvider(Type[] serviceTypes, int port = 39654)
        {
            _serviceTypes = serviceTypes;
            _port         = 39654;

            RPCMapping.Regists(_serviceTypes);

            _RServer          = new RServer();
            _RServer.OnMsg   += _RServer_OnMsg;
            _RServer.OnError += _RServer_OnError;
        }