public static string ExtractData(string val) { if (val.IndexOf(GlobalConstants.InjectedSwitchDataFetch, StringComparison.Ordinal) >= 0) { var start = val.IndexOf("(", StringComparison.Ordinal); if (start > 0) { var end = val.IndexOf(@""",AmbientData", StringComparison.Ordinal); if (end > start) { start += 2; val = val.Substring(start, end - start); val = Dev2DecisionStack.FromVBPersitableModelToJSON(val); } } } return(val); }
public static string ExtractData(string val) { if (val.IndexOf(GlobalConstants.InjectedSwitchDataFetch, StringComparison.Ordinal) >= 0) { // Time to extract the data int start = val.IndexOf("(", StringComparison.Ordinal); if (start > 0) { int end = val.IndexOf(@""",AmbientData", StringComparison.Ordinal); if (end > start) { start += 2; val = val.Substring(start, (end - start)); // Convert back for usage ;) val = Dev2DecisionStack.FromVBPersitableModelToJSON(val); } } } return(val); }
IEnumerable <IDev2Activity> ParseDecision(FlowDecision decision, List <IDev2Activity> seenActivities) { var activity = decision.Condition as DsfFlowDecisionActivity; if (activity != null) { if (seenActivities.Contains(activity)) { return(new List <IDev2Activity> { activity }); } var rawText = activity.ExpressionText; // ReSharper disable MaximumChainedReferences var activityTextjson = rawText.Substring(rawText.IndexOf("{", StringComparison.Ordinal)).Replace(@""",AmbientDataList)", "").Replace("\"", "!"); // ReSharper restore MaximumChainedReferences var activityText = Dev2DecisionStack.FromVBPersitableModelToJSON(activityTextjson); var decisionStack = JsonConvert.DeserializeObject <Dev2DecisionStack>(activityText); var dec = new DsfDecision(activity); if (!seenActivities.Contains(activity)) { seenActivities.Add(dec); } dec.TrueArm = ParseTools(decision.True, seenActivities); dec.FalseArm = ParseTools(decision.False, seenActivities); dec.Conditions = decisionStack; dec.And = decisionStack.Mode == Dev2DecisionMode.AND; return(new List <IDev2Activity> { dec }); } throw new Exception("Invalid activity"); }
public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData, int update) { var dlId = FetchDataListID(oldAmbientData); var newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload); var dds = EvaluateRegion(newDecisionData, dlId, update); var env = Dev2DataListDecisionHandler._environments[dlId]; if (dds != null) { if (dlId != GlobalConstants.NullDataListID) { try { if (dds.TheStack != null) { for (int i = 0; i < dds.TotalDecisions; i++) { var dd = dds.GetModelItem(i); var typeOf = dd.EvaluationFn; // Treat Errors special if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError) { dd.Col1 = env.FetchErrors(); } var op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf); if (op != null) { try { var result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray()); if (!result && dds.Mode == Dev2DecisionMode.AND) { // Naughty stuff, we have a false in AND mode... break return(false); } if (result && dds.Mode == Dev2DecisionMode.OR) { return(true); } } catch (Exception e) { // An error, push into the DL env.AddError(e.Message); return(false); } } else { throw new InvalidExpressionException(string.Format(ErrorResource.CouldNotEvaluateDecisionData, typeOf)); } } // else we are in AND mode and all have passed ;) if (dds.Mode == Dev2DecisionMode.AND) { return(true); } //finally, it must be OR mode with no matches ;( return(false); } throw new InvalidExpressionException(ErrorResource.InvalidModelDataSent); } catch { // all hell has broken loose... ;) throw new InvalidExpressionException(ErrorResource.NoModelDataSent); } } throw new InvalidExpressionException(ErrorResource.NoDataListIDsent); } throw new InvalidExpressionException(ErrorResource.DataListErrors); }
// Guid dlID /// <summary> /// Executes the decision stack. /// </summary> /// <param name="decisionDataPayload">The decision data payload.</param> /// <param name="oldAmbientData">The old ambient data.</param> /// <returns></returns> /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [ + typeOf + ]</exception> public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData) { Guid dlId = FetchDataListID(oldAmbientData); // if(dlId == GlobalConstants.NullDataListID) throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload); var dds = EvaluateRegion(newDecisionData, dlId); var env = _environments[dlId]; if (dds != null) { if (dlId != GlobalConstants.NullDataListID) { try { if (dds.TheStack != null) { for (int i = 0; i < dds.TotalDecisions; i++) { Dev2Decision dd = dds.GetModelItem(i); enDecisionType typeOf = dd.EvaluationFn; // Treat Errors special if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError) { dd.Col1 = String.Join("", env.Errors); } IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf); if (op != null) { try { bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray()); if (!result && dds.Mode == Dev2DecisionMode.AND) { // Naughty stuff, we have a false in AND mode... break return(false); } if (result && dds.Mode == Dev2DecisionMode.OR) { return(true); } } catch (Exception e) { // An error, push into the DL env.AddError(e.Message); return(false); } } else { throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]"); } } // else we are in AND mode and all have passed ;) if (dds.Mode == Dev2DecisionMode.AND) { return(true); } //finally, it must be OR mode with no matches ;( return(false); } throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!"); } catch { // all hell has broken loose... ;) throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!"); } } throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } throw new InvalidExpressionException("Could not populate decision model - DataList Errors!"); }
// Guid dlID /// <summary> /// Executes the decision stack. /// </summary> /// <param name="decisionDataPayload">The decision data payload.</param> /// <param name="oldAmbientData">The old ambient data.</param> /// <returns></returns> /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [ + typeOf + ]</exception> public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData) { // Evaluate decisionDataPayload through the EvaluateFunction ;) Guid dlId = FetchDataListID(oldAmbientData); if (dlId == GlobalConstants.NullDataListID) { throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } // Swap out ! with a new internal token to avoid nasty issues with string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload); var dds = EvaluateRegion(newDecisionData, dlId); ErrorResultTO errors = new ErrorResultTO(); if (dds != null) { if (dlId != GlobalConstants.NullDataListID) { try { if (dds.TheStack != null) { for (int i = 0; i < dds.TotalDecisions; i++) { Dev2Decision dd = dds.GetModelItem(i); enDecisionType typeOf = dd.EvaluationFn; // Treat Errors special if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError) { dd.Col1 = Compiler.EvaluateSystemEntry(dlId, enSystemTag.Dev2Error, out errors); } IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf); if (op != null) { try { bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray()); if (!result && dds.Mode == Dev2DecisionMode.AND) { // Naughty stuff, we have a false in AND mode... break return(false); } if (result && dds.Mode == Dev2DecisionMode.OR) { return(true); } } catch (Exception e) { // An error, push into the DL ErrorResultTO errorErrors; errors.AddError(e.Message); Compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, errors.MakeDataListReady(), out errorErrors); return(false); } } else { throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]"); } } // else we are in AND mode and all have passed ;) if (dds.Mode == Dev2DecisionMode.AND) { return(true); } //finally, it must be OR mode with no matches ;( return(false); } throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!"); } catch { // all hell has broken loose... ;) throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!"); } } throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!"); } throw new InvalidExpressionException("Could not populate decision model - DataList Errors!"); }