/// <summary> /// Creates a new topic. /// </summary> /// <param name="topicName">The name of the topic. Does not include the project id.</param> public async Task <Topic> NewTopicAsync(string topicName) { try { ProjectsResource.TopicsResource.CreateRequest request = Service.Projects.Topics.Create(new Topic(), GetTopicFullName(topicName)); return(await request.ExecuteAsync()); } catch (GoogleApiException e) { throw new DataSourceException(e.Message, e); } }
protected override void ProcessRecord() { foreach (string topicName in Topic) { string formattedTopicname = GetProjectPrefixForTopic(topicName, Project); Topic topic = new Topic() { Name = formattedTopicname }; ProjectsResource.TopicsResource.CreateRequest request = Service.Projects.Topics.Create(topic, formattedTopicname); try { Topic response = request.Execute(); WriteObject(response); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.Conflict) { WriteResourceExistsError( exceptionMessage: $"Cannot create topic '{topicName}' because it already exists.", errorId: "TopicAlreadyExists", targetObject: topicName); } } }