예제 #1
0
        /// <summary>
        /// This is called when the component cache has finished being loaded and is available for use
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void componentCache_ComponentContainerLoaded(object sender, EventArgs e)
        {
            ComponentSettingsNeededEventArgs projectSettings = new ComponentSettingsNeededEventArgs();

            this.ComponentSettingsNeeded?.Invoke(this, projectSettings);

            HashSet <string> componentIds = new HashSet <string>();

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                lbAvailableComponents.Items.Clear();
                lbProjectComponents.Items.Clear();

                availableComponents = componentCache.ComponentContainer.GetExports <BuildComponentFactory,
                                                                                    IBuildComponentMetadata>().ToList();
                availableConfigEditors = componentCache.ComponentContainer.GetExports <IConfigurationEditor,
                                                                                       IConfigurationEditorMetadata>().ToList();

                // Only load those that indicate that they are visible to the property page.  There may be
                // duplicate component IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the first
                // component for a unique ID will be used.
                foreach (var component in availableComponents)
                {
                    if (!componentIds.Contains(component.Metadata.Id) && component.Metadata.IsVisible)
                    {
                        lbAvailableComponents.Items.Add(component.Metadata.Id);
                        componentIds.Add(component.Metadata.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading build components: " + ex.Message, Constants.AppName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                lbAvailableComponents.Items.Refresh();
                Mouse.OverrideCursor = null;
            }

            if (projectSettings.ProjectLoaded)
            {
                if (lbAvailableComponents.Items.Count != 0)
                {
                    lbAvailableComponents.SelectedIndex = 0;
                    gbAvailableComponents.IsEnabled     = gbProjectComponents.IsEnabled = true;
                }
                else
                {
                    MessageBox.Show("No valid build components found", Constants.AppName, MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    gbAvailableComponents.IsEnabled = gbProjectComponents.IsEnabled = false;
                    return;
                }

                this.SelectedComponents = projectSettings.Components;

                foreach (var kv in this.SelectedComponents)
                {
                    lbProjectComponents.Items.Add(new ComponentConfig {
                        Name = kv.Key, Configuration = kv.Value
                    });
                }

                if (lbProjectComponents.Items.Count != 0)
                {
                    lbProjectComponents.Items.Refresh();
                    lbProjectComponents.SelectedIndex = 0;
                    btnDelete.IsEnabled = true;
                }
                else
                {
                    btnConfigure.IsEnabled = btnDelete.IsEnabled = false;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This is called when the component cache has finished being loaded and is available for use
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void componentCache_ComponentContainerLoaded(object sender, EventArgs e)
        {
            ComponentSettingsNeededEventArgs projectSettings = new ComponentSettingsNeededEventArgs();

            this.ComponentSettingsNeeded?.Invoke(this, projectSettings);

            HashSet <string> plugInIds = new HashSet <string>();

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                lbAvailablePlugIns.Items.Clear();
                lbProjectPlugIns.Items.Clear();

                availablePlugIns       = componentCache.ComponentContainer.GetExports <IPlugIn, IPlugInMetadata>().ToList();
                availableConfigEditors = componentCache.ComponentContainer.GetExports <IPlugInConfigurationEditor,
                                                                                       IPlugInConfigurationEditorMetadata>().ToList();

                // There may be duplicate component IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the first
                // component for a unique ID will be used.  We also ignore hidden plug-ins.
                foreach (var plugIn in availablePlugIns)
                {
                    if (!plugIn.Metadata.IsHidden && !plugInIds.Contains(plugIn.Metadata.Id))
                    {
                        lbAvailablePlugIns.Items.Add(plugIn.Metadata.Id);
                        plugInIds.Add(plugIn.Metadata.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading plug-ins: " + ex.Message, Constants.AppName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                lbAvailablePlugIns.Items.Refresh();
                Mouse.OverrideCursor = null;
            }

            if (projectSettings.ProjectLoaded)
            {
                if (lbAvailablePlugIns.Items.Count != 0)
                {
                    lbAvailablePlugIns.SelectedIndex = 0;
                    gbAvailablePlugIns.IsEnabled     = gbProjectPlugIns.IsEnabled = true;
                }
                else
                {
                    MessageBox.Show("No valid plug-ins found", Constants.AppName, MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    gbAvailablePlugIns.IsEnabled = gbProjectPlugIns.IsEnabled = false;
                    return;
                }

                this.SelectedPlugIns = projectSettings.PlugIns;

                foreach (var kv in this.SelectedPlugIns)
                {
                    lbProjectPlugIns.Items.Add(new PlugInConfig {
                        Name = kv.Key, Configuration = kv.Value
                    });
                }

                if (lbProjectPlugIns.Items.Count != 0)
                {
                    lbProjectPlugIns.Items.Refresh();
                    lbProjectPlugIns.SelectedIndex = 0;
                    btnDelete.IsEnabled            = true;
                }
                else
                {
                    btnConfigure.IsEnabled = btnDelete.IsEnabled = false;
                }
            }
        }