Exemplo n.º 1
0
        IYodiiEngineResult DoDynamicResolution(ConfigurationSolver solver, Func <YodiiCommand, bool> existingCommandFilter, YodiiCommand cmd, Action onPreSuccess = null)
        {
            var dynResult = solver.DynamicResolution(existingCommandFilter != null ? _yodiiCommands.Where(existingCommandFilter) : _yodiiCommands, cmd);
            var errors    = _host.Apply(dynResult.Disabled, dynResult.Stopped, dynResult.Running);

            if (errors != null && errors.Any())
            {
                IYodiiEngineResult result = solver.CreateDynamicFailureResult(errors);
                _liveInfo.UpdateRuntimeErrors(errors, solver.FindExistingPlugin);
                return(result);
            }
            // Success:
            if (onPreSuccess != null)
            {
                onPreSuccess();
            }
            bool wasStopped = _currentSolver == null;

            if (_currentSolver != solver)
            {
                _currentSolver = solver;
            }

            _liveInfo.UpdateFrom(_currentSolver);

            _yodiiCommands.Merge(dynResult.Commands);
            if (wasStopped)
            {
                RaisePropertyChanged("IsRunning");
            }
            return(_successResult);
        }
Exemplo n.º 2
0
        public IYodiiEngineResult SetDiscoveredInfo(IDiscoveredInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (info == _discoveredInfo)
            {
                return(_successResult);
            }

            if (IsRunning)
            {
                var r = ConfigurationSolver.CreateAndApplyStaticResolution(this, _manager.FinalConfiguration, info, false, false, false);
                if (r.Item1 != null)
                {
                    Debug.Assert(!r.Item1.Success, "Not null means necessarily an error.");
                    Debug.Assert(r.Item1.Engine == this);
                    return(r.Item1);
                }
                return(DoDynamicResolution(r.Item2, null, null, () => DiscoveredInfo = info));
            }
            else
            {
                DiscoveredInfo = info;
            }
            return(_successResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Triggers the static resolution of the graph (with the current <see cref="DiscoveredInfo"/> and <see cref="Configuration"/>).
        /// This has no impact on the engine and can be called when <see cref="IsRunning"/> is false.
        /// </summary>
        /// <param name="revertServices">True to revert the list of the services (based on their <see cref="IServiceInfo.ServiceFullName"/>).</param>
        /// <param name="revertPlugins">True to revert the list of the plugins (based on their <see cref="IPluginInfo.PluginFullName"/>).</param>
        /// <returns>
        /// The result with a potential non null <see cref="IYodiiEngineResult.StaticFailureResult"/> but always an
        /// available <see cref="IYodiiEngineStaticOnlyResult.StaticSolvedConfiguration"/>.
        /// </returns>
        public IYodiiEngineStaticOnlyResult StaticResolutionOnly(bool revertServices, bool revertPlugins)
        {
            var r = ConfigurationSolver.CreateAndApplyStaticResolution(this, _manager.FinalConfiguration, _discoveredInfo, revertServices, revertPlugins, createStaticSolvedConfigOnSuccess: true);

            Debug.Assert(r.Item1 != null, "Either an error or a successful static resolution.");
            return(r.Item1);
        }
Exemplo n.º 4
0
 public void Stop()
 {
     if (IsRunning)
     {
         _liveInfo.Clear();
         _currentSolver = null;
         RaisePropertyChanged("IsRunning");
     }
 }
Exemplo n.º 5
0
        internal static Tuple <IYodiiEngineStaticOnlyResult, ConfigurationSolver> CreateAndApplyStaticResolution(YodiiEngine engine, FinalConfiguration finalConfiguration, IDiscoveredInfo discoveredInfo, bool revertServices, bool revertPlugins, bool createStaticSolvedConfigOnSuccess)
        {
            ConfigurationSolver          temporarySolver = new ConfigurationSolver(engine, revertServices, revertPlugins);
            IYodiiEngineStaticOnlyResult result          = temporarySolver.StaticResolution(finalConfiguration, discoveredInfo, createStaticSolvedConfigOnSuccess);

            // StaticResolution returns null on success.
            // If there is a result, it is either an error or createStaticSolvedConfigOnSuccess is true and this is a StaticResolutionOnly: in both
            // case we do not need to keep the temporary solver.
            if (result != null)
            {
                temporarySolver = null;
            }
            return(Tuple.Create(result, temporarySolver));
        }
Exemplo n.º 6
0
 public IYodiiEngineResult Start(bool revertServices, bool revertPlugins, IEnumerable <YodiiCommand> persistedCommands = null)
 {
     if (!IsRunning)
     {
         _yodiiCommands.Clear();
         if (persistedCommands != null)
         {
             _yodiiCommands.AddRange(persistedCommands);
         }
         var r = ConfigurationSolver.CreateAndApplyStaticResolution(this, _manager.FinalConfiguration, _discoveredInfo, revertServices, revertPlugins, false);
         if (r.Item1 != null)
         {
             Debug.Assert(!r.Item1.Success, "Not null means necessarily an error.");
             Debug.Assert(r.Item1.Engine == this);
             return(r.Item1);
         }
         return(DoDynamicResolution(r.Item2, null, null));
     }
     return(_successResult);
 }
Exemplo n.º 7
0
 internal static Tuple<IYodiiEngineStaticOnlyResult, ConfigurationSolver> CreateAndApplyStaticResolution( YodiiEngine engine, FinalConfiguration finalConfiguration, IDiscoveredInfo discoveredInfo, bool revertServices, bool revertPlugins, bool createStaticSolvedConfigOnSuccess )
 {
     ConfigurationSolver temporarySolver = new ConfigurationSolver(  engine,revertServices, revertPlugins );
     IYodiiEngineStaticOnlyResult result =  temporarySolver.StaticResolution( finalConfiguration, discoveredInfo, createStaticSolvedConfigOnSuccess );
     // StaticResolution returns null on success.
     // If there is a result, it is either an error or createStaticSolvedConfigOnSuccess is true and this is a StaticResolutionOnly: in both
     // case we do not need to keep the temporary solver.
     if( result != null ) temporarySolver = null;
     return Tuple.Create( result, temporarySolver );
 }
Exemplo n.º 8
0
 internal Tuple <IYodiiEngineStaticOnlyResult, ConfigurationSolver> StaticResolutionByConfigurationManager(FinalConfiguration finalConfiguration)
 {
     Debug.Assert(IsRunning);
     return(ConfigurationSolver.CreateAndApplyStaticResolution(this, finalConfiguration, _discoveredInfo, false, false, false));
 }
Exemplo n.º 9
0
 internal IYodiiEngineResult OnConfigurationChanging(ConfigurationSolver temporarySolver)
 {
     Debug.Assert(IsRunning, "Cannot call this function when the engine is not running");
     return(DoDynamicResolution(temporarySolver, null, null));
 }