Ejemplo n.º 1
0
        public async Task <HypernovaResponse> BatchAsync(HypernovaContentRequest request)
        {
            var requestContent = JsonSerializer.Serialize(request, this.SerializeOptions);

            using var requestBody = new StringContent(requestContent, Encoding.UTF8, MediaTypeNames.Application.Json);

            using var client = HttpClientFactory.CreateClient();
            var response = await client.PostAsync(GetUri(), requestBody).ConfigureAwait(false);

            using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var hypernovaResponse = await JsonSerializer.DeserializeAsync <HypernovaResponse>(responseStream, this.DeserializeOptions);

            return(hypernovaResponse);
        }
Ejemplo n.º 2
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output = output ?? throw new ArgumentNullException(nameof(output));

            output.TagName = null;
            output.TagMode = TagMode.StartTagAndEndTag;

            IDictionary <string, object> metadata = new ExpandoObject();

            foreach (var attribute in context.AllAttributes.Where(a => !"component".Equals(a.Name.ToLowerInvariant()) && !"data".Equals(a.Name.ToLowerInvariant())))
            {
                metadata[attribute.Name] = attribute.Value?.ToString();
            }

            var renderRequest = new HypernovaContentRequest
            {
                Content = new HypernovaRequestContent
                {
                    Name     = Component,
                    Data     = Data,
                    Metadata = metadata
                }
            };

            try
            {
                var renderResponse = await HypernovaClient.BatchAsync(renderRequest).ConfigureAwait(false);

                if (renderResponse.Success)
                {
                    output.Content.SetHtmlContent(renderResponse.Results.Content.Html);
                }
            }
            catch (Exception)
            {
                // Log somehow
            }

            await base.ProcessAsync(context, output).ConfigureAwait(false);
        }