public static IList <string> FindRecords(IBinaryDataList scopingObj, IRecsetSearch searchTO, out ErrorResultTO errors) { IFindRecsetOptions searchOp = FindRecsetOptions.FindMatch(searchTO.SearchType); IList <string> result = new List <string>(); errors = new ErrorResultTO(); if (searchOp != null) { Func <IList <string> > searchFn = searchOp.BuildSearchExpression(scopingObj, searchTO); if (searchFn != null) { result = searchFn.Invoke(); } } return(result); }
private IEnumerable<string> FindRecordIndexForDateTime(IEnumerable<RecordSetSearchPayload> operationRange, IRecsetSearch to, DateTime fromDateTime, DateTime toDateTime) { IList<string> fnResult = new List<string>(); foreach(RecordSetSearchPayload p in operationRange) { DateTime recDateTime; if(DateTime.TryParse(p.Payload, out recDateTime)) { if(recDateTime > fromDateTime && recDateTime < toDateTime) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if(to.RequireAllFieldsToMatch) { return new List<string>(); } } } } return fnResult; }
private static IEnumerable<string> FindRecordIndexForNumeric(IEnumerable<RecordSetSearchPayload> operationRange, IRecsetSearch to, double fromNum, double toNum) { IList<string> fnResult = new List<string>(); foreach(RecordSetSearchPayload p in operationRange) { double recNum; if(double.TryParse(p.Payload, out recNum)) { if(!(recNum > fromNum && recNum < toNum)) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if(to.RequireAllFieldsToMatch) { return new List<string>(); } } } } return fnResult; }
public override Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to) { // Default to a null function result Func <IList <string> > result = () => { ErrorResultTO err; IList <RecordSetSearchPayload> operationRange = GenerateInputRange(to, scopingObj, out err).Invoke(); IList <string> fnResult = new List <string>(); foreach (RecordSetSearchPayload p in operationRange) { if (to.MatchCase) { if (!p.Payload.StartsWith(to.SearchCriteria)) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } else { if (!p.Payload.ToLower().StartsWith(to.SearchCriteria.ToLower())) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } } return(fnResult.Distinct().ToList()); }; return(result); }
// Bug 8725 - Fixed to be double rather than int public override Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to) { Func <IList <string> > result = () => { ErrorResultTO err; IList <RecordSetSearchPayload> operationRange = GenerateInputRange(to, scopingObj, out err).Invoke(); IList <string> fnResult = new List <string>(); double search; if (double.TryParse(to.SearchCriteria, out search)) { foreach (RecordSetSearchPayload p in operationRange) { double tmp; if (double.TryParse(p.Payload, out tmp) && tmp <= search) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } } return(fnResult.Distinct().ToList()); }; return(result); }
private IEnumerable <string> FindRecordIndexForNumeric(IEnumerable <RecordSetSearchPayload> operationRange, IRecsetSearch to, double fromNum, double toNum) { IList <string> fnResult = new List <string>(); foreach (RecordSetSearchPayload p in operationRange) { double recNum; if (!double.TryParse(p.Payload, out recNum)) { continue; } if (recNum > fromNum && recNum < toNum) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } return(fnResult); }
private IEnumerable <string> FindRecordIndexForDateTime(IEnumerable <RecordSetSearchPayload> operationRange, IRecsetSearch to, DateTime fromDateTime, DateTime toDateTime) { IList <string> fnResult = new List <string>(); foreach (RecordSetSearchPayload p in operationRange) { DateTime recDateTime; if (DateTime.TryParse(p.Payload, out recDateTime)) { if (recDateTime > fromDateTime && recDateTime < toDateTime) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } } return(fnResult); }
public override Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to) { Func <IList <string> > result = () => { ErrorResultTO err; IList <RecordSetSearchPayload> operationRange = GenerateInputRange(to, scopingObj, out err).Invoke(); DateTime fromDt; if (DateTime.TryParse(to.From, out fromDt)) { DateTime toDt; if (!DateTime.TryParse(to.To, out toDt)) { throw new InvalidDataException("IsBetween Numeric and DateTime mis-match"); } return(FindRecordIndexForDateTime(operationRange, to, fromDt, toDt).Distinct().ToList()); } double fromNum; if (double.TryParse(to.From, out fromNum)) { double toNum; if (!double.TryParse(to.To, out toNum)) { throw new InvalidDataException("IsBetween Numeric and DateTime mis-match"); } return(FindRecordIndexForNumeric(operationRange, to, fromNum, toNum).Distinct().ToList()); } return(new List <string>()); }; return(result); }
/// <summary> /// Checks the validity of the input argument and returns the fields in a list of strings /// </summary> /// <param name="to">To.</param> /// <param name="bdl">The BDL.</param> /// <param name="errors">The errors.</param> /// <returns></returns> public Func <IList <RecordSetSearchPayload> > GenerateInputRange(IRecsetSearch to, IBinaryDataList bdl, out ErrorResultTO errors) { errors = new ErrorResultTO(); ErrorResultTO allErrors = new ErrorResultTO(); Func <IList <RecordSetSearchPayload> > result = () => { IList <RecordSetSearchPayload> fieldList = new List <RecordSetSearchPayload>(); string InputField = to.FieldsToSearch; string recSet = DataListUtil.ExtractRecordsetNameFromValue(DataListUtil.StripLeadingAndTrailingBracketsFromValue(InputField)); IBinaryDataListEntry bdle; string error; bdl.TryGetEntry(recSet, out bdle, out error); allErrors.AddError(error); if (bdle == null) { throw new RecordsetNotFoundException("Could not find Recordset [ " + recSet + " ]"); } IList <Dev2Column> realCols = bdle.Columns; string[] tmpCols = InputField.Replace(" ", "").Split(','); // Travis.Frisinger : 09.25.2012 // we need to adjust the tmpCols to avoid * causing crap with the match int loc = 0; foreach (string tc in tmpCols) { string recset = DataListUtil.ExtractRecordsetNameFromValue(tc); string field = DataListUtil.ExtractFieldNameFromValue(tc); string myNewSearch = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.MakeValueIntoHighLevelRecordset(recset)); if (field != string.Empty) { myNewSearch = DataListUtil.MakeValueIntoHighLevelRecordset(recset) + "." + field; } tmpCols[loc] = DataListUtil.AddBracketsToValueIfNotExist(myNewSearch); loc++; } int pos = 0; bool found = true; int start; Int32.TryParse(to.StartIndex, out start); if (start == 0) { start = 1; } while (pos < tmpCols.Length && found) { int innerPos; if (IsMatch(tmpCols[pos], recSet, realCols, out innerPos)) { for (int i = start; i <= bdle.FetchLastRecordsetIndex(); i++) { IBinaryDataListItem tmp = bdle.TryFetchRecordsetColumnAtIndex(realCols[innerPos].ColumnName, i, out error); if (error != string.Empty) { allErrors.AddError(error); } RecordSetSearchPayload p = new RecordSetSearchPayload { Index = i, Payload = tmp.TheValue }; fieldList.Add(p); } } else { if (IsRecorsetWithoutField(tmpCols[pos], recSet)) { IIndexIterator ixItr = bdle.FetchRecordsetIndexes(); while (ixItr.HasMore()) { int next = ixItr.FetchNextIndex(); foreach (Dev2Column col in realCols) { IBinaryDataListItem tmp = bdle.TryFetchRecordsetColumnAtIndex(col.ColumnName, next, out error); RecordSetSearchPayload p = new RecordSetSearchPayload { Index = next, Payload = tmp.TheValue }; fieldList.Add(p); } } } else { found = false; } } pos++; } if (!found) { fieldList.Clear(); } return(fieldList); }; return(result); }
public abstract Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to);
public override Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to) { // Default to a null function result // ReSharper disable RedundantAssignment Func <IList <string> > result = () => null; // ReSharper restore RedundantAssignment result = () => { ErrorResultTO err; IList <RecordSetSearchPayload> operationRange = GenerateInputRange(to, scopingObj, out err).Invoke(); IList <string> fnResult = new List <string>(); foreach (RecordSetSearchPayload p in operationRange) { if (!p.Payload.IsHex()) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } return(fnResult.Distinct().ToList()); }; return(result); }
// ReSharper restore RedundantOverridenMember /// <summary> /// Executes the logic of the activity and calls the backend code to do the work /// Also responsible for adding the results to the data list /// </summary> /// <param name="context"></param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = dataObject.DataListID; InitializeDebug(dataObject); try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); // Fetch all fields to search.... IList <string> toSearch = FieldsToSearch.Split(','); // now process each field for entire evaluated Where expression.... IBinaryDataListEntry bdle = compiler.Evaluate(executionId, enActionType.User, SearchCriteria, false, out errors); if (dataObject.IsDebugMode()) { var itemToAdd = new DebugItem(); itemToAdd.Add(new DebugItemResult { Type = DebugItemResultType.Label, Value = "Fields To Search" }); _debugInputs.Add(itemToAdd); } allErrors.MergeErrors(errors); if (bdle != null) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(bdle); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); int idx; if (!Int32.TryParse(StartIndex, out idx)) { idx = 1; } IBinaryDataList toSearchList = compiler.FetchBinaryDataList(executionId, out errors); allErrors.MergeErrors(errors); int iterationIndex = 0; foreach (string s in toSearch) { if (dataObject.IsDebugMode()) { IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors); AddDebugInputItem(s, string.Empty, tmpEntry, executionId); } // each entry in the recordset while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { IRecsetSearch searchTo = ConvertToSearchTo(c.TheValue, idx.ToString(CultureInfo.InvariantCulture)); IList <string> results = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errors); allErrors.MergeErrors(errors); string concatRes = string.Empty; // ReSharper disable LoopCanBeConvertedToQuery foreach (string r in results) // ReSharper restore LoopCanBeConvertedToQuery { concatRes = string.Concat(concatRes, r, ","); } if (concatRes.EndsWith(",")) { concatRes = concatRes.Remove(concatRes.Length - 1); } //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result DataListCleaningUtils.SplitIntoRegions(Result); //2013.06.07: Massimo Guerrera for BUG 9497 - To handle putting out to a scalar as a CSV if (!DataListUtil.IsValueRecordset(Result)) { toUpsert.Add(Result, concatRes); toUpsert.FlushIterationFrame(); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(Result, concatRes, executionId, iterationIndex)); } } else { iterationIndex = 0; foreach (string r in results) { toUpsert.Add(Result, r); toUpsert.FlushIterationFrame(); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(Result, r, executionId, iterationIndex)); } iterationIndex++; } } } } } if (dataObject.IsDebugMode()) { AddDebugInputItem(SearchCriteria, "Where", bdle, executionId); } // now push the result to the server compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); } } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfFindRecordsActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
public override Func <IList <string> > BuildSearchExpression(IBinaryDataList scopingObj, IRecsetSearch to) { Func <IList <string> > result = () => { ErrorResultTO err; IList <RecordSetSearchPayload> operationRange = GenerateInputRange(to, scopingObj, out err).Invoke(); IList <string> fnResult = new List <string>(); string toFind = to.SearchCriteria.Trim(); string toFindLower = toFind.ToLower(); foreach (RecordSetSearchPayload p in operationRange) { string toMatch = p.Payload.Trim(); if (to.MatchCase) { if (toMatch.Equals(toFind, StringComparison.CurrentCulture)) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } else { if (toMatch.ToLower().Equals(toFindLower, StringComparison.CurrentCulture)) { fnResult.Add(p.Index.ToString(CultureInfo.InvariantCulture)); } else { if (to.RequireAllFieldsToMatch) { return(new List <string>()); } } } } return(fnResult.Distinct().ToList()); }; return(result); }