public IResult AddManualTask(int nodeId, int nodeDepth, int rootCaseStateId) { try { const string title = "Task Configuration"; const string prompt = "Select a Task Configuration to include in the Case Filter."; var choices = _tasks.GetManualConfigurations(rootCaseStateId).OrderBy(x => x.Title).ToList(); if (!choices.Any()) { var message = $"You have no manual configuration tasks set-up for the CaseState: {_tasks.GetCaseStateName(rootCaseStateId)}"; return(new ResultFactory().ErrorMessage(message)); } TaskConfiguration chosenConfiguration; if (Coercion.TryCoerceChoice(title, prompt, choices, out chosenConfiguration)) { //Todo:take selected task config and add it to the selected node's children list. If it has no children add it as a row on the groups table before adding to sources. using (var ctx = new PureDataContext(DevDb)) { var nodeConfigGroupId = ctx .Set <TaskConfigGroup>().FirstOrDefault(x => x.ParentTaskConfigId == nodeId || x.ParentCaseStateId == nodeId); //This logic doesn't work. What is cs has same id as tc. //If it doesn't exist within the groups table, create it. if (nodeConfigGroupId == null) { var newConfigGroupRow = new TaskConfigGroup() { ParentTaskConfigId = nodeId, Depth = nodeDepth + 1, }; ctx.Set <TaskConfigGroup>().Add(newConfigGroupRow); ctx.SaveChanges(); //Duplicate nodeConfigGroupId line here when fixed. nodeConfigGroupId = ctx .Set <TaskConfigGroup>().FirstOrDefault(x => x.ParentTaskConfigId == nodeId || x.ParentCaseStateId == nodeId); } var newTaskConfigSource = new TaskConfigSource() { TaskConfigGroupId = nodeConfigGroupId.TaskConfigGroupId, TaskConfigurationId = chosenConfiguration.TaskConfigurationId }; ctx.Set <TaskConfigSource>().Add(newTaskConfigSource); ctx.SaveChanges(); } } return(new ResultFactory().Ok()); } catch (Exception ex) { return(new ResultFactory().Error(ex)); } }
public void Coercion_Coerce() { ICoercion coercion = new Coercion(); var result = coercion.Coerce("source", typeof(string)); Assert.Equal("source", result); }
internal static DialogDebugAdapter MakeDebugger(IDebugTransport transport) { var codeModel = new CodeModel(); var sourceMap = new DebuggerSourceMap(codeModel); var events = new Events <DialogEvents>(); var coercion = new Coercion(); var dataModel = new DataModel(coercion); var debugger = new DialogDebugAdapter(transport, sourceMap, sourceMap, () => { }, events, codeModel, dataModel, NullLogger.Instance, coercion); return(debugger); }
public void ReflectionDataModel_Properties() { ICoercion coercion = new Coercion(); IDataModel reflectionDataModel = new ReflectionDataModel <string>(coercion); Assert.Equal(2, reflectionDataModel.Rank); var names = reflectionDataModel.Names(new List <string> { "context" }); Assert.Equal(2, names.Count()); }
public void ListDataModel_Properties() { ICoercion coercion = new Coercion(); IDataModel listDataModel = new ListDataModel <string>(coercion); Assert.Equal(4, listDataModel.Rank); var names = listDataModel.Names(new List <string> { "context" }); Assert.Single(names); }
public void EnumerableDataModel_Properties() { ICoercion coercion = new Coercion(); var dictionaryDataModel = new EnumerableDataModel <string>(coercion); Assert.Equal(3, dictionaryDataModel.Rank); var names = dictionaryDataModel.Names(new List <string> { "context" }); Assert.Single(names); Assert.Equal(0, names.First()); }
public void DictionaryDataModel_Properties() { ICoercion coercion = new Coercion(); var dictionaryDataModel = new DictionaryDataModel <string, string>(coercion); Assert.Equal(6, dictionaryDataModel.Rank); var context = new Dictionary <string, string> { { "key", "value" } }; var names = dictionaryDataModel.Names(context); Assert.Single(names); Assert.Equal("key", names.First()); }
public void Coercion_Coerce_JToken() { ICoercion coercion = new Coercion(); var writer = new JTokenWriter(); writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue("request"); writer.WritePropertyName("command"); writer.WriteValue("launch"); writer.WriteEndObject(); var result = coercion.Coerce(writer.Token, typeof(JToken)); Assert.Equal(writer.Token, result); }
public void DataModel_Properties() { ICoercion coercion = new Coercion(); IDataModel dataModel = new DataModel(coercion); Assert.Equal(2147483647, dataModel.Rank); var scalar = dataModel.IsScalar("context"); Assert.True(scalar); scalar = dataModel.IsScalar(null); Assert.True(scalar); var names = dataModel.Names("context"); Assert.Empty(names); }
static void Main(string[] args) { jsGlobal = new Global(); // Similar to the local this object var scope = new JSObject(jsGlobal); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); // Right, we're set up. What follows is code auto-generated from JS: scope.SetKey("n", new JSNumber(1)); scope.SetKey("runNextFizzbuzz", new JSNativeFunction(args => { scope.SetKey("str", new JSString("")); if (Coercion.CoerceToBool(Operators.StrictlyEqual(Operators.Remainder(scope.GetKey("n"), new JSNumber(3)), new JSNumber(0))).Value) { scope.SetKey("str", new JSString("Fizz")); } if (Coercion.CoerceToBool(Operators.StrictlyEqual(Operators.Remainder(scope.GetKey("n"), new JSNumber(5)), new JSNumber(0))).Value) { scope.SetKey("str", Operators.Plus(scope.GetKey("str"), new JSString("Buzz"))); } if (Coercion.CoerceToBool(Operators.StrictlyEqual(scope.GetKey("str"), new JSString(""))).Value) { scope.SetKey("str", scope.GetKey("n")); } ((scope.GetKey("console")).GetKey((new JSString("log")).AsCSharpString)).Call(new IJSObject[] { scope.GetKey("str"), }); scope.SetKey("n", Operators.Plus(scope.GetKey("n"), new JSNumber(1))); if (Coercion.CoerceToBool(Operators.StrictlyNotEqual(scope.GetKey("n"), new JSNumber(101))).Value) { (scope.GetKey("runNextFizzbuzz")).Call(new IJSObject[] {}); } return(new JSUndefined()); })); (scope.GetKey("runNextFizzbuzz")).Call(new IJSObject[] {}); watch.Stop(); System.Console.WriteLine($"Execution Time: { watch.ElapsedMilliseconds}ms"); }
public void DataModel_ToString() { ICoercion coercion = new Coercion(); IDataModel dataModel = new DataModel(coercion); var model = dataModel.ToString("context"); Assert.Equal("context", model); var jTokenResult = dataModel.ToString(new JValue(true)); Assert.Equal("True", jTokenResult); var classResult = dataModel.ToString(new Coercion()); Assert.Equal("Microsoft.Bot.Builder.Dialogs.Debugging.DataModels.Coercion", classResult); var enumerableTypeResult = dataModel.ToString(new TestEnumerableDataModel()); Assert.Equal( "Microsoft.Bot.Builder.Dialogs.Debugging.Tests.DataModels.DataModelsTests+TestEnumerableDataModel", enumerableTypeResult); var readOnlyDictionaryTypeResult = dataModel.ToString(new TestReadOnlyDictionaryDataModel()); Assert.Equal( "Microsoft.Bot.Builder.Dialogs.Debugging.Tests.DataModels.DataModelsTests+TestReadOnlyDictionaryDataModel", readOnlyDictionaryTypeResult); var dictionaryTypeResult = dataModel.ToString(new TestDictionaryDataModel()); Assert.Equal( "Microsoft.Bot.Builder.Dialogs.Debugging.Tests.DataModels.DataModelsTests+TestDictionaryDataModel", dictionaryTypeResult); var listTypeResult = dataModel.ToString(new TestListDataModel()); Assert.Equal("Microsoft.Bot.Builder.Dialogs.Debugging.Tests.DataModels.DataModelsTests+TestListDataModel", listTypeResult); }