Ejemplo n.º 1
0
        private void BuildServiceInfos()
        {
            ServiceInfos.Clear();

            CloudFoundryApplicationOptions appOpts = new CloudFoundryApplicationOptions();
            var aopSection = _config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX);

            aopSection.Bind(appOpts);

            ApplicationInstanceInfo appInfo = new ApplicationInstanceInfo(appOpts);
            var serviceSection = _config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);
            CloudFoundryServicesOptions serviceOpts = new CloudFoundryServicesOptions();

            serviceSection.Bind(serviceOpts);

            foreach (KeyValuePair <string, Service[]> serviceopt in serviceOpts.Services)
            {
                foreach (Service s in serviceopt.Value)
                {
                    IServiceInfoFactory factory = FindFactory(s);
                    if (factory != null && factory.Create(s) is ServiceInfo info)
                    {
                        info.ApplicationInfo = appInfo;
                        ServiceInfos.Add(info);
                    }
                }
            }
        }
        private void BuildServiceInfos()
        {
            ServiceInfos.Clear();

            var appInfo     = new CloudFoundryApplicationOptions(_config);
            var serviceOpts = new CloudFoundryServicesOptions(_config);

            foreach (var serviceopt in serviceOpts.Services)
            {
                foreach (var s in serviceopt.Value)
                {
                    var factory = FindFactory(s);
                    if (factory != null && factory.Create(s) is ServiceInfo info)
                    {
                        info.ApplicationInfo = appInfo;
                        ServiceInfos.Add(info);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void LoadComponentData(IEnumerable <Assembly> assemblies)
        {
            if (_loadedData)
            {
                return;
            }

            // Iterate through all loaded assemblies searching for NQ components
            Dictionary <Assembly, ComponentInfo>  componentAssemblies     = new Dictionary <Assembly, ComponentInfo>();
            Dictionary <string, List <Assembly> > componentPartAssemblies = new Dictionary <string, List <Assembly> >();

            foreach (Assembly a in assemblies)
            {
                if (AttributeComponentInfo.IsComponent(a))
                {
                    // Create component info and save it
                    AttributeComponentInfo componentInfo = new AttributeComponentInfo(a);

                    if (!componentInfo.IsComponentPart)
                    {
                        // Add component definition to internal list
                        if (!_componentInfos.ContainsKey(componentInfo.Name))
                        {
                            _componentInfos.Add(componentInfo.Name, componentInfo);
                        }
                        else
                        {
                            // Component is already known
                            _logger.Write(LogType.Error, "Multiple definition of component " + componentInfo.Name + ".");
                            throw new ComponentDefinitionException(ErrorReason.ComponentMultiplyDefined, "Multiple definition of component " + componentInfo.Name + ".");
                        }
                    }
                    else
                    {
                        // Add assembly to temporary parts list
                        if (!componentPartAssemblies.ContainsKey(componentInfo.Name))
                        {
                            componentPartAssemblies.Add(componentInfo.Name, new List <Assembly>());
                        }
                        componentPartAssemblies[componentInfo.Name].Add(a);
                    }

                    // Save assembly and ComponentInfo reference in hashtable for later iteration
                    componentAssemblies.Add(a, componentInfo);
                }
            }

            // Convert part assembly lists to arrays
            foreach (KeyValuePair <string, List <Assembly> > partList in componentPartAssemblies)
            {
                ((ComponentInfo)ComponentInfos[partList.Key]).PartAssemblies = partList.Value;
            }

            // Now iterate through all well-defined NQ components and search for services inside
            foreach (KeyValuePair <Assembly, ComponentInfo> nqAssembly in componentAssemblies)
            {
                ComponentInfo compInfo = nqAssembly.Value;

                Type[] classes = nqAssembly.Key.GetTypes();
                if (classes != null)
                {
                    foreach (Type comptype in classes)
                    {
                        if (AttributeServiceInfo.IsValidServiceClass(comptype))
                        {
                            // Firstly create a NQServiceInfo, we'll get all other information from it later
                            AttributeServiceInfo serviceInfo = new AttributeServiceInfo(comptype, compInfo.Name);

                            if (!ServiceInfos.ContainsKey(serviceInfo.ServiceInterface))
                            {
                                ServiceInfos.Add(serviceInfo.ServiceInterface, serviceInfo);
                            }
                            else
                            {
                                throw new ServiceDefinitionException(ErrorReason.ServiceMultiplyDefined,
                                                                     "Service \"" + serviceInfo.ServiceInterface + "\" is multiply defined.");
                            }
                        }
                    }
                }
            }

            _loadedData = true;
        }
Ejemplo n.º 4
0
        private void BuildServiceInfos()
        {
            var factory = FindFactory(new Service());

            ServiceInfos.Add(factory.Create(null));
        }