Esempio n. 1
0
        /// <summary>
        /// Add the selected plug-in to the project with a default configuration
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnAddPlugIn_Click(object sender, RoutedEventArgs e)
        {
            string key   = (string)lbAvailablePlugIns.SelectedItem;
            var    match = lbProjectPlugIns.Items.Cast <PlugInConfig>().FirstOrDefault(c => c.Name == key);

            if (availablePlugIns != null)
            {
                // No duplicates are allowed
                if (match != null)
                {
                    lbProjectPlugIns.SelectedIndex = lbProjectPlugIns.Items.IndexOf(match);
                }
                else
                {
                    var plugIn = availablePlugIns.FirstOrDefault(p => p.Metadata.Id == key);

                    if (plugIn != null)
                    {
                        try
                        {
                            var c = this.SelectedPlugIns.Add(key, true, null);
                            match = new PlugInConfig {
                                Name = key, Configuration = c
                            };
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.ToString());

                            MessageBox.Show("Unexpected error attempting to add plug-in: " + ex.Message,
                                            Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        lbProjectPlugIns.SelectedIndex = lbProjectPlugIns.Items.Add(match);
                        lbProjectPlugIns.Items.Refresh();
                        btnDelete.IsEnabled = true;

                        this.PlugInsModified?.Invoke(this, EventArgs.Empty);

                        // Open the configuration dialog to configure it when first added if needed
                        if (availableConfigEditors.Any(ed => ed.Metadata.Id == key))
                        {
                            btnConfigure_Click(sender, e);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private async void OnSave(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog()
            {
                Filter = @"Configuration Files (*.config)|*.config"
            };

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var config = new ServerConfig {
                Port = GetPort()
            };

            foreach (var plugin in Server.Manager.PlugIns)
            {
                var filename = Server.Manager.GetFileName(plugin);
                if (config.PlugIns.Any(c => c.FileName.Equals(filename)))
                {
                    continue;
                }

                var elem = new PlugInConfig {
                    FullName = plugin.GetType().FullName,
                    FileName = filename
                };

                foreach (var setting in plugin.Settings)
                {
                    elem.Settings.Add(setting, plugin.Settings[setting]);
                }
                config.PlugIns.Add(elem);
            }

            using (var stream = File.Create(dialog.FileName))
            {
                await JsonSerializer.SerializeAsync(stream, config);
            }
        }