public InternalServiceContainer(ServiceAction sa, IDSFDataObject dataObj, IWorkspace theWorkspace, IEsbChannel esbChannel, EsbExecuteRequest request) : base(sa, dataObj, theWorkspace, esbChannel, request) { var dataListTO = new DataListTO(sa.DataListSpecification.ToString()); if(request.Args == null) { request.Args = new Dictionary<string, StringBuilder>(); foreach(var input in dataListTO.Inputs) { var warewolfEvalResult = dataObj.Environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(input),0,false); if(warewolfEvalResult.IsWarewolfAtomResult) { var scalarResult = warewolfEvalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if(scalarResult != null && !scalarResult.Item.IsNothing) { request.Args.Add(input, new StringBuilder(scalarResult.Item.ToString())); } } } } }
static JToken GetParametersDefinition(out List<JObject> parameters, string dataList, out bool isScalarInputOnly) { var dataListTO = new DataListTO(dataList); var scalarInputs = dataListTO.Inputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetInputs = dataListTO.Inputs.Where(DataListUtil.IsValueRecordset).ToList(); var scalarOutputs = dataListTO.Outputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Outputs.Where(DataListUtil.IsValueRecordset); parameters = null; isScalarInputOnly = true; var dataListSchema = new Dictionary<string, Schema> { { "Output", new Schema { Type = "object", Properties = BuildDefinition(scalarOutputs, recSetOutputs) } } }; if(recSetInputs.Any()) { dataListSchema.Add("DataList", new Schema { Type = "object", Properties = BuildDefinition(scalarInputs, recSetInputs) }); isScalarInputOnly = false; } else { parameters = scalarInputs.Select(scalarInput => new JObject { { "name", scalarInput }, { "in", "query" }, { "required", true }, { "type", "string" } }).ToList(); } var serialized = JsonConvert.SerializeObject(dataListSchema); JToken des = JsonConvert.DeserializeObject(serialized) as JToken; var definitionObject = des; return definitionObject; }
public static void UpdateEnvironmentFromXmlPayload(IDSFDataObject dataObject, StringBuilder rawPayload, string dataList, int update) { string toLoad = DataListUtil.StripCrap(rawPayload.ToString()); // clean up the rubish ;) XmlDocument xDoc = new XmlDocument(); toLoad = string.Format("<Tmp{0}>{1}</Tmp{0}>", Guid.NewGuid().ToString("N"), toLoad); xDoc.LoadXml(toLoad); if(dataList != null) { dataList = dataList.Replace("ADL>", "DataList>").Replace("root>","DataList>"); if (xDoc.DocumentElement != null) { XmlNodeList children = xDoc.DocumentElement.ChildNodes; var dataListTO = new DataListTO(dataList,true); TryConvert(dataObject, children, dataListTO.Inputs, update); } } }
public static void UpdateEnvironmentFromInputPayload(IDSFDataObject dataObject, StringBuilder rawPayload, string dataList,int update) { string toLoad = DataListUtil.StripCrap(rawPayload.ToString()); // clean up the rubish ;) if(toLoad.IsJSON()) { XNode node = JsonConvert.DeserializeXNode(toLoad, "Root"); if(node == null) { return; } toLoad = node.ToString(); } XmlDocument xDoc = new XmlDocument(); toLoad = string.Format("<Tmp{0}>{1}</Tmp{0}>", Guid.NewGuid().ToString("N"), toLoad); xDoc.LoadXml(toLoad); dataList = dataList.Replace("ADL>", "DataList>").Replace("root>", "DataList>"); if (xDoc.DocumentElement != null) { XmlNodeList children = xDoc.DocumentElement.ChildNodes; var dataListTO = new DataListTO(dataList); TryConvert(dataObject, children, dataListTO.Inputs, update); } }
public static string GetJsonOutputFromEnvironment(IDSFDataObject dataObject,string dataList,int update) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("{"); var keyCnt = 0; var scalarOutputs = dataListTO.Outputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Outputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); var recSets = groupedRecSets as IGrouping<string, string>[] ?? groupedRecSets.ToArray(); foreach (var groupedRecSet in recSets) { var i = 0; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfIterator = new WarewolfIterator(environment.Eval(name, update,false)); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } result.Append("\""); result.Append(groupedRecSet.Key); result.Append("\" : ["); while (warewolfListIterators.HasMoreData()) { int colIdx = 0; result.Append("{"); foreach (var namedIterator in iterators) { try { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("\""); result.Append(namedIterator.Key); result.Append("\":\""); result.Append(value); result.Append("\""); colIdx++; if (colIdx < iterators.Count) { result.Append(","); } } catch(Exception e) { Dev2Logger.Log.Debug(e.Message,e); colIdx++; } } if (warewolfListIterators.HasMoreData()) { result = new StringBuilder(result.ToString().TrimEnd(',')); result.Append("}"); result.Append(","); } } result.Append("}"); result.Append("]"); i++; if (i <= recSets.Length) { result.Append(","); } } var scalars = scalarOutputs as string[] ?? scalarOutputs.ToArray(); foreach (var output in scalars) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output), update,false); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("\""); result.Append(output); result.Append("\":\""); result.Append(scalarResult.Item); result.Append("\""); } } keyCnt++; if (keyCnt < scalars.Length) { result.Append(","); } } var jsonOutputFromEnvironment = result.ToString(); jsonOutputFromEnvironment = jsonOutputFromEnvironment.TrimEnd(','); jsonOutputFromEnvironment += "}"; return jsonOutputFromEnvironment; }
public static string GetXmlOutputFromEnvironment(IDSFDataObject dataObject,string dataList,int update) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("<DataList>"); var scalarOutputs = dataListTO.Outputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Outputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); foreach (var groupedRecSet in groupedRecSets) { var i = 1; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfEvalResult = WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing); try { warewolfEvalResult = environment.Eval(name, update,false); } // ReSharper disable once RESP510236 // ReSharper disable once RESP510241 catch(Exception e) { Dev2Logger.Log.Debug("Null Variable",e); } var warewolfIterator = new WarewolfIterator(warewolfEvalResult); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } while (warewolfListIterators.HasMoreData()) { result.Append("<"); result.Append(groupedRecSet.Key); result.Append(string.Format(" Index=\"{0}\">", i)); foreach (var namedIterator in iterators) { try { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("<"); result.Append(namedIterator.Key); result.Append(">"); result.Append(value); result.Append("</"); result.Append(namedIterator.Key); result.Append(">"); } catch(Exception e) { Dev2Logger.Log.Debug(e.Message,e); } } result.Append("</"); result.Append(groupedRecSet.Key); result.Append(">"); i++; } } foreach (var output in scalarOutputs) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output), update,false); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("<"); result.Append(output); result.Append(">"); result.Append(scalarResult.Item); result.Append("</"); result.Append(output); result.Append(">"); } } } result.Append("</DataList>"); return result.ToString(); }
public static string GetXmlInputFromEnvironment(IDSFDataObject dataObject, Guid workspaceGuid, string dataList) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("<" + "DataList" + ">"); var scalarOutputs = dataListTO.Inputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Inputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); foreach (var groupedRecSet in groupedRecSets) { var i = 1; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfIterator = new WarewolfIterator(environment.Eval(name)); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } while (warewolfListIterators.HasMoreData()) { result.Append("<"); result.Append(groupedRecSet.Key); result.Append(string.Format(" Index=\"{0}\">", i)); foreach (var namedIterator in iterators) { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("<"); result.Append(namedIterator.Key); result.Append(">"); result.Append(value); result.Append("</"); result.Append(namedIterator.Key); result.Append(">"); } result.Append("</"); result.Append(groupedRecSet.Key); result.Append(">"); i++; } } foreach (var output in scalarOutputs) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output)); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("<"); result.Append(output); result.Append(">"); result.Append(scalarResult.Item); result.Append("</"); result.Append(output); result.Append(">"); } } } result.Append("</" + "DataList" + ">"); return result.ToString(); }