private static void ValidateEntityResourceProviders(ICollection <IEntityResourceProvider> _entityResourceProviders) { if (_entityResourceProviders == null) { return; } var entityResourceProviders = _entityResourceProviders .Select(p => p as IEntityResourceProviderInternal ?? throw new InvalidEntityResourceProviderException(p.GetType(), "Must be a subclass of 'RESTar.Resources.EntityResourceProvider'")) .ToArray(); entityResourceProviders.ForEach(p => { if (p == null) { throw new ArgumentNullException(nameof(entityResourceProviders), "Found null value in entity resource providers collection"); } p.Validate(); }); if (entityResourceProviders.ContainsDuplicates(p => p.GetType().RESTarTypeName(), out var typeDupe)) { throw new InvalidEntityResourceProviderException(typeDupe.GetType(), $"Two or more external ResourceProviders with the same type '{typeDupe.GetType().RESTarTypeName()}' was found. Include " + "only one in the call to RESTarConfig.Init()"); } if (entityResourceProviders.Select(p => p.Id.ToLower()).ContainsDuplicates(out var idDupe)) { throw new InvalidEntityResourceProviderException(idDupe.GetType(), "Two or more external ResourceProviders had simliar type names, which could lead to confusion. Only one provider " + $"should be associated with '{idDupe}'"); } foreach (var provider in entityResourceProviders.Where(provider => provider is IProceduralEntityResourceProvider)) { var methods = provider.GetType().GetMethods(DeclaredOnly | Instance | NonPublic); if (methods.All(method => method.Name != "SelectProceduralResources" && method.Name != "InsertProceduralResource" && method.Name != "SetProceduralResourceMethods" && method.Name != "SetProceduralResourceDescription" && method.Name != "DeleteProceduralResource")) { throw new InvalidEntityResourceProviderException(provider.GetType(), $"Resource provider '{provider.GetType()}' was declared to support procedural resources, but did not override methods " + "'SelectProceduralResources()', 'InsertProceduralResource()', 'SetProceduralResourceMethods', 'SetProceduralResourceDescription' " + "and 'DeleteProceduralResource' from 'EntityResourceProvider'." ); } } foreach (var provider in entityResourceProviders) { EntityResourceProviders.Add(provider.Id, provider); } }
static ResourceFactory() { StarcounterDeclaredProvider = new StarcounterDeclaredResourceProvider(); DynamitProvider = new DynamitResourceProvider(StarcounterDeclaredProvider.DatabaseIndexer); VrProvider = new VirtualResourceProvider(); EntityResourceProviders.Add(DynamitProvider.Id, DynamitProvider); EntityResourceProviders.Add(StarcounterDeclaredProvider.Id, StarcounterDeclaredProvider); EntityResourceProviders.Add(VrProvider.Id, VrProvider); TerminalProvider = new TerminalResourceProvider(); BinaryProvider = new BinaryResourceProvider(); EventProvider = new EventResourceProvider(); }