public override void UpdateForEachInputs(IList <Tuple <string, string> > updates) { if (updates != null) { foreach (Tuple <string, string> t in updates) { // locate all updates for this tuple Tuple <string, string> t1 = t; var items = InputMappings.Where(c => !string.IsNullOrEmpty(c.InputColumn) && c.InputColumn.Equals(t1.Item1)); // issues updates foreach (var a in items) { a.InputColumn = t.Item2; } if (TableName == t.Item1) { TableName = t.Item2; } if (BatchSize == t.Item1) { BatchSize = t.Item2; } if (Timeout == t.Item1) { Timeout = t.Item2; } } } }
private static async Task LoadBodyFromFile(InputMappings mappings) { List <Task> toBeAwaited = new List <Task>(); foreach (var mockSettings in mappings.BodyCheckMapping.Values) { foreach (var setting in mockSettings) { toBeAwaited.Add(ReadBodyFromFile(setting)); } } foreach (var mockPathSettings in mappings.PathMapping.Values) { toBeAwaited.Add(ReadBodyFromFile(mockPathSettings)); } foreach (var mockStartsWithSettings in mappings.PathStartsWithMapping.Values) { toBeAwaited.Add(ReadBodyFromFile(mockStartsWithSettings)); } foreach (var mockRegexSettings in mappings.PathMatchesRegexMapping.Values) { toBeAwaited.Add(ReadBodyFromFile(mockRegexSettings)); } await Task.WhenAll(toBeAwaited); }
/// <summary> /// Compiles the decision. /// </summary> /// <param name="node">The node.</param> /// <param name="experiment">The experiment.</param> /// <param name="workspaceTypesDirectories">The workspace types directories.</param> /// <param name="loggerNameRoot">The logger name root.</param> private static void CompileDecisionInternal(ExperimentNode node, IExperiment experiment, List <string> workspaceTypesDirectories, LoggerNameRoot loggerNameRoot, Dictionary <string, string> successorNodeLabelIdLookup) { InputMappings availableInputMappingsPerNode = new InputMappings(experiment); Dictionary <string, string> predeccessorsOutputsNameTypeLookup = PreparePredeccessorsOutputsNameTypeLookup(node, availableInputMappingsPerNode); IDecision decisionMetadata = (IDecision)node.Data.Metadata; try { if (decisionMetadata != null) { node.ClearError(); BuildSourceAndCompileDecisionModule(decisionMetadata, successorNodeLabelIdLookup, predeccessorsOutputsNameTypeLookup, workspaceTypesDirectories, loggerNameRoot); decisionMetadata.CompilationStatus = TraceLab.Core.Components.CompilationStatus.Successful; } } catch (ArgumentException ex) { decisionMetadata.CompilationStatus = TraceLab.Core.Components.CompilationStatus.Failed; node.SetError(ex.Message); } }
public IEnumerable <object> GetOutputs() { return(OutputMappings .Select <PositionInOc5State, object>(mapping => { var indexInInputs = InputMappings.IndexOf(mapping); var indexInOc5StateList = mapping.IndexInOc5StateList; switch (mapping.Type) { case PredefinedObjects.Types._boolean: return Bools[indexInOc5StateList]; case PredefinedObjects.Types._integer: return Ints[indexInOc5StateList]; case PredefinedObjects.Types._string: return Strings[indexInOc5StateList]; case PredefinedObjects.Types._float: return Floats[indexInOc5StateList]; case PredefinedObjects.Types._double: return Doubles[indexInOc5StateList]; default: throw new ArgumentException($"No predefined type with index {mapping.Type}!"); } } )); }
/// <summary> /// Compiles all decision nodes code and loops code in the given experiment /// </summary> /// <param name="experiment">The experiment.</param> /// <param name="availableInputMappingsPerNode">The available input mappings per node.</param> /// <param name="workspaceTypesDirectories">The workspace types directories.</param> /// <param name="loggerNameRoot">The logger name root.</param> /// <returns> /// true if there were no errors, otherwise false /// </returns> public static bool CompileAllDecisionNodes(IExperiment experiment, InputMappings availableInputMappingsPerNode, List <string> workspaceTypesDirectories, LoggerNameRoot loggerNameRoot) { bool noErrors = true; foreach (ExperimentNode node in experiment.Vertices) { IDecision decisionMetadata = node.Data.Metadata as IDecision; if (decisionMetadata != null) { try { //build successor nodes label id lookup Dictionary <string, string> successorNodeLabelIdLookup = PrepareSuccessorNodesLabelIdLookup(node, experiment); Dictionary <string, string> predeccessorsOutputsNameTypeLookup = PreparePredeccessorsOutputsNameTypeLookup(node, availableInputMappingsPerNode); node.ClearError(); BuildSourceAndCompileDecisionModule(decisionMetadata, successorNodeLabelIdLookup, predeccessorsOutputsNameTypeLookup, workspaceTypesDirectories, loggerNameRoot); } catch (ArgumentException ex) { noErrors = false; node.SetError(ex.Message); } } } return(noErrors); }
// END HERZUM BUG FIX: alignment input-output TLAB-255 /// <summary> /// Creates the input mapping column with combo box. /// TODO improve the input mapping combo box: /// 1. it doesn't set values until combo box loses focus within table view confirm change - Edited event is raised only then /// 2. there is no indication that the field can be modified - render combo box always, OR show some icon that it can be modified /// </summary> /// <returns> /// The input mapping column with combo box. /// </returns> /// <param name='inputStore'> /// Input store. /// </param> private TreeViewColumn CreateInputMappingColumnWithComboBox(NodeStore inputStore, string columntTitle) { Gtk.CellRendererCombo comboRenderer = new Gtk.CellRendererCombo(); comboRenderer.HasEntry = false; comboRenderer.Mode = CellRendererMode.Editable; comboRenderer.TextColumn = 0; comboRenderer.Editable = true; ListStore comboBoxStore = new ListStore(typeof(string)); comboRenderer.Model = comboBoxStore; //when user activates combo box, refresh combobox store with available input mapping per node comboRenderer.EditingStarted += delegate(object o, EditingStartedArgs args) { comboBoxStore.Clear(); IOItemNode currentItem = (IOItemNode)inputStore.GetNode(new TreePath(args.Path)); ExperimentNode currentNode = m_component.ExperimentNode; string currentType = currentItem.Type; // HERZUM SPRINT 2.4: TLAB-162 //InputMappings availableInputMappingsPerNode = new InputMappings (currentNode.Owner); InputMappings availableInputMappingsPerNode = new InputMappings(m_applicationContext.Application.Experiment); // END HERZUM SPRINT 2.4: TLAB-162 if (currentNode != null && availableInputMappingsPerNode.ContainsMappingsForNode(currentNode)) { foreach (string incomingOutput in availableInputMappingsPerNode[currentNode].Keys) { if (string.Equals(currentType, availableInputMappingsPerNode [currentNode] [incomingOutput])) { comboBoxStore.AppendValues(Mono.Unix.Catalog.GetString(incomingOutput)); } } } }; //when edition has been completed set current item node with proper mapping comboRenderer.Edited += delegate(object o, EditedArgs args) { IOItemNode n = (IOItemNode)inputStore.GetNode(new TreePath(args.Path)); n.MappedTo = args.NewText; RefreshIOHighlightInExperiment(n.MappedTo); }; //finally create the column with above combo renderer var mappedToColumn = new TreeViewColumn(); mappedToColumn.Title = columntTitle; mappedToColumn.PackStart(comboRenderer, true); //this method sets the text view to current mapping, when combo box is not active mappedToColumn.SetCellDataFunc(comboRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, ITreeNode node) { IOItemNode currentItem = (IOItemNode)node; comboRenderer.Text = currentItem.MappedTo; }); return(mappedToColumn); }
List <string> GetNamesFromMappings() { if (InputMappings == null) { return(null); } return(InputMappings.Select(dataColumnMapping => dataColumnMapping.OutputColumn.ColumnName).ToList()); }
List <Type> GETTypesFromMappingTypes() { if (InputMappings == null) { return(null); } return(InputMappings.Select(dataColumnMapping => dataColumnMapping.OutputColumn.DataType).ToList()); }
/// <summary> /// Validates if the list of outputs from incoming vertices satisfies all the inputs for all vertices in the lookup. /// </summary> /// <returns>true, if all vertices have correct mapping, false if there is any node with input that is not satisfied by previous outputs.</returns> public static bool Validate(IExperiment experiment, InputMappings availableInputMappingsPerNode) { bool retVal = true; foreach (ExperimentNode currentNode in availableInputMappingsPerNode.Nodes) { bool validationResults = ValidateInputMapping(currentNode, availableInputMappingsPerNode[currentNode]); if (retVal != false) { retVal = validationResults; } } return(retVal); }
public override int GetHashCode() { unchecked { var hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (InputMappings != null ? InputMappings.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Database != null ? Database.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TableName != null ? TableName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0); hashCode = (hashCode * 397) ^ CheckConstraints.GetHashCode(); hashCode = (hashCode * 397) ^ FireTriggers.GetHashCode(); hashCode = (hashCode * 397) ^ UseInternalTransaction.GetHashCode(); hashCode = (hashCode * 397) ^ KeepIdentity.GetHashCode(); hashCode = (hashCode * 397) ^ KeepTableLock.GetHashCode(); hashCode = (hashCode * 397) ^ (Timeout != null ? Timeout.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BatchSize != null ? BatchSize.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IgnoreBlankRows.GetHashCode(); return(hashCode); } }
public void AssignInputs(params object[] inputs) { InputMappings .ToList() .ForEach( (mapping) => { var indexInInputs = InputMappings.IndexOf(mapping); var indexInOc5StateList = mapping.IndexInOc5StateList; switch (mapping.Type) { case PredefinedObjects.Types._boolean: Bools[indexInOc5StateList] = (bool)inputs[indexInInputs]; break; case PredefinedObjects.Types._integer: Ints[indexInOc5StateList] = (int)inputs[indexInInputs]; break; case PredefinedObjects.Types._string: Strings[indexInOc5StateList] = (string)inputs[indexInInputs]; break; case PredefinedObjects.Types._float: Floats[indexInOc5StateList] = (float)inputs[indexInInputs]; break; case PredefinedObjects.Types._double: Doubles[indexInOc5StateList] = (double)inputs[indexInInputs]; break; default: throw new ArgumentException($"No predefined type with index {mapping.Type}!"); } } ); }
public Response FindMatchingResponseMock(string path, string body, string method, InputMappings mapping) { Response result = null; var pathMappingKey = new PathMappingKey { Path = path, Method = method, }; if (mapping.PathMapping.ContainsKey(pathMappingKey) && mapping.PathMapping[pathMappingKey].Request.Methods.Contains(method)) { result = mapping.PathMapping[pathMappingKey].Response; } if (result == null && mapping.PathStartsWithMapping != null) { foreach (var pathStart in mapping.PathStartsWithMapping) { if (path.StartsWith(pathStart.Key.Path) && pathStart.Value.Request.Methods.Contains(method)) { result = pathStart.Value.Response; } } } if (result == null && mapping.PathMatchesRegexMapping != null) { foreach (var pathRegex in mapping.PathMatchesRegexMapping) { if (pathRegex.Key.Regex.IsMatch(path) && pathRegex.Value.Request.Methods.Contains(method)) { result = pathRegex.Value.Response; } } } if (result == null && mapping.BodyCheckMapping?.ContainsKey(pathMappingKey) == true) { var possibleResults = mapping.BodyCheckMapping[pathMappingKey]; foreach (var possibleResult in possibleResults) { if (!string.IsNullOrEmpty(possibleResult.Request.BodyContains)) { if (body.Contains(possibleResult.Request.BodyContains) && possibleResult.Request.Methods.Contains(method)) { result = possibleResult.Response; } } else if (!string.IsNullOrEmpty(possibleResult.Request.BodyDoesNotContain) && possibleResult.Request.Methods.Contains(method)) { if (!body.Contains(possibleResult.Request.BodyDoesNotContain)) { result = possibleResult.Response; } } } } return(result); }
/// <summary> /// Writes the current controller mappings to the controller's ini file. /// </summary> public void SetMappings() { InputMappings.WriteConfig(ConfigurationFileLocation, Controller); }
public async Task <InputMappings> ParsePathMappings() { var inputMappings = new InputMappings(); if (mockConfiguration?.Any() != true) { return(inputMappings); } foreach (var httpMockSetting in mockConfiguration) { if (!string.IsNullOrEmpty(httpMockSetting.Request.Path)) { if (!string.IsNullOrEmpty(httpMockSetting.Request.BodyContains) || !string.IsNullOrEmpty(httpMockSetting.Request.BodyDoesNotContain)) { foreach (var method in httpMockSetting.Request.Methods) { var key = new PathMappingKey { Path = httpMockSetting.Request.Path, Method = method, }; if (inputMappings.BodyCheckMapping.ContainsKey(key)) { var bodyContainesList = inputMappings.BodyCheckMapping[key]; bodyContainesList.Add(httpMockSetting); } else { inputMappings.BodyCheckMapping.TryAdd(key, new List <HttpMockSetting> { httpMockSetting }); } } } else { foreach (var method in httpMockSetting.Request.Methods) { var key = new PathMappingKey { Path = httpMockSetting.Request.Path, Method = method }; inputMappings.PathMapping.TryAdd(key, httpMockSetting); } } } else if (!string.IsNullOrEmpty(httpMockSetting.Request.PathStartsWith)) { foreach (var method in httpMockSetting.Request.Methods) { var key = new PathMappingKey { Path = httpMockSetting.Request.PathStartsWith, Method = method }; inputMappings.PathStartsWithMapping.TryAdd(key, httpMockSetting); } } else if (!string.IsNullOrWhiteSpace(httpMockSetting.Request.PathMatchesRegex)) { foreach (var method in httpMockSetting.Request.Methods) { var key = new PathMappingRegexKey { Regex = new Regex(httpMockSetting.Request.PathMatchesRegex, RegexOptions.Compiled), Method = method, }; inputMappings.PathMatchesRegexMapping.TryAdd(key, httpMockSetting); } } } await LoadBodyFromFile(inputMappings); return(inputMappings); }
/// <summary> /// Retrieves the current controller mappings from the controller's ini file. /// </summary> public IController GetMappings() { return(InputMappings.ParseConfig(ConfigurationFileLocation, Controller)); }
public override IList <DsfForEachItem> GetForEachInputs() { var items = new[] { BatchSize, Timeout, TableName }.Union(InputMappings.Where(c => !string.IsNullOrEmpty(c.InputColumn)).Select(c => c.InputColumn)).ToArray(); return(GetForEachItems(items)); }
List <Type> GETTypesFromMappingTypes() => InputMappings?.Select(dataColumnMapping => dataColumnMapping.OutputColumn.DataType).ToList();
/// <summary> /// Prepares the predeccessors outputs lookup. /// </summary> /// <param name="vert">The vert.</param> /// <param name="availableInputMappingsPerNode">The available input mappings per node.</param> /// <returns> /// list of all the outputs from previous nodes. the key is output name, and the value is the type of that output /// </returns> public static Dictionary <string, string> PreparePredeccessorsOutputsNameTypeLookup(ExperimentNode vert, InputMappings availableInputMappingsPerNode) { Dictionary <string, string> predeccessorsOutputsNameTypeLookup; if (availableInputMappingsPerNode.TryGetValue(vert, out predeccessorsOutputsNameTypeLookup) == false) { predeccessorsOutputsNameTypeLookup = new Dictionary <string, string>(); //return empty - there is not path from start node to decision } return(predeccessorsOutputsNameTypeLookup); }
List <string> GetNamesFromMappings() => InputMappings?.Select(dataColumnMapping => dataColumnMapping.OutputColumn.ColumnName).ToList();