private void UpdateDataListWithJsonObject(string expression) { if (IsObject && !string.IsNullOrEmpty(JsonString)) { try { var language = FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(expression); if (language.IsJsonIdentifierExpression) { if (DataListSingleton.ActiveDataList != null) { var objToProcess = JsonConvert.DeserializeObject(JsonString) as JObject; var firstOrDefault = objToProcess?.Properties().FirstOrDefault(); if (firstOrDefault != null) { var processString = firstOrDefault.Value.ToString(); DataListSingleton.ActiveDataList.GenerateComplexObjectFromJson( DataListUtil.RemoveLanguageBrackets(expression), processString); } } } } catch (Exception) { //Is not an object identifier } } }
public void ObjectName_GivenIsObjectAndObjectResult_ShouldUpdateDatalist() { //---------------Set up test pack------------------- CustomContainer.DeRegister <IShellViewModel>(); var shellVm = new Mock <IShellViewModel>(); shellVm.Setup(model => model.UpdateCurrentDataListWithObjectFromJson(It.IsAny <string>(), It.IsAny <string>())).Verifiable(); CustomContainer.Register(shellVm.Object); var act = new DsfWebGetActivity { SourceId = Guid.NewGuid(), Outputs = null, IsObject = true }; var outputsRegion = new OutputsRegion(ModelItemUtils.CreateModelItem(act), true) { ObjectResult = this.SerializeToJsonString(new DefaultSerializationBinder()) }; //---------------Assert Precondition---------------- Assert.IsTrue(outputsRegion.IsObject); Assert.IsTrue(!string.IsNullOrEmpty(outputsRegion.ObjectResult)); Assert.IsTrue(FsInteropFunctions.ParseLanguageExpressionWithoutUpdate("[[@objName]]").IsJsonIdentifierExpression); //---------------Execute Test ---------------------- outputsRegion.ObjectName = "[[@objName]]"; //---------------Test Result ----------------------- shellVm.Verify(model => model.UpdateCurrentDataListWithObjectFromJson(It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.AreEqual(outputsRegion.ObjectName, act.ObjectName); }
public void Given_ParseLanguageExpressionWithoutUpdate_Should() { const string personChildName = "[[@Person.Child.Name]]"; var languageExpression = FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(personChildName); var isJsonIdentifierExpression = languageExpression.IsJsonIdentifierExpression; Assert.IsNotNull(languageExpression); Assert.IsTrue(isJsonIdentifierExpression); }
public void Given_LanguageExpressionToString_Should() { const string personChildName = "[[@Person.Child.Name]]"; Assert.IsNotNull(FsInteropFunctions.PositionColumn); var languageExpression = FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(personChildName); var languageExpressionToString = FsInteropFunctions.LanguageExpressionToString(languageExpression); Assert.AreEqual(typeof(string), languageExpressionToString.GetType()); }
public IList <string> FormatDsfActivityField(string activityField) { IList <string> result = new List <string>(); var regions = DataListCleaningUtils.SplitIntoRegionsForFindMissing(activityField); foreach (var region in regions) { // Sashen: 09-10-2012 : Using the new parser var intellisenseParser = new SyntaxTreeBuilder(); var nodes = intellisenseParser.Build(region); // No point in continuing ;) if (nodes == null) { return(result); } if (intellisenseParser.EventLog.HasEventLogs) { var languageParser = new Dev2DataLanguageParser(); try { result = languageParser.ParseForActivityDataItems(region); } catch (Dev2DataLanguageParseError) { return(new List <string>()); } catch (NullReferenceException) { return(new List <string>()); } } var allNodes = new List <Node>(); result = FormatDsfActivityField(result, intellisenseParser, nodes, allNodes); } try { FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(activityField); } catch (Exception) { return(result.Where(lang => activityField.Contains("[[" + lang + "]]")).ToList()); } return(result); }
public void GetValue(string s, List <IServiceInput> dt) { var exp = FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(s); if (exp.IsComplexExpression) { var item = ((LanguageAST.LanguageExpression.ComplexExpression)exp).Item; var vals = item.Where(a => a.IsRecordSetExpression || a.IsScalarExpression || a.IsJsonIdentifierExpression).Select(FsInteropFunctions.LanguageExpressionToString); dt.AddRange(vals.Select(a => new ServiceInput(a, ""))); } if (exp.IsScalarExpression) { dt.Add(new ServiceInput(s, "")); } if (exp.IsRecordSetExpression) { dt.Add(new ServiceInput(s, "")); } if (exp.IsJsonIdentifierExpression) { dt.Add(new ServiceInput(s, "")); } }
/// <summary> /// Is the list. /// </summary> /// <param name="activityField">The activity field.</param> /// <returns></returns> public IList <string> FormatDsfActivityField(string activityField) { //2013.06.10: Ashley Lewis for bug 9306 - handle the case of miss-matched region braces IList <string> result = new List <string>(); var regions = DataListCleaningUtils.SplitIntoRegionsForFindMissing(activityField); foreach (var region in regions) { // Sashen: 09-10-2012 : Using the new parser var intellisenseParser = new SyntaxTreeBuilder(); Node[] nodes = intellisenseParser.Build(region); // No point in continuing ;) if (nodes == null) { return(result); } if (intellisenseParser.EventLog.HasEventLogs) { IDev2StudioDataLanguageParser languageParser = DataListFactory.CreateStudioLanguageParser(); try { result = languageParser.ParseForActivityDataItems(region); } catch (Dev2DataLanguageParseError) { return(new List <string>()); } catch (NullReferenceException) { return(new List <string>()); } } var allNodes = new List <Node>(); if (nodes.Any() && !intellisenseParser.EventLog.HasEventLogs) { nodes[0].CollectNodes(allNodes); // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < allNodes.Count; i++) { if (allNodes[i] is DatalistRecordSetNode) { var refNode = allNodes[i] as DatalistRecordSetNode; string nodeName = refNode.GetRepresentationForEvaluation(); nodeName = nodeName.Substring(2, nodeName.Length - 4); result.Add(nodeName); } else if (allNodes[i] is DatalistReferenceNode) { var refNode = allNodes[i] as DatalistReferenceNode; string nodeName = refNode.GetRepresentationForEvaluation(); nodeName = nodeName.Substring(2, nodeName.Length - 4); result.Add(nodeName); } } } } try { FsInteropFunctions.ParseLanguageExpressionWithoutUpdate(activityField); } catch (Exception) { return(result.Where(lang => activityField.Contains("[[" + lang + "]]")).ToList()); } return(result); }