/// <summary> /// Client constructor Auth credentials / ApiKey can be passed through config /// </summary> /// <param name="config">Config</param> /// <param name="Url">String</param> /// /// <param name="policy">String</param> public Client(IArtesianServiceConfig config, string Url, ArtesianPolicyConfig policy) { _url = config.BaseAddress.ToString().AppendPathSegment(Url); _apiKey = config.ApiKey; _config = config; var cfg = new JsonSerializerSettings(); cfg = cfg.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); cfg = cfg.ConfigureForDictionary(); cfg = cfg.ConfigureForNodaTimeRanges(); cfg.Formatting = Formatting.Indented; cfg.ContractResolver = new DefaultContractResolver(); cfg.Converters.Add(new StringEnumConverter()); cfg.TypeNameHandling = TypeNameHandling.None; cfg.ObjectCreationHandling = ObjectCreationHandling.Replace; var jsonFormatter = new JsonMediaTypeFormatter { SerializerSettings = cfg }; _jsonFormatter = jsonFormatter; _jsonFormatter.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/problem+json")); _msgPackFormatter = new MessagePackMediaTypeFormatter(CustomCompositeResolver.Instance); _lz4msgPackFormatter = new LZ4MessagePackMediaTypeFormatter(CustomCompositeResolver.Instance); //Order of formatters important for correct weight in accept header var formatters = new MediaTypeFormatterCollection(); formatters.Clear(); formatters.Add(_lz4msgPackFormatter); formatters.Add(_msgPackFormatter); formatters.Add(_jsonFormatter); _formatters = formatters; _resilienceStrategy = policy.GetResillianceStrategy(); if (config.ApiKey == null) { var domain = new Uri(config.Domain); var tenantId = domain.Segments .Select(s => s.Trim('/')) .Where(w => !string.IsNullOrWhiteSpace(w)) .FirstOrDefault(); _confidentialClientApplication = ConfidentialClientApplicationBuilder .Create(config.ClientId) .WithTenantId(tenantId) .WithClientSecret(config.ClientSecret) .Build(); } _client = new FlurlClient(_url); _client.WithTimeout(TimeSpan.FromMinutes(ArtesianConstants.ServiceRequestTimeOutMinutes)); }
public static JsonSerializerSettings ConfigureForArkDefault(this JsonSerializerSettings settings) { settings.NullValueHandling = NullValueHandling.Include; settings.TypeNameHandling = TypeNameHandling.None; settings.ObjectCreationHandling = ObjectCreationHandling.Replace; settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb); settings.ConfigureForNodaTimeRanges(); settings.Converters.Add(new StringEnumConverter()); return(settings); }