Exemplo n.º 1
0
        protected MobileCore(IPlatformInjector injector, Options options)
        {
            Logger = options.Logger ?? injector?.CreateLogger() ?? new NullLogger();

            if (injector != null && options.ConfigFileName != null)
            {
                try
                {
                    using (var stream = injector.GetBundledFileStream(options.ConfigFileName))
                    {
                        servicesConfig = MobileCoreJsonParser.Parse(stream);
                    }
                }
                catch (System.Exception e)
                {
                    throw new InitializationException($"{options.ConfigFileName} could not be loaded", e);
                }
            }
            else
            {
                if (options.ConfigJson != null)
                {
                    try
                    {
                        MobileCoreJsonParser.Parse(options.ConfigJson);
                    }
                    catch (System.Exception e)
                    {
                        throw new InitializationException("invalid JSON configuration file", e);
                    }
                }
                else
                {
                    throw new InitializationException("Must provide either filename or JSON configuration in Init() options");
                }
            }
            if (options.HttpServiceModule == null)
            {
                HttpClientHandler httpClientHandler = new HttpClientHandler();
                httpClientHandler.AllowAutoRedirect = options.HttpAllowAutoRedirect;

                HttpClient httpClient = new HttpClient(httpClientHandler);
                httpClient.Timeout = TimeSpan.FromSeconds(DEFAULT_TIMEOUT);
                var httpServiceModule = new SystemNetHttpServiceModule(httpClient);
                var configuration     = GetFirstServiceConfigurationByType(httpServiceModule.Type);
                if (configuration == null)
                {
                    configuration = ServiceConfiguration.Builder.Build();
                }
                httpServiceModule.Configure(this, configuration);
                HttpLayer = httpServiceModule;
            }
            else
            {
                HttpLayer = options.HttpServiceModule;
            }
        }
        private MobileCore(IPlatformInjector injector, Options options)
        {
            Contract.Requires(options != null);
            Logger = options.Logger ?? injector?.CreateLogger() ?? new NullLogger();

            if (injector != null && options.ConfigFileName != null)
            {
                var filename = $"{injector.DefaultResources}.{options.ConfigFileName}";
                try
                {
                    using (var stream = injector.ExecutingAssembly.GetManifestResourceStream(filename))
                    {
                        servicesConfig = MobileCoreJsonParser.Parse(stream);
                    }
                }
                catch (System.Exception e)
                {
                    throw new InitializationException($"{filename} could not be loaded", e);
                }
            }
            else
            {
                if (options.ConfigJson != null)
                {
                    try
                    {
                        MobileCoreJsonParser.Parse(options.ConfigJson);
                    }
                    catch (System.Exception e)
                    {
                        throw new InitializationException("invalid JSON configuration file", e);
                    }
                }
                else
                {
                    throw new InitializationException("Must provide either filename or JSON configuration in Init() options");
                }
            }

            if (options.HttpServiceModule == null)
            {
                HttpClient httpClient = new HttpClient();
                httpClient.Timeout = TimeSpan.FromSeconds(DEFAULT_TIMEOUT);
                var httpServiceModule = new SystemNetHttpServiceModule(httpClient);
                var configuration     = GetServiceConfiguration(httpServiceModule.Type);
                if (configuration == null)
                {
                    configuration = ServiceConfiguration.Builder.Build();
                }
                httpServiceModule.Configure(this, configuration);
                HttpLayer = httpServiceModule;
            }
            else
            {
                HttpLayer = options.HttpServiceModule;
            }
        }
        public void SetUp()
        {
            var assembly = Assembly.GetExecutingAssembly();

            using (var configStream = assembly.GetManifestResourceStream("AeroGear.Mobile.Auth.Tests.Resources.mobile-services.json"))
            {
                var serviceConfig = MobileCoreJsonParser.Parse(configStream);
                var authConfig    = serviceConfig["keycloak"];
                keycloakConfig = new KeycloakConfig(authConfig);
            }
        }
        public void TestMobileCoreParsing()
        {
            var assembly = Assembly.GetExecutingAssembly();

            using (var configStream = assembly.GetManifestResourceStream("AeroGear.Mobile.Core.Tests.Resources.mobile-services.json"))
                using (var reader = new StreamReader(configStream))
                {
                    var configs = MobileCoreJsonParser.Parse(configStream);

                    Assert.NotNull(configs);

                    var keyCloakServiceConfiguration = configs["keycloak"];
                    Assert.AreEqual("https://keycloak-myproject.192.168.64.74.nip.io/auth", keyCloakServiceConfiguration["auth-server-url"]);
                }
        }