Exemplo n.º 1
0
        /// <summary>
        /// Executes the target activity method.
        /// </summary>
        /// <param name="client">The associated Cadence client.</param>
        /// <param name="argBytes">The encoded activity arguments.</param>
        /// <returns>The encoded activity results.</returns>
        private async Task <byte[]> InvokeAsync(CadenceClient client, byte[] argBytes)
        {
            var parameters     = activityMethod.GetParameters();
            var parameterTypes = new Type[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                parameterTypes[i] = parameters[i].ParameterType;
            }

            var resultType       = activityMethod.ReturnType;
            var args             = dataConverter.FromDataArray(argBytes, parameterTypes);
            var serializedResult = emptyBytes;

            if (resultType.IsGenericType)
            {
                // Activity method returns: Task<T>

                var result = await NeonHelper.GetTaskResultAsObjectAsync((Task)activityMethod.Invoke(this, args));

                serializedResult = client.DataConverter.ToData(result);
            }
            else
            {
                // Activity method returns: Task

                await(Task) activityMethod.Invoke(this, args);
            }

            return(serializedResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the target activity method.
        /// </summary>
        /// <param name="argBytes">The encoded activity arguments.</param>
        /// <returns>The encoded activity results.</returns>
        private async Task <byte[]> RunAsync(byte[] argBytes)
        {
            var    args   = dataConverter.FromDataArray(argBytes);
            object result = null;

            if (activityMethod.ReturnType == typeof(Task))
            {
                // The activity method returns [Task] (effectively void).

                await(Task) activityMethod.Invoke(this, args);
            }
            else
            {
                // The activity method returns [Task<T>] (an actual result).

                result = await(Task <object>) activityMethod.Invoke(this, args);
            }

            return(dataConverter.ToData(result));
        }