/// <summary> /// Delete the selected instance from disk. /// </summary> /// <param name="sender">The object that is sending this event.</param> /// <param name="e">The arguments that describe the event.</param> private void btnMakeTemplate_Click(object sender, RoutedEventArgs e) { var textInputDialog = new Dialogs.TextInputDialog(this, "Template Name"); if (!textInputDialog.ShowDialog() ?? false) { return; } var templateName = textInputDialog.Text; // // Check if this template already exists. // if (File.Exists(Path.Combine(Support.GetTemplatesPath(), templateName + ".zip"))) { MessageBox.Show("A template with the name " + templateName + " already exists.", "Cannot make template", MessageBoxButton.OK, MessageBoxImage.Hand); return; } // // Compress the RockWeb folder into a template ZIP file. // var zipFile = Path.Combine(Support.GetTemplatesPath(), templateName + ".zip"); var items = (List <string>)cbInstances.ItemsSource; var path = Path.Combine(Support.GetInstancesPath(), items[cbInstances.SelectedIndex], "RockWeb"); Support.CreateZipFromFolder(zipFile, path); TemplatesView.UpdateTemplates(); }
/// <summary> /// Deploy a template as a new instance to be run. /// </summary> /// <param name="sender">The object that has sent this event.</param> /// <param name="e">The arguments that describe this event.</param> private void btnDeploy_Click(object sender, RoutedEventArgs e) { // // Check if this instance name is valid. // string targetPath = System.IO.Path.Combine(Support.GetInstancesPath(), txtName.Text); bool isValid = !string.IsNullOrWhiteSpace(txtName.Text) && !Directory.Exists(targetPath); if (!isValid) { MessageBox.Show("That instance name already exists or is invalid."); return; } // // Get the path to the template ZIP file. // var items = cbTemplates.ItemsSource as List <string>; string file = items[cbTemplates.SelectedIndex] + ".zip"; string zipfile = System.IO.Path.Combine(Support.GetTemplatesPath(), file); // // Disable any UI controls that should not be available while deploying. // btnDeploy.IsEnabled = btnDelete.IsEnabled = false; // // Deploy the template as a new instance. // new Task(() => { // // Extract the zip file to the target instance path. // Support.ExtractZipFile(zipfile, Path.Combine(targetPath, "RockWeb"), (progress) => { Dispatcher.Invoke(() => { txtStatus.Text = string.Format("Extracting {0:n0}%...", Math.Floor(progress * 100)); }); }); // // Update the UI to indicate that it is deployed. // Dispatcher.Invoke(() => { txtStatus.Text = "Deployed"; UpdateState(); InstancesView.UpdateInstances(); }); }).Start(); }
/// <summary> /// Delete the selected instance from disk. /// </summary> /// <param name="sender">The object that is sending this event.</param> /// <param name="e">The arguments that describe the event.</param> private void btnDelete_Click(object sender, RoutedEventArgs e) { var result = MessageBox.Show("Delete this instance?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { var items = cbInstances.ItemsSource as List <string>; string file = items[cbInstances.SelectedIndex]; string path = Path.Combine(Support.GetInstancesPath(), file); Directory.Delete(path, true); new Thread(LoadData).Start(); } }
/// <summary> /// Load all github tags in the background. /// </summary> private void LoadData() { // // Initialize the LocalDb service only once. // if (localDb == null) { var provider = new SqlLocalDbProvider(); SqlLocalDbInstance instance; try { // // If we find an existing instance then shut it down and delete it. // instance = provider.GetInstance("RockDevBooster"); if (instance.IsRunning) { instance.Stop(); } SqlLocalDbInstance.Delete(instance); } finally { // // Create a new instance and keep a reference to it. // localDb = provider.CreateInstance("RockDevBooster"); localDb.Start(); } } // // Load all the instances from the file system. // var instances = Directory.GetDirectories(Support.GetInstancesPath()) .Select(d => Path.GetFileName(d)).ToList(); // // Convert pre-1.0 instance folders to 1.0 instance folders, which contain a // RockWeb for the current instance data. // foreach (string instance in instances) { string instancePath = Path.Combine(Support.GetInstancesPath(), instance); string rockwebPath = Path.Combine(instancePath, "RockWeb"); if (!Directory.Exists(rockwebPath)) { Directory.CreateDirectory(rockwebPath); foreach (var d in Directory.GetDirectories(instancePath)) { if (!Path.GetFileName(d).Equals("RockWeb", StringComparison.CurrentCultureIgnoreCase)) { Directory.Move(d, Path.Combine(rockwebPath, Path.GetFileName(d))); } } foreach (var f in Directory.GetFiles(instancePath)) { Directory.Move(f, Path.Combine(rockwebPath, Path.GetFileName(f))); } } } // // Update the UI with the new list of instances. // Dispatcher.Invoke(() => { cbInstances.ItemsSource = instances; if (instances.Count > 0) { cbInstances.SelectedIndex = 0; } txtStatus.Text = "Idle"; UpdateState(); }); }
/// <summary> /// Start up a new IIS Express instance for the Rock instance that is selected. /// </summary> /// <param name="sender">The object that is sending this event.</param> /// <param name="e">The arguments that describe the event.</param> private void btnStartStop_Click(object sender, RoutedEventArgs e) { if (btnStartStop.Content.ToString().EndsWith("Start")) { txtStatus.Text = "Starting..."; txtConsole.Text = string.Empty; // // Just in case something goes wrong and they managed to type in a non-numeric. // if (!int.TryParse(txtPort.Text, out int port)) { port = 6229; } // // Find the path to the RockWeb instance. // var items = (List <string>)cbInstances.ItemsSource; var path = Path.Combine(Support.GetInstancesPath(), items[cbInstances.SelectedIndex], "RockWeb"); // // 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); // // Launch the IIS Express process for this RockWeb. // iisExpressProcess = new ConsoleApp(GetIisExecutable()); iisExpressProcess.ProcessExited += IisExpressProcess_Exited; iisExpressProcess.StandardTextReceived += IisExpressProcess_StandardTextReceived; iisExpressProcess.ExecuteAsync(String.Format("/path:{0}", path), String.Format("/port:{0}", port)); // // Update the status text to contain a clickable link to the instance. // 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); } else { if (iisExpressProcess != null) { iisExpressProcess.Kill(); iisExpressProcess = null; } try { var items = (List <string>)cbInstances.ItemsSource; using (var connection = localDb.CreateConnection()) { connection.Open(); // // Shrink the log file. // connection.ChangeDatabase(items[cbInstances.SelectedIndex]); 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}]", items[cbInstances.SelectedIndex]); cmd.ExecuteNonQuery(); } } catch { /* Intentionally left blank */ } txtStatus.Text = "Idle"; } UpdateState(); }