Exemplo n.º 1
0
        public async Task CommandLine()
        {
            using TempFile tmp = new TempFile();
            File.WriteAllText(tmp.File.FullName, C_HelloWorld, Encoding.UTF8);

            StringTemplate source = new StringTemplate(
                StringTemplate.GetVariableTemplate(OperationVariables.VarInputPath.Name),
                new Variable[] {
                OperationVariables.VarInputPath
            }
                );

            SimpleCommandLineOperation op = new SimpleCommandLineOperation(new[]
            {
                new CommandLineTemplate()
                .UseCommand("python")
                .UseArgument(source)
            });

            ResolveContext context = new ResolveContext()
                                     .SetInputPath(tmp.File.FullName)
                                     .SetShell(Utils.GetShell());

            // op.CommandExecuting += Op_CommandExecuting;
            // op.CommandExecuted += Op_CommandExecuted;
            Pipeline <OperationWatcher, Wrapper <bool> > pipeline = await(await op.Resolve(context)).Build(new OperationWatcher(), new Logger());
            PipelineResult <Wrapper <bool> >             res      = await pipeline.Consume();

            Assert.IsTrue(res.IsOk && res.Result !);
        }
Exemplo n.º 2
0
        public async Task Text()
        {
            using TempFile temp = new TempFile();
            ResolveContext   context = new ResolveContext().WithVariable("name", "lily").WithVariable(FileTemplate.Var, temp.File.FullName);
            TextFileTemplate tf      = new TextFileTemplate(new StringTemplate(StringTemplate.GetVariableTemplate("name"), new Variable[] { new Variable("name").NotRequired("") }));
            FileInfo         fi      = await tf.Resolve(context);

            Assert.AreEqual("lily", File.ReadAllText(fi.FullName));
        }
Exemplo n.º 3
0
 private static Package <ITemplate> CreateSingleFile(string name, string ext, string source)
 {
     return(new Package <ITemplate>(new PackageFileTemplate(
                                        new StringTemplate(
                                            StringTemplate.GetVariableTemplate("name") + $".{ext}",
                                            new Variable[] { new Variable("name").Required() }
                                            )
                                        ).UseTemplate(new TextFileTemplate(new StringTemplate(source))))
     {
         Metadata = new PackageMetadata
         {
             Name = name,
             Author = nameof(CodeRunner),
             CreationTime = DateTimeOffset.Now,
             Version = Assembly.GetAssembly(typeof(FileTemplates))?.GetName().Version ?? new Version()
         }
     });
 }
        public static DirectoryTemplate GetDirectoryTemplate(string fileName = DefaultFileName)
        {
            Assert.IsNotNull(fileName);

            FileBasedCommandLineOperationSettings settings = new FileBasedCommandLineOperationSettings();
            PackageDirectoryTemplate res = new PackageDirectoryTemplate(new StringTemplate(StringTemplate.GetVariableTemplate("name"),
                                                                                           new Variable[] { new Variable("name").Required() }));

            return(res.AddFile(fileName)
                   .UseTemplate(new TextFileTemplate(new StringTemplate(JsonFormatter.Serialize(settings, new Newtonsoft.Json.JsonSerializerSettings())))));;
        }