Пример #1
0
        private void Awake()
        {
            InitializeRootFolder();

            AddDisposable(RootAccess.Create(m_ApplicationConfig));
            ApplicationModeAccess.Instance.RequestChangeApplicationMode(ApplicationMode.MainMenu);
        }
Пример #2
0
 internal void SetDependencies
 (
     RESTableConfigurator configurator,
     TypeCache typeCache,
     RootAccess rootAccess
 )
 {
     Configurator = configurator;
     TypeCache    = typeCache;
     RootAccess   = rootAccess;
 }
Пример #3
0
 public void ConfigureRESTable(string rootUri = "/restable")
 {
     ValidateRootUri(ref rootUri);
     Configuration.Update(rootUri: rootUri);
     ResourceCollection.SetDependencies(this, TypeCache, RootAccess);
     ResourceFactory.SetConfiguration(this);
     ResourceFactory.MakeResources();
     IsConfigured = true;
     RootAccess.Load();
     ResourceFactory.BindControllers();
     ResourceFactory.FinalCheck();
     ProtocolProviderManager.OnInit();
 }
Пример #4
0
 public RootClient(RootAccess rootAccess) : base
     (
         origin: OriginType.Internal,
         host: "localhost",
         clientIp: new IPAddress(new byte[] { 127, 0, 0, 1 }),
         proxyIp: null,
         userAgent: null,
         https: false,
         cookies: new Cookies()
     )
 {
     AccessRights = rootAccess;
 }
Пример #5
0
 public RESTableConfigurator
 (
     TypeCache typeCache,
     ResourceCollection resourceCollection,
     ResourceFactory resourceFactory,
     ProtocolProviderManager protocolProviderManager,
     RESTableConfiguration configuration,
     IJsonProvider jsonProvider,
     RootAccess rootAccess
 )
 {
     TypeCache               = typeCache;
     ResourceCollection      = resourceCollection;
     ResourceFactory         = resourceFactory;
     ProtocolProviderManager = protocolProviderManager;
     Configuration           = configuration;
     RootAccess              = rootAccess;
     ApplicationServicesAccessor.JsonProvider       = jsonProvider;
     ApplicationServicesAccessor.ResourceCollection = resourceCollection;
     ApplicationServicesAccessor.TypeCache          = typeCache;
 }
Пример #6
0
 public ResourceFactory
 (
     IEnumerable <IEntityResourceProvider> resourceProviders,
     TerminalResourceProvider terminalResourceProvider,
     BinaryResourceProvider binaryResourceProvider,
     VirtualResourceProvider virtualResourceProvider,
     TypeCache typeCache,
     ResourceValidator resourceValidator,
     ResourceCollection resourceCollection,
     RootAccess rootAccess
 )
 {
     TerminalProvider          = terminalResourceProvider;
     BinaryProvider            = binaryResourceProvider;
     VrProvider                = virtualResourceProvider;
     ExternalResourceProviders = resourceProviders.ToList();
     TypeCache               = typeCache;
     ResourceValidator       = resourceValidator;
     ResourceCollection      = resourceCollection;
     RootAccess              = rootAccess;
     EntityResourceProviders = new Dictionary <string, IEntityResourceProviderInternal>();
 }
Пример #7
0
        public static Metadata GetMetadata(MetadataLevel level, AccessRights rights, RootAccess rootAccess, ResourceCollection resourceCollection, TypeCache typeCache)
        {
            var domain          = rights?.Keys ?? resourceCollection.AllResources;
            var entityResources = domain
                                  .OfType <IEntityResource>()
                                  .Where(r => r.IsGlobal)
                                  .OrderBy(r => r.Name)
                                  .ToList();
            var terminalResources = domain
                                    .OfType <ITerminalResource>()
                                    .ToList();

            if (level == MetadataLevel.OnlyResources)
            {
                return new Metadata
                       {
                           CurrentAccessScope = new Dictionary <IResource, Method[]>(rights ?? rootAccess),
                           EntityResources    = entityResources.ToArray(),
                           TerminalResources  = terminalResources.ToArray()
                       }
            }
            ;

            var checkedTypes = new HashSet <Type>();

            void parseType(Type type)
            {
                switch (type)
                {
                case var _ when type.IsEnum:
                    checkedTypes.Add(type);
                    break;

                case var _ when type.IsNullable(out var baseType):
                    parseType(baseType);

                    break;

                case var _ when type.ImplementsGenericInterface(typeof(IEnumerable <>), out var param) && param.Any():
                    if (param[0].ImplementsGenericInterface(typeof(IEnumerable <>)))
                    {
                        break;
                    }
                    parseType(param[0]);

                    break;

                case var _ when type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>):
                case var _ when IsPrimitive(type):
                case var _ when type == typeof(object):
                    break;

                case var _ when checkedTypes.Add(type):
                {
                    var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance)
                                 .Where(p => !p.RESTableIgnored())
                                 .Select(p => p.FieldType);
                    foreach (var field in fields)
                    {
                        parseType(field);
                    }
                    var properties = typeCache.GetDeclaredProperties(type).Values
                                     .Where(p => !p.Hidden)
                                     .Select(p => p.Type);
                    foreach (var property in properties)
                    {
                        parseType(property);
                    }
                    break;
                }
                }
            }

            var entityTypes   = entityResources.Select(r => r.Type).ToHashSet();
            var terminalTypes = terminalResources.Select(r => r.Type).ToHashSet();

            foreach (var type in entityTypes)
            {
                parseType(type);
            }
            checkedTypes.ExceptWith(entityTypes);
            foreach (var type in terminalTypes)
            {
                parseType(type);
            }
            checkedTypes.ExceptWith(terminalTypes);

            return(new Metadata
            {
                CurrentAccessScope = new Dictionary <IResource, Method[]>(rights ?? rootAccess),
                EntityResources = entityResources.ToArray(),
                TerminalResources = terminalResources.ToArray(),
                EntityResourceTypes = new ReadOnlyDictionary <Type, Member[]>(entityTypes.ToDictionary(t => t, type =>
                                                                                                       typeCache.GetDeclaredProperties(type).Values.Cast <Member>().ToArray())),
                PeripheralTypes = new ReadOnlyDictionary <Type, Member[]>(checkedTypes.ToDictionary(t => t, type =>
                {
                    var props = typeCache.GetDeclaredProperties(type).Values;
                    var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance)
                                 .Where(p => !p.RESTableIgnored())
                                 .Select(f => new Field(f));
                    return props.Union <Member>(fields).ToArray();
                }))
            });
        }