Skip to content

Commit

Permalink
Adding "global::" namespace prefix to avoid namespace conflict inside…
Browse files Browse the repository at this point in the history
… generated executor (#1847)

* Adding "global::" namespace prefix to avoid namespace conflict.

* Updated release notes
  • Loading branch information
kshyju authored Aug 23, 2023
1 parent 38e2712 commit 86f8186
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ internal ICollection<ExecutableFunction> GetFunctions(List<MethodDeclarationSynt
continue;
}

methodParameterList.Add(parameterSymbol.Type.ToDisplayString());
var fullyQualifiedTypeName = parameterSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
methodParameterList.Add(fullyQualifiedTypeName);
}

var methodSymbol = model.GetDeclaredSymbol(method)!;
Expand Down
2 changes: 1 addition & 1 deletion sdk/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

### Microsoft.Azure.Functions.Worker.Sdk.Generators <version>

- <entry>
- Updated source generated versions of FunctionExecutor to use `global::` namespace prefix to avoid ambiguity between namespaces.(#1847)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Azure.Messaging.EventHubs;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Sdk.Generators;
using Microsoft.Extensions.Configuration;
Expand All @@ -22,6 +24,9 @@ public class FunctionExecutorGeneratorTests
typeof(HttpTriggerAttribute).Assembly,
typeof(FunctionAttribute).Assembly,
typeof(QueueTriggerAttribute).Assembly,
typeof(EventHubTriggerAttribute).Assembly,
typeof(QueueMessage).Assembly,
typeof(EventData).Assembly,
typeof(BlobInputAttribute).Assembly,
typeof(LoggingServiceCollectionExtensions).Assembly,
typeof(ServiceProviderServiceExtensions).Assembly,
Expand All @@ -39,8 +44,10 @@ public async Task FunctionsFromMultipleClasses()
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Azure.Storage.Queues.Models;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace MyCompany
{
public class MyHttpTriggers
Expand Down Expand Up @@ -68,6 +75,28 @@ public static class Foo
[Function(""ProcessOrder2"")]
public static async Task<string> MyAsyncStaticMethod([QueueTrigger(""foo"")] string q) => q;
}
public class QueueTriggers
{
private readonly ILogger<QueueTriggers> _logger;
public QueueTriggers(ILogger<QueueTriggers> logger)
{
_logger = logger;
}
[Function(nameof(QueueTriggers))]
public void Run([QueueTrigger(""myqueue-items"")] QueueMessage message)
{
_logger.LogInformation($""Queue message: {message.MessageText}"");
}
[Function(""Run2"")]
public void Run2([QueueTrigger(""myqueue-items"")] string message)
{
_logger.LogInformation($""Queue message: {message}"");
}
}
}
";
var expectedOutput = $@"// <auto-generated/>
Expand All @@ -86,7 +115,8 @@ internal class DirectFunctionExecutor : IFunctionExecutor
private readonly Dictionary<string, Type> types = new()
{{
{{ ""MyCompany.MyHttpTriggers"", Type.GetType(""MyCompany.MyHttpTriggers"")! }},
{{ ""MyCompany.MyHttpTriggers2"", Type.GetType(""MyCompany.MyHttpTriggers2"")! }}
{{ ""MyCompany.MyHttpTriggers2"", Type.GetType(""MyCompany.MyHttpTriggers2"")! }},
{{ ""MyCompany.QueueTriggers"", Type.GetType(""MyCompany.QueueTriggers"")! }}
}};
public DirectFunctionExecutor(IFunctionActivator functionActivator)
Expand All @@ -104,18 +134,30 @@ public async ValueTask ExecuteAsync(FunctionContext context)
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Foo((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
context.GetInvocationResult().Value = i.Foo((global::Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (global::Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.MyHttpTriggers2.Bar"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.MyHttpTriggers2""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers2;
context.GetInvocationResult().Value = i.Bar((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
context.GetInvocationResult().Value = i.Bar((global::Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.Foo.MyAsyncStaticMethod"", StringComparison.OrdinalIgnoreCase))
{{
context.GetInvocationResult().Value = await MyCompany.Foo.MyAsyncStaticMethod((string)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.QueueTriggers.Run"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.QueueTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.QueueTriggers;
i.Run((global::Azure.Storage.Queues.Models.QueueMessage)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.QueueTriggers.Run2"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.QueueTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.QueueTriggers;
i.Run2((string)inputArguments[0]);
}}
}}
}}
{GetExpectedExtensionMethodCode()}
Expand Down Expand Up @@ -196,13 +238,13 @@ public async ValueTask ExecuteAsync(FunctionContext context)
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Run1((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
context.GetInvocationResult().Value = i.Run1((global::Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.MyHttpTriggers.Run2"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Run2((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
context.GetInvocationResult().Value = i.Run2((global::Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (global::Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
}}
}}
}}
Expand All @@ -223,6 +265,8 @@ public async Task StaticMethods()
using System;
using System.Threading.Tasks;
using Microsoft.Azure.Functions.Worker;
using Azure.Messaging.EventHubs;
using System.IO;
namespace FunctionApp26
{
Expand Down Expand Up @@ -258,6 +302,35 @@ public static ValueTask MyValueTaskStaticAsyncMethod2([QueueTrigger(""foo"")] st
return ValueTask.CompletedTask;
}
}
public class BlobTriggers
{
[Function(nameof(BlobTriggers))]
public static async Task Run([BlobTrigger(""items/{name}"", Connection = ""ConStr"")] Stream stream, string name)
{
using var blobStreamReader = new StreamReader(stream);
var content = await blobStreamReader.ReadToEndAsync();
}
}
public class EventHubTriggers
{
[Function(""Run1"")]
public static void Run1([EventHubTrigger(""items"", Connection = ""EventHubConnection"")] EventData[] data)
{
}
[Function(nameof(Run2))]
[EventHubOutput(""dest"", Connection = ""EHConnection"")]
public static string Run2([EventHubTrigger(""queue"", Connection = ""EventHubConnection"", IsBatched = false)] EventData eventData)
{
return eventData.MessageId;
}
[Function(""RunAsync1"")]
public static Task RunAsync1([EventHubTrigger(""items"", Connection = ""Con"")] EventData[] data)
{
return Task.CompletedTask;
}
[Function(""RunAsync2"")]
public static async Task RunAsync2([EventHubTrigger(""items"", Connection = ""Con"")] EventData[] data) => await Task.Delay(10);
}
}".Replace("'", "\"");
var expectedOutput = @$"// <auto-generated/>
using System;
Expand Down Expand Up @@ -308,6 +381,26 @@ public async ValueTask ExecuteAsync(FunctionContext context)
{{
await FunctionApp26.MyQTriggers.MyValueTaskStaticAsyncMethod2((string)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""FunctionApp26.BlobTriggers.Run"", StringComparison.OrdinalIgnoreCase))
{{
await FunctionApp26.BlobTriggers.Run((global::System.IO.Stream)inputArguments[0], (string)inputArguments[1]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""FunctionApp26.EventHubTriggers.Run1"", StringComparison.OrdinalIgnoreCase))
{{
FunctionApp26.EventHubTriggers.Run1((global::Azure.Messaging.EventHubs.EventData[])inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""FunctionApp26.EventHubTriggers.Run2"", StringComparison.OrdinalIgnoreCase))
{{
context.GetInvocationResult().Value = FunctionApp26.EventHubTriggers.Run2((global::Azure.Messaging.EventHubs.EventData)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""FunctionApp26.EventHubTriggers.RunAsync1"", StringComparison.OrdinalIgnoreCase))
{{
await FunctionApp26.EventHubTriggers.RunAsync1((global::Azure.Messaging.EventHubs.EventData[])inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""FunctionApp26.EventHubTriggers.RunAsync2"", StringComparison.OrdinalIgnoreCase))
{{
await FunctionApp26.EventHubTriggers.RunAsync2((global::Azure.Messaging.EventHubs.EventData[])inputArguments[0]);
}}
}}
}}
{GetExpectedExtensionMethodCode()}
Expand Down Expand Up @@ -378,7 +471,7 @@ public async ValueTask ExecuteAsync(FunctionContext context)
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Run1((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
context.GetInvocationResult().Value = i.Run1((global::Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
}}
}}
}}
Expand Down

0 comments on commit 86f8186

Please sign in to comment.