protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();

            var allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                var expression            = Expression ?? string.Empty;
                var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty;
                var decimalPlacesToShow   = DecimalPlacesToShow ?? string.Empty;

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(expression, "Number", dataObject.Environment);
                    if (!String.IsNullOrEmpty(RoundingType))
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams(RoundingType, "Rounding"));
                    }
                    AddDebugInputItem(roundingDecimalPlaces, "Rounding Value", dataObject.Environment);
                    AddDebugInputItem(decimalPlacesToShow, "Decimals to show", dataObject.Environment);
                }
                var colItr                        = new WarewolfListIterator();
                var expressionIterator            = CreateDataListEvaluateIterator(expression, dataObject.Environment);
                var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, dataObject.Environment);
                var decimalPlacesToShowIterator   = CreateDataListEvaluateIterator(decimalPlacesToShow, dataObject.Environment);
                colItr.AddVariableToIterateOn(expressionIterator);
                colItr.AddVariableToIterateOn(roundingDecimalPlacesIterator);
                colItr.AddVariableToIterateOn(decimalPlacesToShowIterator);
                // Loop data ;)
                var rule   = new IsSingleValueRule(() => Result);
                var single = rule.Check();

                while (colItr.HasMoreData())
                {
                    int decimalPlacesToShowValue;
                    var tmpDecimalPlacesToShow = colItr.FetchNextValue(decimalPlacesToShowIterator);
                    var adjustDecimalPlaces    = tmpDecimalPlacesToShow.IsRealNumber(out decimalPlacesToShowValue);
                    if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces)
                    {
                        throw new Exception("Decimals to show is not valid");
                    }

                    var tmpDecimalPlaces           = colItr.FetchNextValue(roundingDecimalPlacesIterator);
                    var roundingDecimalPlacesValue = 0;
                    if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue))
                    {
                        throw new Exception("Rounding decimal places is not valid");
                    }

                    var            binaryDataListItem = colItr.FetchNextValue(expressionIterator);
                    var            val            = binaryDataListItem;
                    FormatNumberTO formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue);
                    var            result         = _numberFormatter.Format(formatNumberTo);

                    if (single != null)
                    {
                        allErrors.AddError(single.Message);
                    }
                    else
                    {
                        UpdateResultRegions(dataObject.Environment, result);
                        if (dataObject.IsDebugMode())
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams(result, Result, "", "="));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFNumberFormatActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfNumberFormatActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }
            }
        }
#pragma warning disable S1541 // Methods and properties should not be too complex
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            var allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                var expression            = Expression ?? string.Empty;
                var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty;
                var decimalPlacesToShow   = DecimalPlacesToShow ?? string.Empty;

                AddDebugInputItems(dataObject, update, expression, roundingDecimalPlaces, decimalPlacesToShow);
                var colItr                        = new WarewolfListIterator();
                var expressionIterator            = CreateDataListEvaluateIterator(expression, dataObject.Environment, update);
                var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, dataObject.Environment, update);
                var decimalPlacesToShowIterator   = CreateDataListEvaluateIterator(decimalPlacesToShow, dataObject.Environment, update);
                colItr.AddVariableToIterateOn(expressionIterator);
                colItr.AddVariableToIterateOn(roundingDecimalPlacesIterator);
                colItr.AddVariableToIterateOn(decimalPlacesToShowIterator);
                // Loop data ;)
                var rule    = new IsSingleValueRule(() => Result);
                var single  = rule.Check();
                var counter = 1;
                while (colItr.HasMoreData())
                {
                    var tmpDecimalPlacesToShow = colItr.FetchNextValue(decimalPlacesToShowIterator);
                    var adjustDecimalPlaces    = tmpDecimalPlacesToShow.IsRealNumber(out int decimalPlacesToShowValue);
                    if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces)
                    {
                        throw new Exception(ErrorResource.DecimalsNotValid);
                    }

                    var tmpDecimalPlaces           = colItr.FetchNextValue(roundingDecimalPlacesIterator);
                    var roundingDecimalPlacesValue = 0;
                    if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue))
                    {
                        throw new Exception(ErrorResource.RoundingNotValid);
                    }
                    string result;
                    var    binaryDataListItem = colItr.FetchNextValue(expressionIterator);
                    var    val = binaryDataListItem;
                    {
                        var formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue);
                        result = _numberFormatter.Format(formatNumberTo);
                    }


                    if (single != null)
                    {
                        allErrors.AddError(single.Message);
                    }
                    else
                    {
                        UpdateResultRegions(dataObject.Environment, result, update == 0 ? counter : update);
                        counter++;
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFNumberFormatActivity", e, GlobalConstants.WarewolfError);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    DisplayAndWriteError(dataObject, DisplayName, allErrors);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Пример #3
0
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            var dataObject = context.GetExtension <IDSFDataObject>();
            var compiler   = DataListFactory.CreateDataListCompiler();

            var           allErrors = new ErrorResultTO();
            ErrorResultTO errors;

            var executionId = DataListExecutionID.Get(context);
            var toUpsert    = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug = dataObject.IsDebugMode();
            InitializeDebug(dataObject);
            try
            {
                var expression            = Expression ?? string.Empty;
                var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty;
                var decimalPlacesToShow   = DecimalPlacesToShow ?? string.Empty;
                var colItr                        = Dev2ValueObjectFactory.CreateIteratorCollection();
                var expressionIterator            = CreateDataListEvaluateIterator(expression, executionId, compiler, colItr, allErrors);
                var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, executionId, compiler, colItr, allErrors);
                var decimalPlacesToShowIterator   = CreateDataListEvaluateIterator(decimalPlacesToShow, executionId, compiler, colItr, allErrors);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(expression, "Number", expressionIterator.FetchEntry(), executionId);
                    if (!String.IsNullOrEmpty(RoundingType))
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams(RoundingType, "Rounding"));
                    }
                    AddDebugInputItem(roundingDecimalPlaces, "Rounding Value", roundingDecimalPlacesIterator.FetchEntry(), executionId);
                    AddDebugInputItem(decimalPlacesToShow, "Decimals to show", decimalPlacesToShowIterator.FetchEntry(), executionId);
                }
                // Loop data ;)
                var rule   = new IsSingleValueRule(() => Result);
                var single = rule.Check();

                while (colItr.HasMoreData())
                {
                    int decimalPlacesToShowValue;
                    var tmpDecimalPlacesToShow = colItr.FetchNextRow(decimalPlacesToShowIterator).TheValue;
                    var adjustDecimalPlaces    = tmpDecimalPlacesToShow.IsRealNumber(out decimalPlacesToShowValue);
                    if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces)
                    {
                        throw new Exception("Decimals to show is not valid");
                    }


                    var tmpDecimalPlaces           = colItr.FetchNextRow(roundingDecimalPlacesIterator).TheValue;
                    var roundingDecimalPlacesValue = 0;
                    if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue))
                    {
                        throw new Exception("Rounding decimal places is not valid");
                    }

                    var            binaryDataListItem = colItr.FetchNextRow(expressionIterator);
                    var            val            = binaryDataListItem.TheValue;
                    FormatNumberTO formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue);
                    var            result         = _numberFormatter.Format(formatNumberTo);

                    if (single != null)
                    {
                        allErrors.AddError(single.Message);
                    }
                    else
                    {
                        UpdateResultRegions(toUpsert, result);
                    }
                }
                compiler.Upsert(executionId, toUpsert, out errors);
                allErrors.MergeErrors(errors);
                if (!allErrors.HasErrors())
                {
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFNumberFormatActivity", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfNumberFormatActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }