Example #1
0
        /// <summary>
        /// Creates a new named plugin, which implements an existing service.
        /// </summary>
        /// <param name="pluginName">Name of the new plugin</param>
        /// <param name="service">Implemented service</param>
        /// <returns>New plugin</returns>
        internal PluginInfo CreateNewPlugin(string pluginName, ServiceInfo service = null)
        {
            Debug.Assert(!String.IsNullOrWhiteSpace(pluginName));

            if (service != null)
            {
                Debug.Assert(ServiceInfos.Contains(service));
            }

            PluginInfo plugin = new PluginInfo(pluginName, AssemblyInfoHelper.ExecutingAssemblyInfo, service);

            CreateLabPlugin(plugin);
            _pluginInfos.Add(plugin);   // Throws on duplicate

            return(plugin);
        }
Example #2
0
            public IConfigurationLayer Create(string layerName = null)
            {
                var layer = new ConfigurationLayer(_parent, layerName);

                _layers.Add(layer);
                return(layer);
            }
Example #3
0
        /// <summary>
        /// Creates a new named service, which specializes another service.
        /// </summary>
        /// <param name="serviceName">Name of the new service</param>
        /// <param name="generalization">Specialized service</param>
        /// <returns>New service</returns>
        /// <remarks>Cannot be used when engine is running.</remarks>
        internal ServiceInfo CreateNewService(string serviceName, ServiceInfo generalization = null)
        {
            Debug.Assert(serviceName != null);
            Debug.Assert(_serviceInfos.Any(x => x.ServiceFullName == serviceName) == false, "Service does not exist and can be added");

            if (generalization != null)
            {
                Debug.Assert(ServiceInfos.Contains(generalization));
            }

            ServiceInfo newService = new ServiceInfo(serviceName, AssemblyInfoHelper.ExecutingAssemblyInfo, generalization);

            CreateLabService(newService);
            _serviceInfos.Add(newService);   // Throws on duplicate


            return(newService);
        }
Example #4
0
            public IYodiiEngineResult Add(string serviceOrPluginFullName, ConfigurationStatus status, string statusReason = "", StartDependencyImpact impact = StartDependencyImpact.Unknown)
            {
                if (String.IsNullOrEmpty(serviceOrPluginFullName))
                {
                    throw new ArgumentException("serviceOrPluginFullName is null or empty");
                }

                ConfigurationItem existing = _items.GetByKey(serviceOrPluginFullName);

                if (existing != null)
                {
                    IYodiiEngineResult res = existing.SetStatus(status);
                    if (res.Success)
                    {
                        return(existing.SetImpact(impact));
                    }
                    return(res);
                }

                ConfigurationItem newItem = new ConfigurationItem(_layer, serviceOrPluginFullName, status, impact, statusReason);

                if (_layer._owner == null)
                {
                    _items.Add(newItem);
                    return(SuccessYodiiEngineResult.NullEngineSuccessResult);
                }

                IYodiiEngineResult result = _layer._owner.OnConfigurationItemAdding(newItem);

                if (result.Success)
                {
                    _items.Add(newItem);
                    _layer._owner.OnConfigurationChanged();
                    return(result);
                }
                newItem.OnRemoved();
                return(result);
            }
Example #5
0
        /// <summary>
        /// Creates a lab wrapper item around an existing mock service, and adds it to our collection.
        /// </summary>
        /// <param name="s">Existing mock service</param>
        private void CreateLabService(ServiceInfo s)
        {
            LabServiceInfo newServiceInfo;

            if (s.Generalization != null)
            {
                LabServiceInfo generalizationLiveInfo = _labServiceInfos.GetByKey((ServiceInfo)s.Generalization);
                newServiceInfo = new LabServiceInfo(s);   // TODO: Running requirement
            }
            else
            {
                newServiceInfo = new LabServiceInfo(s);
            }
            _labServiceInfos.Add(newServiceInfo);
        }
Example #6
0
        /// <summary>
        /// Creates a lab wrapper item around an existing mock plugin, and adds it to our collection.
        /// </summary>
        /// <param name="p">Existing mock plugin</param>
        private void CreateLabPlugin(PluginInfo p)
        {
            LabPluginInfo lp;

            if (p.Service != null)
            {
                p.Service.InternalImplementations.Add(p);
                LabServiceInfo liveService = _labServiceInfos.GetByKey(p.Service);
                lp = new LabPluginInfo(p);
            }
            else
            {
                lp = new LabPluginInfo(p);
            }

            _labPluginInfos.Add(lp);
        }
Example #7
0
        internal void UpdateFrom(IConfigurationSolver solver)
        {
            // 1 - Removes existing items from live info that do not exist anymore in the new running context.
            //     This raises Collection "item removed" events.
            //
            _services.RemoveWhereAndReturnsRemoved(s => solver.FindService(s.ServiceInfo.ServiceFullName) == null).Count();
            _plugins.RemoveWhereAndReturnsRemoved(p => solver.FindPlugin(p.PluginInfo.PluginFullName) == null).Count();

            DelayedPropertyNotification notifier = new DelayedPropertyNotification();

            // 2 - Builds two lists of new Services and new Plugins and for already existing ones,
            //     updates them with the new information.
            //     This update does not trigger any ProprtyChanged events and consider only
            //     direct properties of the object.
            //     Changes to linked items (such as a Generalization reference for instance will be
            //     done later thanks to their Bind method.
            //
            List <LiveServiceInfo> servicesToAdd = new List <LiveServiceInfo>();

            foreach (var s in solver.AllServices)
            {
                LiveServiceInfo ls = _services.GetByKey(s.ServiceInfo.ServiceFullName);
                if (ls == null)
                {
                    servicesToAdd.Add(new LiveServiceInfo(s, _engine));
                }
                else
                {
                    ls.UpdateFrom(s, notifier);
                }
            }

            List <LivePluginInfo> pluginsToAdd = new List <LivePluginInfo>();

            foreach (var p in solver.AllPlugins)
            {
                LivePluginInfo lp = _plugins.GetByKey(p.PluginInfo.PluginFullName);
                if (lp == null)
                {
                    pluginsToAdd.Add(new LivePluginInfo(p, _engine));
                }
                else
                {
                    lp.UpdateFrom(p, notifier);
                }
            }

            // 3 - Intrinsic properties have been updated. We now consider the properties that reference other items.
            //
            Func <string, LiveServiceInfo> serviceFinder = name => _services.GetByKey(name) ?? servicesToAdd.First(ls => ls.ServiceInfo.ServiceFullName == name);
            Func <string, LivePluginInfo>  pluginFinder  = id => _plugins.GetByKey(id) ?? pluginsToAdd.First(lp => lp.PluginInfo.PluginFullName == id);

            using (notifier.SilentMode())
            {
                foreach (var ls in servicesToAdd)
                {
                    ls.Bind(solver.FindExistingService(ls.ServiceInfo.ServiceFullName), serviceFinder, pluginFinder, notifier);
                }
            }
            foreach (var ls in _services)
            {
                ls.Bind(solver.FindExistingService(ls.ServiceInfo.ServiceFullName), serviceFinder, pluginFinder, notifier);
            }

            using (notifier.SilentMode())
            {
                foreach (var lp in pluginsToAdd)
                {
                    lp.Bind(solver.FindExistingPlugin(lp.PluginInfo.PluginFullName), serviceFinder, notifier);
                }
            }
            foreach (var lp in _plugins)
            {
                lp.Bind(solver.FindExistingPlugin(lp.PluginInfo.PluginFullName), serviceFinder, notifier);
            }

            // 4 - It is time to add the new comers: this raises Collection changed "item added" events.
            foreach (var ls in servicesToAdd)
            {
                _services.Add(ls);
            }
            foreach (var lp in pluginsToAdd)
            {
                _plugins.Add(lp);
            }

            // 5 - Raises all PropertyChanged events for all objects.
            notifier.RaiseEvents();
        }