Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #168 from MihaMarkic/feature/async
Browse files Browse the repository at this point in the history
Implements IAsyncParseNodeFactory interface
  • Loading branch information
andrueastman authored May 9, 2024
2 parents ba0f2ee + e59defc commit d945e66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.0] - 2024-05-13

### Added

- Implements IAsyncParseNodeFactory interface which adds async support

## [1.1.5] - 2024-04-19

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Serialization.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.1.5</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
20 changes: 18 additions & 2 deletions src/TextParseNodeFactory.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Kiota.Abstractions.Serialization;

namespace Microsoft.Kiota.Serialization.Text;

/// <summary>
/// The <see cref="IParseNodeFactory"/> implementation for text/plain content types
/// The <see cref="IAsyncParseNodeFactory"/> implementation for text/plain content types
/// </summary>
public class TextParseNodeFactory : IParseNodeFactory
public class TextParseNodeFactory : IAsyncParseNodeFactory
{
/// <inheritdoc />
public string ValidContentType => "text/plain";
Expand All @@ -23,4 +25,18 @@ public IParseNode GetRootParseNode(string contentType, Stream content) {
var stringContent = reader.ReadToEnd();
return new TextParseNode(stringContent);
}
/// <inheritdoc />
public async Task<IParseNode> GetRootParseNodeAsync(string contentType, Stream content, CancellationToken cancellationToken = default)
{
if(string.IsNullOrEmpty(contentType))
throw new ArgumentNullException(nameof(contentType));
else if(!ValidContentType.Equals(contentType, StringComparison.OrdinalIgnoreCase))
throw new ArgumentOutOfRangeException($"expected a {ValidContentType} content type");

_ = content ?? throw new ArgumentNullException(nameof(content));

using var reader = new StreamReader(content);
var stringContent = await reader.ReadToEndAsync().ConfigureAwait(false);
return new TextParseNode(stringContent);
}
}

0 comments on commit d945e66

Please sign in to comment.