public void DynamicSetRunningPlugin(PluginData running) { Debug.Assert(running.Service != null && running.Service.Family == this); Debug.Assert(running != null && running.DynamicStatus.HasValue && running.DynamicStatus.Value >= RunningStatus.Running); Debug.Assert(_dynRunningPlugin == null); _dynRunningPlugin = running; DynamicSetRunningService(running.Service, ServiceRunningStatusReason.StartedBySpecialization); // Stops all plugins except the one that started. PluginData p = running.Service.FirstPlugin; while (p != null) { if (p != running) { Debug.Assert(p.DynamicStatus == null || p.DynamicStatus.Value <= RunningStatus.Stopped); if (p.DynamicStatus == null) { p.DynamicStopBy(PluginRunningStatusReason.StoppedByRunningSibling); } } p = p.NextPluginForService; } // Stops all specializations. ServiceData s = running.Service.FirstSpecialization; while (s != null) { Debug.Assert(s.DynamicStatus == null || s.DynamicStatus.Value <= RunningStatus.Stopped); if (s.DynamicStatus == null) { s.DynamicStopBy(ServiceRunningStatusReason.StoppedByGeneralization); } s = s.NextSpecialization; } }
public void DynamicSetRunningService(ServiceData s, ServiceRunningStatusReason reason) { Debug.Assert(s != null && s.Family == this && !s.Disabled); Debug.Assert(_dynRunningPlugin == null || s.IsGeneralizationOf(_dynRunningPlugin.Service), "If there is running plugin, it can only be one of us."); Debug.Assert(s._dynamicStatus == null || s._dynamicStatus.Value >= RunningStatus.Running); if (s._dynamicStatus == null) { s._dynamicStatus = RunningStatus.Running; s._dynamicReason = reason; } if (s == _dynRunningService) { return; } Debug.Assert(_dynRunningService == null || _dynRunningService.IsStrictGeneralizationOf(s), "If there is already a current running service, it can only be a more specialized one."); var g = s.Generalization; while (g != null) { if (g._dynamicStatus == null) { g._dynamicStatus = RunningStatus.Running; g._dynamicReason = ServiceRunningStatusReason.StartedBySpecialization; } g = g.Generalization; } var prevRunningService = _dynRunningService; _dynRunningService = s; // We must now stop sibling services (and plugins) from this up to the currently running one and // when the current one is null, up to the root. g = s.Generalization; var specRunning = s; while (g != null) { var spec = g.FirstSpecialization; while (spec != null) { if (spec != specRunning && !spec.Disabled) { Debug.Assert(spec.DynamicStatus == null || spec.DynamicStatus.Value <= RunningStatus.Stopped); if (spec.DynamicStatus == null) { spec.DynamicStopBy(ServiceRunningStatusReason.StoppedByGeneralization); } } spec = spec.NextSpecialization; } PluginData p = g.FirstPlugin; while (p != null) { Debug.Assert(p.DynamicStatus == null || p.DynamicStatus.Value <= RunningStatus.Stopped); if (p.DynamicStatus == null) { p.DynamicStopBy(PluginRunningStatusReason.StoppedByStoppedService); } p = p.NextPluginForService; } specRunning = g; g = g.Generalization; if (prevRunningService != null && g == prevRunningService.Generalization) { break; } } }
internal void DynamicStopBy(ServiceRunningStatusReason reason) { Debug.Assert(_dynamicStatus == null); Debug.Assert(reason == ServiceRunningStatusReason.StoppedByGeneralization || reason == ServiceRunningStatusReason.StoppedByCommand || reason == ServiceRunningStatusReason.StoppedByPluginStopped || reason == ServiceRunningStatusReason.StoppedBySiblingRunningService || reason == ServiceRunningStatusReason.StoppedByOptionalReference || reason == ServiceRunningStatusReason.StoppedByOptionalRecommendedReference || reason == ServiceRunningStatusReason.StoppedByRunnableReference || reason == ServiceRunningStatusReason.StoppedByRunnableRecommendedReference || reason == ServiceRunningStatusReason.StoppedByFinalDecision); _dynamicStatus = RunningStatus.Stopped; _dynamicReason = reason; for (int i = 0; i < _inheritedServicesWithThis.Length - 1; ++i) { --_inheritedServicesWithThis[i]._dynamicAvailableServicesCount; } if (_dynamicTotalAvailablePluginsCount > 0) { // Stops the specialized services. ServiceData child = FirstSpecialization; while (child != null) { Debug.Assert(child.DynamicStatus == null || child.DynamicStatus.Value <= RunningStatus.Stopped); if (child.DynamicStatus == null) { child.DynamicStopBy(ServiceRunningStatusReason.StoppedByGeneralization); } child = child.NextSpecialization; } // Stops the plugins. PluginData p = FirstPlugin; while (p != null) { Debug.Assert(p.DynamicStatus == null || p.DynamicStatus.Value <= RunningStatus.Stopped); if (p.DynamicStatus == null) { p.DynamicStopBy(PluginRunningStatusReason.StoppedByStoppedService); } p = p.NextPluginForService; } Debug.Assert(_dynamicTotalAvailablePluginsCount == 0); } foreach (var backRef in _backReferences) { Debug.Assert(backRef.PluginData.DynamicStatus == null || backRef.PluginData.DynamicStatus.Value <= RunningStatus.Stopped || ((backRef.Requirement == DependencyRequirement.Optional || backRef.Requirement == DependencyRequirement.Runnable) && backRef.PluginData.ConfigSolvedImpact != StartDependencyImpact.FullStart) || ((backRef.Requirement == DependencyRequirement.OptionalRecommended || backRef.Requirement == DependencyRequirement.RunnableRecommended) && backRef.PluginData.ConfigSolvedImpact < StartDependencyImpact.StartRecommended)); if (backRef.PluginData.DynamicStatus == null) { PluginRunningStatusReason r = backRef.PluginData.GetStoppedReasonForStoppedReference(backRef.Requirement); if (r != PluginRunningStatusReason.None) { backRef.PluginData.DynamicStopBy(r); } } } }