예제 #1
0
        /// <summary>
        /// Applies the load order specified by the given list of registered plugins
        /// </summary>
        /// <param name="p_lstRegisteredPlugins">The list of registered plugins.</param>
        /// <param name="p_booSortingOnly">Whether we just want to apply the sorting.</param>
        public void ApplyLoadOrder(Dictionary <Plugin, string> p_kvpRegisteredPlugins, bool p_booSortingOnly)
        {
            Transactions.TransactionScope tsTransaction = null;
            try
            {
                tsTransaction = new Transactions.TransactionScope();

                if (!p_booSortingOnly)
                {
                    foreach (KeyValuePair <Plugin, string> kvp in p_kvpRegisteredPlugins)
                    {
                        if (kvp.Value == "1")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.ActivatePlugin(kvp.Key);
                            }
                        }
                        if (kvp.Value == "0")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.DeactivatePlugin(kvp.Key);
                            }
                        }
                    }
                }

                PluginManager.SetPluginOrder(p_kvpRegisteredPlugins.Keys.ToList());

                tsTransaction.Complete();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (tsTransaction != null)
                {
                    tsTransaction.Dispose();
                }
            }
        }
        /// <summary>
        /// The method that is called to start the backgound task.
        /// </summary>
        /// <param name="p_objArgs">Arguments to for the task execution.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override object DoWork(object[] p_objArgs)
        {
            OverallMessage          = String.Format("Applying load order...");
            OverallProgress         = 0;
            OverallProgressStepSize = 1;
            OverallProgressMaximum  = RegisteredPlugins.Count;

            Transactions.TransactionScope tsTransaction = null;
            try
            {
                tsTransaction = new Transactions.TransactionScope();

                if (!SortingOnly)
                {
                    foreach (KeyValuePair <Plugin, string> kvp in RegisteredPlugins)
                    {
                        if (kvp.Value == "1")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.ActivatePlugin(kvp.Key);
                            }
                        }
                        if (kvp.Value == "0")
                        {
                            if (PluginManager.CanChangeActiveState(kvp.Key))
                            {
                                PluginManager.DeactivatePlugin(kvp.Key);
                            }
                        }

                        if (OverallProgress < OverallProgressMaximum)
                        {
                            StepOverallProgress();
                        }
                    }
                }

                PluginManager.SetPluginOrder(RegisteredPlugins.Keys.ToList());

                if (OverallProgress < OverallProgressMaximum)
                {
                    OverallProgress = OverallProgressMaximum;
                }

                tsTransaction.Complete();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (tsTransaction != null)
                {
                    tsTransaction.Dispose();
                }
            }

            return(null);
        }