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;
                }
            }
 /// <summary>
 /// Initializes a new DynamicPropagation based on the StaticPropagation.
 /// </summary>
 protected BasePropagation( BasePropagation staticPropagation )
     : this(staticPropagation.Service)
 {
     Service = staticPropagation.Service;
     _nbTotalAvailablePlugins = staticPropagation._nbTotalAvailablePlugins;
     _nbAvailablePlugins = staticPropagation._nbAvailablePlugins;
     _nbAvailableServices = staticPropagation._nbAvailableServices;
     _theOnlyPlugin = staticPropagation._theOnlyPlugin;
     _theOnlyService = staticPropagation._theOnlyService;
     if( _theOnlyPlugin != null && _theOnlyService != null )
     {
         Copy( staticPropagation._inclServices, _inclServices );
         Copy( staticPropagation._exclServices, _exclServices );
     }
 }
            public bool SetRunningPlugin( PluginData p )
            {
                Debug.Assert( p.Service != null && p.Service.Family == this );
                Debug.Assert( p.ConfigSolvedStatus == SolvedConfigurationStatus.Running, "ConfigSolvedStatus must have been set to Running prior calling this." );
                if( _runningPlugin == p ) return !p.Disabled;
                if( p.Disabled ) return false;

                if( _runningPlugin != null )
                {
                    p.SetDisabled( PluginDisabledReason.AnotherRunningPluginExistsInFamily );
                    if( !_runningPlugin.Disabled ) _runningPlugin.SetDisabled( PluginDisabledReason.AnotherRunningPluginExistsInFamily );
                    return false;
                }

                // Sets running plugin before calling SetRunningService.
                _runningPlugin = p;
                if( !SetRunningService( p.Service, ServiceSolvedConfigStatusReason.FromRunningPlugin ) )
                {
                    p.SetDisabled( PluginDisabledReason.ServiceCanNotBeRunning );
                    return false;
                }

                // We must disable what SetRunningService did not disabled: the sibling plugins and any specializations.
                PluginData sibling = p.Service.FirstPlugin;
                while( sibling != null )
                {
                    if( sibling != p && !sibling.Disabled ) sibling.SetDisabled( PluginDisabledReason.SiblingRunningPlugin );
                    sibling = sibling.NextPluginForService;
                }
                ServiceData s = p.Service.FirstSpecialization;
                while( s != null )
                {
                    if( !s.Disabled ) s.SetDisabled( ServiceDisabledReason.PluginRunningAbove );
                    s = s.NextSpecialization;
                }
                return !p.Disabled;
            }
Exemplo n.º 4
0
 internal void RegisterPluginReference( PluginData p, DependencyRequirement r )
 {
     _backReferences.Add( new BackReference( p, r ) );
 }
            protected void Refresh( int nbTotalAvalaiblePlugins, int nbAvailablePlugins, int nbAvailableServices )
            {
                if( _nbTotalAvailablePlugins == nbTotalAvalaiblePlugins
                    && _nbAvailablePlugins == nbAvailablePlugins
                    && _nbAvailableServices == nbAvailableServices ) return;

                _nbTotalAvailablePlugins = nbTotalAvalaiblePlugins;
                _nbAvailablePlugins = nbAvailablePlugins;
                _nbAvailableServices = nbAvailableServices;

                Debug.Assert( _nbTotalAvailablePlugins >= 1 );
                _theOnlyPlugin = null;
                _theOnlyService = null;
                Array.Clear( _inclServices, 0, 10 );
                Array.Clear( _exclServices, 0, 5 );
                // Retrieves the potential only plugin.
                if( _nbTotalAvailablePlugins == 1 )
                {
                    if( _nbAvailablePlugins == 0 )
                    {
                        ServiceData spec = Service.FirstSpecialization;
                        while( spec != null )
                        {
                            if( IsValidSpecialization( spec ) )
                            {
                                BasePropagation propSpec = GetPropagationInfo( spec );
                                Debug.Assert( propSpec != null );
                                if( propSpec.TheOnlyPlugin != null )
                                {
                                    Debug.Assert( _theOnlyPlugin == null );
                                    _theOnlyPlugin = propSpec.TheOnlyPlugin;
                                }
                            }
                            spec = spec.NextSpecialization;
                        }
                    }
                    else
                    {
                        PluginData p = Service.FirstPlugin;
                        while( p != null )
                        {
                            if( IsValidPlugin( p ) )
                            {
                                Debug.Assert( _theOnlyPlugin == null );
                                _theOnlyPlugin = p;
                            }
                            p = p.NextPluginForService;
                        }
                    }
                    Debug.Assert( _theOnlyPlugin != null && IsValidPlugin( _theOnlyPlugin ) );
                }
                else if( _nbAvailablePlugins == 0 && _nbAvailableServices == 1 )
                {
                    ServiceData spec = Service.FirstSpecialization;
                    while( spec != null )
                    {
                        if( IsValidSpecialization( spec ) )
                        {
                            Debug.Assert( _theOnlyService == null );
                            _theOnlyService = spec;
                        }
                        spec = spec.NextSpecialization;
                    }
                    Debug.Assert( _theOnlyService != null && IsValidSpecialization( _theOnlyService ) );
                }
                Debug.Assert( (_nbTotalAvailablePlugins == 1) == (_theOnlyPlugin != null) );
            }
 protected abstract bool IsValidPlugin( PluginData p );
 protected override bool IsValidPlugin( PluginData p )
 {
     return !p.Disabled;
 }
Exemplo n.º 8
0
 internal void UpdateFrom( PluginData p, DelayedPropertyNotification notifier )
 {
     Debug.Assert( FullName == p.PluginInfo.PluginFullName );
     UpdateItem( p, notifier );
     notifier.Update( this, ref _pluginInfo, p.PluginInfo, () => PluginInfo );
 }
Exemplo n.º 9
0
 internal void Bind( PluginData p, Func<string, LiveServiceInfo> serviceFinder, DelayedPropertyNotification notifier )
 {
     Debug.Assert( _pluginInfo == p.PluginInfo );
     var newService = p.Service != null ? serviceFinder( p.Service.ServiceInfo.ServiceFullName ) : null;
     notifier.Update( this, ref _service, newService, () => Service );
 }
 internal void DynamicResetState()
 {
     _dynRunningService = null;
     _dynRunningPlugin = null;
     Root.DynamicResetState();
 }
Exemplo n.º 11
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 );
 }
Exemplo n.º 12
0
 internal void AddPlugin( PluginData p )
 {
     p.NextPluginForService = FirstPlugin;
     FirstPlugin = p;
     ++PluginCount;
     if( p.Disabled ) ++DisabledPluginCount;
     ServiceData g = this;
     do
     {
         ++g.TotalPluginCount;
         if( p.Disabled ) ++g.TotalDisabledPluginCount;
         g = g.Generalization;
     }
     while( g != null );
 }
Exemplo n.º 13
0
 internal void OnPluginDisabled( PluginData p )
 {
     Debug.Assert( this.IsGeneralizationOf( p.Service ) && p.Disabled );
     if( p.Service == this ) ++DisabledPluginCount;
     ++TotalDisabledPluginCount;
     if( Generalization != null ) Generalization.OnPluginDisabled( p );
     if( !Disabled && Family.Solver.Step >= ConfigurationSolverStep.OnAllPluginsAdded )
     {
         if( TotalAvailablePluginCount == 0 )
         {
             SetDisabled( ServiceDisabledReason.AllPluginsAreDisabled );
         }
         else Family.Solver.DeferPropagation( this );
     }
 }
Exemplo n.º 14
0
        PluginData RegisterPlugin( FinalConfiguration finalConfig, IPluginInfo p )
        {
            PluginData data;
            if( _plugins.TryGetValue( p.PluginFullName, out data ) ) return data;

            ConfigurationStatus pluginStatus = finalConfig.GetStatus( p.PluginFullName );
            ServiceData service = p.Service != null ? _services[p.Service.ServiceFullName] : null;
            if( service == null ) ++_independentPluginsCount;
            data = new PluginData( this, p, service, pluginStatus );
            _plugins.Add( p.PluginFullName, data );
            return data;
        }
Exemplo n.º 15
0
            protected void Refresh(int nbTotalAvalaiblePlugins, int nbAvailablePlugins, int nbAvailableServices)
            {
                if (_nbTotalAvailablePlugins == nbTotalAvalaiblePlugins &&
                    _nbAvailablePlugins == nbAvailablePlugins &&
                    _nbAvailableServices == nbAvailableServices)
                {
                    return;
                }

                _nbTotalAvailablePlugins = nbTotalAvalaiblePlugins;
                _nbAvailablePlugins      = nbAvailablePlugins;
                _nbAvailableServices     = nbAvailableServices;

                Debug.Assert(_nbTotalAvailablePlugins >= 1);
                _theOnlyPlugin  = null;
                _theOnlyService = null;
                Array.Clear(_inclServices, 0, 10);
                Array.Clear(_exclServices, 0, 5);
                // Retrieves the potential only plugin.
                if (_nbTotalAvailablePlugins == 1)
                {
                    if (_nbAvailablePlugins == 0)
                    {
                        ServiceData spec = Service.FirstSpecialization;
                        while (spec != null)
                        {
                            if (IsValidSpecialization(spec))
                            {
                                BasePropagation propSpec = GetPropagationInfo(spec);
                                Debug.Assert(propSpec != null);
                                if (propSpec.TheOnlyPlugin != null)
                                {
                                    Debug.Assert(_theOnlyPlugin == null);
                                    _theOnlyPlugin = propSpec.TheOnlyPlugin;
                                }
                            }
                            spec = spec.NextSpecialization;
                        }
                    }
                    else
                    {
                        PluginData p = Service.FirstPlugin;
                        while (p != null)
                        {
                            if (IsValidPlugin(p))
                            {
                                Debug.Assert(_theOnlyPlugin == null);
                                _theOnlyPlugin = p;
                            }
                            p = p.NextPluginForService;
                        }
                    }
                    Debug.Assert(_theOnlyPlugin != null && IsValidPlugin(_theOnlyPlugin));
                }
                else if (_nbAvailablePlugins == 0 && _nbAvailableServices == 1)
                {
                    ServiceData spec = Service.FirstSpecialization;
                    while (spec != null)
                    {
                        if (IsValidSpecialization(spec))
                        {
                            Debug.Assert(_theOnlyService == null);
                            _theOnlyService = spec;
                        }
                        spec = spec.NextSpecialization;
                    }
                    Debug.Assert(_theOnlyService != null && IsValidSpecialization(_theOnlyService));
                }
                Debug.Assert((_nbTotalAvailablePlugins == 1) == (_theOnlyPlugin != null));
            }
Exemplo n.º 16
0
            public IEnumerable <ServiceData> GetIncludedServices(StartDependencyImpact impact, bool forRunnableStatus)
            {
                if (_theOnlyPlugin != null)
                {
                    return(_theOnlyPlugin.GetIncludedServices(impact, forRunnableStatus));
                }
                if (_theOnlyService != null)
                {
                    return(GetPropagationInfo(_theOnlyService).GetIncludedServices(impact, forRunnableStatus));
                }

                int iImpact = (int)impact;

                if (forRunnableStatus)
                {
                    iImpact *= 2;
                }
                --iImpact;

                IEnumerable <ServiceData> inclExist = _inclServices[iImpact];

                if (inclExist == null)
                {
                    HashSet <ServiceData> incl = null;
                    ServiceData           spec = Service.FirstSpecialization;
                    while (spec != null)
                    {
                        BasePropagation prop = GetPropagationInfo(spec);
                        if (prop != null)
                        {
                            if (incl == null)
                            {
                                incl = new HashSet <ServiceData>(prop.GetIncludedServices(impact, forRunnableStatus));
                            }
                            else
                            {
                                incl.IntersectWith(prop.GetIncludedServices(impact, forRunnableStatus));
                            }
                        }
                        spec = spec.NextSpecialization;
                    }
                    PluginData p = Service.FirstPlugin;
                    while (p != null)
                    {
                        if (!p.Disabled)
                        {
                            if (incl == null)
                            {
                                incl = new HashSet <ServiceData>(p.GetIncludedServices(impact, forRunnableStatus));
                            }
                            else
                            {
                                incl.IntersectWith(p.GetIncludedServices(impact, forRunnableStatus));
                            }
                        }
                        p = p.NextPluginForService;
                    }
                    _inclServices[iImpact] = inclExist = incl ?? Service.InheritedServicesWithThis;
                }
                return(inclExist);
            }
Exemplo n.º 17
0
 protected abstract bool IsValidPlugin(PluginData p);
Exemplo n.º 18
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);
                    }
                }
            }
        }
Exemplo n.º 19
0
 public BackReference( PluginData p, DependencyRequirement r )
 {
     PluginData = p;
     Requirement = r;
 }
Exemplo n.º 20
0
 internal LivePluginInfo( PluginData p, YodiiEngine engine )
     : base(engine, p, p.PluginInfo.PluginFullName)
 {
     _pluginInfo = p.PluginInfo;
 }
Exemplo n.º 21
0
 public SolvedPluginSnapshot( PluginData plugin )
     : base(plugin)
 {
     _pluginInfo = plugin.PluginInfo;
 }
 protected override bool IsValidPlugin( PluginData p )
 {
     return p.DynamicStatus == null;
 }