public async Task <Dictionary <string, object> > Execute(RealWorkfolwActivityDescription activityDescription, RealWorkfolwContext context, Dictionary <string, object> runtimeParameters)
        {
            RealWorkfolwActivityDescriptionDataForResult data = activityDescription.Data as RealWorkfolwActivityDescriptionDataForResult;

            if (data == null)
            {
                string realType;
                if (activityDescription.Data == null)
                {
                    realType = "null";
                }
                else
                {
                    realType = activityDescription.Data.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionDataTypeNotMatch,
                    DefaultFormatting = "工作流活动描述的Data属性的类型不匹配,期待的类型为{0},实际类型为{1},发生位置:{2}",
                    ReplaceParameters = new List <object>()
                    {
                        typeof(RealWorkfolwActivityDescriptionDataForResult).FullName, realType, $"{this.GetType().FullName}.Execute"
                    }
                };

                throw new UtilityException((int)Errors.RealWorkfolwActivityDescriptionDataTypeNotMatch, fragment);
            }

            foreach (var parameterItem in data.ResultParameters)
            {
                var conditionParameterResultObj = await _realWorkfolwActivityParameterHandle.Execute(parameterItem, context);

                context.Result[parameterItem.Name] = conditionParameterResultObj;
            }

            return(new Dictionary <string, object>());
        }
        public async Task <Dictionary <string, object> > Execute(RealWorkfolwActivityDescription activityDescription, RealWorkfolwContext context, Dictionary <string, object> runtimeParameters)
        {
            RealWorkfolwActivityDescriptionDataForTransaction data = activityDescription.Data as RealWorkfolwActivityDescriptionDataForTransaction;

            if (data == null)
            {
                string realType;
                if (activityDescription.Data == null)
                {
                    realType = "null";
                }
                else
                {
                    realType = activityDescription.Data.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionDataTypeNotMatch,
                    DefaultFormatting = "工作流活动描述的Data属性的类型不匹配,期待的类型为{0},实际类型为{1},发生位置:{2}",
                    ReplaceParameters = new List <object>()
                    {
                        typeof(RealWorkfolwActivityDescriptionDataForTransaction).FullName, realType, $"{this.GetType().FullName}.Execute"
                    }
                };

                throw new UtilityException((int)Errors.RealWorkfolwActivityDescriptionDataTypeNotMatch, fragment);
            }

            TransactionScopeOption scope;
            IsolationLevel         level;
            TransactionOptions     transactionOptions = new TransactionOptions();

            switch (data.Scope)
            {
            case "1":
                scope = TransactionScopeOption.Required;
                break;

            case "2":
                scope = TransactionScopeOption.RequiresNew;
                break;

            case "3":
                scope = TransactionScopeOption.Suppress;
                break;

            default:
                scope = TransactionScopeOption.Required;
                break;
            }

            switch (data.Level)
            {
            case "1":
                level = IsolationLevel.ReadCommitted;
                break;

            case "2":
                level = IsolationLevel.ReadUncommitted;
                break;

            case "3":
                level = IsolationLevel.RepeatableRead;
                break;

            case "4":
                level = IsolationLevel.Serializable;
                break;

            case "5":
                level = IsolationLevel.Snapshot;
                break;

            case "6":
                level = IsolationLevel.Unspecified;
                break;

            case "7":
                level = IsolationLevel.Chaos;
                break;

            default:
                level = IsolationLevel.ReadCommitted;
                break;
            }

            transactionOptions.IsolationLevel = level;
            if (data.Timeout.HasValue)
            {
                transactionOptions.Timeout = data.Timeout.Value;
            }

            await using (DBTransactionScope transactionScope = new DBTransactionScope(scope, transactionOptions))
            {
                await ExecuteMatch(data.Activities, context);

                transactionScope.Complete();
            }

            Dictionary <string, object> outputDict = new Dictionary <string, object>();

            foreach (var outputItem in activityDescription.OutputParameters)
            {
                var outputResult = await _realWorkfolwActivityParameterHandle.Execute(outputItem.Value, context);

                outputDict[outputItem.Key] = outputResult;
            }

            return(outputDict);
        }
        public async Task <Dictionary <string, object> > Execute(RealWorkfolwActivityDescription activityDescription, RealWorkfolwContext context, Dictionary <string, object> runtimeParameters)
        {
            Exception exception;
            RealWorkfolwActivityDescriptionDataForWhile data = activityDescription.Data as RealWorkfolwActivityDescriptionDataForWhile;

            if (data == null)
            {
                string realType;
                if (activityDescription.Data == null)
                {
                    realType = "null";
                }
                else
                {
                    realType = activityDescription.Data.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionDataTypeNotMatch,
                    DefaultFormatting = "工作流活动描述的Data属性的类型不匹配,期待的类型为{0},实际类型为{1},发生位置:{2}",
                    ReplaceParameters = new List <object>()
                    {
                        typeof(RealWorkfolwActivityDescriptionDataForWhile).FullName, realType, $"{this.GetType().FullName}.Execute"
                    }
                };

                throw new UtilityException((int)Errors.RealWorkfolwActivityDescriptionDataTypeNotMatch, fragment);
            }

            if (!activityDescription.InputParameters.TryGetValue("condition", out RealWorkfolwActivityParameter conditionParameter))
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundRealWorkfolwActivityDescriptionInputByName,
                    DefaultFormatting = "名称为{0}的工作流描述中找不到名称为{1}的输入参数",
                    ReplaceParameters = new List <object>()
                    {
                        activityDescription.Name, "condition"
                    }
                };

                exception = new UtilityException((int)Errors.NotFoundRealWorkfolwActivityDescriptionInputByName, fragment);
                exception.Data[UtilityExceptionDataKeys.Catch] = true;
                throw exception;
            }

            while (true)
            {
                string   newName   = string.Empty;;
                string[] arrayName = conditionParameter.Name.Split('_');
                if (arrayName.Length > 1)
                {
                    arrayName[arrayName.Length - 1] = Guid.NewGuid().ToString();
                    foreach (var itemName in arrayName)
                    {
                        if (newName == string.Empty)
                        {
                            newName = itemName;
                        }
                        else
                        {
                            newName = $"{newName}_{itemName}";
                        }
                    }
                }
                conditionParameter.Name = newName;

                var conditionParameterResultObj = await _realWorkfolwActivityParameterHandle.Execute(conditionParameter, context);

                var conditionParameterResult = conditionParameterResultObj as bool?;
                if (conditionParameterResult == null)
                {
                    string realType;
                    if (conditionParameterResultObj == null)
                    {
                        realType = null;
                    }
                    else
                    {
                        realType = conditionParameterResultObj.GetType().FullName;
                    }

                    var fragment = new TextFragment()
                    {
                        Code = TextCodes.RealWorkfolwActivityDescriptionInputResultTypeNotMatch,
                        DefaultFormatting = "名称为{0}的工作流描述中名称为{1}的输入参数的结果值类型不匹配,期待的类型为{2},实际类型为{3},参数配置为{4}",
                        ReplaceParameters = new List <object>()
                        {
                            activityDescription.Name, "condition", typeof(bool).FullName, realType, conditionParameter.Configuration
                        }
                    };

                    exception = new UtilityException((int)Errors.RealWorkfolwActivityDescriptionInputResultTypeNotMatch, fragment);
                    exception.Data[UtilityExceptionDataKeys.Catch] = true;
                    throw exception;
                }

                if (conditionParameterResult.Value)
                {
                    await ExecuteMatch(data.Activities, context);
                }
                else
                {
                    break;
                }
            }

            Dictionary <string, object> outputDict = new Dictionary <string, object>();

            foreach (var outputItem in activityDescription.OutputParameters)
            {
                var outputResult = await _realWorkfolwActivityParameterHandle.Execute(outputItem.Value, context);

                outputDict[outputItem.Key] = outputResult;
            }

            return(outputDict);
        }
Example #4
0
        public async Task <Dictionary <string, object> > Execute(RealWorkfolwActivityDescription activityDescription, RealWorkfolwContext context, Dictionary <string, object> runtimeParameters)
        {
            Exception exception;
            RealWorkfolwActivityDescriptionDataForCondition data = activityDescription.Data as RealWorkfolwActivityDescriptionDataForCondition;

            if (data == null)
            {
                string realType;
                if (activityDescription.Data == null)
                {
                    realType = "null";
                }
                else
                {
                    realType = activityDescription.Data.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionDataTypeNotMatch,
                    DefaultFormatting = "工作流活动描述的Data属性的类型不匹配,期待的类型为{0},实际类型为{1},发生位置:{2}",
                    ReplaceParameters = new List <object>()
                    {
                        typeof(RealWorkfolwActivityDescriptionDataForCondition).FullName, realType, $"{this.GetType().FullName}.Execute"
                    }
                };

                throw new UtilityException((int)Errors.RealWorkfolwActivityDescriptionDataTypeNotMatch, fragment);
            }

            if (!activityDescription.InputParameters.TryGetValue("condition", out RealWorkfolwActivityParameter conditionParameter))
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundRealWorkfolwActivityDescriptionInputByName,
                    DefaultFormatting = "名称为{0}的工作流描述中找不到名称为{1}的输入参数",
                    ReplaceParameters = new List <object>()
                    {
                        activityDescription.Name, "condition"
                    }
                };

                exception = new UtilityException((int)Errors.NotFoundRealWorkfolwActivityDescriptionInputByName, fragment);
                exception.Data[UtilityExceptionDataKeys.Catch] = true;
                throw exception;
            }

            var conditionParameterResultObj = await _realWorkfolwActivityParameterHandle.Execute(conditionParameter, context);

            var conditionParameterResult = conditionParameterResultObj as bool?;

            if (conditionParameterResult == null)
            {
                string realType;
                if (conditionParameterResultObj == null)
                {
                    realType = null;
                }
                else
                {
                    realType = conditionParameterResultObj.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionInputResultTypeNotMatch,
                    DefaultFormatting = "名称为{0}的工作流描述中名称为{1}的输入参数的结果值类型不匹配,期待的类型为{2},实际类型为{3},参数配置为{4}",
                    ReplaceParameters = new List <object>()
                    {
                        activityDescription.Name, "condition", typeof(bool).FullName, realType, conditionParameter.Configuration
                    }
                };

                exception = new UtilityException((int)Errors.RealWorkfolwActivityDescriptionInputResultTypeNotMatch, fragment);
                exception.Data[UtilityExceptionDataKeys.Catch] = true;
                throw exception;
            }

            if (conditionParameterResult.Value)
            {
                await ExecuteMatch(data.Match, context);
            }
            else
            {
                bool executed = false;
                foreach (var elseifItem in data.ElseIfs)
                {
                    conditionParameterResultObj = await _realWorkfolwActivityParameterHandle.Execute(elseifItem.Condition, context);

                    conditionParameterResult = conditionParameterResultObj as bool?;
                    if (conditionParameterResult == null)
                    {
                        string realType;
                        if (conditionParameterResultObj == null)
                        {
                            realType = null;
                        }
                        else
                        {
                            realType = conditionParameterResultObj.GetType().FullName;
                        }

                        var fragment = new TextFragment()
                        {
                            Code = TextCodes.RealWorkfolwActivityDescriptionInnerInputResultTypeNotMatch,
                            DefaultFormatting = "名称为{0}的工作流描述中内部输入参数{1}的计算结果类型不匹配,期待类型为{2},实际类型为{3},参数配置为{4}",
                            ReplaceParameters = new List <object>()
                            {
                                activityDescription.Name, elseifItem.Condition.Name, typeof(bool).FullName, realType, elseifItem.Condition.Configuration
                            }
                        };

                        exception = new UtilityException((int)Errors.RealWorkfolwActivityDescriptionInnerInputResultTypeNotMatch, fragment);
                        exception.Data[UtilityExceptionDataKeys.Catch] = true;
                        throw exception;
                    }

                    if (conditionParameterResult.Value)
                    {
                        await ExecuteMatch(elseifItem.Match, context);

                        executed = true;
                        break;
                    }
                }

                if (!executed)
                {
                    await ExecuteMatch(data.Else, context);
                }
            }

            Dictionary <string, object> outputDict = new Dictionary <string, object>();

            foreach (var outputItem in activityDescription.OutputParameters)
            {
                var outputResult = await _realWorkfolwActivityParameterHandle.Execute(outputItem.Value, context);

                outputDict[outputItem.Key] = outputResult;
            }

            return(outputDict);
        }
Example #5
0
        public async Task <Dictionary <string, object> > Execute(RealWorkfolwActivityDescription activityDescription, RealWorkfolwContext context, Dictionary <string, object> runtimeParameters)
        {
            RealWorkfolwActivityDescriptionDataForParallel data = activityDescription.Data as RealWorkfolwActivityDescriptionDataForParallel;

            if (data == null)
            {
                string realType;
                if (activityDescription.Data == null)
                {
                    realType = "null";
                }
                else
                {
                    realType = activityDescription.Data.GetType().FullName;
                }

                var fragment = new TextFragment()
                {
                    Code = TextCodes.RealWorkfolwActivityDescriptionDataTypeNotMatch,
                    DefaultFormatting = "工作流活动描述的Data属性的类型不匹配,期待的类型为{0},实际类型为{1},发生位置:{2}",
                    ReplaceParameters = new List <object>()
                    {
                        typeof(RealWorkfolwActivityDescriptionDataForParallel).FullName, realType, $"{this.GetType().FullName}.Execute"
                    }
                };

                throw new UtilityException((int)Errors.RealWorkfolwActivityDescriptionDataTypeNotMatch, fragment);
            }

            ParallelHelper parallel = new ParallelHelper(data.Max);

            List <RunAsyncAction> actionList = new List <RunAsyncAction>();


            foreach (var item in data.Items)
            {
                RunAsyncAction action = new RunAsyncAction()
                {
                    Action = async() =>
                    {
                        await ExecuteMatch(item.Activities, context);
                    },
                    ErrorHandler = async(ex) =>
                    {
                        Dictionary <string, object> newRuntimeParameters = new Dictionary <string, object>();
                        newRuntimeParameters.Add("exception", ex);

                        var errorHandleResult = await _realWorkfolwActivityCalculate.Execute(item.ErrorHandle, context, newRuntimeParameters);

                        foreach (var resultItem in errorHandleResult)
                        {
                            if (!context.ActivityInnerOutputParameters.TryGetValue($"{item.ErrorHandle.Id.ToString()}_{resultItem.Key}", out List <object> outputResutList))
                            {
                                lock (context.ActivityInnerOutputParameters)
                                {
                                    if (!context.ActivityInnerOutputParameters.TryGetValue($"{item.ErrorHandle.Id.ToString()}_{resultItem.Key}", out outputResutList))
                                    {
                                        outputResutList = new List <object>();
                                        context.ActivityInnerOutputParameters[$"{item.ErrorHandle.Id.ToString()}_{resultItem.Key}"] = outputResutList;
                                    }
                                }
                            }

                            lock (outputResutList)
                            {
                                outputResutList.Add(resultItem.Value);
                            }
                        }
                    }
                };
            }

            await parallel.RunAsync(actionList);

            Dictionary <string, object> outputDict = new Dictionary <string, object>();

            foreach (var outputItem in activityDescription.OutputParameters)
            {
                var outputResult = await _realWorkfolwActivityParameterHandle.Execute(outputItem.Value, context);

                outputDict[outputItem.Key] = outputResult;
            }

            return(outputDict);
        }