コード例 #1
0
        /// <summary>
        /// GetAll Blog Method
        /// </summary>
        /// <param name="request"></param>
        /// <param name="responseStream"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task ListBlog(ListBlogRequest request, IServerStreamWriter <ListBlogResponse> responseStream, ServerCallContext context)
        {
            var filter = new FilterDefinitionBuilder <BsonDocument>().Empty;
            var result = await mongoCollection.FindAsync(filter);

            foreach (var item in result.ToList())
            {
                await responseStream.WriteAsync(new ListBlogResponse()
                {
                    Blog = new Blog.Blog()
                    {
                        AuthorId = item.GetValue("author_id").AsString,
                        Title    = item.GetValue("title").AsString,
                        Content  = item.GetValue("content").AsString
                    }
                });
            }
        }
コード例 #2
0
        public override async Task ListBlog(ListBlogRequest request, IServerStreamWriter <ListBlogResponse> responseStream, ServerCallContext context)
        {
            var filter = new FilterDefinitionBuilder <BsonDocument>().Empty;

            var docs = await(await mongoCollection.FindAsync(filter)).ToListAsync();

            foreach (var doc in docs)
            {
                await Task.Delay(250);

                await responseStream.WriteAsync(new ListBlogResponse
                {
                    Blog = new Blog.Blog
                    {
                        Id       = doc.GetValue("_id").ToString(),
                        AuthorId = doc.GetValue("author_id").AsString,
                        Title    = doc.GetValue("title").AsString,
                        Content  = doc.GetValue("content").AsString
                    }
                });
            }
        }