Пример #1
0
        public async Task DeleteShelf(long shelfId)
        {
            Console.WriteLine($"gRPC: Delete shelf at '{shelfId}':");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            await client.DeleteShelfAsync(new DeleteShelfRequest { Shelf = shelfId });
        }
Пример #2
0
        public async Task DeleteBook(long shelfId, long bookId)
        {
            Console.WriteLine($"gRPC: Delete book '{bookId}' from shelf '{shelfId}':");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            await client.DeleteBookAsync(new DeleteBookRequest { Shelf = shelfId, Book = bookId });
        }
Пример #3
0
        public async Task GetBook(long shelfId, long bookId)
        {
            Console.WriteLine($"gRPC: Get book '{bookId}' from shelf '{shelfId}':");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            Book book = await client.GetBookAsync(new GetBookRequest { Shelf = shelfId, Book = bookId });

            Console.WriteLine($"\t-{book.Id}): <<{book.Title}>> by {book.Author}\n");
        }
Пример #4
0
        public async Task GetShelf(long shelfId)
        {
            Console.WriteLine($"gRPC: Get shelf at '{shelfId}':");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            Shelf shelf = await client.GetShelfAsync(new GetShelfRequest { Shelf = shelfId });

            Console.WriteLine($"\t-{shelf.Id}): {shelf.Theme}");
        }
Пример #5
0
        public async Task <Book> CreateBook(long shelfId, Book book)
        {
            Console.WriteLine($"gRPC: Create book for shelf '{shelfId}':");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            book = await client.CreateBookAsync(new CreateBookRequest { Shelf = shelfId, Book = book });

            Console.WriteLine($"\t-{book.Id}): <<{book.Title}>> by {book.Author}\n");

            return(book);
        }
Пример #6
0
        public async Task ListBooks(long shelfId)
        {
            Console.WriteLine($"\ngRPC: List books at shelf '{shelfId}':");
            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            var listBooksResponse = await client.ListBooksAsync(new ListBooksRequest { Shelf = shelfId });

            foreach (var book in listBooksResponse.Books)
            {
                Console.WriteLine($"\t-{book.Id}): <<{book.Title}>> by {book.Author}");
            }
        }
Пример #7
0
        public async Task <Shelf> CreateShelf(Shelf shelf)
        {
            Console.WriteLine("gRPC: Create shelf:");

            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            shelf = await client.CreateShelfAsync(new CreateShelfRequest { Shelf = shelf });

            Console.WriteLine($"\t-{shelf.Id}): {shelf.Theme}\n");

            return(shelf);
        }
Пример #8
0
        public async Task ListShelves()
        {
            Console.WriteLine("\ngRPC: List shelves:");
            using var channel = GrpcChannel.ForAddress(_baseUri);
            var client = new Bookstore.BookstoreClient(channel);

            var listShelvesResponse = await client.ListShelvesAsync(new Empty());

            foreach (var shelf in listShelvesResponse.Shelves)
            {
                Console.WriteLine($"\t-{shelf.Id}): {shelf.Theme}");
            }
            Console.WriteLine();
        }
Пример #9
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Bookstore.BookstoreClient(channel);

            //add new book
            Console.Write("title: ");
            var title         = Console.ReadLine();
            var bookToBeAdded = new Book()
            {
                Title = title.Trim().Length > 0 ? title : "undefined"
            };
            var response = await client.AddBookAsync(
                new AddBookRequest { Book = bookToBeAdded });

            Console.WriteLine("Adding status: " + response.Status);

            //get books from server
            var responseGetAll = await client.GetAllBooksAsync(new Empty());

            Console.WriteLine("Books from server: " + responseGetAll);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Пример #10
0
        static async Task Main(string[] args)
        {
            //using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            //var client = new Greeter.GreeterClient(channel);
            //var reply = await client.SayHelloAsync(
            //                  new HelloRequest { Name = "GreeterClient" });
            //Console.WriteLine("Greeting: " + reply.Message);
            //Console.WriteLine("Press any key to exit...");
            //Console.ReadKey();

            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Bookstore.BookstoreClient(channel);

            //var bookToBeAdded = new Book() { Title = "Poems" };
            //var response = await client.AddBookAsync(
            //                  new AddBookRequest { Book = bookToBeAdded });
            //Console.WriteLine("Adding status: " + response.Status);

            var response = await client.GetAllBooksAsync(new Empty());

            Console.WriteLine(response);
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }