Ejemplo n.º 1
0
        /// <summary>
        /// Compares two instances of <see cref="PluginItem"/>.
        /// </summary>
        /// <param name="obj">other instance of <see cref="PluginItem"/></param>
        /// <returns>true, if equal</returns>
        public override bool Equals(object obj)
        {
            // Check for right datatype
            if (!(obj is PluginItem))
            {
                return(false);
            }

            PluginItem other = (PluginItem)obj;

            // compare guid
            if (other.guid != guid)
            {
                return(false);
            }

            // compare version
            if (other.version != version)
            {
                return(false);
            }

            // seams to be equal
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the active Producer
        /// </summary>
        /// <param name="guid"><c>guid</c> of new producer</param>
        public void ActivateProducer(Guid guid)
        {
            ignoreStateupdate = true;
            // check, if plugin with that guid exists
            if (!producerList.ContainsKey(guid))
            {
                throw new InvalidOperationException(Resource.PluginManagerActivateProducerNotInList);
            }

            // check, if same plugin is still active
            if (activeProducer == null || activeProducer.Guid != guid)
            {
                // unhook old producer
                if (activeProducer != null)
                {
                    DeactivateProducer(activeProducer.Guid);
                }

                // hook the new one
                activeProducer = producerList[guid];

                if (!config.selectedPlugins.Contains(guid))
                {
                    config.selectedPlugins.Add(guid);
                }
            }
            ignoreStateupdate = false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a plugin to active list
        /// </summary>
        /// <param name="guid"><c>guid</c> of new plugin</param>
        public void ActivateConsumer(Guid guid)
        {
            // Check, if plugin exists
            if (!consumerList.ContainsKey(guid))
            {
                throw new InvalidOperationException(Resource.PluginManagerActivateConsumerNotInList);
            }

            // Add to list
            lock (activeConsumers) {
                if (!activeConsumers.ContainsKey(guid))
                {
                    PluginItem plugin = consumerList[guid];

                    // Activate, if simulation still running
                    if (State == PluginState.Running)
                    {
                        plugin.Consumer.Start();
                    }
                    else if (State == PluginState.Paused)
                    {
                        plugin.Consumer.Pause();
                    }

                    activeConsumers.Add(guid, plugin);

                    // mark as selected in config
                    if (!config.selectedPlugins.Contains(guid))
                    {
                        config.selectedPlugins.Add(guid);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// drops a consumer from active list.
        /// </summary>
        /// <param name="guid"><c>guid</c> of plugin to drop</param>
        public void DeactivateConsumer(Guid guid)
        {
            // Check, if plugin exists
            if (!consumerList.ContainsKey(guid))
            {
                throw new InvalidOperationException(Resource.PluginManagerDeactivateConsumerNotInList);
            }

            // Drop from active list
            lock (activeConsumers) {
                if (activeConsumers.ContainsKey(guid))
                {
                    PluginItem plugin = activeConsumers[guid];

                    activeConsumers.Remove(guid);
                    config.selectedPlugins.Remove(guid);

                    // Stop, if still running
                    if (plugin.Consumer.State == PluginState.Running ||
                        plugin.Consumer.State == PluginState.Paused)
                    {
                        plugin.Consumer.Stop();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deactivates the given producer
        /// </summary>
        /// <param name="guid"><c>guid</c> of producer</param>
        public void DeactivateProducer(Guid guid)
        {
            ignoreStateupdate = true;

            if (activeProducer != null && activeProducer.Guid == guid)
            {
                // unhook producer
                Stop();
                activeProducer = null;
                config.selectedPlugins.Remove(guid);
            }
            ignoreStateupdate = false;
        }
Ejemplo n.º 6
0
        private void pluginListView_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            // Ignore automatic checks
            if (ignoreChecks)
            {
                return;
            }

            ignoreChecks = true;

            // Producer has changed
            if (pluginListView.Items[e.Index].Group == producerGroup)
            {
                // Prevent from uncheck
                if (e.NewValue == CheckState.Unchecked)
                {
                    e.NewValue = CheckState.Checked;
                }
                else
                {
                    foreach (ListViewItem item in pluginListView.Items)
                    {
                        if (item.Index != e.Index && item.Group == producerGroup)
                        {
                            item.Checked = false;
                        }
                    }

                    PluginItem plugin = (PluginItem)pluginListView.Items[e.Index].Tag;
                    manager.ActivateProducer(plugin.Guid);
                }
            }

            // Consumer has changed
            if (pluginListView.Items[e.Index].Group == consumerGroup)
            {
                PluginItem plugin = (PluginItem)pluginListView.Items[e.Index].Tag;
                if (e.NewValue == CheckState.Checked)
                {
                    // Activate
                    manager.ActivateConsumer(plugin.Guid);
                }
                else
                {
                    // Deactivate
                    manager.DeactivateConsumer(plugin.Guid);
                }
            }

            ignoreChecks = false;
        }
Ejemplo n.º 7
0
        private void button_producer(object sender, EventArgs e)
        {
            if (ignoreTimerEvents)
            {
                return;
            }

            ignoreTimerEvents = true;

            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
            PluginItem        plugin   = menuItem.Tag as PluginItem;

            manager.ActivateProducer(plugin.Guid);

            updatePanel();
            ignoreTimerEvents = false;
        }
Ejemplo n.º 8
0
        private void combo_producer(object sender, EventArgs e)
        {
            if (ignoreTimerEvents)
            {
                return;
            }

            ignoreTimerEvents = true;
            if (producerComboBoxToolItem.SelectedItem != null)
            {
                PluginItem plugin = (PluginItem)producerComboBoxToolItem.SelectedItem;
                manager.ActivateProducer(plugin.Guid);
            }
            else
            {
                manager.ActivateProducer(new Guid());
            }
            updatePanel();
            ignoreTimerEvents = false;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Make updates based on manager-settings
        /// </summary>
        private void updatePanel()
        {
            if (ignoreTimerEvents)
            {
                return;
            }

            ignoreTimerEvents = true;

            // Controlling-Buttons
            startMenuItem.Enabled = manager.CanStart;
            startToolItem.Enabled = manager.CanStart;
            pauseToolItem.Enabled = manager.CanPause;
            pauseMenuItem.Enabled = manager.CanPause;
            stopToolItem.Enabled  = manager.CanStop;
            stopMenuItem.Enabled  = manager.CanStop;

            newspanelMenuItem.Checked  = Settings.Default.showNews;
            autoupdateMenuItem.Checked = Settings.Default.checkForUpdates;

            if (manager.FrameLimiterEnabled)
            {
                if ((int)Math.Round(manager.FrameLimit) <= 100)
                {
                    fasterToolItem.Enabled = true;
                }
                else
                {
                    fasterToolItem.Enabled = false;
                }
                if ((int)Math.Round(manager.FrameLimit) > 1)
                {
                    slowerToolItem.Enabled = true;
                }
                else
                {
                    slowerToolItem.Enabled = false;
                }

                speedDropDownToolItem.Text = string.Format(Resource.MainFramesPerSecond, manager.FrameLimit);
            }
            else
            {
                slowerToolItem.Enabled     = false;
                fasterToolItem.Enabled     = false;
                speedDropDownToolItem.Text = Resource.MainSpeedMaximal;
            }

            // producer-list
            List <PluginItem> producerList = new List <PluginItem>(manager.ProducerPlugins);

            for (int i = 0; i < producerComboBoxToolItem.Items.Count; i++)
            {
                PluginItem item = (PluginItem)producerComboBoxToolItem.Items[i];
                if (!producerList.Contains(item))
                {
                    producerComboBoxToolItem.Items.Remove(item);
                    i--;
                }
            }
            foreach (PluginItem item in producerList)
            {
                if (!producerComboBoxToolItem.Items.Contains(item))
                {
                    producerComboBoxToolItem.Items.Add(item);
                }
            }

            // manage tabs
            if (activeProducer != manager.ActiveProducerPlugin)
            {
                // Update Combobox
                producerComboBoxToolItem.SelectedItem = manager.ActiveProducerPlugin;

                // remove old tab
                if (activeProducer != null)
                {
                    if (activeProducer.Producer.Control != null)
                    {
                        tabControl.TabPages.RemoveAt(1);
                    }
                    activeProducer = null;
                }

                // add new tab
                if (manager.ActiveProducerPlugin != null)
                {
                    if (manager.ActiveProducerPlugin.Producer.Control != null)
                    {
                        TabPage page = new TabPage(manager.ActiveProducerPlugin.Name);
                        page.Controls.Add(manager.ActiveProducerPlugin.Producer.Control);
                        tabControl.TabPages.Insert(1, page);
                        manager.ActiveProducerPlugin.Producer.Control.Dock = DockStyle.Fill;
                    }
                    activeProducer = manager.ActiveProducerPlugin;
                }
            }

            // synchronize Consumer
            List <PluginItem> newActiveConsumers = new List <PluginItem>(manager.ActiveConsumerPlugins);

            for (int i = activeConsumers.Count - 1; i >= 0; i--)
            {
                // Kick the old tab
                if (!newActiveConsumers.Contains(activeConsumers[i]))
                {
                    if (tabControl.TabPages.ContainsKey(activeConsumers[i].Guid.ToString()))
                    {
                        tabControl.TabPages.RemoveByKey(activeConsumers[i].Guid.ToString());
                    }
                    activeConsumers.Remove(activeConsumers[i]);
                }
            }
            foreach (PluginItem plugin in newActiveConsumers)
            {
                //Create new, if needed
                if (!activeConsumers.Contains(plugin))
                {
                    // Create Tab and place control
                    if (plugin.Consumer.Control != null)
                    {
                        tabControl.TabPages.Add(plugin.Guid.ToString(), plugin.Name);
                        tabControl.TabPages[plugin.Guid.ToString()].Controls.Add(plugin.Consumer.Control);
                        plugin.Consumer.Control.Dock = DockStyle.Fill;
                    }
                    activeConsumers.Add(plugin);
                }
            }

            // popup exceptions
            if (manager.Exceptions.Count > 0)
            {
                ExceptionViewer problems = new ExceptionViewer(manager.Exceptions);
                problems.ShowDialog(this);
                manager.Exceptions.Clear();
            }

            // StatusBar-information
            stateLabelBarItem.Text = string.Empty;
            switch (manager.State)
            {
            case PluginState.NotReady:
                stateLabelBarItem.Text = Resource.MainStateNotReady;
                break;

            case PluginState.Paused:
                stateLabelBarItem.Text = Resource.MainStatePaused;
                break;

            case PluginState.Ready:
                stateLabelBarItem.Text = Resource.MainStateReady;
                break;

            case PluginState.Running:
                stateLabelBarItem.Text = Resource.MainStateRunning;
                break;
            }

            if (manager.State == PluginState.Running || manager.State == PluginState.Paused)
            {
                progressBarItem.Maximum    = manager.TotalRounds;
                progressBarItem.Value      = manager.CurrentRound;
                stepCounterBarItem.Text    = string.Format(Resource.MainStateRoundIndicator, manager.CurrentRound, manager.TotalRounds);
                progressBarItem.Visible    = true;
                stepCounterBarItem.Visible = true;
            }
            else
            {
                progressBarItem.Visible    = false;
                stepCounterBarItem.Visible = false;
            }

            if (manager.State == PluginState.Running)
            {
                fpsBarItem.Text    = manager.FrameRate.ToString(Resource.MainStateFramesPerSecond);
                fpsBarItem.Visible = true;
            }
            else
            {
                fpsBarItem.Visible = false;
            }

            // Autoupdater
            if (updateUrl != string.Empty)
            {
                if (MessageBox.Show(this,
                                    string.Format(Resource.MainUpdateMessage, Assembly.GetCallingAssembly().GetName().Version, updateVersion),
                                    Resource.MainUpdateTitle, MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information,
                                    MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                {
                    Help.ShowHelp(this, updateUrl);
                    // TODO: Exceptionhandling
                }
                updateUrl = string.Empty;
            }

            ignoreTimerEvents = false;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Make updates based on manager-settings
        /// </summary>
        private void updatePanel()
        {
            if (ignoreTimerEvents)
            {
                return;
            }

            ignoreTimerEvents = true;

            // Controlling-Buttons
            startMenuItem.Enabled = manager.CanStart;
            startToolItem.Enabled = manager.CanStart;
            pauseToolItem.Enabled = manager.CanPause;
            pauseMenuItem.Enabled = manager.CanPause;
            stopToolItem.Enabled  = manager.CanStop;
            stopMenuItem.Enabled  = manager.CanStop;

            if (manager.FrameLimiterEnabled)
            {
                if ((int)Math.Round(manager.FrameLimit) <= 100)
                {
                    fasterToolItem.Enabled = true;
                }
                else
                {
                    fasterToolItem.Enabled = false;
                }
                if ((int)Math.Round(manager.FrameLimit) > 1)
                {
                    slowerToolItem.Enabled = true;
                }
                else
                {
                    slowerToolItem.Enabled = false;
                }

                speedDropDownToolItem.Text = string.Format(Resource.MainFramesPerSecond, manager.FrameLimit);
            }
            else
            {
                slowerToolItem.Enabled     = false;
                fasterToolItem.Enabled     = false;
                speedDropDownToolItem.Text = Resource.MainSpeedMaximal;
            }

            // Producer List (Button-Based)
            List <ToolStripItem> remove = new List <ToolStripItem>();

            foreach (ToolStripItem item in producerButton.DropDownItems)
            {
                if (!manager.ProducerPlugins.Any(p => p == item.Tag))
                {
                    remove.Add(item);
                }
            }
            foreach (var item in remove)
            {
                producerButton.DropDownItems.Remove(item);
            }

            foreach (var item in manager.ProducerPlugins)
            {
                if (producerButton.DropDownItems.Find(item.Guid.ToString(), false).Count() == 0)
                {
                    var menuItem = new ToolStripMenuItem()
                    {
                        Text = item.Name,
                        Name = item.Guid.ToString(),
                        Tag  = item
                    };

                    menuItem.Click += button_producer;

                    producerButton.DropDownItems.Add(menuItem);
                }
            }

            // manage tabs
            if (activeProducer != manager.ActiveProducerPlugin)
            {
                bool isSelected = tabControl.SelectedIndex == 1;

                // Update Mode Display
                producerButton.Text = (manager.ActiveProducerPlugin == null ? Resource.MainNoModeSelected : manager.ActiveProducerPlugin.Name);

                // remove old tab
                if (activeProducer != null)
                {
                    if (activeProducer.Producer.Control != null)
                    {
                        tabControl.TabPages.RemoveAt(1);
                    }
                    activeProducer = null;
                }

                // add new tab
                if (manager.ActiveProducerPlugin != null)
                {
                    if (manager.ActiveProducerPlugin.Producer.Control != null)
                    {
                        TabPage page = new TabPage(manager.ActiveProducerPlugin.Name);
                        page.Padding = new Padding(0);
                        page.Margin  = new Padding(0);
                        page.Controls.Add(manager.ActiveProducerPlugin.Producer.Control);
                        manager.ActiveProducerPlugin.Producer.Control.Padding = new Padding(0);
                        manager.ActiveProducerPlugin.Producer.Control.Margin  = new Padding(0);
                        tabControl.TabPages.Insert(1, page);
                        manager.ActiveProducerPlugin.Producer.Control.Dock = DockStyle.Fill;
                        if (isSelected)
                        {
                            tabControl.SelectedIndex = 1;
                        }
                    }
                    activeProducer = manager.ActiveProducerPlugin;
                }
            }

            // synchronize Consumer
            List <PluginItem> newActiveConsumers = new List <PluginItem>(manager.ActiveConsumerPlugins);

            for (int i = activeConsumers.Count - 1; i >= 0; i--)
            {
                // Kick the old tab
                if (!newActiveConsumers.Contains(activeConsumers[i]))
                {
                    if (tabControl.TabPages.ContainsKey(activeConsumers[i].Guid.ToString()))
                    {
                        tabControl.TabPages.RemoveByKey(activeConsumers[i].Guid.ToString());
                    }
                    activeConsumers.Remove(activeConsumers[i]);
                }
            }
            foreach (PluginItem plugin in newActiveConsumers)
            {
                //Create new, if needed
                if (!activeConsumers.Contains(plugin))
                {
                    // Create Tab and place control
                    if (plugin.Consumer.Control != null)
                    {
                        tabControl.TabPages.Add(plugin.Guid.ToString(), plugin.Name);
                        tabControl.TabPages[plugin.Guid.ToString()].Controls.Add(plugin.Consumer.Control);
                        plugin.Consumer.Control.Dock = DockStyle.Fill;
                    }
                    activeConsumers.Add(plugin);
                }
            }

            // popup exceptions
            if (manager.Exceptions.Count > 0)
            {
                ExceptionViewer problems = new ExceptionViewer(manager.Exceptions);
                problems.ShowDialog(this);
                manager.Exceptions.Clear();
            }

            // StatusBar-information
            stateLabelBarItem.Text = string.Empty;
            switch (manager.State)
            {
            case PluginState.NotReady:
                stateLabelBarItem.Text = Resource.MainStateNotReady;
                break;

            case PluginState.Paused:
                stateLabelBarItem.Text = Resource.MainStatePaused;
                break;

            case PluginState.Ready:
                stateLabelBarItem.Text = Resource.MainStateReady;
                break;

            case PluginState.Running:
                stateLabelBarItem.Text = Resource.MainStateRunning;
                break;
            }

            if (manager.State == PluginState.Running || manager.State == PluginState.Paused)
            {
                progressBarItem.Maximum    = manager.TotalRounds;
                progressBarItem.Value      = manager.CurrentRound;
                stepCounterBarItem.Text    = string.Format(Resource.MainStateRoundIndicator, manager.CurrentRound, manager.TotalRounds);
                progressBarItem.Visible    = true;
                stepCounterBarItem.Visible = true;
            }
            else
            {
                progressBarItem.Visible    = false;
                stepCounterBarItem.Visible = false;
            }

            if (manager.State == PluginState.Running)
            {
                fpsBarItem.Text    = manager.FrameRate.ToString(Resource.MainStateFramesPerSecond);
                fpsBarItem.Visible = true;
            }
            else
            {
                fpsBarItem.Visible = false;
            }

            // Online Connector
            onlineButton.Text    = Connection.Instance.Username;
            onlineButton.Visible = Connection.Instance.IsLoggedIn;
            onlineButton.Enabled = !Connection.Instance.IsBusy;
            if ((ConnectionState)onlineButton.Tag != Connection.Instance.State)
            {
                switch (Connection.Instance.State)
                {
                case ConnectionState.NoConnection:
                    onlineButton.Image       = Resources.connection;
                    onlineButton.ToolTipText = Resource.UpdateNoConnection;
                    break;

                case ConnectionState.TokenInvalid:
                    onlineButton.Image       = Resources.warning;
                    onlineButton.ToolTipText = Resource.UpdateTokenInvalid;
                    break;

                default:
                    onlineButton.Image       = Resources.online;
                    onlineButton.ToolTipText = string.Empty;
                    break;
                }
                onlineButton.Tag = Connection.Instance.State;
            }

            loginButton.Visible = !Connection.Instance.IsLoggedIn;
            loginButton.Enabled = !Connection.Instance.IsBusy;

            versionButton.Visible = !string.IsNullOrEmpty(Properties.Settings.Default.updateLink);

            ignoreTimerEvents = false;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Sets the current visible plugin
        /// </summary>
        /// <param name="guid">visible Plugin</param>
        public void SetVisiblePlugin(Guid guid)
        {
            ignoreStateupdate = true;
            // Set old plugin to invisible
            if (visiblePlugin != null)
            {
                if (visiblePlugin.IsConsumer)
                {
                    try {
                        visiblePlugin.Consumer.SetVisibility(false);
                    }
                    catch (Exception ex) {
                        exceptions.Add(
                            new Exception(
                                string.Format(
                                    Resource.PluginManagerProducerVisibilitySetFailed,
                                    visiblePlugin.Name,
                                    visiblePlugin.Version),
                                ex));
                    }
                }
                else
                {
                    try {
                        visiblePlugin.Producer.SetVisibility(false);
                    }
                    catch (Exception ex) {
                        exceptions.Add(
                            new Exception(
                                string.Format(
                                    Resource.PluginManagerConsumerVisibilitySetFailed,
                                    visiblePlugin.Name,
                                    visiblePlugin.Version),
                                ex));
                    }
                }
            }

            // Set new plugin to visible
            if (producerList.ContainsKey(guid))
            {
                visiblePlugin = producerList[guid];
                try {
                    visiblePlugin.Producer.SetVisibility(true);
                }
                catch (Exception ex) {
                    exceptions.Add(
                        new Exception(
                            string.Format(
                                Resource.PluginManagerProducerVisibilitySetFailed,
                                visiblePlugin.Name,
                                visiblePlugin.Version),
                            ex));
                }
            }
            else if (consumerList.ContainsKey(guid))
            {
                visiblePlugin = consumerList[guid];
                try {
                    visiblePlugin.Consumer.SetVisibility(true);
                }
                catch (Exception ex) {
                    exceptions.Add(
                        new Exception(
                            string.Format(
                                Resource.PluginManagerConsumerVisibilitySetFailed,
                                visiblePlugin.Name,
                                visiblePlugin.Version),
                            ex));
                }
            }
            else
            {
                visiblePlugin = null;
            }
            ignoreStateupdate = false;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// search in given assembly for a new plugin
        /// </summary>
        /// <param name="assembly">assembly to search in</param>
        /// <returns>true, if there are valid plugins inside</returns>
        private bool addPlugin(Assembly assembly)
        {
            bool hit = false;

            // Get all includes Types
            foreach (Type type in assembly.GetExportedTypes())
            {
                // Find the attribute
                List <CustomStateItem> readCustomStates  = new List <CustomStateItem>();
                List <CustomStateItem> writeCustomStates = new List <CustomStateItem>();

                foreach (CustomAttributeData customAttribute in  CustomAttributeData.GetCustomAttributes(type))
                {
                    string name;
                    string dataType;
                    string description;
                    switch (customAttribute.Constructor.ReflectedType.FullName)
                    {
                    case "AntMe.SharedComponents.Plugin.ReadCustomStateAttribute":
                        name        = string.Empty;
                        dataType    = string.Empty;
                        description = string.Empty;
                        foreach (CustomAttributeNamedArgument argument in customAttribute.NamedArguments)
                        {
                            switch (argument.MemberInfo.Name)
                            {
                            case "Name":
                                name = (string)argument.TypedValue.Value;
                                break;

                            case "Type":
                                dataType = (string)argument.TypedValue.Value;
                                break;

                            case "Description":
                                description = (string)argument.TypedValue.Value;
                                break;
                            }
                        }
                        readCustomStates.Add(new CustomStateItem(name, dataType, description));
                        break;

                    case "AntMe.SharedComponents.Plugin.WriteCustomStateAttribute":
                        name        = string.Empty;
                        dataType    = string.Empty;
                        description = string.Empty;
                        foreach (CustomAttributeNamedArgument argument in customAttribute.NamedArguments)
                        {
                            switch (argument.MemberInfo.Name)
                            {
                            case "Name":
                                name = (string)argument.TypedValue.Value;
                                break;

                            case "Type":
                                dataType = (string)argument.TypedValue.Value;
                                break;

                            case "Description":
                                description = (string)argument.TypedValue.Value;
                                break;
                            }
                        }
                        writeCustomStates.Add(new CustomStateItem(name, dataType, description));
                        break;
                    }
                }

                // If type has an attribute, search for the interfaces
                foreach (Type plugin in type.GetInterfaces())
                {
                    // Producer found
                    if (plugin == typeof(IProducerPlugin))
                    {
                        // Create an instance of plugin and add to list
                        PluginItem item = null;
                        try {
                            IProducerPlugin producerPlugin =
                                (IProducerPlugin)Activator.CreateInstance(type, false);
                            item =
                                new PluginItem(producerPlugin, writeCustomStates.ToArray(), readCustomStates.ToArray());
                            hit = true;
                        }
                        catch (Exception ex) {
                            exceptions.Add(
                                new Exception(
                                    string.Format(
                                        Resource.PluginManagerProducerPluginCommonProblems,
                                        type.FullName,
                                        assembly.GetFiles()[0].Name),
                                    ex));
                        }

                        // Warnings, of there is another Version of that plugin
                        if (item != null && producerList.ContainsKey(item.Guid))
                        {
                            if (producerList[item.Guid].Version > item.Version)
                            {
                                exceptions.Add(
                                    new Exception(
                                        string.Format(
                                            Resource.PluginManagerProducerPluginNewerVersionLoaded,
                                            item.Name,
                                            item.Version)));
                                item = null;
                            }
                            else if (producerList[item.Guid].Version < item.Version)
                            {
                                exceptions.Add(
                                    new Exception(
                                        string.Format(
                                            Resource.PluginManagerProducerPluginNewerVersion,
                                            item.Name,
                                            item.Version)));
                                DeactivateProducer(item.Guid);
                                producerList.Remove(item.Guid);
                            }
                            else
                            {
                                // Samle plugin still loaded
                                item = null;
                            }
                        }

                        // add to list
                        if (item != null)
                        {
                            // Check, if plugin is preselected or saved as selected
                            producerList.Add(item.Guid, item);
                            if (config.selectedPlugins.Contains(item.Guid) ||
                                (!config.loaded &&
                                 type.GetCustomAttributes(typeof(PreselectedAttribute), false).Length > 0))
                            {
                                ActivateProducer(item.Guid);
                            }

                            // Load Settings
                            if (File.Exists(configPath + item.Guid + Resources.PluginSettingsFileExtension))
                            {
                                try {
                                    item.Producer.Settings =
                                        File.ReadAllBytes(
                                            configPath + item.Guid + Resources.PluginSettingsFileExtension);
                                }
                                catch (Exception ex) {
                                    exceptions.Add(
                                        new Exception(
                                            string.Format(
                                                Resource.PluginManagerProducerPluginSettingsLoadFailed,
                                                item.Name,
                                                item.Version),
                                            ex));
                                }
                            }
                        }
                    }

                    // Consumer found
                    else if (plugin == typeof(IConsumerPlugin))
                    {
                        // Create an instance of plugin and add to list
                        PluginItem item = null;
                        try {
                            IConsumerPlugin consumerPlugin =
                                (IConsumerPlugin)Activator.CreateInstance(type, false);
                            item =
                                new PluginItem(consumerPlugin, writeCustomStates.ToArray(), readCustomStates.ToArray());
                            hit = true;
                        }
                        catch (Exception ex) {
                            exceptions.Add(
                                new Exception(
                                    string.Format(
                                        Resource.PluginManagerConsumerPluginCommonProblems,
                                        type.FullName,
                                        assembly.GetFiles()[0].Name),
                                    ex));
                        }

                        // Warnings, of there is another Version of that plugin
                        if (item != null && consumerList.ContainsKey(item.Guid))
                        {
                            if (consumerList[item.Guid].Version > item.Version)
                            {
                                exceptions.Add(
                                    new Exception(
                                        string.Format(
                                            Resource.PluginManagerConsumerPluginNewerVersionLoaded,
                                            item.Name,
                                            item.Version)));
                                item = null;
                            }
                            else if (consumerList[item.Guid].Version < item.Version)
                            {
                                exceptions.Add(
                                    new Exception(
                                        string.Format(
                                            Resource.PluginManagerConsumerPluginNewerVersion,
                                            item.Name,
                                            item.Version)));
                                DeactivateConsumer(item.Guid);
                                consumerList.Remove(item.Guid);
                            }
                            else
                            {
                                // Same plugin still loaded
                                item = null;
                            }
                        }

                        // add to list
                        if (item != null)
                        {
                            consumerList.Add(item.Guid, item);

                            // Check, if plugin is preselected or saved as selected
                            if (config.selectedPlugins.Contains(item.Guid) ||
                                (!config.loaded &&
                                 type.GetCustomAttributes(typeof(PreselectedAttribute), false).Length > 0))
                            {
                                ActivateConsumer(item.Guid);
                            }

                            // Load Settings
                            if (File.Exists(configPath + item.Guid + Resources.PluginSettingsFileExtension))
                            {
                                try {
                                    item.Consumer.Settings =
                                        File.ReadAllBytes(
                                            configPath + item.Guid + Resources.PluginSettingsFileExtension);
                                }
                                catch (Exception ex) {
                                    exceptions.Add(
                                        new Exception(
                                            string.Format(
                                                Resource.PluginManagerConsumerPluginSettingsLoadFailed,
                                                item.Name,
                                                item.Version),
                                            ex));
                                }
                            }
                        }
                    }
                }
            }
            return(hit);
        }