Skip to content

Commit

Permalink
Merge pull request #733 from JetBrains/232-mb-templates
Browse files Browse the repository at this point in the history
Azure Functions: Update file templates #730
  • Loading branch information
maartenba authored Nov 16, 2023
2 parents 9502ed1 + 96bb465 commit c7610eb
Show file tree
Hide file tree
Showing 38 changed files with 899 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ javaVersion=17
org.gradle.jvmargs='-Duser.language=en'
sources=false

intellij_version=IC-232.8660-EAP-CANDIDATE-SNAPSHOT
intellij_version=IC-2023.2
#rider_version=RD-2023.2-EAP10-SNAPSHOT
rider_version=RD-2023.2
build_common_code_with=rider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li>Azure Functions: Support debugging .NET 4.8 isolated worker projects (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/691">#691</a>)</li>
<li>Update Azure logo for Rider's Azure Toolkit icons (<a href="https://youtrack.jetbrains.com/issue/RIDER-78226">RIDER-78226</a>)</li>
<li>Azurite - Reference Azurite executable directly (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/712">#712</a> and <a href="https://youtrack.jetbrains.com/issue/RIDER-98716">RIDER-98716</a>)</li>
<li>Azure Functions: Update file templates (<a href="https://github.com/JetBrains/azure-tools-for-intellij/issues/730">#730</a>)</li>
</ul>
<h4>Fixed bugs:</h4>
<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Rider.SDK" Version="$(RiderSDKVersion)" />
<PackageReference Include="CitizenMatt.ReSharper.LiveTemplateCompiler" Version="3.3.0">
<PackageReference Include="CitizenMatt.ReSharper.LiveTemplateCompiler" Version="3.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public override void InitDefaultSettings(ISettingsStorageMountPoint mountPoint)
AddToQuickList(mountPoint, myCSharpMainPoint, "Queue Trigger", ++pos, "7ee1ed3e-3090-4119-9043-e88d376059dc");
AddToQuickList(mountPoint, myCSharpMainPoint, "Service Bus Queue Trigger", ++pos, "063aeef7-6174-4705-ab87-b8fc949b596a");
AddToQuickList(mountPoint, myCSharpMainPoint, "Service Bus Topic Trigger", ++pos, "5e6a4a74-7465-4e18-b1eb-a82294ad3391");
AddToQuickList(mountPoint, myCSharpMainPoint, "SQL Trigger", ++pos, "4bf02cbd-c8db-46aa-ba9e-56df85f88cec");
AddToQuickList(mountPoint, myCSharpMainPoint, "Timer Trigger", ++pos, "60bbd781-cc83-4969-8940-44e09ce85725");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Publish Output Binding", ++pos, "a50d2862-4c19-4ab2-90d8-4b61be652e5f");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Service Invocation Trigger", ++pos, "6a12542b-e634-41c1-a11b-804f08792e6e");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Topic Trigger", ++pos, "e0938da7-d4be-412b-aa79-a23745721fda");

// C# templates - Isolated Worker
AddToQuickList(mountPoint, myCSharpMainPoint, "Blob Trigger", ++pos, "7ae1d45e-28cd-48d2-bbb6-bc92bbd64254");
Expand All @@ -82,7 +86,11 @@ public override void InitDefaultSettings(ISettingsStorageMountPoint mountPoint)
AddToQuickList(mountPoint, myCSharpMainPoint, "Queue Trigger", ++pos, "05e6f400-869c-4d10-b9e5-1bec3a50dd75");
AddToQuickList(mountPoint, myCSharpMainPoint, "Service Bus Queue Trigger", ++pos, "3c11cff7-99a9-47c5-90dd-eb39bf4adf27");
AddToQuickList(mountPoint, myCSharpMainPoint, "Service Bus Topic Trigger", ++pos, "7f50ad96-6a80-4be0-96b8-9d224997a9aa");
AddToQuickList(mountPoint, myCSharpMainPoint, "SQL Trigger", ++pos, "707c458f-6b00-4ae6-aba8-0a02606c76be");
AddToQuickList(mountPoint, myCSharpMainPoint, "Timer Trigger", ++pos, "ee9b1573-f483-4960-986e-a16242fb0607");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Publish Output Binding", ++pos, "5bd6f10c-21a5-4b73-82d0-9da395333736");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Service Invocation Trigger", ++pos, "5c9abf80-0f16-48dd-bc66-d6b3c9fcf7d4");
AddToQuickList(mountPoint, myCSharpMainPoint, "Dapr Topic Trigger", ++pos, "d9d5ba30-b25c-4010-bf55-94fa43e880f4");

// F# templates - Default Worker
AddToQuickList(mountPoint, myFSharpMainPoint, "Blob Trigger", ++pos, "3e3ef753-81d7-4130-a8c9-aff5cabc23ed");
Expand All @@ -92,6 +100,15 @@ public override void InitDefaultSettings(ISettingsStorageMountPoint mountPoint)
AddToQuickList(mountPoint, myFSharpMainPoint, "HTTP Trigger", ++pos, "e8104b0a-97de-4847-b8f0-5b9f438bdc92");
AddToQuickList(mountPoint, myFSharpMainPoint, "Queue Trigger", ++pos, "bfccc7d5-0a43-4fc2-a4d4-580d1265b536");
AddToQuickList(mountPoint, myFSharpMainPoint, "Timer Trigger", ++pos, "71a9a23c-c542-4e82-af8d-4a1bb410a6b2");

// F# templates - Isolated Worker
AddToQuickList(mountPoint, myFSharpMainPoint, "Blob Trigger", ++pos, "9e3ef753-81d7-4130-a8c9-aff5cabc23ed");
AddToQuickList(mountPoint, myFSharpMainPoint, "Cosmos DB Trigger", ++pos, "91ebe6f2-b045-4476-87ef-d9458ec74c23");
AddToQuickList(mountPoint, myFSharpMainPoint, "Event Grid Trigger", ++pos, "9c32fa2b-ec21-4789-ba43-b5a897fb8f5b");
AddToQuickList(mountPoint, myFSharpMainPoint, "Event Hub Trigger", ++pos, "9a3273cb-d595-4bd6-9b69-8eaf71120b55");
AddToQuickList(mountPoint, myFSharpMainPoint, "HTTP Trigger", ++pos, "98104b0a-97de-4847-b8f0-5b9f438bdc92");
AddToQuickList(mountPoint, myFSharpMainPoint, "Queue Trigger", ++pos, "9fccc7d5-0a43-4fc2-a4d4-580d1265b536");
AddToQuickList(mountPoint, myFSharpMainPoint, "Timer Trigger", ++pos, "98a9a23c-c542-4e82-af8d-4a1bb410a6b2");
}

private void InitialiseQuickList(ISettingsStorageMountPoint mountPoint, IMainScopePoint quickList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ shortenReferences: True
image: AzureFunctionsTrigger
customProperties: Extension=cs, FileName=CosmosDbTrigger, ValidateFileName=True
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker
parameterOrder: (HEADER), (NAMESPACE), (CLASS), DATABASEVALUE, COLLECTIONVALUE, (CONNECTIONVALUE)
parameterOrder: (HEADER), (NAMESPACE), (CLASS), DATABASEVALUE, CONTAINERVALUE, (CONNECTIONVALUE)
HEADER-expression: fileheader()
NAMESPACE-expression: fileDefaultNamespace()
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
DATABASEVALUE-expression: constant("databaseName")
COLLECTIONVALUE-expression: constant("collectionName")
CONTAINERVALUE-expression: constant("containerName")
CONNECTIONVALUE-expression: constant("")
---

Expand All @@ -21,7 +21,6 @@ CONNECTIONVALUE-expression: constant("")
$HEADER$using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
Expand All @@ -33,16 +32,25 @@ namespace $NAMESPACE$
[FunctionName("$CLASS$")]
public static async Task RunAsync([CosmosDBTrigger(
databaseName: "$DATABASEVALUE$",
collectionName: "$COLLECTIONVALUE$",
ConnectionStringSetting = "$CONNECTIONVALUE$",
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, ILogger log)
containerName: "$CONTAINERVALUE$",
Connection = "$CONNECTIONVALUE$",
LeaseContainerName = "leases",
CreateLeaseContainerIfNotExists = true)]IReadOnlyList<ToDoItem> input,
ILogger log)
{
if (input != null && input.Count > 0)
{
log.LogInformation("Documents modified " + input.Count);
log.LogInformation("First document Id " + input[0].Id);$END$
}
log.LogInformation("First document Id " + input[0].id);
}$END$
}
}
// Customize the model with your own desired properties
public class ToDoItem
{
public string id { get; set; }
public string Description { get; set; }
}
}
```
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
guid: a50d2862-4c19-4ab2-90d8-4b61be652e5f
type: File
reformat: True
shortenReferences: True
image: AzureFunctionsTrigger
customProperties: Extension=cs, FileName=DaprPublishOutputBinding, ValidateFileName=True
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker
parameterOrder: (HEADER), (NAMESPACE), (CLASS), PUBSUBNAME, TOPICVALUE, (SCHEDULE)
HEADER-expression: fileheader()
NAMESPACE-expression: fileDefaultNamespace()
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
TOPICVALUE-expression: constant("topic")
PUBSUBNAME-expression: constant("pubsub")
SCHEDULE-expression: constant("*/10 * * * * *")
---

# Dapr Publish Output Binding

```
$HEADER$using System.Threading.Tasks;
using CloudNative.CloudEvents;
using Microsoft.Azure.Functions.Extensions.Dapr.Core;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Dapr;
using Microsoft.Extensions.Logging;
namespace $NAMESPACE$
{
public static class $CLASS$
{
/// <summary>
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension.
/// These tasks should be completed prior to running :
/// 1. Install Dapr
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start
/// Function will be invoked by Timer trigger and publish messages to message bus.
/// </summary>
/// <param name="log">Function logger.</param>
[FunctionName("$CLASS$")]
// we can try using Function timer trigger.
// Rename the template to PublishTemplate
public static void Run([TimerTrigger("$SCHEDULE$")] TimerInfo myTimer,
[DaprPublish(PubSubName = "$PUBSUBNAME$", Topic = "$TOPICVALUE$")] out DaprPubSubEvent pubEvent,
ILogger log)
{
log.LogInformation("C# DaprPublish output binding function processed a request.");
pubEvent = new DaprPubSubEvent("Invoked by Timer trigger: " + $"Hello, World! The time is {System.DateTime.UtcNow}");$END$
}
}
// Below Azure function will receive message published on topic $TOPICVALUE$, and it will log the message
public static class $CLASS$TopicTrigger
{
/// <summary>
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension.
/// This function will get invoked when a message is published on topic $TOPICVALUE$
/// </summary>
/// <param name="subEvent">Cloud event sent by Dapr runtime.</param>
/// <param name="log">Function logger.</param>
[FunctionName("$CLASS$TopicTrigger")]
public static async Task RunAsync(
[DaprTopicTrigger("$PUBSUBNAME$", Topic = "$TOPICVALUE$")] CloudEvent subEvent,
ILogger log)
{
log.LogInformation("C# Dapr Topic Trigger function processed a request from the Dapr Runtime.");
log.LogInformation($"Topic A received a message: {subEvent.Data}.");
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
guid: 6a12542b-e634-41c1-a11b-804f08792e6e
type: File
reformat: True
shortenReferences: True
image: AzureFunctionsTrigger
customProperties: Extension=cs, FileName=DaprServiceInvocationTrigger, ValidateFileName=True
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker
parameterOrder: (HEADER), (NAMESPACE), (CLASS)
HEADER-expression: fileheader()
NAMESPACE-expression: fileDefaultNamespace()
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
---

# Dapr Service Invocation Trigger

```
$HEADER$using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Extensions.Dapr.Core;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Dapr;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Threading.Tasks;
namespace $NAMESPACE$
{
public static class $CLASS$
{
/// <summary>
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension.
/// These tasks should be completed prior to running :
/// 1. Install Dapr
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start
/// Invoke function app by dapr cli: dapr invoke --app-id functionapp --method {yourFunctionName} --data '{ \"data\": {\"value\": { \"orderId\": \"41\" } } }'
/// Invoke function app by http trigger:
/// curl 'http://localhost:7071/api/invoke/functionapp/{yourFunctionName}' `
/// --header 'Content-Type: application/json' `
/// --data '{
/// "data": {
/// "value": {
/// "orderId": "41"
/// }
/// }
/// }'
/// <param name="payload">Payload of dapr service invocation trigger.</param>
/// <param name="log">Function logger.</param>
/// </summary>
[FunctionName("$CLASS$")]
public static async Task RunAsync(
[DaprServiceInvocationTrigger] string payload,
ILogger log)
{
log.LogInformation("Azure function triggered by Dapr Service Invocation Trigger.");
log.LogInformation($"Dapr service invocation trigger payload: {payload}");$END$
}
}
public static class $CLASS$InvokeOutputBinding
{
/// <summary>
/// Sample to use a Dapr Invoke Output Binding to perform a Dapr Server Invocation operation hosted in another Darp'd app.
/// Here this function acts like a proxy
/// </summary>
[FunctionName("$CLASS$InvokeOutputBinding")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "invoke/{appId}/{methodName}")] HttpRequest req,
[DaprInvoke(AppId = "{appId}", MethodName = "{methodName}", HttpVerb = "post")] IAsyncCollector<InvokeMethodParameters> output,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var outputContent = new InvokeMethodParameters
{
Body = requestBody
};
await output.AddAsync(outputContent);
return new OkObjectResult("Successfully performed service invocation using Dapr invoke output binding.");
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
guid: e0938da7-d4be-412b-aa79-a23745721fda
type: File
reformat: True
shortenReferences: True
image: AzureFunctionsTrigger
customProperties: Extension=cs, FileName=DaprTopicTrigger, ValidateFileName=True
scopes: InAzureFunctionsCSharpProject;MustUseAzureFunctionsDefaultWorker
parameterOrder: (HEADER), (NAMESPACE), (CLASS), PUBSUBNAME, TOPICVALUE, STATESTORE, STATESTOREKEY
HEADER-expression: fileheader()
NAMESPACE-expression: fileDefaultNamespace()
CLASS-expression: getAlphaNumericFileNameWithoutExtension()
TOPICVALUE-expression: constant("topic")
PUBSUBNAME-expression: constant("pubsub")
STATESTORE-expression: constant("statestore")
STATESTOREKEY-expression: constant("product")
---

# Dapr Topic Trigger

```
$HEADER$using System.Text.Json;
using System.Threading.Tasks;
using CloudNative.CloudEvents;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Dapr;
using Microsoft.Extensions.Logging;
namespace $NAMESPACE$
{
public static class $CLASS$
{
/// <summary>
/// Visit https://aka.ms/azure-functions-dapr to learn how to use the Dapr extension.
/// These tasks should be completed prior to running :
/// 1. Install Dapr
/// Start function app with Dapr: dapr run --app-id functionapp --app-port 3001 --dapr-http-port 3501 -- func host start
/// Invoke function app: dapr publish --pubsub pubsub --publish-app-id functionapp --topic $TOPICVALUE$ --data '{\"value\": { \"orderId\": \"42\" } }'
/// </summary>
/// <param name="subEvent">Cloud event sent by Dapr runtime.</param>
/// <param name="value">Value will be saved against the given key in state store.</param>
/// <param name="log">Function logger.</param>
[FunctionName("$CLASS$")]
public static void Run(
[DaprTopicTrigger("$PUBSUBNAME$", Topic = "$TOPICVALUE$")] CloudEvent subEvent,
[DaprState("$STATESTORE$", Key = "$STATESTOREKEY$")] out object value,
ILogger log)
{
log.LogInformation("C# DaprTopic trigger with DaprState output binding function processed a request from the Dapr Runtime.");
value = subEvent.Data;$END$
}
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
using Azure.Messaging.EventGrid;
namespace $NAMESPACE$
{
Expand All @@ -37,4 +37,4 @@ namespace $NAMESPACE$
}
}
}
```
```
Loading

0 comments on commit c7610eb

Please sign in to comment.