Skip to content

Templates for Durable Functions Entity in isolated #1666

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<file src="..\..\..\Functions.Templates\Templates\KustoInputBinding-CSharp-Isolated\**" target="content\KustoInputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\KustoOutputBinding-CSharp-Isolated\**" target="content\KustoOutputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsOrchestration-CSharp-Isolated\**" target="content\DurableFunctionsOrchestration-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityClass-CSharp-Isolated\**" target="content\DurableFunctionsEntityClass-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityFunction-CSharp-Isolated\**" target="content\DurableFunctionsEntityFunction-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\SqlTrigger-CSharp-Isolated\**" target="content\SqlTrigger-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\EventGridBlobTrigger-CSharp-Isolated-6.x\**" target="content\EventGridBlobTrigger-CSharp-Isolated-6.x" />
<file src="..\..\..\Functions.Templates\Templates\DaprServiceInvocationTrigger-CSharp-Isolated\**" target="content\DaprServiceInvocationTrigger-CSharp-Isolated" exclude="**\*.md" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<file src="..\..\..\Functions.Templates\Templates\KustoInputBinding-CSharp-Isolated\**" target="content\KustoInputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\KustoOutputBinding-CSharp-Isolated\**" target="content\KustoOutputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsOrchestration-CSharp-Isolated\**" target="content\DurableFunctionsOrchestration-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityClass-CSharp-Isolated\**" target="content\DurableFunctionsEntityClass-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityFunction-CSharp-Isolated\**" target="content\DurableFunctionsEntityFunction-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\SqlTrigger-CSharp-Isolated\**" target="content\SqlTrigger-CSharp-Isolated" />

<file src="..\..\..\Functions.Templates\Templates\DaprServiceInvocationTrigger-CSharp-Isolated\**" target="content\DaprServiceInvocationTrigger-CSharp-Isolated" exclude="**\*.md" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<file src="..\..\..\Functions.Templates\Templates\KustoInputBinding-CSharp-Isolated\**" target="content\KustoInputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\KustoOutputBinding-CSharp-Isolated\**" target="content\KustoOutputBinding-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsOrchestration-CSharp-Isolated\**" target="content\DurableFunctionsOrchestration-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityClass-CSharp-Isolated\**" target="content\DurableFunctionsEntityClass-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\DurableFunctionsEntityFunction-CSharp-Isolated\**" target="content\DurableFunctionsEntityFunction-CSharp" />
<file src="..\..\..\Functions.Templates\Templates\SqlTrigger-CSharp-Isolated\**" target="content\SqlTrigger-CSharp-Isolated" />
<file src="..\..\..\Functions.Templates\Templates\EventGridBlobTrigger-CSharp-Isolated-6.x\**" target="content\EventGridBlobTrigger-CSharp-Isolated-6.x" />
<file src="..\..\..\Functions.Templates\Templates\DaprServiceInvocationTrigger-CSharp-Isolated\**" target="content\DaprServiceInvocationTrigger-CSharp-Isolated" exclude="**\*.md" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"author": "Microsoft",
"classifications": [
"Azure Function",
"Durable Functions Entity (class)"
],
"name": "DurableFunctionsEntityClass",
"identity": "Azure.Function.CSharp.Isolated.DurableFunctionsEntityClass.1.x",
"groupIdentity": "Azure.Function.DurableFunctionsEntity",
"shortName": "durable",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "DurableFunctionsEntityClassCSharp",
"symbols": {
"namespace": {
"description": "namespace for the generated code",
"replaces": "Company.Function",
"type": "parameter"
},
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
}
},
"primaryOutputs": [
{
"path": "DurableFunctionsEntityClassCSharp.cs"
}
],
"defaultName": "DurableFunctionsEntityClassCSharp",
"postActions": [
{
"Description": "Adding reference to Microsoft.Azure.Functions.Worker.Extensions.DurableTask NuGet package.",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.Functions.Worker.Extensions.DurableTask",
"version": "1.3.0",
"projectFileExtensions": ".csproj"
}
},
{
"Description": "Adding Reference to Microsoft.Azure.Functions.Worker.Extensions.Http Nuget package",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.Functions.Worker.Extensions.Http",
"version": "3.3.0",
"projectFileExtensions": ".csproj"
}
},
{
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens the function class file in the editor.",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": {
"text": "Durable Functions Entity (class)",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "2030"
},
"description": {
"text": "A C# Entity class that acts as a stateful counter in Durable Functions.",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "2031"
},
"order": 600,
"icon": "vs-2017.3/functionF.png",
"learnMoreLink": "https://go.microsoft.com/fwlink/?linkid=848145",
"uiFilters": [
"functions"
],
"symbolInfo": []
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;

namespace Company.Function;

public class Counter : TaskEntity<int>
{
readonly ILogger logger;

public Counter(ILogger<Counter> logger)
{
this.logger = logger;
}

public void Add(int amount) => this.State += amount;

public void Reset() => this.State = 0;

public int Get() => this.State;

[Function(nameof(Counter))]
public Task RunEntityAsync([EntityTrigger] TaskEntityDispatcher dispatcher)
{
return dispatcher.DispatchAsync(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"author": "Microsoft",
"classifications": [
"Azure Function",
"Durable Functions Entity (function)"
],
"name": "DurableFunctionsEntityFunction",
"identity": "Azure.Function.CSharp.Isolated.DurableFunctionsEntityFunction.1.x",
"groupIdentity": "Azure.Function.DurableFunctionsEntity",
"shortName": "durable",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "DurableFunctionsEntityFunctionCSharp",
"symbols": {
"namespace": {
"description": "namespace for the generated code",
"replaces": "Company.Function",
"type": "parameter"
},
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
}
},
"primaryOutputs": [
{
"path": "DurableFunctionsEntityFunctionCSharp.cs"
}
],
"defaultName": "DurableFunctionsEntityFunctionCSharp",
"postActions": [
{
"Description": "Adding reference to Microsoft.Azure.Functions.Worker.Extensions.DurableTask NuGet package.",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.Functions.Worker.Extensions.DurableTask",
"version": "1.3.0",
"projectFileExtensions": ".csproj"
}
},
{
"Description": "Adding Reference to Microsoft.Azure.Functions.Worker.Extensions.Http Nuget package",
"ActionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"ContinueOnError": "true",
"ManualInstructions": [],
"args": {
"referenceType": "package",
"reference": "Microsoft.Azure.Functions.Worker.Extensions.Http",
"version": "3.3.0",
"projectFileExtensions": ".csproj"
}
},
{
"description": "Restore NuGet packages required by this project.",
"manualInstructions": [],
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
"continueOnError": true
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens the function class file in the editor.",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": {
"text": "Durable Functions Entity (function)",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "2030"
},
"description": {
"text": "A C# Entity function that acts as a stateful counter in Durable Functions.",
"package": "{E9BCFE2B-304A-4D7F-836F-F3A4FB1A1451}",
"id": "2031"
},
"order": 600,
"icon": "vs-2017.3/functionF.png",
"learnMoreLink": "https://go.microsoft.com/fwlink/?linkid=848145",
"uiFilters": [
"functions"
],
"symbolInfo": []
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;

namespace Company.Function;

public static class DurableFunctionsEntityFunctionCSharp
{
[Function(nameof(Counter))]
public static Task DispatchAsync([EntityTrigger] TaskEntityDispatcher dispatcher)
{
return dispatcher.DispatchAsync(operation =>
{
if (operation.State.GetState(typeof(int)) is null)
{
operation.State.SetState(0);
}

switch (operation.Name.ToLowerInvariant())
{
case "add":
int state = operation.State.GetState<int>();
state += operation.GetInput<int>();
operation.State.SetState(state);
return new(state);
case "reset":
operation.State.SetState(0);
break;
case "get":
return new(operation.State.GetState<int>());
case "delete":
operation.State.SetState(null);
break;
}

return default;
});
}
}