/// <summary> /// Initializes a new instance of the <see cref="ResponseEncoder"/> class. /// </summary> /// <param name="mapper">Used to find content id for the send objects.</param> /// <param name="encoder">Serializes the sent object.</param> public ResponseEncoder(ContentMapper mapper, IContentEncoder encoder) { if (mapper == null) throw new ArgumentNullException("mapper"); if (encoder == null) throw new ArgumentNullException("encoder"); _mapper = mapper; _encoder = encoder; }
/// <summary> /// If a given object can be encoded. /// </summary> /// <param name="Object">Object to encode.</param> /// <param name="Grade">How well the object can be encoded.</param> /// <param name="Encoder">Best encoder for the object.</param> /// <param name="AcceptedContentTypes">Optional array of accepted content types. If array is empty, all content types are accepted.</param> /// <returns>If the object can be encoded.</returns> public static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder, params string[] AcceptedContentTypes) { string Key; if (AcceptedContentTypes is null || AcceptedContentTypes.Length == 0) { Key = Object.GetType().FullName; }
public HttpClientRequest AddAcceptEncoding(IContentEncoder decoder) { if (Decoder != null) { throw new InvalidOperationException("You can set decoder only once"); } Decoder = decoder; return(this); }
public HttpClientRequest AddContentEncoder(IContentEncoder encoder) { if (Encoder != null) { throw new InvalidOperationException("You can set encoder only once"); } Encoder = encoder; return(this); }
/// <summary> /// Default constructor /// </summary> /// <param name="contentEncoders"></param> public ContentEncodingProvider(IEnumerable <IContentEncoder> contentEncoders) { _contentEncoders = contentEncoders.Reverse().ToArray(); if (_contentEncoders.Length == 1) { _onlyContentEncoder = _contentEncoders[0]; } }
/// <summary> /// Initializes a new instance of the <see cref="ResponseEncoder"/> class. /// </summary> /// <param name="mapper">Used to find content id for the send objects.</param> /// <param name="encoder">Serializes the sent object.</param> public ResponseEncoder(ContentMapper mapper, IContentEncoder encoder) { if (mapper == null) { throw new ArgumentNullException("mapper"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } _mapper = mapper; _encoder = encoder; }
/// <summary> /// If a given object can be encoded. /// </summary> /// <param name="Object">Object to encode.</param> /// <param name="Grade">How well the object can be encoded.</param> /// <param name="Encoder">Best encoder for the object.</param> /// <returns>If the object can be encoded.</returns> public static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder) { Grade = Grade.NotAtAll; Encoder = null; foreach (IContentEncoder Encoder2 in Encoders) { if (Encoder2.Encodes(Object, out Grade Grade2) && Grade2 > Grade) { Grade = Grade2; Encoder = Encoder2; } } return(Encoder != null); }
/// <summary> /// If a given object can be encoded. /// </summary> /// <param name="Object">Object to encode.</param> /// <param name="Grade">How well the object can be encoded.</param> /// <param name="Encoder">Best encoder for the object.</param> /// <param name="AcceptedContentTypes">Optional array of accepted content types. If array is empty, all content types are accepted.</param> /// <returns>If the object can be encoded.</returns> public static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder, params string[] AcceptedContentTypes) { Grade = Grade.NotAtAll; Encoder = null; foreach (IContentEncoder Encoder2 in Encoders) { if (Encoder2.Encodes(Object, out Grade Grade2, AcceptedContentTypes) && Grade2 > Grade) { Grade = Grade2; Encoder = Encoder2; } } return(Encoder != null); }
public RestClient(Uri baseUri, TimeSpan timeout, Func <HttpMessageHandler> handlerFactory, IContentEncoder contentEncoder, IResponseDeserializer responseDeserializer) { ContentEncoder = contentEncoder; ResponseDeserializer = responseDeserializer; Timeout = timeout; BaseUri = baseUri; _client = new HttpClient(handlerFactory()) { Timeout = Timeout, BaseAddress = BaseUri }; _client.DefaultRequestHeaders.Accept.Clear(); }
public static IServiceCollection Create(this IServiceCollection ignore, IContentRepository contentRepo, IArchiveProvider archiveProvider, IContactProvider contactProvider, ISearchProvider searchProvider, IPageGenerator pageGen, IHomePageGenerator homePageGen, INavigationProvider navProvider, IRedirectProvider redirectProvider, ISyndicationProvider syndicationProvider, ISettings settings, IEnumerable <Category> categories, IContentEncoder contentEncoder, IContentItemPageGenerator contentItemPageGen) { IServiceCollection container = new ServiceCollection(); container.AddSingleton <IPageGenerator>(pageGen); container.AddSingleton <IHomePageGenerator>(homePageGen); container.AddSingleton <INavigationProvider>(navProvider); container.AddSingleton <IArchiveProvider>(archiveProvider); container.AddSingleton <IContactProvider>(contactProvider); container.AddSingleton <ISearchProvider>(searchProvider); container.AddSingleton <ISyndicationProvider>(syndicationProvider); container.AddSingleton <IEnumerable <Category> >(categories); container.AddSingleton <IRedirectProvider>(redirectProvider); container.AddSingleton <IContentEncoder>(contentEncoder); container.AddSingleton <IContentItemPageGenerator>(contentItemPageGen); container.AddSingleton <IContentRepository>(contentRepo); settings.SourceConnection = contentRepo.GetSourceConnection(); container.AddSingleton <ISettings>(settings); return(container); }
public HttpClientBuilder WithCustomDecoder(IContentEncoder decoder) { _decoders.Add(decoder); return(this); }