public void AttachItemPropertyWithDelegateNull() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemPropertySI<DebugItemProperty1, DebugItemStateProperty1, DebugItemInfoProperty1>(extensionPack, "Debug"); // Attach Property mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug", (i) => { return null; }); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(0, item.Properties.Count()); }
public void AttachItemProperty() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemPropertySI<DebugItemProperty1, DebugItemStateProperty1, DebugItemInfoProperty1>(extensionPack, "Debug"); // Attach Property mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty<DebugItemProperty1>(); Assert.IsNotNull(prop); }
private int AssignField(IDSFDataObject dataObject, int update, int innerCount, AssignObjectDTO t) { if (!string.IsNullOrEmpty(t.FieldName)) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignJson(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank) { var length = dataObject.Environment.GetObjectLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceObjectBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } } innerCount++; return(innerCount); }
private static void CreateDebugState(string result, string workflowName, string taskName) { string user = Thread.CurrentPrincipal.Identity.Name.Replace("\\", "-"); var state = new DebugState { HasError = true, ID = Guid.NewGuid(), Message = string.Format("{0}", result), StartTime = DateTime.Now, EndTime = DateTime.Now, ErrorMessage = string.Format("{0}", result), DisplayName = workflowName }; var debug = new DebugItem(); debug.Add(new DebugItemResult { Type = DebugItemResultType.Label, Value = "Warewolf Execution Error:", Label = "Scheduler Execution Error", Variable = result }); var js = new Dev2JsonSerializer(); Thread.Sleep(5000); string correlation = GetCorrelationId(WarewolfTaskSchedulerPath + taskName); if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } File.WriteAllText( string.Format("{0}DebugItems_{1}_{2}_{3}_{4}.txt", OutputPath, workflowName.Replace("\\", "_"), DateTime.Now.ToString("yyyy-MM-dd"), correlation, user), js.SerializeToBuilder(new List <DebugState> { state }).ToString()); }
void AddDebugInputValues(IDSFDataObject dataObject, IEnumerable <string> toSearch, IDataListCompiler compiler, Guid executionId, ref ErrorResultTO errorTos) { if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "In Field(s)"), debugItem); foreach (var s in toSearch) { var searchFields = s; if (DataListUtil.IsValueRecordset(s)) { searchFields = searchFields.Replace("()", "(*)"); } IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, searchFields, false, out errorTos); AddDebugItem(new DebugItemVariableParams(searchFields, "", tmpEntry, executionId), debugItem); } _debugInputs.Add(debugItem); AddResultDebugInputs(ResultsCollection, executionId, compiler); AddDebugInputItem(new DebugItemStaticDataParams(RequireAllFieldsToMatch ? "YES" : "NO", "Require All Fields To Match")); AddDebugInputItem(new DebugItemStaticDataParams(RequireAllTrue ? "YES" : "NO", "Require All Matches To Be True")); } }
public void DebugItem_GroupIndex_Greater_And_Equal_To_MaxItemDispatchCount() { var oldWebServerUri = EnvironmentVariables.WebServerUri; try { EnvironmentVariables.WebServerUri = "http://localhost:3142"; var item = new DebugItem(); item.Add(new DebugItemResult { GroupIndex = 11, GroupName = "Hello", Value = "world" }); Assert.AreEqual(1, item.ResultsList.Count); Assert.AreEqual(11, item.ResultsList[0].GroupIndex); Assert.AreEqual("Hello", item.ResultsList[0].GroupName); Assert.IsFalse(item.ResultsList[0].HasError); Assert.AreEqual("world", item.ResultsList[0].Value); Assert.IsTrue(item.ResultsList[0].MoreLink.StartsWith("http://localhost:3142/Services/FetchDebugItemFileService?DebugItemFilePath=C:\\ProgramData\\Warewolf\\Temp\\Warewolf\\Debug\\", StringComparison.Ordinal), "Expected " + item.ResultsList[0].MoreLink); } finally { EnvironmentVariables.WebServerUri = oldWebServerUri; } }
public void DebugItem_With_Results_AddRange_Matching_Label() { var results = new[] { new DebugItemResult(), new DebugItemResult { GroupName = "group1", GroupIndex = 1, Type = DebugItemResultType.Variable } }; var item = new DebugItem(results); Assert.AreEqual(1, item.ResultsList.Count); Assert.AreEqual(0, item.ResultsList[0].GroupIndex); Assert.IsNull(item.ResultsList[0].GroupName); Assert.IsFalse(item.ResultsList[0].HasError); Assert.IsNull(item.ResultsList[0].Value); Assert.IsNull(item.ResultsList[0].MoreLink); }
void GetTestOurputResultForDebug(IDSFDataObject dataObject) { var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.ActivityID == _originalUniqueID); var serviceTestSteps = serviceTestStep?.Children; UpdateDebugStateWithAssertions(dataObject, serviceTestSteps?.ToList()); if (serviceTestStep != null) { var testRunResult = new TestRunResult(); GetFinalTestRunResult(serviceTestStep, testRunResult, dataObject); serviceTestStep.Result = testRunResult; var debugItems = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName); debugItems = debugItems.Where(state => state.WorkSurfaceMappingId == serviceTestStep.ActivityID).ToList(); var debugStates = debugItems.LastOrDefault(); var debugItemStaticDataParams = new DebugItemServiceTestStaticDataParams(serviceTestStep.Result.Message, serviceTestStep.Result.RunTestResult == RunResult.TestFailed); var itemToAdd = new DebugItem(); itemToAdd.AddRange(debugItemStaticDataParams.GetDebugItemResult()); debugStates?.AssertResultList?.Add(itemToAdd); } }
/// <summary> /// Fetches the type of the execution. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="dlId">The dl ID.</param> /// <param name="compiler">The compiler.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private ForEachBootstrapTO FetchExecutionType(IDSFDataObject dataObject, Guid dlId, IDataListCompiler compiler, out ErrorResultTO errors) { if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(ForEachType.GetDescription(), ""), debugItem); if (ForEachType == enForEachType.NumOfExecution && !string.IsNullOrEmpty(NumOfExections)) { IBinaryDataListEntry numOfExectionsEntry = compiler.Evaluate(dlId, enActionType.User, NumOfExections, false, out errors); AddDebugItem(new DebugItemVariableParams(NumOfExections, "Number", numOfExectionsEntry, dlId), debugItem); } if (ForEachType == enForEachType.InCSV && !string.IsNullOrEmpty(CsvIndexes)) { IBinaryDataListEntry csvIndexesEntry = compiler.Evaluate(dlId, enActionType.User, CsvIndexes, false, out errors); AddDebugItem(new DebugItemVariableParams(CsvIndexes, "Csv Indexes", csvIndexesEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRange && !string.IsNullOrEmpty(From)) { IBinaryDataListEntry fromEntry = compiler.Evaluate(dlId, enActionType.User, From, false, out errors); AddDebugItem(new DebugItemVariableParams(From, "From", fromEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRange && !string.IsNullOrEmpty(To)) { IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, To, false, out errors); AddDebugItem(new DebugItemVariableParams(To, "To", toEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRecordset && !string.IsNullOrEmpty(Recordset)) { var toEmit = Recordset.Replace("()", "(*)"); IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, toEmit, false, out errors); AddDebugItem(new DebugItemVariableParams(toEmit, "Recordset", toEntry, dlId), debugItem); } _debugInputs.Add(debugItem); } var result = new ForEachBootstrapTO(ForEachType, From, To, CsvIndexes, NumOfExections, Recordset, dlId, compiler, out errors); return(result); }
void AddInputDebug(IExecutionEnvironment env, int update) { if (FilterCriteria != null && FilterCriteria.Any()) { var requireAllCriteriaToMatch = RequireAllCriteriaToMatch ? "Yes" : "No"; foreach (var varDebug in FilterCriteria) { if (string.IsNullOrEmpty(varDebug.FieldName)) { return; } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", _indexCounter.ToString(CultureInfo.InvariantCulture)), debugItem); var fieldName = varDebug.FieldName; if (!string.IsNullOrEmpty(fieldName)) { AddDebugItem(new DebugEvalResult(fieldName, "Field Name", env, update), debugItem); //AddDebugItem(new DebugItemStaticDataParams(varDebug.FieldName, "Field Name"), debugItem); } var searchType = varDebug.SearchType; if (!string.IsNullOrEmpty(searchType)) { AddDebugItem(new DebugEvalResult(searchType, "Search Type", env, update), debugItem); } var valueToMatch = varDebug.ValueToMatch; if (!string.IsNullOrEmpty(valueToMatch)) { AddDebugItem(new DebugEvalResult(valueToMatch, "Value", env, update), debugItem); } AddDebugItem(new DebugEvalResult(requireAllCriteriaToMatch, "Require All Criteria To Match", env, update), debugItem); _indexCounter++; _debugInputs.Add(debugItem); } } }
// Travis.Frisinger - 28.01.2013 : Amended for Debug public override List <DebugItem> GetDebugOutputs(IExecutionEnvironment dataList) { if (_debugOutputs != null && _debugOutputs.Count > 0) { return(_debugOutputs); } var result = new List <DebugItem>(); string resultString = _theResult.ToString(); DebugItem itemToAdd = new DebugItem(); IDataListCompiler c = DataListFactory.CreateDataListCompiler(); var val = new StringBuilder(Dev2DecisionStack.ExtractModelFromWorkflowPersistedData(ExpressionText)); try { Dev2DecisionStack dds = c.ConvertFromJsonToModel <Dev2DecisionStack>(val); if (_theResult.ToString() == "True") { resultString = dds.TrueArmText; } else if (_theResult.ToString() == "False") { resultString = dds.FalseArmText; } itemToAdd.AddRange(new DebugItemStaticDataParams(resultString, "").GetDebugItemResult()); result.Add(itemToAdd); } // ReSharper disable EmptyGeneralCatchClause catch (Exception) // ReSharper restore EmptyGeneralCatchClause { itemToAdd.AddRange(new DebugItemStaticDataParams(resultString, "").GetDebugItemResult()); result.Add(itemToAdd); } return(result); }
public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update) { if (env == null) { return(_debugInputs); } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "Put Data"), debugItem); AddDebugItem(new DebugEvalResult(PutData, "", env, update), debugItem); _debugInputs.Add(debugItem); if (IsPutDataBase64) { debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", nameof(IsPutDataBase64)), debugItem); AddDebugItem(new DebugEvalResult(IsPutDataBase64.ToString(), "", env, update), debugItem); _debugInputs.Add(debugItem); } base.GetDebugInputs(env, update); return(_debugInputs); }
void AddSingleDebugOutputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update) { const string VariableLabelText = ""; const string NewFieldLabelText = ""; var debugItem = new DebugItem(); try { if (!DataListUtil.IsEvaluated(assignValue.Value)) { AddNotEvaluatedDebugOutputItem(environment, innerCount, assignValue, update, VariableLabelText, NewFieldLabelText, debugItem); } if (DataListUtil.IsEvaluated(assignValue.Value)) { AddEvaluatedDebugOutputItem(environment, innerCount, assignValue, update, VariableLabelText, NewFieldLabelText, debugItem); } } catch (NullValueInVariableException) { AddDebugItem(new DebugItemWarewolfAtomResult("", assignValue.Value, "", environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } _debugOutputs.Add(debugItem); }
List <DebugItem> GetDebugOutputs(string theResult) { var result = new List <DebugItem>(); var resultString = theResult; var itemToAdd = new DebugItem(); var dds = Conditions; try { resultString = GetResultString(theResult, dds); itemToAdd.AddRange(new DebugItemStaticDataParams(resultString, "").GetDebugItemResult()); result.Add(itemToAdd); } catch (Exception) { itemToAdd.AddRange(new DebugItemStaticDataParams(resultString, "").GetDebugItemResult()); result.Add(itemToAdd); } _inner?.SetDebugOutputs(result); return(result); }
private void AssignField(IDSFDataObject dataObject, int update, int innerCount, ActivityDTO t) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignWithFrame(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank && !assignValue.Name.Contains(DataListUtil.ObjectStartMarker)) { var length = dataObject.Environment.GetLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceRecordsetBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } }
// ReSharper disable UnusedParameter.Local void AddDebugTos(IDev2DataListUpsertPayloadBuilder <string> toUpsert, Guid executionId) // ReSharper restore UnusedParameter.Local { int innerCount = 1; const string VariableLabelText = "Variable"; const string NewFieldLabelText = "New Value"; foreach (DebugTO debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo != null && debugOutputTo.TargetEntry != null && debugOutputTo.TargetEntry.ComplexExpressionAuditor != null) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugTOParams(debugOutputTo, true, VariableLabelText, NewFieldLabelText), debugItem); innerCount++; _debugInputs.Add(debugItem); } } innerCount = 1; foreach (DebugTO debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo != null && debugOutputTo.TargetEntry != null && debugOutputTo.TargetEntry.ComplexExpressionAuditor != null) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem); _debugOutputs.Add(debugItem); innerCount++; } } }
private static void Deserialize(IByteReaderBase reader, ICollection <IDebugItem> items) { var count = reader.ReadInt32(); for (var i = 0; i < count; i++) { var item = new DebugItem(); var resultCount = reader.ReadInt32(); for (var j = 0; j < resultCount; j++) { item.Add(new DebugItemResult { Type = (DebugItemResultType)reader.ReadInt32(), Label = reader.ReadString(), Variable = reader.ReadString(), Value = reader.ReadString(), GroupName = reader.ReadString(), GroupIndex = reader.ReadInt32(), MoreLink = reader.ReadString() }, true); } items.Add(item); } }
void AddResultDebugInputs(IEnumerable <XPathDTO> resultsCollection, Guid executionId, IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); var i = 1; foreach (var xPathDto in resultsCollection) { if (!String.IsNullOrEmpty(xPathDto.OutputVariable)) { var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, xPathDto.XPath, false, out errorsTo); errors.MergeErrors(errorsTo); compiler.Evaluate(executionId, enActionType.User, xPathDto.OutputVariable, false, out errorsTo); errors.MergeErrors(errorsTo); if (_isDebugMode) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", i.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugItemVariableParams(xPathDto.OutputVariable, "", expressionsEntry, executionId), itemToAdd); _debugInputs.Add(itemToAdd); i++; } } } }
public List <DebugItem> GetDebugInputs(IList <IDev2Definition> inputs, IBinaryDataList dataList, ErrorResultTO errors) { if (errors == null) { throw new ArgumentNullException("errors"); } var results = new List <DebugItem>(); foreach (IDev2Definition dev2Definition in inputs) { var variableName = GetVariableName(dev2Definition); DebugItem itemToAdd = new DebugItem(); AddDebugItem(new DebugEvalResult(variableName, "", DataObject.Environment), itemToAdd); results.Add(itemToAdd); } foreach (IDebugItem debugInput in results) { debugInput.FlushStringBuilder(); } return(results); }
void Debug(IDSFDataObject dataObject, string firstOrDefault, Dev2Switch ds) { try { if (dataObject.IsDebugMode()) { var result = new List <DebugItem>(); var itemToAdd = new DebugItem(); var debugResult = new DebugItemWarewolfAtomResult(firstOrDefault, "", ds.SwitchVariable, "", "Switch on", "", "="); itemToAdd.AddRange(debugResult.GetDebugItemResult()); result.Add(itemToAdd); _debugInputs = result; if (Inner != null) { Inner.SetDebugInputs(_debugInputs); } } } catch (Exception e) { Dev2Logger.Warn(e.Message, GlobalConstants.WarewolfWarn); } }
public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update) { base.GetDebugInputs(env, update); var head = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(a.Value, update)))).Where(a => !(String.IsNullOrEmpty(a.Name) && String.IsNullOrEmpty(a.Value))); var query = ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(QueryString, update)); var url = ResourceCatalog.GetResource <WebSource>(Guid.Empty, SourceId); var headerString = string.Join(" ", head.Select(a => a.Name + " : " + a.Value)); var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "URL"), debugItem); AddDebugItem(new DebugEvalResult(url.Address, "", env, update), debugItem); _debugInputs.Add(debugItem); debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "Query String"), debugItem); AddDebugItem(new DebugEvalResult(query, "", env, update), debugItem); _debugInputs.Add(debugItem); debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", nameof(Headers)), debugItem); AddDebugItem(new DebugEvalResult(headerString, "", env, update), debugItem); _debugInputs.Add(debugItem); return(_debugInputs); }
public override List <DebugItem> GetDebugInputs(IExecutionEnvironment env, int update) { if (env == null) { return(new List <DebugItem>()); } base.GetDebugInputs(env, update); DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "OverWrite"), debugItem); string value = OverWriteMode ? "True" : "False"; AddDebugItem(new DebugEvalResult(value, "", env, update), debugItem); _debugInputs.Add(debugItem); debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "Add"), debugItem); value = AddMode ? "True" : "False"; AddDebugItem(new DebugEvalResult(value, "", env, update), debugItem); _debugInputs.Add(debugItem); return(_debugInputs); }
#pragma warning disable S1541 // Methods and properties should not be too complex private void AddEvaluatedDebugInputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update, DebugItem debugItem, string VariableLabelText, string NewFieldLabelText) #pragma warning restore S1541 // Methods and properties should not be too complex { if (assignValue.Name.EndsWith("()]]")) { throw new Exception("Append data to array"); } var oldValueResult = environment.Eval(assignValue.Name, update); var newValueResult = environment.Eval(assignValue.Value, update); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); if (oldValueResult.IsWarewolfAtomResult && newValueResult.IsWarewolfAtomResult) { var valueResult = newValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; var scalarResult = oldValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; if (valueResult != null && scalarResult != null) { AddDebugItem(new DebugItemWarewolfAtomResult(ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item), ExecutionEnvironment.WarewolfAtomToString(valueResult.Item), assignValue.Name, environment.EvalToExpression(assignValue.Value, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } } else if (newValueResult.IsWarewolfAtomResult && oldValueResult.IsWarewolfAtomListresult) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, newValueResult, environment.EvalToExpression(assignValue.Value, update), assignValue.Name, VariableLabelText, NewFieldLabelText, "="), debugItem); } else if (oldValueResult.IsWarewolfAtomResult && newValueResult.IsWarewolfAtomListresult) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, newValueResult, environment.EvalToExpression(assignValue.Value, update), assignValue.Name, VariableLabelText, NewFieldLabelText, "="), debugItem); } else { if (oldValueResult.IsWarewolfAtomListresult && newValueResult.IsWarewolfAtomListresult) { var old = (CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult)oldValueResult; if (!old.Item.Any()) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, newValueResult, environment.EvalToExpression(assignValue.Value, update), assignValue.Name, VariableLabelText, NewFieldLabelText, "="), debugItem); } else { var recSetResult = oldValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; AddDebugItem(new DebugItemWarewolfAtomListResult(recSetResult, newValueResult, environment.EvalToExpression(assignValue.Value, update), assignValue.Name, VariableLabelText, NewFieldLabelText, "="), debugItem); } } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { ErrorResultTO allErrors = new ErrorResultTO(); if (dataObject.ExecutingUser != null) { _currentIdentity = dataObject.ExecutingUser.Identity; } var indexCounter = 0; InitializeDebug(dataObject); try { CleanArgs(); foreach (GatherSystemInformationTO item in SystemInformationCollection) { try { indexCounter++; if (dataObject.IsDebugMode()) { var inputToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", indexCounter.ToString(CultureInfo.InvariantCulture)), inputToAdd); AddDebugItem(new DebugItemStaticDataParams("", dataObject.Environment.EvalToExpression(item.Result, update), "", "="), inputToAdd); AddDebugItem(new DebugItemStaticDataParams(item.EnTypeOfSystemInformation.GetDescription(), ""), inputToAdd); _debugInputs.Add(inputToAdd); } var hasErrors = allErrors.HasErrors(); if (!hasErrors) { string val = GetCorrectSystemInformation(item.EnTypeOfSystemInformation); string expression = item.Result; var regions = DataListCleaningUtils.SplitIntoRegions(expression); if (regions.Count > 1) { allErrors.AddError("Multiple variables in result field."); } else { foreach (var region in regions) { dataObject.Environment.AssignWithFrame(new AssignValue(region, val), update); } } } } catch (Exception err) { dataObject.Environment.Assign(item.Result, null, update); allErrors.AddError(err.Message); } } dataObject.Environment.CommitAssign(); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { int innerCount = 1; foreach (GatherSystemInformationTO item in SystemInformationCollection) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment, update), itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } } catch (Exception e) { Dev2Logger.Log.Error("DSFGatherSystemInformationTool", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors); foreach (var error in allErrors.FetchErrors()) { dataObject.Environment.AddError(error); } } if (dataObject.IsDebugMode()) { if (hasErrors) { int innerCount = 1; foreach (GatherSystemInformationTO item in SystemInformationCollection) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment, update), itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); var env = dataObject.Environment; WarewolfListIterator iter = new WarewolfListIterator(); InitializeDebug(dataObject); try { var sourceString = SourceString ?? ""; if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(sourceString, "String to Split", env, update)); AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction")); AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows")); AddDebug(ResultsCollection, dataObject.Environment, update); } var res = new WarewolfIterator(env.Eval(sourceString, update)); iter.AddVariableToIterateOn(res); IDictionary <string, int> positions = new Dictionary <string, int>(); CleanArguments(ResultsCollection); ResultsCollection.ToList().ForEach(a => { if (!positions.ContainsKey(a.OutputVariable)) { positions.Add(a.OutputVariable, update == 0 ? 1 : update); } IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors); }); bool singleInnerIteration = ArePureScalarTargets(ResultsCollection); var resultsEnumerator = ResultsCollection.GetEnumerator(); var debugDictionary = new List <string>(); while (res.HasMoreData()) { const int OpCnt = 0; var item = res.GetNextValue(); // item is the thing we split on if (!string.IsNullOrEmpty(item)) { string val = item; var blankRows = new List <int>(); if (SkipBlankRows) { var strings = val.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); var newSourceString = string.Join(Environment.NewLine, strings); val = newSourceString; } else { var strings = val.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int blankRow = 0; blankRow < strings.Length; blankRow++) { if (String.IsNullOrEmpty(strings[blankRow])) { blankRows.Add(blankRow); } } } ErrorResultTO errors; IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, env, out errors, update); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { if (tokenizer != null) { int pos = 0; int end = ResultsCollection.Count - 1; // track used tokens so we can adjust flushing ;) while (tokenizer.HasMoreOps()) { var currentval = resultsEnumerator.MoveNext(); if (!currentval) { if (singleInnerIteration) { break; } resultsEnumerator.Reset(); resultsEnumerator.MoveNext(); } string tmp = tokenizer.NextToken(); if (tmp.StartsWith(Environment.NewLine) && !SkipBlankRows) { resultsEnumerator.Reset(); while (resultsEnumerator.MoveNext()) { var tovar = resultsEnumerator.Current.OutputVariable; if (!String.IsNullOrEmpty(tovar)) { var assignToVar = ExecutionEnvironment.ConvertToIndex(tovar, positions[tovar]); env.AssignWithFrame(new AssignValue(assignToVar, ""), update); positions[tovar] = positions[tovar] + 1; } } resultsEnumerator.Reset(); resultsEnumerator.MoveNext(); } if (blankRows.Contains(OpCnt) && blankRows.Count != 0) { tmp = tmp.Replace(Environment.NewLine, ""); while (pos != end + 1) { pos++; } } var outputVar = resultsEnumerator.Current.OutputVariable; if (!String.IsNullOrEmpty(outputVar)) { var assignVar = ExecutionEnvironment.ConvertToIndex(outputVar, positions[outputVar]); if (ExecutionEnvironment.IsRecordsetIdentifier(assignVar)) { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } else if (ExecutionEnvironment.IsScalar(assignVar) && positions[outputVar] == 1) { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } else { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } positions[outputVar] = positions[outputVar] + 1; } if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); var outputVarTo = resultsEnumerator.Current.OutputVariable; AddDebugItem(new DebugEvalResult(outputVarTo, "", env, update), debugItem); if (!debugDictionary.Contains(outputVarTo)) { debugDictionary.Add(outputVarTo); } } if (pos == end) { } else { pos++; } } } } } env.CommitAssign(); if (singleInnerIteration) { break; } } if (dataObject.IsDebugMode()) { var outputIndex = 1; foreach (var varDebug in debugDictionary) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outputIndex.ToString(CultureInfo.InvariantCulture)), debugItem); var dataSplitUsesStarForOutput = varDebug.Replace("().", "(*)."); AddDebugItem(new DebugEvalResult(dataSplitUsesStarForOutput, "", env, update), debugItem); _debugOutputs.Add(debugItem); outputIndex++; } } } catch (Exception e) { Dev2Logger.Error("DSFDataSplit", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDataSplitActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
void AddDefaultDebugItem(int innerCount, DebugItem debugItem) { AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); }
public void PropertyWithInfo() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemPropertyI<DebugItemProperty1, DebugItemInfoProperty1>(extensionPack, "Debug"); // Attach Property mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty<DebugItemProperty1>(); Assert.IsNotNull(prop); var state = item.GetState(); Assert.AreEqual(0, state.Properties.Count()); var stateProp = state.GetProperty<DebugItemStateProperty1>(); Assert.IsNull(stateProp); var info = item.GetItemInfo(item2); Assert.AreEqual(1, info.Properties.Count()); var infoProp = info.GetProperty<DebugItemInfoProperty1>(); Assert.IsNotNull(infoProp); }
public void CreateInstanceStateDelegate() { int caller = 0; mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug", (i) => { caller++; return new DebugItemState(i); }); Assert.AreEqual(1, mapper.Items.Count()); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); var state = item.GetState(); Assert.AreEqual(typeof(DebugItemState), state.GetType()); Assert.AreEqual(1, caller); }
public void CreateInstanceStateDelegateWrongType() { int caller = 0; mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug", (i) => { caller++; return new DebugItemStateSpecialized(i); }); Assert.AreEqual(1, mapper.Items.Count()); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); try { var state = item.GetState(); Assert.Fail(); } catch (NotSupportedException) { } }
public void ReadXml(XmlReader reader) { reader.MoveToContent(); DisplayName = reader.GetAttribute("DisplayName"); Guid guid; Guid.TryParse(reader.GetAttribute("ID"), out guid); ID = guid; Guid.TryParse(reader.GetAttribute("OriginalInstanceID"), out guid); OriginalInstanceID = guid; Guid.TryParse(reader.GetAttribute("ParentID"), out guid); ParentID = guid; Guid.TryParse(reader.GetAttribute("ServerID"), out guid); ServerID = guid; StateType state; Enum.TryParse(reader.GetAttribute("StateType"), out state); StateType = state; Guid.TryParse(reader.GetAttribute("SessionID"), out guid); SessionID = guid; while(reader.Read()) { if(reader.IsStartElement("HasError")) { var result = reader.ReadElementString("HasError"); bool boolean; var exists = bool.TryParse(result, out boolean); HasError = exists && boolean; } if(reader.IsStartElement("ErrorMessage")) { ErrorMessage = reader.ReadElementString("ErrorMessage"); } if(reader.IsStartElement("Version")) { Version = reader.ReadElementString("Version"); } if(reader.IsStartElement("Name")) { Name = reader.ReadElementString("Name"); } if(reader.IsStartElement("ActivityType")) { var result = reader.ReadElementString("ActivityType"); ActivityType activityType; Enum.TryParse(result, out activityType); ActivityType = activityType; } if(reader.IsStartElement("Duration")) { DurationString = reader.ReadElementString("Duration"); } if(reader.IsStartElement("StartTime")) { var result = reader.ReadElementString("StartTime"); DateTime date; DateTime.TryParse(result, out date); StartTime = date; } if(reader.IsStartElement("EndTime")) { var result = reader.ReadElementString("EndTime"); DateTime date; DateTime.TryParse(result, out date); EndTime = date; } if(reader.IsStartElement("Inputs")) { Inputs = new List<IDebugItem>(); reader.ReadStartElement(); while(reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem") { var item = new DebugItem(); item.ReadXml(reader); Inputs.Add(item); } reader.ReadEndElement(); } if(reader.IsStartElement("Outputs")) { Outputs = new List<IDebugItem>(); reader.ReadStartElement(); while(reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DebugItem") { var item = new DebugItem(); item.ReadXml(reader); Outputs.Add(item); } reader.ReadEndElement(); } if(reader.IsStartElement("ExecutionOrigin")) { var result = reader.ReadElementString("ExecutionOrigin"); ExecutionOrigin origin; var exists = Enum.TryParse(result, out origin); if(exists) { ExecutionOrigin = origin; } } if(reader.IsStartElement("ExecutingUser")) { ExecutingUser = reader.ReadElementString("ExecutingUser"); } if(reader.IsStartElement("NumberOfSteps")) { int numberOfSteps; var success = int.TryParse(reader.ReadElementString("NumberOfSteps"), out numberOfSteps); if(success) { NumberOfSteps = numberOfSteps; } } if(reader.NodeType == XmlNodeType.EndElement && reader.Name == "DebugState") { reader.ReadEndElement(); break; } } }
public void CreateInstanceWithoutRegister() { try { DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.Fail(); } catch (NotSupportedException) { } }
public void ExtenderOrder() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); List<int> caller = new List<int>(); // Register Extender mapper.RegisterItemExtender<DebugItem>(extensionPack, "Debug", (i) => { caller.Add(1); }, 10); mapper.RegisterItemExtender<DebugItem>(extensionPack, "Debug", (i) => { caller.Add(2); }, 20); mapper.RegisterItemExtender<Item>(extensionPack, "Debug", (i) => { caller.Add(3); }, 5); mapper.RegisterItemExtender<Item>(extensionPack, "Debug", (i) => { caller.Add(4); }, 15); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Left); Assert.AreEqual(4, caller.Count); Assert.AreEqual(3, caller[0]); Assert.AreEqual(1, caller[1]); Assert.AreEqual(4, caller[2]); Assert.AreEqual(2, caller[3]); }
private void AddDebugInputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update, DebugItem debugItem, string VariableLabelText, string NewFieldLabelText) { if (assignValue.Name.EndsWith("()]]")) { throw new Exception("Append data to array"); } var evalResult = environment.Eval(assignValue.Name, update); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); if (evalResult.IsWarewolfAtomResult) { if (evalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult scalarResult) { AddDebugItem(new DebugItemWarewolfAtomResult(ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item), assignValue.Value, environment.EvalToExpression(assignValue.Name, update), "", VariableLabelText, NewFieldLabelText, "="), debugItem); } } else { if (evalResult.IsWarewolfAtomListresult) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, assignValue.Value, "", environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } } }
public void PropertyWithStateAndDelegateWrongType() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property int caller = 0; mapper.RegisterItemPropertyS<DebugItemProperty1, DebugItemStateProperty1>(extensionPack, "Debug", (i, p) => { caller++; return new DebugItemStateProperty1Specialized(i, (DebugItemProperty1)p); }); // Attach Property mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty<DebugItemProperty1>(); Assert.IsNotNull(prop); try { var state = item.GetState(); Assert.Fail(); } catch (NotSupportedException) { } var info = item.GetItemInfo(item2); Assert.AreEqual(0, info.Properties.Count()); var infoProp = info.GetProperty<DebugItemInfoProperty1>(); Assert.IsNull(infoProp); }
private void AddDebugOutputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update, string VariableLabelText, string NewFieldLabelText, DebugItem debugItem) { var evalResult = environment.Eval(assignValue.Name, update); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), debugItem); if (evalResult.IsWarewolfAtomResult) { if (evalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult scalarResult) { AddDebugItem(new DebugItemWarewolfAtomResult(ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item), assignValue.Value, environment.EvalToExpression(assignValue.Name, update), "", VariableLabelText, NewFieldLabelText, "="), debugItem); } } else { if (evalResult.IsWarewolfAtomListresult && evalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult recSetResult) { AddDebugItem(new DebugItemWarewolfAtomListResult(recSetResult, "", "", environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } } }
public void CreateInstance() { mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); Assert.AreEqual(1, mapper.Items.Count()); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); var state = item.GetState(); Assert.AreEqual(typeof(DebugItemState), state.GetType()); var info = item.GetItemInfo(item2); Assert.AreEqual(typeof(DebugItemInfo), info.GetType()); }
void AddSingleInputDebugItemAfterException(IExecutionEnvironment environment, IAssignValue assignValue, int update, DebugItem debugItem, string VariableLabelText, string NewFieldLabelText) { if (DataListUtil.IsEvaluated(assignValue.Value)) { var newValueResult = environment.Eval(assignValue.Value, update); if (newValueResult.IsWarewolfAtomResult && newValueResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult valueResult) { AddDebugItem(new DebugItemWarewolfAtomResult("", ExecutionEnvironment.WarewolfAtomToString(valueResult.Item), environment.EvalToExpression(assignValue.Name, update), assignValue.Value, VariableLabelText, NewFieldLabelText, "="), debugItem); } if (newValueResult.IsWarewolfAtomListresult) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, newValueResult, environment.EvalToExpression(assignValue.Value, update), assignValue.Name, VariableLabelText, NewFieldLabelText, "="), debugItem); } } else { AddDebugItem(new DebugItemWarewolfAtomResult("", assignValue.Value, environment.EvalToExpression(assignValue.Name, update), "", VariableLabelText, NewFieldLabelText, "="), debugItem); } }
public void PropertyWithStateAndDelegateNull() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property int caller = 0; mapper.RegisterItemPropertyS<DebugItemProperty1, DebugItemStateProperty1>(extensionPack, "Debug", (i, p) => { caller++; return null; }); // Attach Property mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug"); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); DebugItem item2 = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); var prop = item.GetProperty<DebugItemProperty1>(); Assert.IsNotNull(prop); var state = item.GetState(); Assert.AreEqual(0, state.Properties.Count()); var stateProp = state.GetProperty<DebugItemStateProperty1>(); Assert.IsNull(stateProp); Assert.AreEqual(1, caller); var info = item.GetItemInfo(item2); Assert.AreEqual(0, info.Properties.Count()); var infoProp = info.GetProperty<DebugItemInfoProperty1>(); Assert.IsNull(infoProp); }
void AddEvaluatedDebugInputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update, DebugItem debugItem, string VariableLabelText, string NewFieldLabelText) { var oldValueResult = environment.Eval(assignValue.Name, update); var newValueResult = environment.Eval(assignValue.Value, update); AddDefaultDebugItem(innerCount, debugItem); if (oldValueResult.IsWarewolfAtomResult && newValueResult.IsWarewolfAtomResult) { var valueResult = newValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; var scalarResult = oldValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; if (valueResult != null && scalarResult != null) { AddDebugItem(new DebugItemWarewolfAtomResult(ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item), ExecutionEnvironment.WarewolfAtomToString(valueResult.Item), assignValue.Name, environment.EvalToExpression(assignValue.Value, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } } else if (newValueResult.IsWarewolfAtomResult && oldValueResult.IsWarewolfAtomListresult || oldValueResult.IsWarewolfAtomResult && newValueResult.IsWarewolfAtomListresult) { AddDebugItem(new DebugItemWarewolfAtomListResult(null, newValueResult, environment.EvalToExpression(assignValue.Value, update), environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } else { if (oldValueResult.IsWarewolfAtomListresult && newValueResult.IsWarewolfAtomListresult) { var recSetResult = oldValueResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; AddDebugItem(new DebugItemWarewolfAtomListResult(recSetResult, newValueResult, environment.EvalToExpression(assignValue.Value, update), environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } } }
public void PropertyOnlyDelegateSpecialized() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemProperty<DebugItemProperty1>(extensionPack, "Debug"); // Attach Property int caller = 0; mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug", (i) => { caller++; return new DebugItemProperty1Specialized(i); }); try { DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.Fail(); } catch (NotSupportedException) { } Assert.AreEqual(1, caller); }
void AddNotEvaluatedDebugOutputItem(IExecutionEnvironment environment, int innerCount, IAssignValue assignValue, int update, string VariableLabelText, string NewFieldLabelText, DebugItem debugItem) { var evalResult = environment.Eval(assignValue.Name, update); AddDefaultDebugItem(innerCount, debugItem); if (evalResult.IsWarewolfAtomResult && evalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult scalarResult) { AddDebugItem(new DebugItemWarewolfAtomResult(ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item), assignValue.Value, environment.EvalToExpression(assignValue.Name, update), "", VariableLabelText, NewFieldLabelText, "="), debugItem); } if (evalResult.IsWarewolfAtomListresult && evalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult recSetResult) { AddDebugItem(new DebugItemWarewolfAtomListResult(recSetResult, "", "", environment.EvalToExpression(assignValue.Name, update), VariableLabelText, NewFieldLabelText, "="), debugItem); } }
public void AttachItemPropertyWithDelegateValue() { // Register Item mapper.RegisterItem<DebugItem, DebugItemState, DebugItemInfo>(extensionPack, "Debug"); // Register Property mapper.RegisterItemPropertySI<DebugItemProperty1, DebugItemStateProperty1, DebugItemInfoProperty1>(extensionPack, "Debug"); // Attach Property int caller = 0; mapper.AttachItemProperty<DebugItem, DebugItemProperty1>(extensionPack, "Debug", (i) => { caller++; return new DebugItemProperty1(i); }); DebugItem item = new DebugItem(mapper, Vector2.Zero, Angle.Right); Assert.AreEqual(1, item.Properties.Count()); Assert.AreEqual(1, caller); var prop = item.GetProperty<DebugItemProperty1>(); Assert.IsNotNull(prop); }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { var allErrors = new ErrorResultTO(); var errors = new ErrorResultTO(); allErrors.MergeErrors(errors); InitializeDebug(dataObject); JsonMappings = JsonMappings.Where(validMapping).ToList(); // Process if no errors try { if (JsonMappings == null) { dataObject.Environment.AddError("Json Mappings supplied to activity is null."); } // ReSharper disable AssignNullToNotNullAttribute if (!dataObject.Environment.Errors.Any() && !JsonMappings.Any()) // ReSharper restore AssignNullToNotNullAttribute { dataObject.Environment.AddError("No Json Mappings supplied to activity."); } // ReSharper disable AssignNullToNotNullAttribute if (!dataObject.Environment.Errors.Any()) // ReSharper restore AssignNullToNotNullAttribute { JsonMappings.ToList().ForEach(m => { var validationResult = new IsValidJsonCreateMappingInputRule(() => m).Check(); if (validationResult != null) { dataObject.Environment.AddError(validationResult.Message); } }); } if (dataObject.IsDebugMode()) { int j = 0; // ReSharper disable PossibleNullReferenceException foreach (JsonMappingTo a in JsonMappings.Where(to => !String.IsNullOrEmpty(to.SourceName))) // ReSharper restore PossibleNullReferenceException { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(string.Empty, (++j).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugEvalResult(a.SourceName, string.Empty, dataObject.Environment, update), debugItem); _debugInputs.Add(debugItem); } } // TODO: More validation through IRule, IRuleSet to throw out anything not in spec if (!dataObject.Environment.Errors.Any()) { // JsonMappings.Count() is larger than zero var json = new JObject(); // outermost JSON would always be a single JObject, i.e. {'name': value} // ReSharper disable AssignNullToNotNullAttribute List <JsonMappingTo> jsonMappingList = JsonMappings.ToList(); // ReSharper restore AssignNullToNotNullAttribute // build the list of JsonMappingCompoundTo - a compound is either a single expression or a comma seperated list of expressions // ReSharper disable MaximumChainedReferences List <JsonMappingCompoundTo> results = jsonMappingList.Where(to => !String.IsNullOrEmpty(to.SourceName)).Select(jsonMapping => new JsonMappingCompoundTo(dataObject.Environment, jsonMapping )).ToList(); // ReSharper restore MaximumChainedReferences // main loop for producing largest list of zipped values results.ForEach(x => { // if it is not a compound, if (!x.IsCompound) { // add JProperty, with name x.DestinationName, and value eval(x.SourceName) json.Add(new JProperty( x.DestinationName, x.EvaluatedResultIndexed(0)) ); } else { // if it is a compound, if (!x.EvalResult.IsWarewolfRecordSetResult) { json.Add(new JProperty( x.DestinationName, x.ComplexEvaluatedResultIndexed(0)) ); } else if (x.EvalResult.IsWarewolfRecordSetResult) { json.Add( x.ComplexEvaluatedResultIndexed(0)); } } } ); dataObject.Environment.Assign(JsonString, json.ToString(Formatting.None), update); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugEvalResult(JsonString, string.Empty, dataObject.Environment, update)); } /* * var rule = new IsSingleValueRule(() => CountNumber); * var single = rule.Check(); * if (single != null) * { * allErrors.AddError(single.Message); * } * else * { * var count = 0; * if (dataObject.Environment.HasRecordSet(RecordsetName)) * { * count = dataObject.Environment.GetCount(rs); * } * var value = count.ToString(); * dataObject.Environment.Assign(CountNumber, value); * AddDebugOutputItem(new DebugEvalResult(CountNumber, "", dataObject.Environment)); * } * */ } } catch (Exception e) { // ReSharper disable AssignNullToNotNullAttribute JsonMappings.ToList().ForEach(x => // ReSharper restore AssignNullToNotNullAttribute { AddDebugInputItem(new DebugItemStaticDataParams("", x.SourceName, "SourceName", "=")); AddDebugInputItem(new DebugItemStaticDataParams("", x.DestinationName, "DestinationName")); }); allErrors.AddError(e.Message); dataObject.Environment.Assign(JsonString, string.Empty, update); AddDebugOutputItem(new DebugItemStaticDataParams(string.Empty, JsonString, "", "=")); } finally { // Handle Errors bool hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCreateJsonActivity", allErrors); string errorString = allErrors.MakeDataListReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
private static void Deserialize(IByteReaderBase reader, ICollection<IDebugItem> items) { var count = reader.ReadInt32(); for(var i = 0; i < count; i++) { var item = new DebugItem(); var resultCount = reader.ReadInt32(); for(var j = 0; j < resultCount; j++) { item.Add(new DebugItemResult { Type = (DebugItemResultType)reader.ReadInt32(), Label = reader.ReadString(), Variable = reader.ReadString(), Value = reader.ReadString(), GroupName = reader.ReadString(), GroupIndex = reader.ReadInt32(), MoreLink = reader.ReadString() }, true); } items.Add(item); } }