public override bool TryCompare(IDateTimeDiffTO dateTimeDiffTo, out string result, out string error) { result = ""; error = ""; var dateTimeParser = DateTimeConverterFactory.CreateStandardParser(); var parsedCorreclty = DateTime.TryParseExact(dateTimeDiffTo.Input1, dateTimeDiffTo.InputFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate); if (parsedCorreclty) { _input1 = parsedDate; parsedCorreclty = DateTime.TryParseExact(dateTimeDiffTo.Input2, dateTimeDiffTo.InputFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate1); if (parsedCorreclty) { _input2 = parsedDate1; parsedCorreclty = OutputFormats.TryGetValue(dateTimeDiffTo.OutputType, out Func <DateTime, DateTime, double> returnedFunc); if (returnedFunc != null) { var tmpAmount = returnedFunc.Invoke(_input1, _input2); var wholeValue = Convert.ToInt64(Math.Floor(tmpAmount)); result = wholeValue.ToString(CultureInfo.InvariantCulture); } } return(parsedCorreclty); } error = ErrorResource.CannorParseInputDateTimeWithGivenFormat; return(parsedCorreclty); }
public void TryCompare_Years_Equal_Expected_One_Years() { string result; string error; OutputType = "Years"; IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); IDateTimeDiffTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, Input2, InputFormat, OutputType); comparer.TryCompare(dateTimeResult, out result, out error); Assert.IsTrue(result == "1"); }
public void TryCompare_Years_Negative_Years_Expected_NegativeOne_Years() { string result; string error; Input2 = "2010/06/05 08:20:30:124 AM"; OutputType = "Years"; IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); IDateTimeDiffTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, Input2, InputFormat, OutputType); comparer.TryCompare(dateTimeResult, out result, out error); Assert.IsTrue(result == "-1"); }
public void TryCompare_SplitSeconds_One_Over_Expected_One_SplitSeconds() { string result; string error; Input2 = "2011/06/05 08:20:30:124 AM"; OutputType = "Split Secs"; IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); IDateTimeDiffTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, Input2, InputFormat, OutputType); comparer.TryCompare(dateTimeResult, out result, out error); Assert.AreEqual("1", result); }
public void TryCompare_SplitSeconds_One_Short_Expected_Zero_SplitSeconds() { string result; string error; Input2 = "2011/06/05 08:20:30:122 AM"; OutputType = "Split Secs"; IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); IDateTimeDiffTO dateTimeResult = DateTimeConverterFactory.CreateDateTimeDiffTO(Input1, Input2, InputFormat, OutputType); comparer.TryCompare(dateTimeResult, out result, out error); Assert.IsTrue(result == "-1"); }
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"); }
public void TryCompare_Weeks_Equal_Expected_One_Weeks() { string result; string error; Input2 = "2011/06/12 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.IsTrue(result == "1"); }
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); }
public void TryCompare_Seconds_One_Over_Expected_One_Seconds() { string result; string error; _input2 = "2011/06/05 08:20:31:124 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"); }
public void TryCompare_Minutes_Negative_Expected_NegativeOne_Minutes() { string result; string error; _input2 = "2011/06/05 08:19:30:123 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"); }
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"); }
public bool TryCompare(IDateTimeDiffTO dateTimeDiffTo, out string result, out string error) { //local variable declarations result = ""; //Creation of parser to get the DateTime Objects IDateTimeParser dateTimeParser = DateTimeConverterFactory.CreateParser(); IDateTimeResultTO tmpRes; //try create the first DateTime object bool noErrorOccured = dateTimeParser.TryParseDateTime(dateTimeDiffTo.Input1, dateTimeDiffTo.InputFormat, out tmpRes, out error); if (noErrorOccured) { //Set the first DateTime object _input1 = tmpRes.ToDateTime(); //try create the second DateTime object noErrorOccured = dateTimeParser.TryParseDateTime(dateTimeDiffTo.Input2, dateTimeDiffTo.InputFormat, out tmpRes, out error); } if (noErrorOccured) { //Set the first DateTime object _input2 = tmpRes.ToDateTime(); //Try get the function according to what the OutputType is Func <DateTime, DateTime, double> returnedFunc; noErrorOccured = OutputFormats.TryGetValue(dateTimeDiffTo.OutputType, out returnedFunc); if (returnedFunc != null) { //Invoke the function the return the difference double tmpAmount = returnedFunc.Invoke(_input1, _input2); //Splits the double that is returned into a whole number and to a string long wholeValue = Convert.ToInt64(Math.Floor(tmpAmount)); result = wholeValue.ToString(CultureInfo.InvariantCulture); } } return(noErrorOccured); }
public bool TryCompare(IDateTimeDiffTO dateTimeDiffTo, out string result, out string error) { //local variable declarations result = ""; //Creation of parser to get the DateTime Objects IDateTimeParser dateTimeParser = DateTimeConverterFactory.CreateParser(); IDateTimeResultTO tmpRes; //try create the first DateTime object bool noErrorOccured = dateTimeParser.TryParseDateTime(dateTimeDiffTo.Input1, dateTimeDiffTo.InputFormat, out tmpRes, out error); if (noErrorOccured) { //Set the first DateTime object _input1 = tmpRes.ToDateTime(); //try create the second DateTime object noErrorOccured = dateTimeParser.TryParseDateTime(dateTimeDiffTo.Input2, dateTimeDiffTo.InputFormat, out tmpRes, out error); } if (noErrorOccured) { //Set the first DateTime object _input2 = tmpRes.ToDateTime(); //Try get the function according to what the OutputType is Func<DateTime, DateTime, double> returnedFunc; noErrorOccured = OutputFormats.TryGetValue(dateTimeDiffTo.OutputType, out returnedFunc); if (returnedFunc != null) { //Invoke the function the return the difference double tmpAmount = returnedFunc.Invoke(_input1, _input2); //Splits the double that is returned into a whole number and to a string long wholeValue = Convert.ToInt64(Math.Floor(tmpAmount)); result = wholeValue.ToString(CultureInfo.InvariantCulture); } } return noErrorOccured; }
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); } } }
// 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); } } }