Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick b94324c from 8.x to 7.x: Provide async APIs for CsdlWriter and SchemaWriter (#3006) #3060

Open
wants to merge 2 commits into
base: release-7.x
Choose a base branch
from

Conversation

WanjohiSammy
Copy link
Contributor

Issues

This pull request fixes #xxx.

Description

  • Cherry-pick b94324c from 8.x to 7.x
  • Ensure compatibility with older .NET versions.

The current CsdlWriter class provides only synchronous methods for writing CSDL (WriteCsdl and TryWriteCsdl).
Also SchemaWriter class exposes only syncronous methods for writing Schema (TryWriteSchema)

Main Changes

Provide APIs for writing CSDL asynchronously:

  • WriteCsdlAsync
  • TryWriteCsdlAsync
  • TryWriteSchemaAsync

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

* Add corresponding async methods for syncronous methods of EdmModelCsdlSchemaJsonWriter

* Implemented asynchronous counterparts for synchronous virtual and abstract methods for EdmModelCsdlSchemaWriter class

* Added asynchronous implementations for the synchronous methods in EdmModelCsdlSchemaXmlWriter

* Added corresponding asynchronous methods for EdmModelReferenceElementsJsonVisitor, EdmModelCsdlSerializationVisitor and EdmModelReferenceElementsXmlVisitor

* Added asynchronous counterparts for csdl writer methods

* Added async corresponding sync methods for EdmModelVisitor

* Fix WriteStartElementAsync prefix and namespace missing

* Added csdl async/await and functional tests for csdl writer async methods

* Added async APIs to net48 public API

* Fixed comments to add ConfigureAwait(false)

* Added configureAwait(false) to await tests

* Elude await/async in BeginElementAsync method Func<TElement, Task> params

* Rewrite the doc string of the async methods to add <returns> and provide correct summary

* Rewrite WriteSchemata to WriteSchema

* Move the asynhronous tests to .Async partial classes

* Added ContextUrlWriterReaderTests.Async partial class with async tests and fix asynhronous equal true when writing xml

* Added doc string for <params></params>

* Resolve missing spaces

* Added Returns Documentation string for WriteCsdlAsync

* Remove unnecessary 'else'

* Added WriteMetadataDocumentAsync methods and tests

* Rename test functions for WriteMetadataDocumentAsync

* Renaming WriteSchema to WriteSchemas and WriteSchemaAsync to WriteSchemasAsync

* Provide the correct file in copyright for the added files

* Rename partial class OasisActionsFunctionsRelationshipChangesAcceptanceTests to OasisActionsFunctionsRelationshipChangesAcceptanceTest to reuse the methods used in main class OasisActionsFunctionsRelationshipChangesAcceptanceTest
@WanjohiSammy WanjohiSammy changed the title Provide async APIs for CsdlWriter and SchemaWriter (#3006) Cherry-pick b94324c from 8.x to 7.x: Provide async APIs for CsdlWriter and SchemaWriter (#3006) Sep 9, 2024
Copy link
Contributor

@habbes habbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there's a lot of cases where we use Task.FromResult(0) where Task.CompletedTask appears to be more appropriate, and there are cases missing ConfigureAwait(false).

/// <param name="error">The error instance to write.</param>
/// <param name="includeDebugInformation">A flag indicating whether error details should be written (in debug mode only) or not.</param>
/// <param name="maxInnerErrorDepth">The maximum number of nested inner errors to allow.</param>
internal static async Task WriteXmlErrorAsync(XmlWriter writer, ODataError error, bool includeDebugInformation, int maxInnerErrorDepth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still write the XML payload?
I don't think so, we only output the JSON payload exception the CSDL, right?
If that's the case, why do we need to implement the XML related async methods?

@@ -12,6 +12,7 @@
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to add a new file and put all new added 'async' methods into this new file and leave the existing file unchanged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants