public void TestExposedTypes2() { ExposedTypes types = new ExposedTypes() .Add(new ExposedTypeConfigurations() { new ExposedTypeConfiguration() { TypeName = typeof(Test1).AssemblyQualifiedName, Attributes = new List <ExposedAttributeTypeConfiguration>() { new ExposedAttributeTypeConfiguration() { Context = "Test33", } } } }) .AddAttributesInTypeDescriptors() ; var l = TypeDescriptor.GetAttributes(typeof(Test1)).OfType <ExposeClassAttribute>().ToList(); Assert.AreEqual(l.Count() == 1, true); }
/// <summary> /// Register all configurations from class decorated by. ExposeClass(Context = "Configuration", DisplayName = "key in configuration") /// </summary> /// <param name="services">The services.</param> /// <param name="configuration">The configuration.</param> public static ExposedTypes RegisterConfigurations(this IServiceCollection services, IConfiguration configuration) { var types = new ExposedTypes(); // Add configuration type manualy. var __configuration = typeof(ExposedTypeConfigurations).LoadConfiguration(configuration) as ExposedTypeConfigurations; if (__configuration != null) { types.Add(__configuration) .AddAttributesInTypeDescriptors(); } // Add configuration type by attribute in code. types.Remove(typeof(ExposedTypeConfigurations)); var configs = types.GetTypes(ConstantsCore.Configuration).ToArray(); RegenerateSchemas(types); foreach (var _type in configs) { foreach (var attribute in _type.Value) { AppendConfiguration(services, configuration, _type.Key, attribute); } } return(types); }
public void Install(IObjectFactoryBuilder builder) { var objectFactory = builder.BuildObjectFactory(); var paperCatalog = new AggregateCatalog(); var exposedCatalog = objectFactory.CreateObject <ExposedPaperCatalog>(); paperCatalog.AddCatalog(exposedCatalog); foreach (var type in ExposedTypes.GetTypes <IPaperCatalog>()) { try { var catalog = (IPaperCatalog)objectFactory.CreateObject(type); paperCatalog.AddCatalog(catalog); } catch (Exception ex) { ex.Trace(); } } builder.AddSingleton <IPaperCatalog>(paperCatalog); }
private void Initialize(IWebApp webApp) { Console.WriteLine("---PAPERS---"); try { var factory = new PaperDescriptorFactory(webApp); var types = ExposedTypes.GetTypes <IPaper>().Distinct(); foreach (var type in types) { try { var descriptor = factory.CreatePaperDescriptor(type); var id = $"{descriptor.Catalog}/{descriptor.Paper}"; descriptorMap[id] = descriptor; Console.WriteLine($"/Paper/Api/Catalogs/{descriptor.Catalog}/Papers/{descriptor.Paper}"); } catch (Exception ex) { ex.Trace(); } } } catch (Exception ex) { ex.Trace(); } finally { Console.WriteLine("------"); } }
public void AddExposedTypes() { var knownTypes = ExposedTypes .GetTypes <Entity>() .Concat(ExposedTypes.GetTypes <IPaper>()); knownTypes.ForEach(Add); }
public void AddExposedTypes() { var knownTypes = ExposedTypes .GetTypes <Entity>() .Concat(ExposedTypes.GetTypes <IPaper>()); AddRange(knownTypes); }
private IEnumerable <PaperRendererInfo> EnumeratePaperRenderers() { var rendererTypes = ExposedTypes.GetTypes <IPaperRenderer>(); foreach (var rendererType in rendererTypes) { var renderers = EnumeratePaperRenderers(rendererType); foreach (var renderer in renderers) { yield return(renderer); } } }
public static Router Create(WebApp webApp) { var router = new Router(); var routerTypes = ExposedTypes.GetTypes <IPipelineRouter>().ToArray(); foreach (var routerType in routerTypes) { try { IPipelineRouter instance; // XXX: O roteador customizado pode ser instanciado com ou sem IWebApp, // mas isso é muito pouco. Melhor seria disponibilizar todos os objetos // de contexto da plataforma disponíveis no ato da instanciação do roteador. var ctor = routerType.GetConstructor(new[] { typeof(IWebApp) }); if (ctor != null) { instance = (IPipelineRouter)ctor.Invoke(new[] { webApp }); } else { instance = (IPipelineRouter)Activator.CreateInstance(routerType); } instance.Map(router); } catch (Exception ex) { ex.Trace(); } } var pipelineTypes = ExposedTypes.GetTypes <IPipeline>().ToArray(); foreach (var pipelineType in pipelineTypes) { try { var instance = new PipelineRouter(pipelineType, webApp.UrlPrefix); instance.Map(router); } catch (Exception ex) { ex.Trace(); } } return(router); }
private void AddExposedCollections <TContract>(IObjectFactory factory, Func <TContract, T> converter) where TContract : class { var types = ExposedTypes.GetTypes <ICatalogCollection <TContract> >(); foreach (var type in types) { try { var collection = (ICatalogCollection <TContract>)factory.CreateObject(type); var items = collection.Items.Select(converter); AddCollection(collection.Name, items); } catch (Exception ex) { ex.Trace(); } } }
public static ModuleCollection Create(WebApp webApp) { var modules = new ModuleCollection(); var types = ExposedTypes.GetTypes <IModule>(); foreach (var type in types) { try { var module = (IModule)Activator.CreateInstance(type); modules.Add(module); } catch (Exception ex) { ex.Trace(); } } return(modules); }
private IEnumerable <PaperRendererInfo> EnumeratePaperRenderers(Type rendererType) { var attribute = rendererType.GetCustomAttribute <PaperRendererAttribute>(); if (attribute == null) { Trace.TraceError($"O renderizador {rendererType.FullName} não está mapeado com o atributo obrigatório {typeof(PaperRendererAttribute).FullName}."); yield break; } var paperTypes = ExposedTypes.GetTypes(attribute.PaperContractName); foreach (var paperType in paperTypes) { var renderers = EnumeratePaperRenderers(rendererType, paperType); foreach (var renderer in renderers) { yield return(renderer); } } }
private void AddExposedItems <TContract>(IObjectFactory factory, Func <TContract, T> converter) where TContract : class { var types = ExposedTypes.GetTypes <TContract>(); foreach (var type in types) { try { var contract = (TContract)factory.CreateObject(type); var collection = contract._GetAttribute <CatalogAttribute>(); var collectionName = collection?.CollectionName ?? type.Assembly.FullName.Split(',').First(); var item = converter.Invoke(contract); AddCollection(collectionName, item); } catch (Exception ex) { ex.Trace(); Console.WriteLine(ex.GetStackTrace()); } } }
// This method gets called by the runtime. Use this method to add services to the container. public virtual void ConfigureServices(IServiceCollection services) { //Func<ServiceDescriptor, string> GetText = (s) => { // if (s.ImplementationType != null) // return s.ImplementationType.FullName; // else if(s.ImplementationInstance != null) // return s.ImplementationInstance.GetType().FullName; // return string.Empty; //}; //foreach (var item in services) // Debug.WriteLine($"{item.ServiceType.ToString()} => {GetText(item)}"); // var vars = Environment.GetEnvironmentVariables(); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); BaseStartup.Types = services.RegisterConfigurations(Configuration); ResolveBuilders(services); if (_useSwagger) { AddSwagger(services); } services.AddControllers(); services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) ; //services.AddRazorPages(); //services.AddServerSideBlazor(); }
private static void RegenerateSchemas(ExposedTypes types) { // var dir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "Schemas")); if (!dir.Exists) { dir.Create(); } var configs = types.GetTypes(ConstantsCore.Configuration).ToArray(); foreach (var _type in configs) { if (_type.Value.Count == 1) { var name = _type.Value.First().Name; WriteSchema(dir, _type.Key, name); } } WriteSchema(dir, typeof(Initialization), "appsettings"); }
public static IApplicationBuilder UseInkeeperRestApi(this IApplicationBuilder app) { var services = from type in ExposedTypes.GetTypes() from attr in type.GetCustomAttributes(true).OfType <RestAttribute>() select new { type, attr }; foreach (var service in services) { try { var route = service.attr.Route; if (route == null) { var words = service.type.FullName.EnumerateWords(); route = string.Join("/", words); } if (route.EndsWith("/")) { route = route.Substring(0, route.Length - 1); } if (!route.StartsWith("/")) { route = "/" + route; } app.Map(route, map => map.UseMiddleware <RestMiddleware>(route, service.type)); } catch (Exception ex) { ex.Trace(); } } return(app); }
public void Fill() { try { var paperTypes = ExposedTypes.GetTypes <IPaper>(); foreach (var paperType in paperTypes) { try { var paperId = PaperId.Identify(paperType); Add(paperId, paperType); } catch (Exception ex) { ex.Trace($"Falha importando o esquema de Paper: {paperType.FullName}"); } } } catch (Exception ex) { ex.Trace("Não foi possível importar os esquemas de Papers da pasta do aplicativo."); } }
public void TestExposedTypes() { ExposedTypes types = new ExposedTypes(); var ctx = types.GetContexts(); Assert.AreEqual(ctx.Count() == 2, true); var types2 = types.GetTypes(); Assert.AreEqual(types2.Count() == 2, true); types.Add(new ExposedTypeConfigurations() { }) .Add(new ExposedTypeConfigurations() { new ExposedTypeConfiguration() { TypeName = typeof(Test1).AssemblyQualifiedName, Attributes = new List <ExposedAttributeTypeConfiguration>() { new ExposedAttributeTypeConfiguration() { Context = "Test33", } } } }); ctx = types.GetContexts(); Assert.AreEqual(ctx.Count() == 3, true); types2 = types.GetTypes(); Assert.AreEqual(types2.Count() == 3, true); }