-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ActivityInputConverter * Handle null input for Activity
- Loading branch information
Showing
6 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Worker.Extensions.DurableTask/ActivityInputConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Functions.Worker.Converters; | ||
using Microsoft.DurableTask.Worker; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Extensions.DurableTask; | ||
|
||
internal class ActivityInputConverter : IInputConverter | ||
{ | ||
private readonly DurableTaskWorkerOptions options; | ||
|
||
public ActivityInputConverter(IOptions<DurableTaskWorkerOptions> options) | ||
{ | ||
this.options = options?.Value ?? throw new ArgumentNullException(nameof(options)); | ||
} | ||
|
||
public ValueTask<ConversionResult> ConvertAsync(ConverterContext context) | ||
{ | ||
if (context is null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (context.Source is null) | ||
{ | ||
return new(ConversionResult.Success(null)); | ||
} | ||
|
||
if (context.Source is not string source) | ||
{ | ||
throw new InvalidOperationException($"Expected converter source to be a string, received {context.Source?.GetType()}."); | ||
} | ||
|
||
object? value = this.options.DataConverter.Deserialize(source, context.TargetType); | ||
return new(ConversionResult.Success(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters