/// <summary> /// Execute NuGet to restore all package references. /// </summary> /// <returns>True if the operation succeeded.</returns> private bool NuGetRestore() { // // Execute 'nuget.exe restore' in the solution directory. // var process = new Utilities.ConsoleApp(Path.Combine(Environment.CurrentDirectory, "nuget.exe")) { WorkingDirectory = Support.GetBuildPath() }; process.StandardTextReceived += Console_StandardTextReceived; process.ExecuteAsync("restore"); // // Wait for it to finish. // while (process.Running) { Thread.Sleep(100); } // // Make sure it worked. // if (process.ExitCode != 0) { UpdateStatusText("NuGet Restore Failed."); return(false); } return(true); }
/// <summary> /// Notification that the application is about to shutdown. Terminate all our child /// processes. /// </summary> /// <param name="sender">The object that is sending this event.</param> /// <param name="e">The arguments that describe the event.</param> private void Dispatcher_ShutdownStarted(object sender, EventArgs e) { // // If we have an IIS Express process, then kill it. // if (iisExpressProcess != null) { iisExpressProcess.Kill(); iisExpressProcess = null; } // // If we have a LocalDb instance, then kill it off. // if (localDb != null) { if (localDb.IsRunning) { localDb.Stop(); } localDb = null; } UpdateState(); }
/// <summary> /// Build the release so we have compiled DLLs. /// </summary> private void BuildRelease() { // // Restore any NuGet packages. // UpdateStatusText("Restoring References"); if (!NuGetRestore()) { BuildCompleted?.Invoke(this, new EventArgs()); return; } // // For some reason, MSBuild fails completely and the devenv build method // does not copy indirect DLL references (e.g. the NuGet DLLs) into the // RockWeb folder, so we need to do that manually. // foreach (var d in GetReferencedProjects()) { CopyProjectReferences(d); } // // Launch a new devenv.com process to build the solution. // UpdateStatusText("Building..."); var process = new Utilities.ConsoleApp(DevEnvExecutable); process.StandardTextReceived += Console_StandardTextReceived; process.WorkingDirectory = Support.GetBuildPath(); process.ExecuteAsync("Rock.sln", "/Build"); // // Wait for it to complete. // while (process.Running) { Thread.Sleep(100); } // // Check if our build worked or not. // if (process.ExitCode != 0) { UpdateStatusText("Build Failed."); BuildCompleted?.Invoke(this, new EventArgs()); return; } BuildTemplate(); }
/// <summary> /// Stops the instance. /// </summary> public void StopInstance() { if (iisExpressProcess != null) { iisExpressProcess.Kill(); iisExpressProcess = null; } if (RunningInstanceName != null) { try { using (var connection = localDb.CreateConnection()) { connection.Open(); // // Shrink the log file. // connection.ChangeDatabase(RunningInstanceName); var cmd = connection.CreateCommand(); cmd.CommandText = "DBCC SHRINKFILE ([Database_log.ldf], 1)"; cmd.ExecuteNonQuery(); // // Detach the database. // connection.ChangeDatabase("master"); cmd = connection.CreateCommand(); cmd.CommandText = string.Format("exec sp_detach_db [{0}]", RunningInstanceName); cmd.ExecuteNonQuery(); } } catch { /* Intentionally left blank */ } RunningInstanceName = null; } Dispatcher.Invoke(() => { txtStatus.Text = "Idle"; UpdateState(); }); }
/// <summary> /// Execute NuGet to restore all package references. /// </summary> /// <returns>True if the operation succeeded.</returns> private bool NuGetRestore(string projectPath) { // // Check if the project even uses NuGet packages. // if (!File.Exists(Path.Combine(projectPath, "packages.config"))) { return(true); } // // Execute 'nuget.exe restore' in the solution directory. // var process = new Utilities.ConsoleApp(Path.Combine(Environment.CurrentDirectory, "nuget.exe")) { WorkingDirectory = projectPath }; process.StandardTextReceived += Console_StandardTextReceived; process.ErrorTextReceived += Console_StandardTextReceived; process.ExecuteAsync("restore", "-PackagesDirectory", "packages"); // // Wait for it to finish. // while (process.Running) { Thread.Sleep(100); } // // Make sure it worked. // if (process.ExitCode != 0) { UpdateStatusText("NuGet Restore Failed."); return(false); } return(true); }
/// <summary> /// Build the project so we have compiled DLLs. /// </summary> public bool BuildProject(string projectFile, string msbuild) { // // Restore any NuGet packages. // UpdateStatusText("Restoring References"); if (!NuGetRestore(Path.GetDirectoryName(projectFile))) { return(false); } // // Launch a new devenv.com process to build the solution. // UpdateStatusText("Building..."); var process = new Utilities.ConsoleApp(msbuild); process.StandardTextReceived += Console_StandardTextReceived; process.ErrorTextReceived += Console_StandardTextReceived; process.WorkingDirectory = Path.GetDirectoryName(projectFile); process.ExecuteAsync(projectFile, "/P:Configuration=Release"); // // Wait for it to complete. // while (process.Running) { Task.Delay(100).Wait(); } // // Check if our build worked or not. // if (process.ExitCode != 0) { return(false); } return(true); }
/// <summary> /// The IIS Express process has ended, perhaps unexpectedly. /// </summary> /// <param name="sender">The object that is sending this event.</param> /// <param name="e">The arguments that describe the event.</param> private void IisExpressProcess_Exited(object sender, EventArgs e) { iisExpressProcess = null; Dispatcher.Invoke(() => { UpdateState(); }); }
/// <summary> /// Starts the instance. /// </summary> /// <param name="instanceName">Name of the instance.</param> /// <exception cref="Exception"> /// There is an instance already running. /// or /// </exception> public void StartInstance(string instanceName, int port) { int instanceIndex = -1; if (iisExpressProcess != null) { throw new Exception("There is an instance already running."); } Dispatcher.Invoke(() => { txtStatus.Text = "Starting..."; txtConsole.Text = string.Empty; var items = (List <string>)cbInstances.ItemsSource; instanceIndex = items.IndexOf(instanceName); if (instanceIndex != -1) { cbInstances.SelectedIndex = instanceIndex; } txtPort.Text = port.ToString(); }); // // Find the path to the RockWeb instance. // var path = Path.Combine(Support.GetInstancesPath(), instanceName, "RockWeb"); if (!Directory.Exists(path) || instanceIndex == -1) { throw new Exception(string.Format("The instance '{0}' was not found.", instanceName)); } // // Check if the Database file already exists and if not create the // Run.Migration file so Rock initializes itself. // var dbPath = Path.Combine(path, "App_Data", "Database.mdf"); if (!File.Exists(dbPath)) { var runMigrationPath = Path.Combine(path, "App_Data", "Run.Migration"); File.WriteAllText(runMigrationPath, string.Empty); } ConfigureConnectionString(path); // // Prepare the IIS Express process for this RockWeb. // iisExpressProcess = new Utilities.ConsoleApp(GetIisExecutable()); iisExpressProcess.ProcessExited += IisExpressProcess_Exited; iisExpressProcess.StandardTextReceived += IisExpressProcess_StandardTextReceived; RunningInstanceName = instanceName; // // Update the status text to contain a clickable link to the instance. // Dispatcher.Invoke(() => { var linkText = string.Format("http://localhost:{0}/", port); var link = new Hyperlink(new Run(linkText)) { NavigateUri = new Uri(linkText) }; link.RequestNavigate += StatusLink_RequestNavigate; txtStatus.Inlines.Clear(); txtStatus.Inlines.Add(new Run("Running at ")); txtStatus.Inlines.Add(link); UpdateState(); }); // // Launch IIS Express. // iisExpressProcess.ExecuteAsync(String.Format("/path:{0}", path), String.Format("/port:{0}", port)); }