-
Notifications
You must be signed in to change notification settings - Fork 182
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
Getting batched events #205
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
07b64d9
MetadataGenerator adds cardinality-many and value provider understand…
mhoeger b88044b
update sdk e2e test for datatype
mhoeger 992201a
move cardinality and datatype stuff to later
mhoeger 2d527aa
resolve typeof's
mhoeger dbfd447
cardinality through IBatchedInput - tests need changes
mhoeger c51705d
re-add removed stuff
mhoeger e97c883
fix spacing
mhoeger c178301
add comments
mhoeger e9d95d2
Update tests and make SDK generation exceptions surface as build error
mhoeger 6815331
fixing low hanging cr changes
mhoeger c5f1185
minor updates from cr
mhoeger b54d254
change where we get default value
mhoeger 8ce8fce
casing
mhoeger 182e9a4
fix docs
mhoeger 8876297
Modify batched output to be ISupportCardinality - set up for extensib…
mhoeger 8d0d9a1
array converter only
mhoeger 4f59720
test fixes
mhoeger d0db91d
release notes
mhoeger b734b7f
update array converter logic
mhoeger 775d70e
remove nested type search and update readme because double and int ar…
mhoeger 8fb62e2
address comment to make default value attribute (a temporary attribut…
mhoeger 37de7a8
nit: add example to readme
mhoeger ea58fa3
update namespace
mhoeger 13594cd
namespace reference
mhoeger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
extensions/Worker.Extensions.Abstractions/DefaultValueAttribute.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,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Extensions.Abstractions | ||
{ | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class DefaultValueAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Define a default value for a property on a FunctionAttribute type. | ||
/// </summary> | ||
/// <param name="stringDefault"></param> | ||
public DefaultValueAttribute(string stringDefault) | ||
{ | ||
DefaultStringValue = stringDefault; | ||
} | ||
|
||
public DefaultValueAttribute(bool boolDefault) | ||
{ | ||
DefaultBoolValue = boolDefault; | ||
} | ||
|
||
public string? DefaultStringValue { get; } | ||
|
||
public bool? DefaultBoolValue { get; } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
extensions/Worker.Extensions.Abstractions/ISupportCardinality.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,26 @@ | ||
// 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.Collections.Generic; | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Extensions.Abstractions | ||
{ | ||
public interface ISupportCardinality | ||
{ | ||
/// <summary> | ||
/// Configures the "cardinality" property | ||
/// This property indicates that the requested type is an array. Note that for | ||
/// inputs and outputs, the effect of cardinality may be different (ex: electing to | ||
/// receive a collection of events vs. indicating that my return type will be | ||
/// a collection). | ||
/// </summary> | ||
public Cardinality Cardinality { get; set; } | ||
} | ||
|
||
public enum Cardinality | ||
{ | ||
Many, | ||
One | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
extensions/Worker.Extensions.Abstractions/InputBindingAttribute.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Sdk | ||
{ | ||
internal static class Constants | ||
{ | ||
// Our types | ||
internal const string BindingType = "Microsoft.Azure.Functions.Worker.Extensions.Abstractions.BindingAttribute"; | ||
internal const string OutputBindingType = "Microsoft.Azure.Functions.Worker.Extensions.Abstractions.OutputBindingAttribute"; | ||
internal const string FunctionNameType = "Microsoft.Azure.Functions.Worker.FunctionAttribute"; | ||
internal const string ExtensionsInformationType = "Microsoft.Azure.Functions.Worker.Extensions.Abstractions.ExtensionInformationAttribute"; | ||
internal const string HttpResponseType = "Microsoft.Azure.Functions.Worker.Http.HttpResponseData"; | ||
internal const string DefaultValueAttributeType = "Microsoft.Azure.Functions.Worker.Extensions.Abstractions.DefaultValueAttribute"; | ||
|
||
// System types | ||
internal const string IEnumerableType = "System.Collections.IEnumerable"; | ||
internal const string IEnumerableGenericType = "System.Collections.Generic.IEnumerable`1"; | ||
internal const string IEnumerableOfStringType = "System.Collections.Generic.IEnumerable`1<System.String>"; | ||
internal const string IEnumerableOfBinaryType = "System.Collections.Generic.IEnumerable`1<System.Byte[]>"; | ||
internal const string IEnumerableOfT = "System.Collections.Generic.IEnumerable`1<T>"; | ||
internal const string IEnumerableOfKeyValuePair = "System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<TKey,TValue>>"; | ||
internal const string GenericIEnumerableArgumentName = "T"; | ||
internal const string StringType = "System.String"; | ||
internal const string ByteArrayType = "System.Byte[]"; | ||
internal const string LookupGenericType = "System.Linq.Lookup`2"; | ||
internal const string DictionaryGenericType = "System.Collections.Generic.Dictionary`2"; | ||
internal const string TaskGenericType = "System.Threading.Tasks.Task`1"; | ||
internal const string TaskType = "System.Threading.Tasks.Task"; | ||
internal const string VoidType = "System.Void"; | ||
internal const string ReadOnlyMemoryOfBytes = "System.ReadOnlyMemory`1<System.Byte>"; | ||
|
||
internal const string ReturnBindingName = "$return"; | ||
internal const string HttpTriggerBindingType = "HttpTrigger"; | ||
internal const string IsBatchedKey = "IsBatched"; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
@@ -14,16 +14,39 @@ public static class CustomAttributeExtensions | |
public static IDictionary<string, object> GetAllDefinedProperties(this CustomAttribute attribute) | ||
{ | ||
var properties = new Dictionary<string, object>(); | ||
|
||
// To avoid needing to instantiate any types, assume that the constructor | ||
// argument names are equal to property names. | ||
LoadDefaultProperties(properties, attribute); | ||
LoadConstructorArguments(properties, attribute); | ||
LoadDefinedProperties(properties, attribute); | ||
|
||
return properties; | ||
} | ||
|
||
private static void LoadConstructorArguments(IDictionary<string, object> properties, CustomAttribute attribute) | ||
private static IEnumerable<(string, CustomAttributeArgument?)> GetDefaultValues(this CustomAttribute attribute) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is all should be removed later... after above todo is done: |
||
{ | ||
return attribute.AttributeType.Resolve().Properties | ||
.Select(p => (p.Name, p.CustomAttributes | ||
.Where(attribute => string.Equals(attribute.AttributeType.FullName, Constants.DefaultValueAttributeType, StringComparison.Ordinal)) | ||
.SingleOrDefault() | ||
?.ConstructorArguments.SingleOrDefault())) | ||
.Where(t => t.Item2 is not null); | ||
} | ||
|
||
private static void LoadDefaultProperties(IDictionary<string, object> properties, CustomAttribute attribute) | ||
{ | ||
var propertyDefaults = attribute.GetDefaultValues(); | ||
|
||
foreach (var propertyDefault in propertyDefaults) | ||
{ | ||
if (propertyDefault.Item2 is not null) | ||
{ | ||
properties[propertyDefault.Item1] = propertyDefault.Item2.Value.Value; | ||
} | ||
} | ||
} | ||
|
||
private static void LoadConstructorArguments(IDictionary<string, object> properties, CustomAttribute attribute) | ||
{ | ||
var constructorParams = attribute.Constructor.Resolve().Parameters; | ||
for (int i = 0; i < attribute.ConstructorArguments.Count; i++) | ||
|
@@ -34,13 +57,12 @@ private static void LoadConstructorArguments(IDictionary<string, object> propert | |
string? paramName = param?.Name; | ||
object? paramValue = arg.Value; | ||
|
||
if (paramName == null || paramValue == null) | ||
if (paramName is null || paramValue is null) | ||
{ | ||
continue; | ||
} | ||
|
||
paramValue = GetEnrichedValue(param!.ParameterType, paramValue); | ||
|
||
paramValue = GetEnrichedValue(param!.ParameterType, paramValue); | ||
properties[paramName] = paramValue!; | ||
} | ||
} | ||
|
@@ -50,15 +72,16 @@ private static void LoadDefinedProperties(IDictionary<string, object> properties | |
foreach (CustomAttributeNamedArgument property in attribute.Properties) | ||
{ | ||
object? propVal = property.Argument.Value; | ||
string? propName = property.Name; | ||
|
||
if (propVal == null) | ||
if (propVal is null || propName is null) | ||
{ | ||
continue; | ||
} | ||
|
||
propVal = GetEnrichedValue(property.Argument.Type, propVal); | ||
|
||
properties[property.Name] = propVal!; | ||
properties[propName] = propVal!; | ||
} | ||
} | ||
|
||
|
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,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Sdk | ||
{ | ||
internal enum DataType | ||
{ | ||
Undefined, | ||
Binary, | ||
String, | ||
Stream | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary to set default while we do not load attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:No need to change for right now, but I wonder if we should move this to a different namespace so it's not discoverable and polluting?