private int InvokeScript(VariableDictionary variables) { if (!File.Exists(scriptFile)) { throw new CommandException("Could not find script file: " + scriptFile); } var engine = new ScriptEngineSelector().SelectEngine(scriptFile); var runner = new CommandLineRunner( new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var result = engine.Execute(scriptFile, variables, runner); return(result.ExitCode); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg"); if (!File.Exists(packageFile)) { throw new CommandException("Could not find package file: " + packageFile); } if (variablesFile != null && !File.Exists(variablesFile)) { throw new CommandException("Could not find variables file: " + variablesFile); } Log.Info("Deploying package: " + packageFile); if (variablesFile != null) { Log.Info("Using variables from: " + variablesFile); } var variables = new VariableDictionary(variablesFile); var fileSystem = new CalamariPhysicalFileSystem(); var scriptEngine = new ScriptEngineSelector(); var replacer = new ConfigurationVariablesReplacer(); var substituter = new FileSubstituter(); var configurationTransformer = new ConfigurationTransformer(variables.GetFlag(SpecialVariables.Package.IgnoreConfigTransformationErrors), variables.GetFlag(SpecialVariables.Package.SuppressConfigTransformationLogging)); var embeddedResources = new ExecutingAssemblyEmbeddedResources(); var iis = new InternetInformationServer(); var semaphore = new SystemSemaphore(); var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables))); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), new ExtractPackageToApplicationDirectoryConvention(new LightweightPackageExtractor(), fileSystem, semaphore), new FeatureScriptConvention(DeploymentStages.BeforePreDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, scriptEngine, fileSystem, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPreDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), new SubstituteInFilesConvention(fileSystem, substituter), new ConfigurationTransformsConvention(fileSystem, configurationTransformer), new ConfigurationVariablesConvention(fileSystem, replacer), new AzureConfigurationConvention(), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureScriptConvention(DeploymentStages.BeforeDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, scriptEngine, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), new LegacyIisWebSiteConvention(fileSystem, iis), new AzureUploadConvention(), new AzureDeploymentConvention(), new FeatureScriptConvention(DeploymentStages.BeforePostDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, scriptEngine, fileSystem, commandLineRunner), new FeatureScriptConvention(DeploymentStages.AfterPostDeploy, fileSystem, embeddedResources, scriptEngine, commandLineRunner), }; var deployment = new RunningDeployment(packageFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }