Exemple #1
0
        public async Task <Dictionary <string, object> > Calculate(RealWorkfolwActivity activity, RealWorkfolwContext context)
        {
            /*var inputParameters = await GetInputParameters(activity);
             * Dictionary<string, object> inputObjects = new Dictionary<string, object>();
             * foreach(var inputItem in inputParameters)
             * {
             *  inputObjects.Add(inputItem.Key, await _realWorkfolwActivityParameterHandle.Execute(inputItem.Value, context));
             * }
             */
            RealWorkfolwActivityDescription activityDescription = null;

            if (!activity.Extensions.TryGetValue("description", out object objActivityDescription))
            {
                activityDescription = await _realWorkfolwActivityResolve.Execute(activity.Configuration);

                lock (activity)
                {
                    activity.Extensions["description"] = activityDescription;
                }
            }
            else
            {
                activityDescription = (RealWorkfolwActivityDescription)objActivityDescription;
            }

            var outputObjects = await _realWorkfolwActivityCalculate.Execute(activityDescription, context, new Dictionary <string, object>());

            //context.ActivityOutputParameters[activity.ID.ToString()] = outputObjects;

            return(outputObjects);
        }
        public async Task ExecuteMatch(List <RealWorkfolwActivityDescription> descriptions, RealWorkfolwContext context)
        {
            foreach (var matchItem in descriptions)
            {
                var matchItemResult = await _realWorkfolwActivityCalculate.Execute(matchItem, context, new Dictionary <string, object>());

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

                    lock (outputResutList)
                    {
                        outputResutList.Add(resultItem.Value);
                    }
                }
            }
        }
Exemple #3
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);
        }