/// <summary>
        /// Import the given github version as a new template.
        /// </summary>
        /// <param name="sender">The object that sent this event.</param>
        /// <param name="e">The event arguments.</param>
        private void btnImport_Click(object sender, RoutedEventArgs e)
        {
            var        vs = VisualStudioInstall.GetDefaultInstall();
            GitHubItem item;

            if (cbSourceType.SelectedItem.ToString() == "Release Version" || cbSourceType.SelectedItem.ToString() == "Branch" || cbSourceType.SelectedItem.ToString() == "Pull Request")
            {
                var items = cbSource.ItemsSource as List <GitHubItem>;
                item = items[cbSource.SelectedIndex];
            }
            else
            {
                item = new GitHubItem
                {
                    DisplayName = txtSource.Text.ToLowerInvariant(),
                    ZipballUrl  = string.Format("https://github.com/SparkDevNetwork/Rock/archive/{0}.zip", txtSource.Text.ToLowerInvariant())
                };
            }

            //
            // Check if this template already exists.
            //
            var templateName = "RockBase-" + item.Title;

            if (File.Exists(Path.Combine(Support.GetTemplatesPath(), templateName + ".zip")))
            {
                MessageBox.Show("A template with the name " + templateName + " already exists.", "Cannot import", MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }

            //
            // Initialize a new release builder to process this import operation.
            //
            ReleaseBuilder = new Builders.ReleaseBuilder();
            ReleaseBuilder.StatusTextChanged += ReleaseBuilder_StatusTextChanged;
            ReleaseBuilder.ConsoleOutput     += ReleaseBuilder_ConsoleOutput;
            ReleaseBuilder.BuildCompleted    += ReleaseBuilder_BuildCompleted;

            //
            // Prepare the UI for the import operation.
            //
            btnImport.IsEnabled = false;
            txtConsole.Text     = string.Empty;

            //
            // Start a task in the background to download and build the github release.
            //
            new Task(() =>
            {
                ReleaseBuilder.DownloadRelease(item.ZipballUrl, vs.GetExecutable(), "RockBase-" + item.Title);
            }).Start();
        }
        /// <summary>
        /// Build a plugin.
        /// </summary>
        /// <param name="sender">The object that sent this event.</param>
        /// <param name="e">The event arguments.</param>
        private void btnBuildPlugin_Click(object sender, RoutedEventArgs e)
        {
            var vs = VisualStudioInstall.GetDefaultInstall();

            //
            // Prepare the UI for the import operation.
            //
            btnSelect.IsEnabled      = false;
            btnBuildPlugin.IsEnabled = false;
            txtConsole.Text          = string.Empty;

            BuildPluginAsync(vs.GetMsBuild());
        }
Пример #3
0
        public PreferencesView()
        {
            InitializeComponent();

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                var vsList = VisualStudioInstall.GetVisualStudioInstances();
                var vs     = VisualStudioInstall.GetDefaultInstall();

                cbVisualStudio.ItemsSource = vsList;

                if (vs != null)
                {
                    int selectedIndex = vsList.IndexOf(vsList.Where(v => v.Path == vs.Path).FirstOrDefault());
                    cbVisualStudio.SelectedIndex = selectedIndex;
                }

                cbAutoUpdate.IsChecked = Settings.Default.AutoUpdate;
            }

            CheckForUpdatesAndPromptUser();
        }
Пример #4
0
        /// <summary>
        /// Installs the plugin specified by the plugin spec file.
        /// </summary>
        /// <param name="pluginFile">The plugin spec file.</param>
        /// <exception cref="Exception"></exception>
        public void InstallPlugin(string pluginFile, bool verbose)
        {
            var rockWeb    = Path.Combine(Path.Combine(Support.GetInstancesPath(), Name), "RockWeb");
            var pluginPath = Path.GetDirectoryName(pluginFile);

            if (!Directory.Exists(rockWeb))
            {
                throw new Exception(string.Format("Cannot install plugin '{0}'; instance '{1}' does not exist.", pluginFile, Name));
            }

            var pluginJson = File.ReadAllText(pluginFile);
            var plugin     = JsonConvert.DeserializeObject <Shared.PluginFormat.Plugin>(pluginJson);

            plugin.ConfigureDefaults();

            var logger = new EventHandler <string>((sender, message) =>
            {
                if (verbose)
                {
                    if (message.EndsWith("\n"))
                    {
                        message = message.Substring(0, message.Length - 1);
                    }
                    if (message.EndsWith("\r"))
                    {
                        message = message.Substring(0, message.Length - 1);
                    }

                    var bootstrap = ( Bootstrapper )((Jint.Runtime.Interop.ObjectWrapper)Engine.GetValue("__Bootstrap").AsObject()).Target;
                    bootstrap.Log(message);
                }
            });

            //
            // Initialize a new release builder to process this import operation.
            //
            var projectBuilder = new Builders.ProjectBuilder();

            projectBuilder.ConsoleOutput += logger;

            if (!projectBuilder.BuildProject(plugin.CombinePaths(pluginPath, plugin.ProjectFile), VisualStudioInstall.GetDefaultInstall().GetMsBuild()))
            {
                throw new Exception("Build Plugin Failed");
            }

            var pluginBuilder = new Builders.PluginBuilder(plugin, pluginPath);

            pluginBuilder.LogMessage += logger;

            var stream = pluginBuilder.Build();

            using (var zf = new ZipFile(stream))
            {
                foreach (ZipEntry entry in zf)
                {
                    if (!entry.Name.StartsWith("content/"))
                    {
                        continue;
                    }

                    if (entry.IsFile)
                    {
                        string fullpath  = Path.Combine(rockWeb, entry.Name.Replace("content/", ""));
                        string directory = Path.GetDirectoryName(fullpath);

                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }

                        using (FileStream streamWriter = File.Create(fullpath))
                        {
                            using (var zipStream = zf.GetInputStream(entry))
                            {
                                zipStream.CopyTo(streamWriter);
                            }
                        }
                    }
                }

                var sqlInstallEntry = zf.GetEntry("install/run.sql");
                if (sqlInstallEntry != null)
                {
                    string sqlScript;

                    using (var zipStream = zf.GetInputStream(sqlInstallEntry))
                    {
                        using (StreamReader reader = new StreamReader(zipStream, Encoding.UTF8))
                        {
                            sqlScript = reader.ReadToEnd();
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(sqlScript))
                    {
                        using (var connection = Views.InstancesView.DefaultInstancesView.GetSqlConnection())
                        {
                            var command = connection.CreateCommand();
                            command.CommandText = sqlScript;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }