예제 #1
0
        public override IEnumerable <IDev2Activity> GetNextNodes()
        {
            var nextNodes = new List <IDev2Activity>();

            if (TrueArm != null)
            {
                nextNodes.Add(TrueArm?.FirstOrDefault());
            }
            if (FalseArm != null)
            {
                nextNodes.Add(FalseArm?.FirstOrDefault());
            }
            return(nextNodes);
        }
예제 #2
0
        public override IDev2Activity Execute(IDSFDataObject dataObject, int update)
        {
            ErrorResultTO allErrors = new ErrorResultTO();

            try
            {
                InitializeDebug(dataObject);


                if (dataObject.IsDebugMode())
                {
                    _debugInputs = CreateDebugInputs(dataObject.Environment);
                    DispatchDebugState(dataObject, StateType.Before, 0);
                }

                var stack = Conditions.TheStack.Select(a => ParseDecision(dataObject.Environment, a));


                var factory = Dev2DecisionFactory.Instance();
                var res     = stack.SelectMany(a =>
                {
                    if (a.EvaluationFn == enDecisionType.IsError)
                    {
                        return(new[] { dataObject.Environment.AllErrors.Count > 0 });
                    }
                    if (a.EvaluationFn == enDecisionType.IsNotError)
                    {
                        return(new[] { dataObject.Environment.AllErrors.Count == 0 });
                    }
                    IList <bool> ret = new List <bool>();
                    var iter         = new WarewolfListIterator();
                    var c1           = new WarewolfAtomIterator(a.Cols1);
                    var c2           = new WarewolfAtomIterator(a.Cols2);
                    var c3           = new WarewolfAtomIterator(a.Cols3);
                    iter.AddVariableToIterateOn(c1);
                    iter.AddVariableToIterateOn(c2);
                    iter.AddVariableToIterateOn(c3);
                    while (iter.HasMoreData())
                    {
                        ret.Add(factory.FetchDecisionFunction(a.EvaluationFn).Invoke(new[] { iter.FetchNextValue(c1), iter.FetchNextValue(c2), iter.FetchNextValue(c3) }));
                    }
                    return(ret);
                });
                var resultval = And ? res.Aggregate(true, (a, b) => a && b) : res.Any(a => a);
                if (dataObject.IsDebugMode())
                {
                    _debugOutputs = GetDebugOutputs(resultval.ToString());
                }

                if (resultval)
                {
                    if (TrueArm != null)
                    {
                        var activity = TrueArm.FirstOrDefault();
                        return(activity);
                    }
                }
                else
                {
                    if (FalseArm != null)
                    {
                        var activity = FalseArm.FirstOrDefault();
                        return(activity);
                    }
                }
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDeleteRecordsActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }
            }
            if (dataObject.IsDebugMode())
            {
                _debugOutputs = new List <DebugItem>();
                _debugOutputs = new List <DebugItem>();
                DispatchDebugState(dataObject, StateType.Duration, update);
            }
            return(null);
        }
예제 #3
0
#pragma warning disable S1541 // Methods and properties should not be too complex
#pragma warning disable S3776 // Cognitive Complexity of methods should not be too high
        IDev2Activity ExecuteDecision(IDSFDataObject dataObject)
#pragma warning restore S3776 // Cognitive Complexity of methods should not be too high
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            InitializeDebug(dataObject);

            if (dataObject.IsDebugMode())
            {
                _debugInputs = CreateDebugInputs(dataObject.Environment);
                DispatchDebugState(dataObject, StateType.Before, 0);
            }

            var errorIfNull = !Conditions.TheStack.Any(decision => decision.EvaluationFn == enDecisionType.IsNull || decision.EvaluationFn == enDecisionType.IsNotNull);

            var stack = Conditions.TheStack.Select(a => ParseDecision(dataObject.Environment, a, errorIfNull));

            var factory = Dev2DecisionFactory.Instance();
            var res     = stack.SelectMany(a =>
            {
                if (a.EvaluationFn == enDecisionType.IsError)
                {
                    return(new[] { dataObject.Environment.AllErrors.Count > 0 });
                }
                if (a.EvaluationFn == enDecisionType.IsNotError)
                {
                    return(new[] { dataObject.Environment.AllErrors.Count == 0 });
                }
                IList <bool> ret = new List <bool>();
                var iter         = new WarewolfListIterator();
                var c1           = new WarewolfAtomIterator(a.Cols1);
                var c2           = new WarewolfAtomIterator(a.Cols2);
                var c3           = new WarewolfAtomIterator(a.Cols3);
                iter.AddVariableToIterateOn(c1);
                iter.AddVariableToIterateOn(c2);
                iter.AddVariableToIterateOn(c3);
                while (iter.HasMoreData())
                {
                    try
                    {
                        ret.Add(factory.FetchDecisionFunction(a.EvaluationFn).Invoke(new[] { iter.FetchNextValue(c1), iter.FetchNextValue(c2), iter.FetchNextValue(c3) }));
                    }
                    catch (Exception)
                    {
                        if (errorIfNull)
                        {
                            throw;
                        }
                        ret.Add(false);
                    }
                }
                return(ret);
            });

            var results   = res as IList <bool> ?? res.ToList();
            var resultval = true;

            if (results.Any())
            {
                if (And)
                {
                    if (results.Any(b => !b))
                    {
                        resultval = false;
                    }
                }
                else
                {
                    resultval = results.Any(b => b);
                }
            }

            Result = GetResultString(resultval.ToString(), Conditions);
            if (dataObject.IsDebugMode())
            {
                _debugOutputs = GetDebugOutputs(resultval.ToString());
            }
            if (resultval)
            {
                if (TrueArm != null)
                {
                    var activity = TrueArm.FirstOrDefault();
                    return(activity);
                }
            }
            else
            {
                if (FalseArm != null)
                {
                    var activity = FalseArm.FirstOrDefault();
                    return(activity);
                }
            }

            return(null);
        }