public User GetUser(long id) { if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } return(_clientFactory.Create(UsersService).Get <User>($"users/{id}")); }
public async Task <IEnumerable <ArticleProjection> > Handle(AllArticles request, CancellationToken cancellationToken) { var client = _clientFactory.Create(); var allArticlesAsync = Task.Run( () => client.GetAllAsync(new Empty()).ResponseAsync, cancellationToken); var tagsView = await _mediator.Send(new AllTags(), cancellationToken); var articles = await allArticlesAsync; var result = new List <ArticleProjection>(); foreach (var article in articles.Items) { var articleTags = tagsView.Tags .Where(t => t.ArticleIds.Contains(article.Id)) .Select(t => t.Name) .ToArray(); var projection = new ArticleProjection { Id = Guid.Parse(article.Id), Title = article.Title, Description = article.Description, Body = article.Body, Slug = article.Slug, CreatedAtUtc = article.CreatedAtUtc.ToDateTimeOffset(), UpdatedAtUtc = article.UpdatedAtUtc.ToDateTimeOffset(), TagList = articleTags }; result.Add(projection); } return(result); }
public async Task <ArticleProjection> Handle(GetBySlug query, CancellationToken cancellationToken) { var client = _clientFactory.Create(); var response = await client.GetBySlugAsync(query.ToGrpcQuery); if (!response.HasResult) { return(null); } var result = new ArticleProjection { Id = Guid.Parse(response.View.Id), Title = response.View.Title, Description = response.View.Description, Body = response.View.Body, CreatedAtUtc = response.View.CreatedAtUtc.ToDateTimeOffset(), UpdatedAtUtc = response.View.UpdatedAtUtc.ToDateTimeOffset(), Slug = response.View.Slug }; var tagsView = await _mediator.Send(new AllByArticleId(response.View.Id), cancellationToken); if (tagsView.Tags == null || tagsView.Tags.All(view => view == null)) { return(result); } var tagNames = tagsView.Tags.Select(view => view.Name).ToArray(); result.TagList = tagNames; return(result); }
private async Task <Dto[]> ReadData() { using (var client = serviceClientFactory.Create("Platformer")) { return((await client.Get <Dto[]>("v2/info/vars")).Resource); } }
private void Run(IServiceRunTarget target) { if (_client == null) { _client = _clientFactory.Create(); } try { target.Run(_client); } catch (Exception exception) { Reporter.Report(string.Format("{0}: {1}", target.Name, Res.RunError), exception); Clean(target); Clean(); } }
public User GetUser(long id) { return(_clientFactory.Create(UsersService).Get <User>($"users/{id}")); }
public async Task <TagsView> Handle(AllByArticleId request, CancellationToken cancellationToken) { var client = _clientFactory.Create(); return(await client.GetByArticleAsync(request.ToGrpcQuery)); }
public async Task OnGet() { var client = _serviceClientFactory.Create("api1"); ProtectedResource = await client.GetAsync <string>("ProtectedResource"); }
private Task <Option <TagService.TagServiceClient, Error> > GetClientOrErrorAsync() { var result = _clientFactory.Create().Some <TagService.TagServiceClient, Error>(); return(Task.FromResult(result)); }
public async Task <TagsView> Handle(AllTags request, CancellationToken cancellationToken) { var client = _clientFactory.Create(); return(await client.GetAllAsync(new Empty())); }