|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Threading; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using DurableTask.Core; |
| 9 | +using Newtonsoft.Json; |
| 10 | +using Newtonsoft.Json.Linq; |
| 11 | + |
| 12 | +namespace Microsoft.Azure.WebJobs.Extensions.DurableTask |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Provides access to internal functionality for the purpose of implementing durability providers. |
| 16 | + /// </summary> |
| 17 | + public static class ProviderUtils |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// Returns the instance id of the entity scheduler for a given entity id. |
| 21 | + /// </summary> |
| 22 | + /// <param name="entityId">The entity id.</param> |
| 23 | + /// <returns>The instance id of the scheduler.</returns> |
| 24 | + public static string GetSchedulerIdFromEntityId(EntityId entityId) |
| 25 | + { |
| 26 | + return EntityId.GetSchedulerIdFromEntityId(entityId); |
| 27 | + } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Reads the state of an entity from the serialized entity scheduler state. |
| 31 | + /// </summary> |
| 32 | + /// <param name="state">The orchestration state of the scheduler.</param> |
| 33 | + /// <param name="serializerSettings">The serializer settings.</param> |
| 34 | + /// <param name="result">The serialized state of the entity.</param> |
| 35 | + /// <returns>true if the entity exists, false otherwise.</returns> |
| 36 | + public static bool TryGetEntityStateFromSerializedSchedulerState(OrchestrationState state, JsonSerializerSettings serializerSettings, out string result) |
| 37 | + { |
| 38 | + if (state != null |
| 39 | + && state.OrchestrationInstance != null |
| 40 | + && state.Input != null) |
| 41 | + { |
| 42 | + var schedulerState = JsonConvert.DeserializeObject<SchedulerState>(state.Input, serializerSettings); |
| 43 | + |
| 44 | + if (schedulerState.EntityExists) |
| 45 | + { |
| 46 | + result = schedulerState.EntityState; |
| 47 | + return true; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + result = null; |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Converts the DTFx representation of the orchestration state into the DF representation. |
| 57 | + /// </summary> |
| 58 | + /// <param name="orchestrationState">The orchestration state.</param> |
| 59 | + /// <returns>The orchestration status.</returns> |
| 60 | + public static DurableOrchestrationStatus ConvertOrchestrationStateToStatus(OrchestrationState orchestrationState) |
| 61 | + { |
| 62 | + return DurableClient.ConvertOrchestrationStateToStatus(orchestrationState); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments