Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/IntegrationTest.Billing/IntegrationTest.Billing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ProjectReference Include="..\NServiceBus.AzureFunctions.Analyzer\NServiceBus.AzureFunctions.Analyzer.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\NServiceBus.AzureFunctions.CodeFixes\NServiceBus.AzureFunctions.CodeFixes.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\IntegrationTest.Shared\IntegrationTest.Shared.csproj" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions src/IntegrationTest.Sales/IntegrationTest.Sales.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ProjectReference Include="..\NServiceBus.AzureFunctions.Analyzer\NServiceBus.AzureFunctions.Analyzer.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\NServiceBus.AzureFunctions.CodeFixes\NServiceBus.AzureFunctions.CodeFixes.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\IntegrationTest.Shared\IntegrationTest.Shared.csproj" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions src/IntegrationTest.Shipping/IntegrationTest.Shipping.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ProjectReference Include="..\NServiceBus.AzureFunctions.Analyzer\NServiceBus.AzureFunctions.Analyzer.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\NServiceBus.AzureFunctions.CodeFixes\NServiceBus.AzureFunctions.CodeFixes.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\IntegrationTest.Shared\IntegrationTest.Shared.csproj" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions src/IntegrationTest/IntegrationTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<ProjectReference Include="..\NServiceBus.AzureFunctions.Analyzer\NServiceBus.AzureFunctions.Analyzer.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\NServiceBus.AzureFunctions.CodeFixes\NServiceBus.AzureFunctions.CodeFixes.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<ProjectReference Include="..\IntegrationTest.Shared\IntegrationTest.Shared.csproj" />
<ProjectReference Include="..\IntegrationTest.Sales\IntegrationTest.Sales.csproj" />
<ProjectReference Include="..\IntegrationTest.Billing\IntegrationTest.Billing.csproj" />
Expand Down
32 changes: 22 additions & 10 deletions src/NServiceBus.AzureFunctions.Analyzer/DiagnosticIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ namespace NServiceBus.AzureFunctions.Analyzer;

using Microsoft.CodeAnalysis;

public static class DiagnosticIds
#if !FIXES
public
#endif
static class DiagnosticIds
{
public const string ClassMustBePartial = "NSBFUNC001";
public const string ShouldNotImplementIHandleMessages = "NSBFUNC002";
public const string MethodMustBePartial = "NSBFUNC003";
public const string MissingAddNServiceBusFunctionsCall = "NSBFUNC004";
public const string MultipleConfigureMethods = "NSBFUNC005";
public const string AutoCompleteEnabled = "NSBFUNC006";
public const string InvalidFunctionMethod = "NSBFUNC007";

internal static readonly DiagnosticDescriptor ClassMustBePartialDescriptor = new(
id: ClassMustBePartial,
Expand All @@ -35,6 +39,15 @@ public static class DiagnosticIds
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

internal static readonly DiagnosticDescriptor MissingAddNServiceBusFunctionsCallDescriptor = new(
id: MissingAddNServiceBusFunctionsCall,
title: "AddNServiceBusFunctions() is not called",
messageFormat: "This project has NServiceBus endpoint registrations but does not call builder.AddNServiceBusFunctions(). Endpoints will not be started.",
category: "NServiceBus.AzureFunctions",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
customTags: [WellKnownDiagnosticTags.CompilationEnd]);

internal static readonly DiagnosticDescriptor MultipleConfigureMethodsDescriptor = new(
id: MultipleConfigureMethods,
title: "Multiple configuration methods found",
Expand All @@ -46,17 +59,16 @@ public static class DiagnosticIds
internal static readonly DiagnosticDescriptor AutoCompleteMustBeExplicitlyDisabled = new(
id: AutoCompleteEnabled,
title: "Message auto completion must be explicitly disabled",
messageFormat: "The auto complete property on the service bus trigger for method '{0}' must be explicitly set to false",
messageFormat: "The '{1}' property on [{2}] for method '{0}' must be explicitly set to false",
category: "NServiceBus.AzureFunctions",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);

internal static readonly DiagnosticDescriptor MissingAddNServiceBusFunctionsCallDescriptor = new(
id: MissingAddNServiceBusFunctionsCall,
title: "AddNServiceBusFunctions() is not called",
messageFormat: "This project has NServiceBus endpoint registrations but does not call builder.AddNServiceBusFunctions(). Endpoints will not be started.",
internal static readonly DiagnosticDescriptor InvalidFunctionMethodDescriptor = new(
id: InvalidFunctionMethod,
title: "Invalid NServiceBus function method",
messageFormat: "Method '{0}' is not a valid NServiceBus function: {1}",
category: "NServiceBus.AzureFunctions",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
customTags: [WellKnownDiagnosticTags.CompilationEnd]);
}
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public static void Emit(SourceProductionContext context, CompositionSpec? compos
{
context.CancellationToken.ThrowIfCancellationRequested();
writer.WriteLine($"foreach (var manifest in global::{registrationClass.FullClassName}.GetFunctionManifests())");
writer.WriteLine(" global::NServiceBus.FunctionsHostApplicationBuilderExtensions.AddNServiceBusFunction(builder, manifest);");
writer.WriteLine("{");
writer.WriteLine(" manifest.Register(builder, manifest);");
writer.WriteLine("}");
}

writer.CloseCurlies();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace NServiceBus.AzureFunctions.Analyzer;

using NServiceBus.Core.Analyzer;

public sealed partial class FunctionEndpointGenerator
{
static readonly ParameterRole MessageActions = new("MessageActions");

static readonly TriggerDefinition AzureServiceBusTrigger = new(
TriggerAttributeMetadataName: "Microsoft.Azure.Functions.Worker.ServiceBusTriggerAttribute",
AdditionalParameterTypes: new AdditionalParameterType[]
{
new("Microsoft.Azure.Functions.Worker.ServiceBusMessageActions", MessageActions)
}.ToImmutableEquatableArray(),
ProcessorTypeFullyQualified: "global::NServiceBus.AzureFunctions.AzureServiceBus.AzureServiceBusMessageProcessor",
AddressExtraction: AddressExtractionPolicy.FromNamedConstructorParameter("queueName"),
ConnectionSetting: ConnectionSettingPolicy.FromNamedProperty("Connection"),
AutoComplete: AutoCompletePolicy.MustBeFalseFor("AutoCompleteMessages"),
RegistrationMethodFullyQualified: "global::NServiceBus.AzureFunctions.AzureServiceBus.AzureServiceBusFunctionManifestRegistration.Register",
ProcessMethodName: "Process",
Shape: TriggerShape.Required(
ParameterRole.TriggerMessage,
MessageActions,
ParameterRole.FunctionContext,
ParameterRole.CancellationToken));
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ static void EmitMethodBodies(SourceProductionContext spc, ImmutableArray<Functio
writer.WriteLine("{");
writer.Indentation++;
writer.WriteLine($"var processor = {func.FunctionContextParamName}.InstanceServices");
writer.WriteLine($" .GetKeyedService<global::NServiceBus.AzureFunctions.AzureServiceBus.AzureServiceBusMessageProcessor>(\"{func.FunctionName}\");");
writer.WriteLine($" .GetKeyedService<{func.ProcessorTypeFullyQualified}>(\"{func.FunctionName}\");");
writer.WriteLine("if (processor is null)");
writer.WriteLine("{");
writer.Indentation++;
writer.WriteLine($"throw new global::System.InvalidOperationException(\"{func.FunctionName} has not been registered.\");");
writer.Indentation--;
writer.WriteLine("}");
writer.WriteLine($"return processor.Process({func.MessageParamName}, {func.MessageActionsParamName}, {func.FunctionContextParamName}, {func.CancellationTokenParamName});");
writer.WriteLine($"return {func.ProcessCallExpression};");
writer.Indentation--;
writer.WriteLine("}");
}
Expand Down Expand Up @@ -97,8 +97,9 @@ static void EmitRegistration(SourceProductionContext spc, ImmutableArray<Functio
foreach (var func in functions.OrderBy(f => f.FunctionName, StringComparer.Ordinal))
{
writer.WriteLine("yield return new global::NServiceBus.FunctionManifest(");
writer.WriteLine($" \"{func.FunctionName}\", \"{func.QueueName}\", \"{func.ConnectionName}\",");
writer.WriteLine($" {GenerateConfigureMethodCall(func.ConfigureMethod)});");
writer.WriteLine($" \"{func.FunctionName}\", \"{func.AddressName}\", \"{func.ConnectionSettingName}\",");
writer.WriteLine($" {GenerateConfigureMethodCall(func.ConfigureMethod)},");
writer.WriteLine($" {func.RegistrationMethodFullyQualified});");
}

writer.WriteLine("yield break;");
Expand All @@ -113,4 +114,4 @@ static string GenerateConfigureMethodCall(ConfigureMethodSpec configureMethod)
return $"(endpointconfiguration, iconfiguration, ihostenvironment) => {configureMethod.ContainingTypeFullyQualified}.{configureMethod.MethodName}({argumentList})";
}
}
}
}
Loading
Loading