in code/PublishToEmbeddedSocial/EmbeddedSocial/EmbeddedSocial.cs [277:330]
private async Task DeleteTopic(string topicName)
{
// get the handle for the topic name
HttpOperationResponse<GetTopicByNameResponse> getTopicByNameOperationResponse = await this.client.Topics.GetTopicByNameWithHttpMessagesAsync(topicName: topicName, publisherType: PublisherType.App, authorization: this.authorization);
// check response
if (getTopicByNameOperationResponse == null || getTopicByNameOperationResponse.Response == null)
{
throw new Exception("got null response");
}
else if (!getTopicByNameOperationResponse.Response.IsSuccessStatusCode)
{
throw new Exception("request failed with HTTP code: " + getTopicByNameOperationResponse.Response.StatusCode + ", and reason: " + getTopicByNameOperationResponse.Response.ReasonPhrase);
}
else if (getTopicByNameOperationResponse.Body == null)
{
throw new Exception("got null response body");
}
else if (string.IsNullOrWhiteSpace(getTopicByNameOperationResponse.Body.TopicHandle))
{
throw new Exception("topicHandle is null or whitespace");
}
// delete the topic
string topicHandle = getTopicByNameOperationResponse.Body.TopicHandle;
HttpOperationResponse deleteTopicOperationResponse = await this.client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle: topicHandle, authorization: this.authorization);
// check response
if (deleteTopicOperationResponse == null || deleteTopicOperationResponse.Response == null)
{
throw new Exception("got null response");
}
else if (!deleteTopicOperationResponse.Response.IsSuccessStatusCode)
{
throw new Exception("request failed with HTTP code: " + deleteTopicOperationResponse.Response.StatusCode + ", and reason: " + deleteTopicOperationResponse.Response.ReasonPhrase);
}
// delete the topic name
DeleteTopicNameRequest deleteTopicNameRequest = new DeleteTopicNameRequest()
{
PublisherType = PublisherType.App
};
HttpOperationResponse deleteTopicNameOperationResponse = await this.client.Topics.DeleteTopicNameWithHttpMessagesAsync(topicName: topicName, request: deleteTopicNameRequest, authorization: this.authorization);
// check response
if (deleteTopicNameOperationResponse == null || deleteTopicNameOperationResponse.Response == null)
{
throw new Exception("got null response");
}
else if (!deleteTopicNameOperationResponse.Response.IsSuccessStatusCode)
{
throw new Exception("request failed with HTTP code: " + deleteTopicNameOperationResponse.Response.StatusCode + ", and reason: " + deleteTopicNameOperationResponse.Response.ReasonPhrase);
}
}