예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="keepRunningLaunchedOptionals">if false, all plugins that are "optional" but are already launched will be stopped</param>
        /// <returns></returns>
        public bool Apply(bool stopLaunchedOptionals)
        {
            if (_planCalculator != null)
            {
                throw new InvalidOperationException(Runner.R.ReentrantApplyCall);
            }
            if (_contextObject == null)
            {
                throw new InvalidOperationException(Runner.R.InitializeRequired);
            }

            bool errorWhileApplying = false;

            if (_runningConfig.IsDirty)
            {
                // Allocates a new PlanCalculator and reuses it as long as reapplying is needed.
                _planCalculator = new PlanCalculator(_discoverer, _host.IsPluginRunning);
                try
                {
                    do
                    {
                        RunnerRequirementsSnapshot        requirements   = new RunnerRequirementsSnapshot(_requirements);
                        SolvedPluginConfigurationSnapshot configSnapshot = new SolvedPluginConfigurationSnapshot(_config.SolvedPluginConfiguration);

                        // During call to ObtainBestPlan, no reentrancy can occur (ObtainBestPlan does not call
                        // any external functions or objects nor does it raise any event).
                        // Once obtained, the best plan is also available through _planCalculator.LastBestPlan property.
                        ExecutionPlan bestPlan = _planCalculator.ObtainBestPlan(requirements.FinalConfigSnapshot, stopLaunchedOptionals);
                        if (bestPlan.Impossible)
                        {
                            errorWhileApplying = true;
                        }
                        else
                        {
                            // Here is where rentrancy may occur.
                            // Starting/stopping any plugin may start/stop others or enable/disable this runner.
                            var result = _host.Execute(bestPlan.PluginsToDisable, bestPlan.PluginsToStop, bestPlan.PluginsToStart);
                            if (result.Status != ExecutionPlanResultStatus.Success)
                            {
                                Debug.Assert(result.Culprit != null, "An error is necessarily associated to a plugin.");
                                _requirements.SetRunningError(result);
                                errorWhileApplying = true;
                            }
                            else
                            {
                                _planCalculator.ReapplyNeeded = false;
                                _requirements.UpdateRunningStatus(requirements.FinalConfigSnapshot);
                                _runningConfig.Apply(configSnapshot, requirements);
                            }
                        }
                    }while(_planCalculator.ReapplyNeeded && !errorWhileApplying);

                    if (ApplyDone != null)
                    {
                        ApplyDone(this, new ApplyDoneEventArgs(!errorWhileApplying));
                    }
                }
                finally
                {
                    _planCalculator = null;
                }
            }
            return(!errorWhileApplying);
        }
예제 #2
0
 internal void Apply(SolvedPluginConfigurationSnapshot snapshotConfig, RunnerRequirementsSnapshot snapShotRunner)
 {
     _pluginConfig = snapshotConfig;
     _requirements = snapShotRunner;
 }