public static void InitCtx(TestContext testContext) { var dir = AppDomain.CurrentDomain.BaseDirectory; var file = Path.Combine(dir, "dmn/dmn1.3/parallel.dmn"); def = DmnDefinitionFactory.CreateDmnDefinition(DmnParser.Parse13(file)); }
// ReSharper disable once InconsistentNaming protected static DmnDefinition DEF(string dmnFile, SourceEnum source) { return (source != SourceEnum.Builder ? DmnDefinitionFactory.CreateDmnDefinition(MODEL(dmnFile, source)) : DmnBuilderSamples.Files[dmnFile]); }
/// <summary> /// Creates the execution context from <paramref name="sourceModel"/> /// </summary> /// <param name="sourceModel">Source model to create the execution context for</param> /// <returns><paramref name="sourceModel"/> execution context</returns> /// <exception cref="ArgumentNullException"><paramref name="sourceModel"/> is null</exception> public static DmnExecutionContext CreateExecutionContext(DmnModel sourceModel) { if (sourceModel == null) { throw new ArgumentNullException(nameof(sourceModel)); } var definition = DmnDefinitionFactory.CreateDmnDefinition(sourceModel); return(CreateExecutionContext(definition)); }
/// <summary> /// Creates the execution context from <paramref name="sourceModel"/> /// </summary> /// <param name="sourceModel">Source model to create the execution context for</param> /// <param name="configure">Optional configuration action</param> /// <typeparam name="T">Type of the execution context to be created. Must be <see cref="DmnExecutionContext"/> or its descendant</typeparam> /// <returns><paramref name="sourceModel"/> execution context</returns> /// <exception cref="ArgumentNullException"><paramref name="sourceModel"/> is null</exception> public static DmnExecutionContext CreateCustomExecutionContext <T>( DmnModel sourceModel, Action <DmnExecutionContextOptions> configure = null) where T : DmnExecutionContext { if (sourceModel == null) { throw new ArgumentNullException(nameof(sourceModel)); } var definition = DmnDefinitionFactory.CreateDmnDefinition(sourceModel); return(CreateCustomExecutionContext <T>(definition, configure)); }
// [TestMethod] public void GenerateBuildersFromDmn() { var nl = Environment.NewLine; var split = "//------------------------------------" + nl; var dir = AppDomain.CurrentDomain.BaseDirectory; dir = Path.Combine(dir, "dmn"); var o = ""; var p = ""; var d = ""; var idx = 0; foreach (var file in Directory.GetFiles(dir, "*.dmn")) { var fileName = Path.GetFileName(file); if ( fileName.ToLower().EndsWith("_err.dmn") || fileName == "hitpolicy_WrongAggregation.dmn" || fileName == "hitpolicy_WrongPolicy.dmn") { continue; } var model = DmnParser.Parse(file); var def = DmnDefinitionFactory.CreateDmnDefinition(model); idx++; var prefix = $"f{idx:0#}"; var dmnPropName = fileName.Replace(".dmn", ""); dmnPropName = char.ToUpperInvariant(dmnPropName[0]) + dmnPropName.Substring(1); d += $@" Files[""{fileName}""]={dmnPropName};" + nl; p += $" public static DmnDefinition {dmnPropName} {{get;}}" + nl; o += split; o += $"//{fileName}" + nl; o += split; o += nl; o += $"{dmnPropName} = new DmnDefinitionBuilder()" + nl; foreach (var variable in def.Variables.Values) { if (variable.IsInputParameter) { if (variable.Type != null) { o += $@" .WithInput<{variable.Type?.Name ?? "object"}>(""{variable.Name}"", out var {prefix}{variable.Name})" + nl; } else { o += $@" .WithInput(""{variable.Name}"", out var {prefix}{variable.Name})" + nl; } } else { o += $@" .WithVariable<{variable.Type?.Name ?? "object"}>(""{variable.Name}"", out var {prefix}{variable.Name})" + nl; } } var generatedDecisions = new List <IDmnDecision>(); foreach (var decision in def.Decisions.Values) { o = GenerateDecisionBuilder(prefix, decision, o, generatedDecisions); } o += " .Build();" + nl; o += nl; } var c = ""; c += "public static class DmnBuilderSamples{" + nl; c += " public static Dictionary<string,DmnDefinition> Files=new Dictionary<string,DmnDefinition>();" + nl; c += p + nl; c += " static DmnBuilderSamples(){" + nl; c += o + nl; c += nl; c += d; c += " }" + nl; c += "}" + nl; }