/// <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); } } } }
/// <summary> /// Called internally to initialize the activity. /// </summary> /// <param name="client">The associated client.</param> /// <param name="activityType">Specifies the target activity type.</param> /// <param name="activityMethod">Specifies the target activity method.</param> /// <param name="dataConverter">Specifies the data converter to be used for parameter and result serilization.</param> /// <param name="contextId">The activity's context ID or <c>null</c> for local activities.</param> internal void Initialize(CadenceClient client, Type activityType, MethodInfo activityMethod, IDataConverter dataConverter, long?contextId) { Covenant.Requires <ArgumentNullException>(client != null, nameof(client)); Covenant.Requires <ArgumentNullException>(activityType != null, nameof(activityType)); Covenant.Requires <ArgumentNullException>(activityMethod != null, nameof(activityMethod)); Covenant.Requires <ArgumentNullException>(dataConverter != null, nameof(dataConverter)); CadenceHelper.ValidateActivityImplementation(activityType); var activityTask = new ActivityTask() { // $todo(jefflill): Need to initialize these properties. }; this.Client = client; this.ActivityTask = activityTask; this.Activity = new Activity(this); this.activityType = activityType; this.activityMethod = activityMethod; this.dataConverter = dataConverter; this.ContextId = contextId; this.CancellationTokenSource = new CancellationTokenSource(); this.CancellationToken = CancellationTokenSource.Token; }