/// <summary> /// Called internally to execute the activity. /// </summary> /// <param name="client">The Cadence client.</param> /// <param name="args">The encoded activity arguments.</param> /// <returns>The activity results.</returns> internal async Task <byte[]> OnInvokeAsync(CadenceClient client, byte[] args) { await SyncContext.Clear; Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); // Capture the activity information. var reply = (ActivityGetInfoReply)(await Client.CallProxyAsync( new ActivityGetInfoRequest() { ContextId = ContextId, })); reply.ThrowOnError(); ActivityTask = reply.Info.ToPublic(); // Invoke the activity. if (IsLocal) { // This doesn't make sense for local activities. ActivityTask.ActivityTypeName = null; return(await InvokeAsync(client, args)); } else { // Track the activity. var activityKey = new ActivityKey(client, ContextId); try { lock (syncLock) { idToActivity[activityKey] = this; } return(await InvokeAsync(client, args)); } catch (Exception e) { logger.LogError(e); throw; } finally { lock (syncLock) { idToActivity.Remove(activityKey); } } } }
/// <summary> /// Called internally to execute the activity. /// </summary> /// <param name="client">The Cadence client.</param> /// <param name="args">The encoded activity arguments.</param> /// <returns>Thye activity results.</returns> internal async Task <byte[]> OnRunAsync(CadenceClient client, byte[] args) { Covenant.Requires <ArgumentNullException>(client != null); if (IsLocal) { return(await RunAsync(args)); } else { // Capture the activity information. var reply = (ActivityGetInfoReply)(await Client.CallProxyAsync( new ActivityGetInfoRequest() { ContextId = ContextId.Value, })); reply.ThrowOnError(); ActivityTask = reply.Info.ToPublic(); // Track the activity. var activityKey = new ActivityKey(client, ContextId.Value); try { lock (syncLock) { idToActivity[activityKey] = this; } return(await RunAsync(args)); } finally { lock (syncLock) { idToActivity.Remove(activityKey); } } } }