public static CodeTypeDeclaration Ensure(CodeGeneratorContext context) { var type = context.CreateIntentRequestHandler(BuiltInIntent.Fallback).FirstType(); var handle = type.MethodStatements(CodeConstants.HandlerPrimaryMethod); CodeGeneration_Interaction.AddHandlerCheck(handle, context, CodeConstants.FallbackMarker); var returnStmt = handle.OfType <CodeMethodReturnStatement>().First(); if (!(returnStmt.Expression is CodeMethodInvokeExpression)) { handle.Remove(returnStmt); handle.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("await " + BuiltInIntent.Fallback.Safe()), "Fallback" ).AddFlowParameters())); } var invoke = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("await Navigation"), CodeConstants.NavigationMethodName); invoke.AddFlowParameters(); return(type); }
public static Task CreateIn(CodeGeneratorContext context, string directoryFullName) { CodeGeneration_Story.CreateProjectFile(context); if (!context.RequestHandlers.ContainsKey("AMAZON.StopIntent")) { CodeGeneration_Interaction.AddIntent(context, new List <string> { "stop" }, new CodeStatementCollection()); } UpdatePipeline((CodeCompileUnit)context.OtherFiles["Pipeline.cs"], context.RequestHandlers.Keys.ToArray()); CodeGeneration_Fallback.Ensure(context); var json = JsonSerializer.Create(new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented }); using (var csharp = CodeDomProvider.CreateProvider(CodeDomProvider.GetLanguageFromExtension(".cs"))) { var sceneFileDirectory = Path.Combine(directoryFullName, "Scenes"); var handlerFileDirectory = Path.Combine(directoryFullName, "RequestHandlers"); Directory.CreateDirectory(sceneFileDirectory); Directory.CreateDirectory(handlerFileDirectory); return(Task.WhenAll( OutputRootFiles(context.OtherFiles, csharp, json, directoryFullName), OutputSkillManifest(context, json, directoryFullName), OutputSceneFiles(context.SceneFiles, csharp, sceneFileDirectory), OutputRequestHandlers(context.RequestHandlers, csharp, handlerFileDirectory) )); } }
protected override Task Begin(SceneInstructionContainer instructions, CodeGeneratorContext context) { CodeStatementCollection statements = context.CodeScope.Statements(); switch (instructions) { case If ifStmt: { var codeIf = new CodeConditionStatement(CodeGeneration_Condition.Generate(ifStmt.Condition)); statements.Add(codeIf); context.CodeScope.Push(codeIf); break; } case Hear hear when !context.CodeScope.OfType <Hear>().Any(): CodeGeneration_Interaction.AddHearMarker(context, statements); CodeGeneration_Interaction.AddIntent(context, hear.Phrases, statements); break; } return(base.Begin(instructions, context)); }