コード例 #1
0
        /// <summary>
        /// Load all github tags in the background.
        /// </summary>
        private async void LoadData()
        {
            var client         = new GitHubClient(new ProductHeaderValue("RockDevBooster"));
            var tags           = client.Repository.GetAllTags("SparkDevNetwork", "Rock");
            var minimumVersion = new Version(1, 1, 0);

            var vsList = Support.GetVisualStudioInstances();

            List <GitHubTag> list;

            try
            {
                list = ( await tags )
                       .Select(t => new GitHubTag(t))
                       .Where(t => t.Version >= minimumVersion)
                       .OrderByDescending(t => t.Version)
                       .ToList();
            }
            catch
            {
                list = new List <GitHubTag>();
            }
            list.Insert(0, new GitHubTag());

            Dispatcher.Invoke(() =>
            {
                cbTags.ItemsSource   = list;
                txtStatus.Text       = string.Empty;
                cbTags.SelectedIndex = 0;

                cbVisualStudio.ItemsSource = vsList;
                if (vsList.Count > 0)
                {
                    cbVisualStudio.SelectedIndex = 0;
                }
            });
        }
コード例 #2
0
        /// <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();
            });
        }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
        /// <summary>
        /// Build a package from all the components available.
        /// </summary>
        protected void BuildPackage()
        {
            txtStatus.Text = "Packaging...";

            //
            // Get all our staging paths.
            //
            var stagingPath   = Support.GetPackageBuildPath();
            var contentPath   = Path.Combine(stagingPath, "content");
            var installPath   = Path.Combine(stagingPath, "install");
            var uninstallPath = Path.Combine(stagingPath, "uninstall");

            //
            // Get the filename the user wants to save the plugin into.
            //
            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.DereferenceLinks = false;
            saveFileDialog.FileName         = Plugin.Name.Replace(" ", "") + ".plugin";
            saveFileDialog.DefaultExt       = "plugin";
            saveFileDialog.Filter           = "Plugin Files (*.plugin)|*.plugin|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog() == false)
            {
                txtStatus.Text = "Cancelled";
                UpdateState();

                return;
            }
            string pluginFileName = saveFileDialog.FileName;

            txtConsole.AppendText(string.Format("\nBuilding package \"{0}\"\n", pluginFileName));
            txtConsole.ScrollToEnd();

            //
            // Delete any failed builds.
            //
            if (Directory.Exists(stagingPath))
            {
                Directory.Delete(stagingPath, true);
            }

            //
            // Create all our staging paths.
            //
            Directory.CreateDirectory(stagingPath);
            Directory.CreateDirectory(contentPath);
            Directory.CreateDirectory(installPath);
            Directory.CreateDirectory(uninstallPath);

            //
            // Copy the Controls, Themes, Webhooks.
            //
            CopyFiles(GetPluginRelativePath(Plugin, Plugin.ControlsPath), CombinePaths(contentPath, Plugin.PluginPath, Plugin));
            CopyFiles(GetPluginRelativePath(Plugin, Plugin.ThemesPath), CombinePaths(contentPath, "Themes", null));
            CopyFiles(GetPluginRelativePath(Plugin, Plugin.WebhooksPath), CombinePaths(contentPath, "Webhooks", null));

            //
            // Copy DLLs.
            //
            string projectFile = GetPluginRelativePath(Plugin, Plugin.ProjectFile);

            if (File.Exists(projectFile))
            {
                var dlls = GetFileList(Path.Combine(PluginPath, "obj", "Release"))
                           .Select(f => Path.GetFileName(f))
                           .Where(f => f.EndsWith(".dll"))
                           .ToList();
                dlls.AddRange(Plugin.DLLs);
                CopyDLLs(Path.GetDirectoryName(GetPluginRelativePath(Plugin, Plugin.ProjectFile)), dlls, Path.Combine(contentPath, "bin"));
            }

            //
            // Copy the SQL scripts.
            //
            if (!string.IsNullOrWhiteSpace(Plugin.InstallSql))
            {
                CopyFile(GetPluginRelativePath(Plugin, Plugin.InstallSql), Path.Combine(installPath, "run.sql"));
            }
            if (!string.IsNullOrWhiteSpace(Plugin.UninstallSql))
            {
                CopyFile(GetPluginRelativePath(Plugin, Plugin.UninstallSql), Path.Combine(uninstallPath, "run.sql"));
            }

            //
            // Copy any additional files.
            //
            foreach (var file in Plugin.Copy)
            {
                CopyFile(GetPluginRelativePath(Plugin, file.Source), CombinePaths(contentPath, file.Destination, Plugin));
            }

            //
            // Build the install deletefile.lst.
            //
            var files = Plugin.RemoveFilesOnInstall.Select(f => f.Replace("/", "\\")).ToList();

            File.WriteAllLines(Path.Combine(installPath, "deletefile.lst"), files.ToArray());

            //
            // Build the uninstall deletefile.lst.
            //
            string stripPath = string.Format("{0}\\", contentPath);

            files = GetFileList(contentPath).Select(f => f.Replace(stripPath, string.Empty)).ToList();
            files.AddRange(Plugin.RemoveFilesOnUninstall.Select(f => f.Replace("/", "\\")));
            File.WriteAllLines(Path.Combine(uninstallPath, "deletefile.lst"), files.ToArray());

            //
            // Zip it all up.
            //
            txtConsole.AppendText("Compressing zip file\n");
            txtConsole.ScrollToEnd();
            Support.CreateZipFromFolder(pluginFileName, stagingPath);

            txtStatus.Text = "Package Built.";
            UpdateState();
        }