本文整理汇总了C#中IScriptEngine.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IScriptEngine.Execute方法的具体用法?C# IScriptEngine.Execute怎么用?C# IScriptEngine.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScriptEngine
的用法示例。
在下文中一共展示了IScriptEngine.Execute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScript
private CalamariResult ExecuteScript(IScriptEngine psse, string scriptName, CalamariVariableDictionary variables)
{
var capture = new CaptureCommandOutput();
var runner = new CommandLineRunner(capture);
var result = psse.Execute(scriptName, variables, runner);
return new CalamariResult(result.ExitCode, capture);
}
示例2: Run
public string Run(IScriptEngine engine, string[] args)
{
PrepareConsole();
var core = CreateCore(engine);
var evaluator = core.Evaluator;
var stdin = new StandardInputStream(evaluator, ConsoleColor.Green);
core.AddNativeModule("stdin", stdin);
SetOutputs(core);
if (args == null || args.Length == 0)
{
core.Sleep();
}
else if (args.Length == 1)
{
var path = "/" + args[0];
try
{
core.Run(path);
}
catch
{
core.Sleep();
}
}
else if (args.Length > 1)
{
evaluator.Execute("args = []");
var init = string.Empty;
var length = args.Length;
for (var i = 0; i < length; i++)
{
var arg = args[i];
var name = $"arg{i + 1}";
engine.Script[name] = arg;
init += $"args.push({name});";
}
evaluator.Execute(init);
}
if (core.Sleeping)
{
core.ExposeGlobalRequire();
engine.Execute("require('repl').hook(require('stdin'))");
stdin.Run();
}
return null;
}
示例3: SetUp
public void SetUp()
{
fileSystem = Substitute.For<ICalamariFileSystem>();
fileSystem.EnumerateFiles(Arg.Any<string>(), Arg.Any<string[]>()).Returns(new[]
{
TestEnvironment.ConstructRootedPath("App", "MyApp", "Hello.ps1"),
TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.ps1"),
TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.csx"),
TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1")
});
commandResult = new CommandResult("PowerShell.exe foo bar", 0, null);
scriptEngine = Substitute.For<IScriptEngine>();
scriptEngine.Execute(Arg.Any<string>(), Arg.Any<CalamariVariableDictionary>(), Arg.Any<ICommandLineRunner>()).Returns(c => commandResult);
scriptEngine.GetSupportedExtensions().Returns(new[] {"csx", "ps1"});
runner = Substitute.For<ICommandLineRunner>();
deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), new CalamariVariableDictionary());
}
示例4: ExecuteScript
public CommandResult ExecuteScript(IScriptEngine scriptEngine, string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner)
{
var workingDirectory = Path.GetDirectoryName(scriptFile);
variables.Set("OctopusAzureTargetScript", scriptFile);
// If the Azure PowerShell module to use has not been explicitly configured, then default to the version
// bundled with Calamari
SetOutputVariable(SpecialVariables.Action.Azure.Output.ModulePath,
variables.Get(SpecialVariables.Action.Azure.PowerShellModulePath, BuiltInAzurePowershellModulePath), variables);
SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionId, variables.Get(SpecialVariables.Action.Azure.SubscriptionId), variables);
SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionName, variables.Get(SpecialVariables.Account.Name), variables);
using (new TemporaryFile(CreateAzureCertificate(workingDirectory, variables)))
using (var contextScriptFile = new TemporaryFile(CreateContextScriptFile(workingDirectory)))
{
return scriptEngine.Execute(contextScriptFile.FilePath, variables, commandLineRunner);
}
}