public void Process(JObject command, Context context) { var varName = JSONUtil.GetText(command, "#store"); if (varName == null) { varName = JSONUtil.GetText(command, "name"); } var value = JSONUtil.GetToken(command, "value"); var storeMode = StoreMode.Replace; var mode = command["mode"]; if (mode != null && mode.ToString() == "merge") { storeMode = StoreMode.Merge; } if (command["#debug"] != null && command["#debug"].ToString() == "true") { if (storeMode == StoreMode.Merge) { context.Trace($"Merging {JSONUtil.SingleLine(value)} into {varName}"); } else { context.Trace($"Setting {varName} to {JSONUtil.SingleLine(value)}"); } } context.Store(varName, value, storeMode); }
public void CreateRecords(List <Entity> cdsEntities, CDSConnection cdsConnection) { var num = cdsEntities.Count; var i = 0; foreach (var item in cdsEntities) { //Entity cdsEntity = new Entity(item.LogicalName); i++; Console.Write($"Adding record {i} of {num}..."); cdsConnection.Create(item); Console.WriteLine("Added." + JSONUtil.SingleLine(JArray.FromObject(item.Attributes))); } }
private JArray RunSequenceRule(JToken query, JObject rule, Context context) { var results = new JArray(); var whenSequence = rule["when-sequence"]; if (whenSequence != null) { // get the object at the current sequence position int?pos = JSONUtil.GetInt32(rule, "#seq-pos"); if (pos == null) { pos = 0; rule.Add("#seq-pos", 0); } var jaWhenSequence = (JArray)whenSequence; var currentItem = jaWhenSequence[pos]; context.Trace($"Examining {JSONUtil.SingleLine(query)} against {JSONUtil.SingleLine(jaWhenSequence)} at pos = {pos} ({JSONUtil.SingleLine(currentItem)})"); // try the unification at the current position - will return null if not able to unify var unification = Unification.Unify(currentItem, query); // if able to unify, instantiate constituent at that position if (unification != null) { context.Trace($"Unified {JSONUtil.SingleLine(currentItem)} with {JSONUtil.SingleLine(query)}"); currentItem = Unification.ApplyUnification(currentItem, unification); jaWhenSequence[pos] = currentItem; pos++; rule["#seq-pos"] = pos; // if sequence is complete, then return unification for the "then" portion to fire if (pos == jaWhenSequence.Count) { context.Trace($"Detected completed sequence {JSONUtil.SingleLine(jaWhenSequence)}"); //var clonedRule = (JObject)rule.DeepClone(); rule.Add("#unification", unification); // include the unification information results.Add(rule); } // if sequence is not complete, then throw a new arc on the open arcs for next round else { context.Trace($"Adding extended sequence {JSONUtil.SingleLine(jaWhenSequence)} [{pos}] to open arcs"); var arcSet = context.Fetch("#seq-arcs"); JObject joArcSet = null; JArray arcs = null; if (arcSet == null) { joArcSet = new JObject(); arcs = new JArray(); joArcSet.Add("rules", arcs); context.Store("#seq-arcs", joArcSet); } else { joArcSet = (JObject)arcSet; arcs = (JArray)joArcSet["rules"]; } arcs.Add(rule); //context.Store("#seq-arcs", joArcSet); } } } if (results.Count == 0) { return(null); } return(results); }