public void Process(JObject command, Context context) { // get the query object // this will be used to match against the rules var query = JSONUtil.GetToken(command, "#assert"); if (query == null) { query = JSONUtil.GetToken(command, "query"); } // search through each Item in the Context var items = context.Items.Keys.ToList(); foreach (var item in items) { // search the Item for matching rules // unifying any variables provided by the query var jtItem = context.Items[item]; var results = this.FindRules(jtItem, query, context); if (results == null) { continue; } // if there were any results (rules that matched) foreach (var result in results) { var jaResults = (JArray)result; foreach (var jaResult in jaResults) { // grab the then (consequent) portion into an array of commands var then = jaResult["then"]; // apply the unification that was determined when the rule was matched var unification = (JObject)jaResult["#unification"]; unification.Add("?#", query); then = Unification.ApplyUnification(then, unification); // grab the array of commands (convert single to array) var jCommands = new JArray(); if (then is JObject) { jCommands.Add(then); } else if (then is JArray) { jCommands = (JArray)then; } // run each command foreach (JObject joTokenCommand in jCommands) { context.CommandEngine.RunCommand(joTokenCommand, context); } } } } }
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 Process(JObject command, Context context) { var entity = JSONUtil.GetToken(command, "#cds-retrieve-data"); if (entity == null) { entity = JSONUtil.GetToken(command, "entity"); } if (entity == null) { return; } //string optionset = null; //if (entity.Length == 0) { optionset = CommandEngine.GetCommandArgument(command, "Option Set"); } string into = CommandEngine.GetCommandArgument(command, "into"); //string env = CommandEngine.GetCommandArgument(command, "env"); CDSConnection cdsConnection = CDSConnection.FromCommand(command, context); if (cdsConnection == null) { return; } ColumnSet columns = new ColumnSet(true); if (command["fields"] != null) { string fieldlist = command["fields"].ToString(); if (fieldlist.Length > 0) { List <string> fields = fieldlist.Split(',').Select(p => p.Trim()).ToList(); columns = new ColumnSet(fields.ToArray()); } } //var cdsConnection = (CDSConnection)context.GetConnection(env); //if (optionset == null) //{ Console.WriteLine("Loading CDS Entity Data {0} into {1}", entity, into); var sub = cdsConnection.RetrieveEntityData(entity.ToString(), columns); context.Store(into, sub); //} //else //{ //Console.WriteLine("Loading CDS OptionSet {0} into {1}", entity, into); // var sub = cdsConnection.RetrieveOptionSet(entity, optionset); // context.Store(into, sub); //} }
public void Process(JObject command, Context context) { // get default property var query = JSONUtil.GetToken(command, "#run-rules"); if (query == null) { query = JSONUtil.GetToken(command, "query"); } var items = context.Items.Keys.ToList(); foreach (var item in items) { var jtItem = context.Items[item]; var results = this.FindRules(jtItem, query); if (results == null) { continue; } foreach (var result in results) { var then = result["then"]; var unification = (JObject)result["#unification"]; unification.Add("?#", query); then = Unification.ApplyUnification(then, unification); if (then is JObject) { context.CommandEngine.RunCommand(then, context); } else if (then is JArray jCommands) { foreach (JObject joTokenCommand in jCommands) { context.CommandEngine.RunCommand(joTokenCommand, context); } } } } }
public void Process(JObject command, Context context) { // get default property var item = JSONUtil.GetToken(command, "communicate"); if (item == null) { item = JSONUtil.GetToken(command, "#communicate"); } if (item == null) { item = JSONUtil.GetToken(command, "#say"); } // get all other properties var select = JSONUtil.GetText(command, "select"); var rate = JSONUtil.GetInt32(command, "rate"); item = context.ReplaceVariables(item); if (select != null) { item = item.SelectToken(select); } if (rate != null) { var iRate = (int)rate; // get it? :) foreach (char c in item.ToString()) { Console.Write(c); System.Threading.Thread.Sleep(iRate); } Console.WriteLine(); } else { Console.WriteLine(item); } }