Class HttpConnector
This class implements the IHttpConnectable interface and uses the standard microsoft http client.
Inheritance
Namespace: TeleScope.Connectors.Http
Assembly: TeleScope.Connectors.Http.dll
Syntax
public class HttpConnector : object, IHttpConnectable, IConnectable, IDisposable
Constructors
| Improve this Doc View SourceHttpConnector()
The default empty constructor binds a logger for internal usage.
Declaration
public HttpConnector()
HttpConnector(HttpClient)
Saves the property and calls the empty default constructor.
Declaration
public HttpConnector(HttpClient client)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpClient | client | The http client to perform requests. |
HttpConnector(HttpClient, HttpEndpoint)
Saves the properties and calls the empty default constructor.
Declaration
public HttpConnector(HttpClient client, HttpEndpoint endpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpClient | client | The http client to perform requests. |
| HttpEndpoint | endpoint | The endpoint configuration executed by the client. |
Properties
| Improve this Doc View SourceIsConnected
Gets the state, if the connection is established or not.
Declaration
public bool IsConnected { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Methods
| Improve this Doc View SourceAddCancelToken(CancellationToken)
Adds the
Declaration
public IHttpConnectable AddCancelToken(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The token that is provided by the host system. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
AddHeader(String, String)
Adds an http header to the next request as simple pair of name and value.
Declaration
public IHttpConnectable AddHeader(string name, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The name of the header information. |
| System.String | value | The value of the header information. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
CallAsync()
Performs the http request asynchronously that is defined by the http endpoint and optional parameters.
Declaration
public Task<string> CallAsync()
Returns
| Type | Description |
|---|---|
| Task<System.String> | The executing task whereby the result is the raw string of the response body. |
CallAsync<T>(Func<String, T>)
Performs the http request asynchronously that is defined by the http endpoint and optional parameters.
Declaration
public Task<T> CallAsync<T>(Func<string, T> convert)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<System.String, T> | convert | The function converts the response body into the generic type T. |
Returns
| Type | Description |
|---|---|
| Task<T> | The executing task whereby the result of the task is of type T. |
Type Parameters
| Name | Description |
|---|---|
| T | The generic returned type T. |
Connect()
Tests the connection with the internal http client and endpoint.
Declaration
public IHttpConnectable Connect()
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
Connect(HttpClient, HttpEndpoint)
Tests the connection with the given http client and endpoint and stores both parameters internally.
Declaration
public IHttpConnectable Connect(HttpClient client, HttpEndpoint endpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpClient | client | The http client that will be used by the connector. |
| HttpEndpoint | endpoint | The endpoint configuration. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
Connect(HttpEndpoint)
Tests the connection to the given endpoint and stores the parameter internally. The http client must be ready-to-use before calling this method.
Declaration
public IHttpConnectable Connect(HttpEndpoint endpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpEndpoint | endpoint | The endpoint configuration. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
DisableCaching()
Disables the caching mechanism and frees the allocated memory.
Declaration
public IHttpConnectable DisableCaching()
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
Disconnect()
Disposes the http client and deletes the internal fields.
Declaration
public IConnectable Disconnect()
Returns
| Type | Description |
|---|---|
| IConnectable | The calling instance. |
Dispose()
Disposes all managed resources and supresses the
Declaration
public void Dispose()
Dispose(Boolean)
Implements the Dispose function.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposing | If True, the internal managed resouces will be disposed. |
Finalize()
The finalizer disposes the unmanged resources.
Declaration
protected void Finalize()
SetContent(String)
Sets the payload of the http request which must be represented as json compliant string.
Declaration
public IHttpConnectable SetContent(string jsonContent)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | jsonContent | The payload for the next http request. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
SetContent(String, Encoding, String)
Sets the payload of the next http request.
Declaration
public IHttpConnectable SetContent(string content, Encoding encoding, string mediatype)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | content | The payload as string. |
| Encoding | encoding | The encoding to format the string before serialization. |
| System.String | mediatype | The media type of the payload. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
SetRequest(String, HttpMethod)
Updates the request part of the http endpoint configuration.
Declaration
public IHttpConnectable SetRequest(string request, HttpMethod method)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | request | The request part of the url. |
| HttpMethod | method | Optional: The method type of the call. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
SetRequest(HttpEndpoint)
Updates the complete http endpoint configuration.
Declaration
public IHttpConnectable SetRequest(HttpEndpoint newEndpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpEndpoint | newEndpoint | The new endpoint configuration. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
WithCaching(UInt32, UInt32)
Adds a caching mechanism for all upcoming http requests.
Declaration
public IHttpConnectable WithCaching(uint refreshSeconds = null, uint expirationSeconds = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.UInt32 | refreshSeconds | The timeout in seconds where the cache will return (refresh) the cached data. |
| System.UInt32 | expirationSeconds | The timeout in seconds where the cache will expire the cached data. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
WithCaching(TimeSpan, TimeSpan)
Adds a caching mechanism for all upcoming http requests.
Declaration
public IHttpConnectable WithCaching(TimeSpan refreshExpiration, TimeSpan resetExpiration)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | refreshExpiration | The timeout where the cache will return (refresh) the cached data. |
| TimeSpan | resetExpiration | The timeout where the cache will expire the cached data. |
Returns
| Type | Description |
|---|---|
| IHttpConnectable | The calling instance. |
Events
| Improve this Doc View SourceCompleted
The event is invoked when a type specific method or action has finished successfully.
Declaration
public event ConnectorCompletedEventHandler Completed
Event Type
| Type | Description |
|---|---|
| ConnectorCompletedEventHandler |
Connected
The event is invoked when the Connect method has finished successfully.
Declaration
public event ConnectorEventHandler Connected
Event Type
| Type | Description |
|---|---|
| ConnectorEventHandler |
Disconnected
The event is invoked when the Disconnect method has finished successfully.
Declaration
public event ConnectorEventHandler Disconnected
Event Type
| Type | Description |
|---|---|
| ConnectorEventHandler |
Failed
The event is invoked when any method or action has finished with a failure.
Declaration
public event ConnectorFailedEventHandler Failed
Event Type
| Type | Description |
|---|---|
| ConnectorFailedEventHandler |