Пример #1
0
        private static void ServeRegistries(ILogger logger, string registries)
        {
            string                   contentRoot            = GetArgument("ContentRoot", $"Enter the path to the content root (default: {defaultContentRoot} ");
            DataSettings             dataSettings           = DataSettings.Current;
            IApplicationNameProvider appNameProvider        = DefaultConfigurationApplicationNameProvider.Instance;
            ServiceRegistryService   serviceRegistryService = ServiceRegistryService.GetLocalServiceRegistryService(dataSettings, appNameProvider, GetArgument("AssemblySearchPattern", "Please specify the AssemblySearchPattern to use"), logger);

            string[]        requestedRegistries = registries.DelimitSplit(",");
            HashSet <Type>  serviceTypes        = new HashSet <Type>();
            ServiceRegistry allTypes            = new ServiceRegistry();

            foreach (string registryName in requestedRegistries)
            {
                ServiceRegistry registry = serviceRegistryService.GetServiceRegistry(registryName);
                foreach (string className in registry.ClassNames)
                {
                    registry.Get(className, out Type type);
                    if (type.HasCustomAttributeOfType <ProxyAttribute>())
                    {
                        serviceTypes.Add(type);
                    }
                }
                allTypes.CombineWith(registry);
            }
            Type[] services = serviceTypes.ToArray();
            if (services.Length == 0)
            {
                throw new ArgumentException("No services were loaded");
            }
            ServeServiceTypes(contentRoot, ServiceConfig.GetConfiguredHostPrefixes(), allTypes, services);
            Pause($"Gloo server is serving services\r\n\t{services.ToArray().ToDelimited(s => s.FullName, "\r\n\t")}");
        }
Пример #2
0
        public void CreateRegistry()
        {
            DataSettings             dataSettings           = DataSettings.Default;
            IApplicationNameProvider appNameProvider        = DefaultConfigurationApplicationNameProvider.Instance;
            ServiceRegistryService   serviceRegistryService = ServiceRegistryService.GetLocalServiceRegistryService(dataSettings, appNameProvider, GetArgument("AssemblySearchPattern", "Please specify the AssemblySearchPattern to use"), GetLogger());

            List <dynamic>            types        = new List <dynamic>();
            string                    assemblyPath = "\r\n";
            DirectoryInfo             sysData      = DataSettings.Current.GetSysDataDirectory(nameof(ServiceRegistry).Pluralize());
            ServiceRegistryRepository repo         = DataSettings.Current.GetSysDaoRepository <ServiceRegistryRepository>();
            ServiceRegistryDescriptor registry     = new ServiceRegistryDescriptor();

            while (!assemblyPath.Equals(string.Empty))
            {
                if (!string.IsNullOrEmpty(assemblyPath.Trim()))
                {
                    Assembly assembly = Assembly.LoadFrom(assemblyPath);
                    if (assembly == null)
                    {
                        OutLineFormat("Assembly not found: {0}", ConsoleColor.Magenta, assemblyPath);
                    }
                    else
                    {
                        OutLineFormat("Storing assembly file chunks: {0}", ConsoleColor.Cyan, assembly.FullName);
                        serviceRegistryService.FileService.StoreFileChunks(assembly.GetFileInfo(), assembly.FullName);
                        string className = "\r\n";
                        while (!className.Equals(string.Empty))
                        {
                            if (!string.IsNullOrEmpty(className.Trim()))
                            {
                                Type type = GetType(assembly, className);
                                if (type == null)
                                {
                                    Thread.Sleep(300);
                                    OutLineFormat("Specified class was not found in the current assembly: {0}", assembly.FullName);
                                }
                                else
                                {
                                    registry.AddService(type, type);
                                }
                            }
                            Thread.Sleep(300);
                            className = Prompt("Enter the name of a class to add to the service registry (leave blank to finish)");
                        }
                    }
                }
                Thread.Sleep(300);
                assemblyPath = Prompt("Enter the path to an assembly file containing service types (leave blank to finish)");
            }
            string registryName = Prompt("Enter a name for the registry");
            string path         = Path.Combine(sysData.FullName, $"{registryName}.json");

            registry.Name = registryName;
            registry.Save(repo);
            registry.ToJsonFile(path);
        }
Пример #3
0
        public void CanRegisterContainer()
        {
            ServiceRegistryService svc = GetServiceRegistrationService(nameof(ServiceRegistryLoaderTest));
            List <ServiceRegistryContainerRegistrationResult> results = svc.RegisterServiceRegistryContainers(Assembly.GetExecutingAssembly());

            Expect.AreEqual(1, results.Count);
            CoreServices.ServiceRegistry registry = svc.GetServiceRegistry(results[0].Name);
            TestRegistryClass            instance = registry.Get <TestRegistryClass>();

            Expect.AreEqual(instance.SetByCtor, TestRegistryContainer.TestValue);
            Expect.AreEqual(typeof(ConsoleLogger), instance.Logger.GetType());
        }
Пример #4
0
        public void ServiceRegistryLoaderTest()
        {
            ServiceRegistryService svc = GetServiceRegistrationService(nameof(ServiceRegistryLoaderTest));
            string name = nameof(ServiceRegistryLoaderTest);

            svc.RegisterServiceRegistryLoader(name, typeof(TestServiceRegistryContainer).GetMethod("Create"), true);

            CoreServices.ServiceRegistry reg = svc.GetServiceRegistry(name);
            TestMonkey value = reg.Get <TestMonkey>();

            Expect.AreEqual("SomeValue", value.Name);
            Expect.IsNull(value.Logger);
            reg.SetProperties(value);
            Expect.IsObjectOfType <ConsoleLogger>(value.Logger);
        }