Exemplo n.º 1
0
 // constructor for dependency injection
 public MainService(Notification.NotificationClient notificationClient, User.UserClient userClient,
                    McsvChatDbContext db)
 {
     _notificationClient = notificationClient;
     _userClient         = userClient;
     _db = db;
 }
Exemplo n.º 2
0
        private static async Task GetUserById(int userId, User.UserClient userServiceClient)
        {
            var jwt = await GetJwt();

            var headers = new Metadata
            {
                { "Authorization", $"Bearer {jwt}" }
            };

            var getUserByIdViewModel = new GetUserByIdViewModel
            {
                UserId = userId,
            };

            try
            {
                var user = userServiceClient.GetUser(getUserByIdViewModel, headers);

                Console.WriteLine($"{user.Id} - {user.FirstName} {user.Surname} - {user.EmailAddress}");
            }
            catch (RpcException ex)
            {
                Console.WriteLine($"{ex.Status.StatusCode} - {ex.Status.Detail}");
            }
        }
Exemplo n.º 3
0
        public async Task UserClient_RemovePoints_ToUserThatDoesNotExist_SetsToZero()
        {
            // arrange
            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var removeQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = 100
            };

            var getQuery = new UserQuery
            {
                Id = id
            };

            // act
            var removeResult = await client.RemovePointsAsync(removeQuery);

            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, removeResult.Status, "RemovePoints() failed.");
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(0, getResult.Amount);
        }
Exemplo n.º 4
0
        public async Task UserClient_AddPoints_ToUserThatDoesExist_ReturnsExtraPoints()
        {
            // arrange
            var startingAmount   = Rng.Next();
            var additionalAmount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var createQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = startingAmount
            };

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = additionalAmount
            };

            // act
            var createResult = await client.AddPointsAsync(createQuery);

            var addResult = await client.AddPointsAsync(addQuery);

            // assert
            Assert.AreEqual(Status.Success, createResult.Status, "AddPoints() failed.");
            Assert.AreEqual(Status.Success, addResult.Status, "AddPoints() failed.");
            Assert.AreEqual(startingAmount + additionalAmount, addResult.Amount);
        }
Exemplo n.º 5
0
        static async Task Main(string[] args)
        {
            using var grpcChannel = GrpcChannel.ForAddress(_grpcServerAddress);
            var userServiceClient = new User.UserClient(grpcChannel);

            GetUsersInGroupList(userServiceClient);
            Console.WriteLine("");
            await GetUsersInGroupStream(userServiceClient);

            Console.WriteLine("");
            Console.WriteLine("Enter the ID of the user to list their details, or type \"exit\" to quit.");

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "exit")
                {
                    break;
                }

                var userId = int.Parse(input);

                await GetUserById(userId, userServiceClient);
            }

            Console.WriteLine("End");
        }
Exemplo n.º 6
0
        public async Task UserClient_GetPoints_ToUserThatDoesExist_ReturnsPoints()
        {
            // arrange
            var amount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = amount
            };

            var getQuery = new UserQuery
            {
                Id = id
            };

            // act
            var addResult = await client.AddPointsAsync(addQuery);

            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, addResult.Status, "AddPoints() failed.");
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(amount, getResult.Amount);
        }
Exemplo n.º 7
0
        public UserService(ILogger <UserService> logger, IOptions <AppSettings> appSettings)
        {
            _logger = logger;

            var channel = GrpcChannel.ForAddress(appSettings.Value.Urls.AuthUrl);

            _client = new User.UserClient(channel);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client  = new User.UserClient(channel);

            //CreateUserTest(client);
            //GetUserTest(client);
            CreateUserDetailTest(client);
        }
Exemplo n.º 9
0
        private static void GetUserTest(User.UserClient client)
        {
            var getUser = client.GetUserInfo(new UserRequest
            {
                Id = 2
            });

            Console.WriteLine(getUser);
        }
Exemplo n.º 10
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (UserInfo.User != null)
     {
         var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);
         var client  = new User.UserClient(channel);
         var re      = client.Logout(new LogoutModel());
     }
 }
Exemplo n.º 11
0
        // Método para inicializar o client GRPC usado para a autenticação
        private void StartGRPCConnection()
        {
            // No caso de a conexão já ter sido inicializada, não necessita de fazer mais nenhuma operação
            if (AuthClient != null)
            {
                return;
            }

            // É criado um client de autenticação
            AuthClient = new User.UserClient(Program.ConnectionChannel);
        }
Exemplo n.º 12
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new User.UserClient(channel);

            var reply = await client.MoveAsync(new MoveRequest { Amount = 11, Direction = Direction.Forward });

            System.Console.WriteLine("Greeting: " + reply.Result);
            System.Console.WriteLine("Press any key to exit...");
            System.Console.ReadKey();
        }
Exemplo n.º 13
0
        static void MainX(string[] args)
        {
            Channel channel = new Channel("localhost:57601", ChannelCredentials.Insecure);
            var     client  = new User.UserClient(channel);
            var     req     = new CreateUserRequest {
                Name = "Test"
            };
            var resp = client.Create(req);

            Console.WriteLine(resp.Id);
        }
Exemplo n.º 14
0
        public List <UserDTO> Handle(GetUsersQuery query)
        {
            var client   = new User.UserClient(ChannelFactory.Create("https://localhost:5001"));
            var response = client.GetUsersAsync(new GetUsersRequest()).GetAwaiter().GetResult();

            return(response.Users.Select(x => new UserDTO
            {
                Id = Guid.Parse(x.Id),
                UserName = x.UserName,
                Email = x.Email,
            }).ToList());
        }
        public List <UserDTO> Handle(GetUsersQuery query)
        {
            var client   = new User.UserClient(ChannelFactory.Create(_configuration["Services:Identity:Grpc"]));
            var response = client.GetUsersAsync(new GetUsersRequest()).GetAwaiter().GetResult();

            return(response.Users.Select(x => new UserDTO
            {
                Id = Guid.Parse(x.Id),
                UserName = x.UserName,
                Email = x.Email,
            }).ToList());
        }
Exemplo n.º 16
0
        static async Task <List <UserReply> > GetUsers(User.UserClient client)
        {
            List <UserReply> users = new();

            using var clientData = client.GetUsers(new UsersRequest());
            while (await clientData.ResponseStream.MoveNext(new System.Threading.CancellationToken()))
            {
                var user = clientData.ResponseStream.Current;
                users.Add(user);
            }
            return(users);
        }
Exemplo n.º 17
0
 private static void CreateUserTest(User.UserClient client)
 {
     for (var i = 0; i < 5; i++)
     {
         var response = client.CreateUser(new UserModel
         {
             Adress = "Subu Yazılım",
             Name   = "ishakdolek",
             Age    = 30
         });
         Console.WriteLine(response.Message);
     }
 }
        public void Tcp_Sending_Receiving_Packets()
        {
            SimpleServer server = new SimpleServer();

            server.Start(20, 8888);


            Thread.Sleep(10);

            SimpleNetworking.User.UserClient userClient = new User.UserClient();
            userClient.Connect(IPAddress.Parse("127.0.0.1"), 8888);

            Thread.Sleep(4 * 1000);

            Packet sendPacket = new ExamplePacket {
                DataString = "Hello?"
            };

            userClient.Send(sendPacket, ProtocolType.Tcp);
            userClient.Send(sendPacket, ProtocolType.Udp);
            userClient.Send(sendPacket, ProtocolType.Udp);
            userClient.Send(sendPacket, ProtocolType.Udp);

            server.Clients[userClient.Id].Send(sendPacket, ProtocolType.Tcp);
            server.Clients[userClient.Id].Send(sendPacket, ProtocolType.Udp);
            server.Clients[userClient.Id].Send(sendPacket, ProtocolType.Udp);

            Stopwatch timer = new Stopwatch();

            timer.Start();
            for (int i = 0; i < 2000; i++)
            {
                server.Clients[userClient.Id].Send(sendPacket, ProtocolType.Udp);
            }
            timer.Stop();
            timer.Reset();
            timer.Start();
            for (int i = 0; i < 2000; i++)
            {
                userClient.Send(sendPacket, ProtocolType.Tcp);
            }
            timer.Stop();
            server.Clients[userClient.Id].Disconnect();

            Thread.Sleep(10);

            Assert.Equal(2000 + 4, server.ReceivedPackets.Count);
            Assert.Equal(2000 + 3, userClient.ReceivedPackets.Count);
            Assert.True(userClient.Id != 0);
        }
Exemplo n.º 19
0
        private void button1_Click(object sender, EventArgs e)
        {
            var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);
            var client  = new User.UserClient(channel);
            var user    = client.Login(new LoginModel()
            {
                UserName = "", Password = "", Domain = ""
            });

            if (user != null)
            {
                UserInfo.User = user;
            }
        }
Exemplo n.º 20
0
        private static void GetUsersInGroupList(User.UserClient userServiceClient)
        {
            var getUsersInGroupViewModel = new GetUsersInGroupViewModel
            {
                GroupId = 1,
            };

            var userList = userServiceClient.GetUsersInGroupList(getUsersInGroupViewModel);

            foreach (var user in userList.Users)
            {
                Console.WriteLine($"{user.Id} - {user.FirstName} {user.Surname} - {user.EmailAddress} - {user.Role}|{user.MembershipId}");
            }
        }
Exemplo n.º 21
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Please type your full name:");
            var fullName = Console.ReadLine();
            var channel  = GrpcChannel.ForAddress("https://localhost:5001");
            var client   = new User.UserClient(channel);
            var reply    = await client.SaveInfoAsync(new UserRequest()
            {
                Fullname = fullName
            });

            Console.WriteLine(reply.Status);
            Console.ReadKey();
        }
Exemplo n.º 22
0
        private static async Task GetUsersInGroupStream(User.UserClient userServiceClient)
        {
            var getUsersInGroupViewModel = new GetUsersInGroupViewModel
            {
                GroupId = 1,
            };

            using var call = userServiceClient.GetUsersInGroupStream(getUsersInGroupViewModel);
            while (await call.ResponseStream.MoveNext())
            {
                var user = call.ResponseStream.Current;

                Console.WriteLine($"{user.Id} - {user.FirstName} {user.Surname} - {user.EmailAddress} - {user.Role}|{user.MembershipId}");
            }
        }
Exemplo n.º 23
0
    public void SendUser()
    {
        var client = new User.UserClient(channel);

        Debug.Log(userNameText.text);
        var name  = userNameText.text;
        var reply = client.Create(new CreateUserRequest {
            Name = name
        });

        Debug.Log("Your ID is" + reply.Id);
        PlayerPrefs.SetString("userId", reply.Id);
        channel.ShutdownAsync().Wait();
        SceneManager.LoadScene("Main");
    }
Exemplo n.º 24
0
    // Start is called before the first frame update
    void Start()
    {
        channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
        var client = new User.UserClient(channel);

        var reply = client.SayHello(new UserRequest()
        {
            Name = "123456"
        });

        Debug.Log("Greeting: " + reply.Message);



//        var client = new greeter
//        GreeterServer
    }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);

            var    client = new User.UserClient(channel);
            String user   = "******";

            var reply = client.SayHello(new UserRequest()
            {
                Name = user
            });

            Console.WriteLine("Greeting: " + reply.Message);

            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemplo n.º 26
0
        public async Task UserClient_GetPoints_ToUserThatDoesNotExist_ReturnsZero()
        {
            // arrange
            var channel = GetChannel();
            var client  = new User.UserClient(channel);

            var getQuery = new UserQuery
            {
                Id = "1"
            };

            // act
            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(0, getResult.Amount);
        }
Exemplo n.º 27
0
        public List <UserDTO> Handle(GetUsersQuery query)
        {
            var token   = _httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).GetAwaiter().GetResult();
            var headers = new Metadata
            {
                { "Authorization", $"Bearer {token}" },
            };

            var client   = new User.UserClient(ChannelFactory.Create(_configuration["Services:Identity:Grpc"]));
            var response = client.GetUsersAsync(new GetUsersRequest(), headers).GetAwaiter().GetResult();

            return(response.Users.Select(x => new UserDTO
            {
                Id = Guid.Parse(x.Id),
                UserName = x.UserName,
                Email = x.Email,
            }).ToList());
        }
Exemplo n.º 28
0
        // Tyler doesn't get we validate in Skyra, not in here.
        // [Test]
        public async Task UserClient_RemovePoints_WithNegativeAmount_ReturnsFailedStatus()
        {
            // arrange
            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = -10
            };

            // act
            var addResult = await client.AddPointsAsync(addQuery);

            // assert
            Assert.AreEqual(Status.Failed, addResult.Status, "AddPoints() did not fail.");
        }
Exemplo n.º 29
0
        public async Task <IActionResult> Index()
        {
            string channelTarget = Configuration["ServerURL"];

            _token = await Authenticate();

            var channel = CreateAuthenticatedChannel(channelTarget);


            var userClient = new User.UserClient(channel);

            var clientreq = new UserInput {
                UserId = 4
            };
            var user = await userClient.GetUserInfoAsync(clientreq);

            var jsonResult = Json(new { getAllResult = user });

            return(jsonResult);
        }
Exemplo n.º 30
0
        public async Task UserClient_AddMoney_ToUserThatDoesNotExist_ReturnsSameMoney()
        {
            // arrange
            var amount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var query = new UserMoneyQuery
            {
                Id     = id,
                Amount = amount
            };

            // act
            var result = await client.AddMoneyAsync(query);

            // assert
            Assert.AreEqual(Status.Success, result.Status, "AddMoney() failed.");
            Assert.AreEqual(amount, result.Amount);
        }