/// <summary> /// Initializes a new instance of the <see cref="ExternalScript"/> class. /// </summary> /// <param name="scriptFile"> /// The physical script file that will be executed when Windows Sandbox is booted up. /// </param> /// <param name="translator"> /// Translator that generates the a command in order this script to be launched from powershell. /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> public ExternalScript(FileSystemInfo scriptFile, IPowershellTranslator translator) : this( scriptFile, translator, FileSystemAbstractions.CopyFileToDestination) { }
/// <summary> /// Initializes a new instance of the <see cref="ExternalScript"/> class. /// This constructor is solely for testing purposes and contains framework specific classes that cannot be tested. /// </summary> /// <param name="scriptFile"> /// The physical script file that will be executed when Windows Sandbox is booted up. /// </param> /// <param name="translator"> /// Translator that generates the a command in order this script to be launched from powershell. /// </param> /// <param name="copyFileToDestination"> /// Delegate that takes source and destination as parameter and copies source to destination. /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> internal ExternalScript( FileSystemInfo scriptFile, IPowershellTranslator translator, Func <string, string, CancellationToken, Task> copyFileToDestination) { if (scriptFile == null) { throw new ArgumentNullException(nameof(scriptFile)); } if (translator == null) { throw new ArgumentNullException(nameof(translator)); } if (copyFileToDestination == null) { throw new ArgumentNullException(nameof(copyFileToDestination)); } ScriptFile = scriptFile; Translator = translator; _copyFileToDestination = copyFileToDestination; }
/// <summary> /// Initializes a new instance of the <see cref="ChocolateyPackageManagerScript"/> class. /// </summary> /// <param name="applications"> /// Applications that will be installed using this package manager. /// </param> /// <param name="translator"> /// Translator that will used to generate command that will be run from powershell. /// <para> /// The default translate is <see cref="PowershellTranslator"/>. /// </para> /// <para> /// This constructor is defined solely if the user has defined custom translator using <see cref="IPowershellTranslator"/>. /// </para> /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> public ChocolateyPackageManagerScript(IEnumerable <string> applications, IPowershellTranslator translator) : this( applications, translator, $"{nameof(ChocolateyPackageManagerScript)}.ps1") { }
/// <summary> /// Initializes a new instance of the <see cref="ExternalScript"/> class. /// This constructor is solely for testing purposes and contains framework specific classes that cannot be tested. /// </summary> /// <param name="commands"> /// Literal user scripts. /// </param> /// <param name="translator"> /// Translator that will generate command which will call this script from powershell. /// </param> /// <param name="scriptFileName"> /// The script file name including the extension that will be generated with containing user scripts. /// </param> /// <param name="writeAllBytesAsync"> /// Delegate that takes filePath, content and cancellation token as parameter and generate a new file asynchronously. /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> internal LiteralScript( IList <string> commands, IPowershellTranslator translator, string scriptFileName, Func <string, byte[], CancellationToken, Task> writeAllBytesAsync) { if (commands == null || !commands.Any()) { throw new ArgumentNullException(nameof(commands)); } if (translator == null) { throw new ArgumentNullException(nameof(translator)); } if (string.IsNullOrWhiteSpace(scriptFileName)) { throw new ArgumentNullException(nameof(scriptFileName)); } if (writeAllBytesAsync == null) { throw new ArgumentNullException(nameof(writeAllBytesAsync)); } Translator = translator; _commands = commands; _baseScriptFileName = scriptFileName; _writeAllBytesAsync = writeAllBytesAsync; }
/// <summary> /// Initializes a new instance of the <see cref="LiteralScript"/> class. /// </summary> /// <param name="commands"> /// Literal user scripts. /// </param> /// <param name="translator"> /// Translator that will generate command which will call this script from powershell. /// </param> /// <param name="scriptFileName"> /// The script file name including the extension that will be generated with containing user scripts. /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> public LiteralScript(IList <string> commands, IPowershellTranslator translator, string scriptFileName) : this( commands, translator, scriptFileName, FileSystemAbstractions.WriteAllBytesAsync) { }
public static async Task <LiteralScript> ProcessLiteralScriptFactory( IList <string> scripts, IPowershellTranslator translator, string scriptName, IOptions options) { var literalScript = new LiteralScript(scripts, translator, scriptName); await literalScript.Process(options); return(literalScript); }
/// <summary> /// Initializes a new instance of the <see cref="ChocolateyPackageManagerScript"/> class. /// </summary> /// <param name="applications"> /// Applications that will be installed using this package manager. /// </param> /// <param name="translator"> /// Translator that will used to generate command that will be run from powershell. /// <para> /// The default translate is <see cref="PowershellTranslator"/>. /// </para> /// <para> /// This constructor is defined solely if the user has defined custom translator using <see cref="IPowershellTranslator"/>. /// </para> /// </param> /// <param name="scriptName"> /// The name of the script that will be generated. /// <para>The default is ChocolateyPackageManagerScript.ps1</para> /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> public ChocolateyPackageManagerScript( IEnumerable <string> applications, IPowershellTranslator translator, string scriptName) : this( applications, translator, scriptName, new StringBuilder(), FileSystemAbstractions.WriteAllBytesAsync) { }
public void ShouldInitializeTranslator() { string fileName = "MockFileName"; FileSystemInfo fileSystemInfo = new MockFileSystemInfo(fileName); IPowershellTranslator translator = new PowershellTranslator(); ExternalScript externalScript = new ExternalScript(fileSystemInfo, translator); IPowershellTranslator expected = translator; IPowershellTranslator actual = externalScript.Translator; Assert.Equal(expected, actual); }
/// <summary> /// Initializes a new instance of the <see cref="ChocolateyPackageManagerScript"/> class. /// This constructor is solely for testing purposes and contains framework specific classes that cannot be tested. /// </summary> /// <param name="applications"> /// Applications that will be installed using this package manager. /// </param> /// <param name="translator"> /// Translator that will used to generate command that will be run from powershell. /// <para> /// The default translate is <see cref="PowershellTranslator"/>. /// </para> /// <para> /// This constructor is defined solely if the user has defined custom translator using <see cref="IPowershellTranslator"/>. /// </para> /// </param> /// <param name="scriptName"> /// The name of the script that will be generated. /// <para>The default is ChocolateyPackageManagerScript.ps1</para> /// </param> /// <param name="writeAllBytesAsync"> /// Delegate that takes filePath, content and cancellation token as parameter and generate a new file asynchronously. /// </param> /// <exception cref="ArgumentNullException">Thrown when any of the parameters are null.</exception> internal ChocolateyPackageManagerScript( IEnumerable <string> applications, IPowershellTranslator translator, string packageManagerScriptName, StringBuilder sbChocolateyPackageManagerBuilder, Func <string, byte[], CancellationToken, Task> writeAllBytesAsync) { if (applications == null || !applications.Any()) { throw new ArgumentNullException(nameof(applications)); } if (translator == null) { throw new ArgumentNullException(nameof(translator)); } if (string.IsNullOrWhiteSpace(packageManagerScriptName)) { throw new ArgumentNullException(nameof(packageManagerScriptName)); } if (sbChocolateyPackageManagerBuilder == null) { throw new ArgumentNullException(nameof(sbChocolateyPackageManagerBuilder)); } if (writeAllBytesAsync == null) { throw new ArgumentNullException(nameof(writeAllBytesAsync)); } Applications = applications; Translator = translator; _packageManagerScriptName = packageManagerScriptName; _sbChocolatePackageManagerBuilder = sbChocolateyPackageManagerBuilder; _writeAllBytesAsync = writeAllBytesAsync; }