Beispiel #1
0
        private Program(ServerProgramOptions options) : base(options)
        {
            var channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);

            _client = new SocketExchange.SocketExchangeClient(channel);

            try
            {
                var message = _client.SayHello(new HelloMessage {
                    Version = Options.Version
                });
                Console.WriteLine($"Connected to SocketExchange v{message.Version} on 127.0.0.1:50051");
            }
            catch
            {
                Console.WriteLine("Error: Connection to SocketExchange on 127.0.0.1:50051 failed");
                Environment.Exit(1);
            }
        }
        private Program(ServerProgramOptions options) : base(options)
        {
            var dataPath = Path.Combine(GetThisFileDirectory(), "..", "..", "data", "csvdb");

            var socketSerializer = new CustomSocketSerializer();
            var socketParser     = new CsvRecordParser <CustomSocket>(socketSerializer);
            var socketOptions    = new CsvRepositoryOptions
            {
                IdPropertyName = "SocketName",
                CsvFileName    = Path.Combine(dataPath, "socket.csv"),
                WalFileName    = Path.Combine(dataPath, "wal_socket.txt")
            };
            var socketsRepository =
                new CsvRepository <CustomSocket>(socketSerializer, socketParser, socketOptions).Sync();
            var socketService = new SocketService(socketsRepository);

            var socketGroupSerializer = new SocketGroupSerializer();
            var socketGroupParser     = new CsvRecordParser <SocketGroup>(socketGroupSerializer);
            var socketGroupOptions    = new CsvRepositoryOptions
            {
                IdPropertyName = "GroupName",
                CsvFileName    = Path.Combine(dataPath, "socketGroup.csv"),
                WalFileName    = Path.Combine(dataPath, "wal_socketGroup.txt")
            };
            var socketGroupRepository =
                new CsvRepository <SocketGroup>(socketGroupSerializer, socketGroupParser, socketGroupOptions).Sync();
            var socketGroupService = new GroupService(socketGroupRepository);

            var socketExchangeOptions = new SocketExchangeOptions {
                Version = Options.Version, Debug = options.Debug
            };
            var socketExchange = new SocketExchangeImpl(socketService, socketGroupService, socketExchangeOptions);

            Server = new Grpc.Core.Server
            {
                Services = { SocketExchange.BindService(socketExchange) },
                Ports    = { new ServerPort("localhost", Options.Port, ServerCredentials.Insecure) }
            };
        }