static void Bootstrap(FileInfo csdl, string subscriptionId, string appServiceName) { if (subscriptionId != null) { Console.WriteLine($"Subscription Id: {subscriptionId}"); } if (csdl != null) { Console.WriteLine($"Csdl Path: {csdl.FullName}"); } Console.WriteLine("Cloning from git ....."); string _args = "https://github.com/habbes/ODataApiServiceHackathon.git"; string tempWorkingDir = Path.GetTempPath() + appServiceName; Console.WriteLine(tempWorkingDir); while (Directory.Exists(tempWorkingDir)) { tempWorkingDir += "-" + RandomString(3); } Console.WriteLine($"Cloning to {tempWorkingDir}"); Repository.Clone(_args, tempWorkingDir); var projectPreparer = new ProjectPreparer(tempWorkingDir, csdl.FullName, appServiceName); projectPreparer.Prepare(); var parametersJsonPath = projectPreparer.ParamsPath; var projectZipPath = projectPreparer.ZipPath; Console.WriteLine($"JsonParams {parametersJsonPath}"); Console.WriteLine($"ProjectZip {projectZipPath}"); //Execute the powershell script using (PowerShell PowerShellInst = PowerShell.Create()) { //string path = System.IO.Path.GetDirectoryName(@"C:\Temp\") + "\\Get-EventLog.ps1"; string path = @"ODataCLI\deploy.ps1"; if (!string.IsNullOrEmpty(path)) { PowerShellInst .AddScript(File.ReadAllText(path)) .AddParameter("subscriptionId", subscriptionId) .AddParameter("projectFilePath", projectZipPath) .AddParameter("parametersFilePath", parametersJsonPath) .AddParameter("resourceGroupName", $"rg_{appServiceName}") .AddParameter("deploymentName", $"dpl_{appServiceName}") .Invoke(); } } Console.WriteLine($"Cleaning directory: {tempWorkingDir}"); DeleteDirectory(tempWorkingDir); }
static void Bootstrap(FileInfo csdl, string subscriptionId, string appServiceName) { if (subscriptionId != null) { Console.WriteLine($"Subscription Id: {subscriptionId}"); } if (csdl != null) { Console.WriteLine($"Schema Path: {csdl.FullName}"); } if (appServiceName != null) { Console.WriteLine($"App service name: {appServiceName}"); } Console.WriteLine("Preparing your API service..."); string _args = "https://github.com/habbes/ODataApiServiceHackathon.git"; string tempWorkingDir = Path.GetTempPath() + appServiceName; while (Directory.Exists(tempWorkingDir)) { tempWorkingDir += "-" + RandomString(3); } Repository.Clone(_args, tempWorkingDir); var projectPreparer = new ProjectPreparer(tempWorkingDir, csdl.FullName, appServiceName); projectPreparer.Prepare(); var parametersJsonPath = projectPreparer.ParamsPath; var projectZipPath = projectPreparer.ZipPath; // We experienced issues using PowerShell, propbably because it's a .Net Framework library // We also had issues related to execution policies // We resorted to call the powershell script from the Process.ExecuteAsync instead // We can restore this (and reinstall the NuGet package) once we figure out how to get it to work //Execute the powershell script //using (PowerShell PowerShellInst = PowerShell.Create()) //{ // //string path = System.IO.Path.GetDirectoryName(@"C:\Temp\") + "\\Get-EventLog.ps1"; // string path = @"RapidApi\deploy.ps1"; // if (!string.IsNullOrEmpty(path)) // { // PowerShellInst // //.AddScript("Set-ExecutionPolicy RemoteSigned") // .AddScript(File.ReadAllText(path)) // .AddParameter("subscriptionId", subscriptionId) // .AddParameter("projectFilePath", projectZipPath) // .AddParameter("parametersFilePath", parametersJsonPath) // .AddParameter("resourceGroupName", $"rg_{appServiceName}") // .AddParameter("deploymentName", $"dpl_{appServiceName}") // .Invoke(new[] { "Set - ExecutionPolicy Unrestricted - Scope Process" }); // } //} var args = $"--subscription {subscriptionId} --projectFilePath {projectZipPath} --parametersFilePath {parametersJsonPath} --resourceGroupName rg{appServiceName} --deploymentName dpl_{appServiceName} --templateFilePath RapidApi\\azuredeploy.json"; Process.ExecuteAsync("powershell", $" -ExecutionPolicy RemoteSigned -File \"RapidApi\\deploy.ps1\" {args}", Environment.CurrentDirectory, stdOut => { Console.WriteLine(stdOut); }, stdErr => { Console.Error.WriteLine(stdErr); }).Wait(); DeleteDirectory(tempWorkingDir); }