private async Task CreateTopic()

in code/PublishToEmbeddedSocial/EmbeddedSocial/EmbeddedSocial.cs [107:171]


        private async Task CreateTopic(string topicName, string topicTitle, string topicText, string topicCategory)
        {
            // format the input into an Embedded Social topic request
            PostTopicRequest topicRequest = new PostTopicRequest()
            {
                PublisherType = PublisherType.App,
                Text = topicText,
                Title = topicTitle,
                BlobType = BlobType.Unknown,
                BlobHandle = string.Empty,
                Categories = topicCategory,
                Language = TopicLanguage,
                DeepLink = string.Empty,
                FriendlyName = topicName,
                Group = string.Empty
            };

            // publish to Embedded Social
            HttpOperationResponse<PostTopicResponse> postTopicOperationResponse = await this.client.Topics.PostTopicWithHttpMessagesAsync(request: topicRequest, authorization: this.authorization);

            // check response
            if (postTopicOperationResponse == null || postTopicOperationResponse.Response == null)
            {
                throw new Exception("got null response");
            }
            else if (!postTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                throw new Exception("request failed with HTTP code: " + postTopicOperationResponse.Response.StatusCode + ", and reason: " + postTopicOperationResponse.Response.ReasonPhrase);
            }
            else if (postTopicOperationResponse.Body == null)
            {
                throw new Exception("got null response body");
            }
            else if (string.IsNullOrWhiteSpace(postTopicOperationResponse.Body.TopicHandle))
            {
                throw new Exception("topicHandle is null or whitespace");
            }

            // publish the name for the topic
            string topicHandle = postTopicOperationResponse.Body.TopicHandle;
            PostTopicNameRequest topicNameRequest = new PostTopicNameRequest()
            {
                PublisherType = PublisherType.App,
                TopicName = topicName,
                TopicHandle = topicHandle
            };

            HttpOperationResponse postTopicNameOperationResponse = await this.client.Topics.PostTopicNameWithHttpMessagesAsync(request: topicNameRequest, authorization: this.authorization);

            // check response
            if (postTopicNameOperationResponse == null || postTopicNameOperationResponse.Response == null)
            {
                // attempt to clean up the topic first
                HttpOperationResponse deleteTopicOperationResponse = await this.client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle: topicHandle, authorization: this.authorization);

                throw new Exception("got null response");
            }
            else if (!postTopicNameOperationResponse.Response.IsSuccessStatusCode)
            {
                // attempt to clean up the topic first
                HttpOperationResponse deleteTopicOperationResponse = await this.client.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle: topicHandle, authorization: this.authorization);

                throw new Exception("request failed with HTTP code: " + postTopicNameOperationResponse.Response.StatusCode + ", and reason: " + postTopicNameOperationResponse.Response.ReasonPhrase);
            }
        }