Skip to content

TopicClient

Namespace: IntegrationTests.ApiClient

public class TopicClient

Inheritance ObjectTopicClient

Properties

BaseUrl

public string BaseUrl { get; set; }

Property Value

String

ReadResponseAsString

public bool ReadResponseAsString { get; set; }

Property Value

Boolean

Constructors

TopicClient(String, HttpClient)

public TopicClient(string baseUrl, HttpClient httpClient)

Parameters

baseUrl String

httpClient HttpClient

Methods

CreateTopicAsync(TopicSetting)

Creates a new MQTT topic configuration for sensor monitoring.

public Task<Object> CreateTopicAsync(TopicSetting topicSetting)

Parameters

topicSetting TopicSetting

The complete topic setting configuration to create.

Returns

Topic setting created successfully. Returns the new topic ID.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint allows administrators to add new sensor configurations to the monitoring system.

Each topic setting maps a physical sensor to its MQTT topic and location within the building.

Authorization Required: Bearer token with Admin role

Required Fields:

- sensorName: Unique identifier for the sensor (e.g., "TempSensor_03")

- sensorLocation: Physical location (e.g., "North", "South", "East", "West", "Center")

- mqttTopic: MQTT topic path for this sensor (e.g., "sensors/temperature/east")

Example Request:

json <br>{ <br>"sensorName": "TempSensor_03", <br>"sensorLocation": "East", <br>"mqttTopic": "sensors/temperature/east", <br>"isActive": true, <br>"description": "Temperature sensor in the eastern section" <br>} <br>

Example Response:

json <br>{ <br>"id": 3, <br>"message": "Topic created successfully" <br>} <br>

Validation Rules:

- Sensor names must be unique across the system

- MQTT topics should follow the pattern: sensors/temperature/{location}

- Location names should be descriptive and consistent

CreateTopicAsync(TopicSetting, CancellationToken)

Creates a new MQTT topic configuration for sensor monitoring.

public Task<Object> CreateTopicAsync(TopicSetting topicSetting, CancellationToken cancellationToken)

Parameters

topicSetting TopicSetting

The complete topic setting configuration to create.

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Topic setting created successfully. Returns the new topic ID.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint allows administrators to add new sensor configurations to the monitoring system.

Each topic setting maps a physical sensor to its MQTT topic and location within the building.

Authorization Required: Bearer token with Admin role

Required Fields:

- sensorName: Unique identifier for the sensor (e.g., "TempSensor_03")

- sensorLocation: Physical location (e.g., "North", "South", "East", "West", "Center")

- mqttTopic: MQTT topic path for this sensor (e.g., "sensors/temperature/east")

Example Request:

json <br>{ <br>"sensorName": "TempSensor_03", <br>"sensorLocation": "East", <br>"mqttTopic": "sensors/temperature/east", <br>"isActive": true, <br>"description": "Temperature sensor in the eastern section" <br>} <br>

Example Response:

json <br>{ <br>"id": 3, <br>"message": "Topic created successfully" <br>} <br>

Validation Rules:

- Sensor names must be unique across the system

- MQTT topics should follow the pattern: sensors/temperature/{location}

- Location names should be descriptive and consistent

DeleteTopicAsync(TopicSetting)

public Task<Object> DeleteTopicAsync(TopicSetting topicSetting)

Parameters

topicSetting TopicSetting

Returns

Task<Object>

Exceptions

ApiException

A server side error occurred.

DeleteTopicAsync(TopicSetting, CancellationToken)

public Task<Object> DeleteTopicAsync(TopicSetting topicSetting, CancellationToken cancellationToken)

Parameters

topicSetting TopicSetting

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<Object>

Exceptions

ApiException

A server side error occurred.

GetAllSensorTypesAsync()

public Task<ICollection<String>> GetAllSensorTypesAsync()

Returns

Task<ICollection<String>>

Exceptions

ApiException

A server side error occurred.

GetAllSensorTypesAsync(CancellationToken)

public Task<ICollection<String>> GetAllSensorTypesAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<ICollection<String>>

Exceptions

ApiException

A server side error occurred.

GetAllTopicsAsync()

Retrieves all configured MQTT topic settings from the system.

public Task<ICollection<TopicSetting>> GetAllTopicsAsync()

Returns

Successfully retrieved all topic settings.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint returns all MQTT topic configurations including:

- Sensor names and their physical locations (North, South, etc.)

- MQTT topic mappings for each sensor

- Configuration metadata for the monitoring system

Authorization Required: Bearer token with Admin role

This information is essential for:

- System administration and configuration management

- Troubleshooting sensor connectivity issues

- Understanding the current sensor topology

Example Response:

json <br>[ <br>{ <br>"id": 1, <br>"sensorName": "TempSensor_01", <br>"sensorLocation": "North", <br>"mqttTopic": "sensors/temperature/north", <br>"isActive": true <br>}, <br>{ <br>"id": 2, <br>"sensorName": "TempSensor_02", <br>"sensorLocation": "South", <br>"mqttTopic": "sensors/temperature/south", <br>"isActive": true <br>} <br>] <br>

GetAllTopicsAsync(CancellationToken)

Retrieves all configured MQTT topic settings from the system.

public Task<ICollection<TopicSetting>> GetAllTopicsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Successfully retrieved all topic settings.

Exceptions

ApiException

A server side error occurred.

Remarks:

This endpoint returns all MQTT topic configurations including:

- Sensor names and their physical locations (North, South, etc.)

- MQTT topic mappings for each sensor

- Configuration metadata for the monitoring system

Authorization Required: Bearer token with Admin role

This information is essential for:

- System administration and configuration management

- Troubleshooting sensor connectivity issues

- Understanding the current sensor topology

Example Response:

json <br>[ <br>{ <br>"id": 1, <br>"sensorName": "TempSensor_01", <br>"sensorLocation": "North", <br>"mqttTopic": "sensors/temperature/north", <br>"isActive": true <br>}, <br>{ <br>"id": 2, <br>"sensorName": "TempSensor_02", <br>"sensorLocation": "South", <br>"mqttTopic": "sensors/temperature/south", <br>"isActive": true <br>} <br>] <br>

ReadObjectResponseAsync<T>(HttpResponseMessage, IReadOnlyDictionary<String, IEnumerable<String>>, CancellationToken)

protected Task<ObjectResponseResult<T>> ReadObjectResponseAsync<T>(HttpResponseMessage response, IReadOnlyDictionary<String, IEnumerable<String>> headers, CancellationToken cancellationToken)

Type Parameters

T

Parameters

response HttpResponseMessage

headers IReadOnlyDictionary<String, IEnumerable<String>>

cancellationToken CancellationToken

Returns

Task<ObjectResponseResult<T>>

UpdateTopicAsync(TopicSetting)

public Task<Object> UpdateTopicAsync(TopicSetting topicSetting)

Parameters

topicSetting TopicSetting

Returns

Task<Object>

Exceptions

ApiException

A server side error occurred.

UpdateTopicAsync(TopicSetting, CancellationToken)

public Task<Object> UpdateTopicAsync(TopicSetting topicSetting, CancellationToken cancellationToken)

Parameters

topicSetting TopicSetting

cancellationToken CancellationToken

A cancellation token that can be used by other objects or threads to receive notice of cancellation.

Returns

Task<Object>

Exceptions

ApiException

A server side error occurred.