/// <summary>
 /// Called before DynamicResetState on plugins.
 /// </summary>
 public void DynamicResetState()
 {
     _dynPropagation = null;
     _dynamicTotalAvailablePluginsCount = TotalAvailablePluginCount;
     _dynamicAvailablePluginsCount = AvailablePluginCount;
     _dynamicAvailableServicesCount = AvailableServiceCount;
     switch( FinalConfigSolvedStatus )
     {
         case SolvedConfigurationStatus.Disabled:
             {
                 _dynamicReason = ServiceRunningStatusReason.StoppedByConfig;
                 _dynamicStatus = RunningStatus.Disabled;
                 break;
             }
         case SolvedConfigurationStatus.Running:
             {
                 _dynamicReason = ServiceRunningStatusReason.StartedByConfig;
                 _dynamicStatus = RunningStatus.RunningLocked;
                 break;
             }
         default:
             {
                 _dynamicReason = ServiceRunningStatusReason.None;
                 _dynamicStatus = null;
                 break;
             }
     }
     ServiceData s = FirstSpecialization;
     while( s != null )
     {
         s.DynamicResetState();
         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;
                }
            }
Example #3
0
 internal void OnDirectPluginStarted(PluginData runningPlugin)
 {
     Debug.Assert(_dynamicStatus == null || _dynamicStatus.Value >= RunningStatus.Running);
     Debug.Assert(runningPlugin != null);
     if (_dynamicStatus == null)
     {
         _dynamicStatus = RunningStatus.Running;
         _dynamicReason = ServiceRunningStatusReason.StartedByPlugin;
     }
     Debug.Assert(runningPlugin.DynamicStatus.HasValue && runningPlugin.DynamicStatus.Value >= RunningStatus.Running);
     Family.DynamicSetRunningPlugin(runningPlugin);
 }
Example #4
0
 internal void DynamicStartBy(ServiceRunningStatusReason reason)
 {
     Debug.Assert(_dynamicStatus == null || _dynamicStatus.Value >= RunningStatus.Running);
     Debug.Assert(reason == ServiceRunningStatusReason.StartedByCommand ||
                  reason == ServiceRunningStatusReason.StartedByPropagation ||
                  reason == ServiceRunningStatusReason.StartedByOptionalReference ||
                  reason == ServiceRunningStatusReason.StartedByOptionalRecommendedReference ||
                  reason == ServiceRunningStatusReason.StartedByRunnableReference ||
                  reason == ServiceRunningStatusReason.StartedByRunnableRecommendedReference ||
                  reason == ServiceRunningStatusReason.StartedByRunningReference
                  );
     if (_dynamicStatus == null)
     {
         Family.DynamicSetRunningService(this, reason);
         DynPropagateStart();
     }
 }
Example #5
0
        /// <summary>
        /// Called before DynamicResetState on plugins.
        /// </summary>
        public void DynamicResetState()
        {
            _dynPropagation = null;
            _dynamicTotalAvailablePluginsCount = TotalAvailablePluginCount;
            _dynamicAvailablePluginsCount      = AvailablePluginCount;
            _dynamicAvailableServicesCount     = AvailableServiceCount;
            switch (FinalConfigSolvedStatus)
            {
            case SolvedConfigurationStatus.Disabled:
            {
                _dynamicReason = ServiceRunningStatusReason.StoppedByConfig;
                _dynamicStatus = RunningStatus.Disabled;
                break;
            }

            case SolvedConfigurationStatus.Running:
            {
                _dynamicReason = ServiceRunningStatusReason.StartedByConfig;
                _dynamicStatus = RunningStatus.RunningLocked;
                break;
            }

            default:
            {
                _dynamicReason = ServiceRunningStatusReason.None;
                _dynamicStatus = null;
                break;
            }
            }
            ServiceData s = FirstSpecialization;

            while (s != null)
            {
                s.DynamicResetState();
                s = s.NextSpecialization;
            }
        }
 internal void OnDirectPluginStarted( PluginData runningPlugin )
 {
     Debug.Assert( _dynamicStatus == null || _dynamicStatus.Value >= RunningStatus.Running );
     Debug.Assert( runningPlugin != null );
     if( _dynamicStatus == null )
     {
         _dynamicStatus = RunningStatus.Running;
         _dynamicReason = ServiceRunningStatusReason.StartedByPlugin;
     }
     Debug.Assert( runningPlugin.DynamicStatus.HasValue && runningPlugin.DynamicStatus.Value >= RunningStatus.Running );
     Family.DynamicSetRunningPlugin( runningPlugin );
 }
        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 );
                }
            }
        }
 internal void DynamicStartBy( ServiceRunningStatusReason reason )
 {
     Debug.Assert( _dynamicStatus == null || _dynamicStatus.Value >= RunningStatus.Running );
     Debug.Assert( reason == ServiceRunningStatusReason.StartedByCommand
                     || reason == ServiceRunningStatusReason.StartedByPropagation
                     || reason == ServiceRunningStatusReason.StartedByOptionalReference
                     || reason == ServiceRunningStatusReason.StartedByOptionalRecommendedReference
                     || reason == ServiceRunningStatusReason.StartedByRunnableReference
                     || reason == ServiceRunningStatusReason.StartedByRunnableRecommendedReference
                     || reason == ServiceRunningStatusReason.StartedByRunningReference
                     );
     if( _dynamicStatus == null )
     {
         Family.DynamicSetRunningService( this, reason );
         DynPropagateStart();
     }
 }
Example #9
0
            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;
                    }
                }
            }
Example #10
0
        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);
                    }
                }
            }
        }