Exemple #1
0
        public void TryCompare_Seconds_Equal_Expected_One_Seconds()
        {
            string result;
            string error;

            _input2     = "2011/06/05 08:20:31:123 AM";
            _outputType = "Seconds";
            IDateTimeComparer comparer       = DateTimeConverterFactory.CreateComparer();
            IDateTimeDiffTO   dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, _input2, InputFormat, _outputType);

            comparer.TryCompare(dateTimeResult, out result, out error);
            Assert.IsTrue(result == "1");
        }
Exemple #2
0
        public void TryCompare_Minutes_One_Over_Expected_One_Minutes()
        {
            string result;
            string error;

            _input2     = "2011/06/05 08:21:30:124 AM";
            _outputType = "Minutes";
            IDateTimeComparer comparer       = DateTimeConverterFactory.CreateComparer();
            IDateTimeDiffTO   dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, _input2, InputFormat, _outputType);

            comparer.TryCompare(dateTimeResult, out result, out error);
            Assert.IsTrue(result == "1");
        }
Exemple #3
0
        public void TryCompare_Hours_One_Short_Expected_Zero_Hours()
        {
            string result;
            string error;

            _input2     = "2011/06/05 09:20:30:122 AM";
            _outputType = "Hours";
            IDateTimeComparer comparer       = DateTimeConverterFactory.CreateComparer();
            IDateTimeDiffTO   dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, _input2, InputFormat, _outputType);

            comparer.TryCompare(dateTimeResult, out result, out error);
            Assert.IsTrue(result == "0");
        }
Exemple #4
0
        public void TryCompare_Weeks_Negative_Expected_NegativeOne_Weeks()
        {
            string result;
            string error;

            _input2     = "2011/05/28 08:20:30:123 AM";
            _outputType = "Weeks";
            IDateTimeComparer comparer       = DateTimeConverterFactory.CreateComparer();
            IDateTimeDiffTO   dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, _input2, InputFormat, _outputType);

            comparer.TryCompare(dateTimeResult, out result, out error);
            Assert.AreEqual("-2", result);
        }
Exemple #5
0
        public void TryCompare_Days_Negative_Expected_NegativeOne_Days()
        {
            string result;
            string error;

            _input2     = "2011/06/04 08:20:30:123 AM";
            _outputType = "Days";
            IDateTimeComparer comparer       = DateTimeConverterFactory.CreateComparer();
            IDateTimeDiffTO   dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, _input2, InputFormat, _outputType);

            comparer.TryCompare(dateTimeResult, out result, out error);
            Assert.IsTrue(result == "-1");
        }
        protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            // Process if no errors
            try
            {
                if (dataObject.IsDebugMode())
                {
                    if (string.IsNullOrEmpty(Input1))
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(CultureInfo.CurrentCulture), "now()", "Input 1", "="));
                    }
                    else
                    {
                        AddDebugInputItem(Input1, "Input 1", dataObject.Environment);
                    }

                    if (string.IsNullOrEmpty(Input2))
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(CultureInfo.CurrentCulture), "now()", "Input 2", "="));
                    }
                    else
                    {
                        AddDebugInputItem(Input2, "Input 2", dataObject.Environment);
                    }

                    AddDebugInputItem(InputFormat, "Input Format", dataObject.Environment);
                    if (!String.IsNullOrEmpty(OutputType))
                    {
                        AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In"));
                    }
                }
                var colItr = new WarewolfListIterator();

                var input1Itr = new WarewolfIterator(dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1));
                colItr.AddVariableToIterateOn(input1Itr);

                var evalInp2 = dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2);

                var input2Itr = new WarewolfIterator(evalInp2);
                colItr.AddVariableToIterateOn(input2Itr);

                var ifItr = new WarewolfIterator(dataObject.Environment.Eval(InputFormat ?? string.Empty));
                colItr.AddVariableToIterateOn(ifItr);
                int indexToUpsertTo = 1;

                while (colItr.HasMoreData())
                {
                    IDateTimeDiffTO transObj = ConvertToDateTimeDiffTo(colItr.FetchNextValue(input1Itr),
                                                                       colItr.FetchNextValue(input2Itr),
                                                                       colItr.FetchNextValue(ifItr),
                                                                       OutputType);
                    //Create a DateTimeComparer using the DateTimeConverterFactory
                    IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer();
                    //Call the TryComparer method on the DateTimeComparer and pass it the IDateTimeDiffTO created from the ConvertToDateTimeDiffTO Method
                    string result;
                    string error;
                    string expression = Result;
                    if (comparer.TryCompare(transObj, out result, out error))
                    {
                        if (DataListUtil.IsValueRecordset(Result) &&
                            DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star)
                        {
                            expression = Result.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            expression = Result;
                        }

                        var rule   = new IsSingleValueRule(() => Result);
                        var single = rule.Check();
                        if (single != null)
                        {
                            allErrors.AddError(single.Message);
                        }
                        else
                        {
                            dataObject.Environment.Assign(expression, result);
                        }
                    }
                    else
                    {
                        DoDebugOutput(dataObject, expression);
                        allErrors.AddError(error);
                    }
                    indexToUpsertTo++;
                }

                allErrors.MergeErrors(errors);
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, null, dataObject.Environment));
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDateTime", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfDateTimeDifferenceActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    dataObject.Environment.Assign(Result, null);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }
            }
        }
Exemple #7
0
        // ReSharper restore RedundantOverridenMember

        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>();



            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            allErrors.MergeErrors(errors);
            InitializeDebug(dataObject);
            // Process if no errors
            try
            {
                IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

                toUpsert.IsDebug = dataObject.IsDebugMode();
                IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection();
                var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString();
                if (!string.IsNullOrEmpty(datalist))
                {
                    ValidateInput(datalist, allErrors, Input1);
                    ValidateInput(datalist, allErrors, Input2);
                }
                IBinaryDataListEntry input1Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator input1Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input1Entry);
                colItr.AddIterator(input1Itr);

                IBinaryDataListEntry input2Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator input2Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input2Entry);
                colItr.AddIterator(input2Itr);

                IBinaryDataListEntry inputFormatEntry = compiler.Evaluate(executionId, enActionType.User, InputFormat ?? string.Empty, false, out errors);
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator ifItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputFormatEntry);
                colItr.AddIterator(ifItr);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, "Input 1", input1Entry, executionId);
                    AddDebugInputItem(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, "Input 2", input2Entry, executionId);
                    AddDebugInputItem(InputFormat, "Input Format", inputFormatEntry, executionId);
                    AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In"));
                }

                int indexToUpsertTo = 1;

                while (colItr.HasMoreData())
                {
                    IDateTimeDiffTO transObj = ConvertToDateTimeDiffTo(colItr.FetchNextRow(input1Itr).TheValue,
                                                                       colItr.FetchNextRow(input2Itr).TheValue,
                                                                       colItr.FetchNextRow(ifItr).TheValue,
                                                                       OutputType);
                    //Create a DateTimeComparer using the DateTimeConverterFactory
                    IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer();
                    //Call the TryComparer method on the DateTimeComparer and pass it the IDateTimeDiffTO created from the ConvertToDateTimeDiffTO Method
                    string result;
                    string error;
                    if (comparer.TryCompare(transObj, out result, out error))
                    {
                        string expression;
                        if (DataListUtil.IsValueRecordset(Result) &&
                            DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star)
                        {
                            expression = Result.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                        }
                        else
                        {
                            expression = Result;
                        }

                        //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                        var rule   = new IsSingleValueRule(() => Result);
                        var single = rule.Check();
                        if (single != null)
                        {
                            allErrors.AddError(single.Message);
                        }
                        else
                        {
                            toUpsert.Add(expression, result);
                        }
                    }
                    else
                    {
                        DoDebugOutput(dataObject, Result, result, executionId, indexToUpsertTo);
                        allErrors.AddError(error);
                    }
                    indexToUpsertTo++;
                }

                compiler.Upsert(executionId, toUpsert, out errors);
                allErrors.MergeErrors(errors);
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDateTime", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfDateTimeDifferenceActivity", 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);
                }
            }
        }