This file contains hidden or 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
| public class LRUCache<TKey, TValue> | |
| { | |
| readonly int capacity; | |
| readonly Dictionary<TKey, LinkedListNode<(TKey key, TValue value)>> cache; | |
| readonly LinkedList<(TKey key, TValue value)> list; | |
| readonly object syncLock = new object(); | |
| public LRUCache(int capacity) | |
| { | |
| this.capacity = capacity; |
This file contains hidden or 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
| class ParallelTaskChaining : Workflow<string, string> | |
| { | |
| public override async Task<string> RunAsync(WorkflowContext context, string input) | |
| { | |
| // Fan-out to 10 parallel task chains | |
| List<Task> parallelChains = new(); | |
| for (int i = 0; i < 10; i++) | |
| { | |
| // RunSequence encapsulates the task chain as a single task. | |
| Task chainTask = RunSequence(context); |
This file contains hidden or 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
| namespace ConsoleApp1 | |
| { | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics.Tracing; | |
| using System.Linq; | |
| using System.Reflection; | |
| using DurableTask.AzureStorage; | |
| using Microsoft.CodeAnalysis; | |
| using Microsoft.CodeAnalysis.CSharp; |
This file contains hidden or 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
| public class CounterEntity | |
| { | |
| [JsonProperty("value")] | |
| public int CurrentValue { get; set; } | |
| public void Add(int amount) => this.CurrentValue += amount; | |
| public void Reset() => this.CurrentValue = 0; | |
| public int Get() => this.CurrentValue; |
This file contains hidden or 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
| public static async Task Counter( | |
| [EntityTrigger] IDurableEntityContext ctx) | |
| { | |
| int currentValue = ctx.GetState<int>(); | |
| switch (ctx.OperationName) | |
| { | |
| case "add": | |
| int amount = ctx.GetInput<int>(); | |
| currentValue += amount; |
This file contains hidden or 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
| public string FetchAccessToken() | |
| { | |
| string idToken = this.Request.Headers["X-MS-TOKEN-AAD-ACCESS-TOKEN"]; | |
| string tokenUrl = Environment.GetEnvironmentVariable("WEBSITE_AUTH_OPENID_ISSUER").TrimEnd('/') + "/oauth2/token"; | |
| var paramBuilder = new StringBuilder(); | |
| paramBuilder.Append("grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer"); | |
| paramBuilder.Append("&client_id=").Append(Environment.GetEnvironmentVariable("WEBSITE_AUTH_CLIENT_ID")); | |
| paramBuilder.Append("&client_secret=").Append(Environment.GetEnvironmentVariable("WEBSITE_AUTH_CLIENT_SECRET")); | |
| paramBuilder.Append("&scope=").Append(WebUtility.UrlEncode("https://graph.microsoft.com/user.read")); |