Пример #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns> 是否初始化成功</returns>
        public bool Initialize(Tools.Logger logger)
        {
            bool ret = false;

            try
            {
                gRpcImpl = new GRPCImpl();

                if (this.LoadConfig() && gRpcImpl.Initialize(logger, MessageProcessor.Instance.AddQueue))
                {
                    this.logger = logger;

                    ret = CreatServer(gRpcImpl);
                }
                else
                {
                    SaveLog("[Error] GRPCServer::Initialize, Initialize Fail");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");

                SaveLog($"[Error] GRPCServer::Initialize, Catch Error, Msg:{ex.Message}");
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// 建立GRPC Server
        /// </summary>
        /// <param name="rpcInstance"> 綁定的Service 實例</param>
        /// <returns> 是否建立成功 </returns>
        private bool CreatServer(GRPCImpl impl)
        {
            bool ret = false;

            try
            {
                grpcServer = new Server
                {
                    Services = { Post.BindService(impl) },
                    Ports    = { new ServerPort(serverIP, serverPort, ServerCredentials.Insecure) }
                };

                grpcServer.Start();

                ret = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");

                SaveLog($"[Error] GRPCServer::CreatServer, Catch Error, Msg:{ex.Message}");
            }

            return(ret);
        }