Exemplo n.º 1
0
        public Task <object?> EvaluateAsync(
            string expression,
            Type returnType,
            ActivityExecutionContext context,
            CancellationToken cancellationToken)
        {
            var result = context.GetVariable(expression);

            return(Task.FromResult(result));
        }
Exemplo n.º 2
0
        private static void ThrowErrorIfFirstRun(ActivityExecutionContext context)
        {
            var hasExecuted = context.GetVariable <bool>("HasExecuted");

            if (!hasExecuted)
            {
                context.SetVariable("HasExecuted", true);
                throw new Exception("Something bad happened. Please retry workflow.");
            }
        }
Exemplo n.º 3
0
        public Task <object?> EvaluateAsync(string expression, Type returnType, ActivityExecutionContext context, CancellationToken cancellationToken)
        {
            var matches = rx.Matches(expression);

            foreach (Match match in matches)
            {
                var variable = match.Groups[1].Value;

                string replacement = match.Groups[0].Value;

                switch (variable)
                {
                case "correlationId":
                    replacement = $"'{context.WorkflowExecutionContext.CorrelationId}'";
                    break;

                case "workflowDefinitionId":
                    replacement = $"'{context.WorkflowInstance.DefinitionId}'";
                    break;

                case "workflowDefinitionVersion":
                    replacement = $"{context.WorkflowInstance.DefinitionVersionId}";
                    break;

                case "workflowInstanceId":
                    replacement = $"'{context.WorkflowInstance.Id}'";
                    break;

                default:
                    if (context.HasVariable(variable))
                    {
                        var value = context.GetVariable(variable);
                        if (value is not null)
                        {
                            replacement = IsNumber(value)? $"{value}" : $"'{value}'";
                        }
                        else
                        {
                            replacement = "NULL";
                        }
                    }
                    break;
                }

                expression = expression.Replace(match.Groups[0].Value, replacement);
            }

            return(Task.FromResult(expression.Parse(returnType)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the control ID of the active call session in the workflow if the specified call control ID is null or empty.
        /// </summary>
        public static string GetFromNumber(this ActivityExecutionContext context, string?fromNumber)
        {
            if (!string.IsNullOrWhiteSpace(fromNumber))
            {
                return(fromNumber);
            }

            fromNumber = context.GetVariable <string>(FromNumberVariableName);

            if (!string.IsNullOrWhiteSpace(fromNumber))
            {
                return(fromNumber);
            }

            throw new MissingFromNumberException("No From Number specified");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the control ID of the active call session in the workflow if the specified call control ID is null or empty.
        /// </summary>
        public static string GetCallControlId(this ActivityExecutionContext context, string?callControlId)
        {
            if (!string.IsNullOrWhiteSpace(callControlId))
            {
                return(callControlId);
            }

            callControlId = context.GetVariable <string>(CallControlIdVariableName);

            if (!string.IsNullOrWhiteSpace(callControlId))
            {
                return(callControlId);
            }

            throw new MissingCallControlIdException("No Call Control ID specified");
        }
Exemplo n.º 6
0
 private int GetCurrentCount(ActivityExecutionContext context) => context.GetVariable <int>("CurrentCount");
 public static string?GetCallerNumber(this ActivityExecutionContext context) => context.GetVariable <string>(CallerNumberVariableName);
Exemplo n.º 8
0
 private int GetCounter(ActivityExecutionContext context) => context.GetVariable <int>(CounterVariableName);