Beispiel #1
0
        /// <summary>
        /// Initialize a new instance of the control.
        /// </summary>
        public InstancesView()
        {
            InitializeComponent();

            DefaultInstancesView = this;
            UpdateInstances();

            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
        /// <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();
        }