Esempio n. 1
0
        internal RestClient(RestClientSettings settings)
        {
            if (string.IsNullOrWhiteSpace(settings.Token.AccessToken))
            {
                throw new ArgumentException("Token does not exist.");
            }

            _httpClient = new HttpClient();
            _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {settings.Token.AccessToken}");
        }
Esempio n. 2
0
        private static RestClientSettings GetRestClientSettings(IServiceCollection services)
        {
            using (var serviceProvider = services.BuildServiceProvider())
            {
                var configuration        = serviceProvider.GetService <IConfiguration>();
                var configurationSection = configuration.GetSection(ConfigurationSectionName);

                services.Configure <RestClientSettings>(configurationSection);

                var restClientSettings = new RestClientSettings();
                configurationSection.Bind(restClientSettings);

                return(restClientSettings);
            }
        }
Esempio n. 3
0
        public static void InitImpl()
        {
            if (BooksApp != null)
            {
                return;
            }
            LoadAppConfig();
            LogFilePath = AppConfiguration["LogFilePath"];
            if (File.Exists(LogFilePath))
            {
                File.Delete(LogFilePath);
            }

            BooksApp         = new BooksEntityApp();
            BooksApp.LogPath = LogFilePath;
            //Add mock email/sms service
            // NotificationListener = new NotificationListener(BooksApp, blockAll: true);
            // Setup mock messaging service
            LoginMessagingService = new MockLoginMessagingService();
            var loginConfig = BooksApp.GetConfig <Modules.Login.LoginModuleSettings>();

            loginConfig.MessagingService = LoginMessagingService;
            BooksApp.Init();
            //connect to database
            var driver     = new MsSqlDbDriver();
            var dbOptions  = MsSqlDbDriver.DefaultMsSqlDbOptions;
            var connString = AppConfiguration["MsSqlConnectionString"];
            var dbSettings = new DbSettings(driver, dbOptions, connString, upgradeMode: DbUpgradeMode.Always); // schemas);

            BooksApp.ConnectTo(dbSettings);

            // Logging app
            LoggingApp = new DbLoggingEntityApp();
            LoggingApp.ListenTo(BooksApp);
            var logConnString = AppConfiguration["MsSqlLogConnectionString"];
            var logDbSettings = new DbSettings(driver, dbOptions, logConnString, upgradeMode: DbUpgradeMode.Always); // schemas);

            LoggingApp.ConnectTo(logDbSettings);

            // create sample data
            DataUtility.DeleteAllData(BooksApp,
                                      exceptEntities: new Type[] { typeof(IDbInfo), typeof(IDbModuleInfo) });
            SampleDataGenerator.CreateUnitTestData(BooksApp);

            // Start service
            var serviceUrl = AppConfiguration["ServiceUrl"];

            StartService(serviceUrl);
            // create client
            var useXml = false;

            if (useXml)
            {
                var clientSettings = new RestClientSettings(serviceUrl, serializer: new XmlContentSerializer(), badRequestContentType: typeof(string)); // typeof(List<ClientFault>));
                Client = new RestClient(clientSettings);
            }
            else
            {
                Client = new RestClient(serviceUrl, badRequestContentType: typeof(List <ClientFault>)); //json, very simple setup
            }
            RestClient.SharedHttpClientHandler.AllowAutoRedirect = false;                               //we need it for Redirect test
            // Setup handler converting BadRequestException into ClientFaultException, with list of faults already converted
            Client.Settings.Events.ReceivedError += (s, e) => {
                if (e.CallData.Exception is BadRequestException bre)
                {
                    e.CallData.Exception = new ClientFaultException((IList <ClientFault>)bre.Details);
                }
            };
        }
Esempio n. 4
0
 public RestClientFactory(IOptions <RestClientSettings> options) : base()
 {
     settings = options.Value;
 }