コード例 #1
0
        public override void ExecuteCmdlet()
        {
            // Create a new Event Grid Topic
            Dictionary <string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(this.Tag, true);
            Dictionary <string, UserIdentityProperties> userAssignedIdentities = null;

            if (IdentityId != null && IdentityId.Length > 0)
            {
                userAssignedIdentities = new Dictionary <string, UserIdentityProperties>();
                foreach (string identityId in IdentityId)
                {
                    userAssignedIdentities.Add(identityId, new UserIdentityProperties());
                }
            }

            if (this.ShouldProcess(this.Name, $"Create a new EventGrid topic {this.Name} in Resource Group {this.ResourceGroupName}"))
            {
                SystemTopic topic = this.Client.CreateSystemTopic(
                    this.ResourceGroupName,
                    this.Name,
                    this.Location,
                    this.Source,
                    this.TopicType,
                    this.IdentityType,
                    userAssignedIdentities,
                    tagDictionary);

                PSSystemTopic psTopic = new PSSystemTopic(topic);
                this.WriteObject(psTopic);
            }
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = string.Empty;
            string topicName         = string.Empty;
            IEnumerable <SystemTopic> topicsList;
            string nextLink    = null;
            string newNextLink = null;
            int?   providedTop = null;

            if (MyInvocation.BoundParameters.ContainsKey(nameof(this.Top)))
            {
                providedTop = this.Top;
            }

            else if (!string.IsNullOrEmpty(this.Name))
            {
                // If Name is provided, ResourceGroup should be non-empty as well
                resourceGroupName = this.ResourceGroupName;
                topicName         = this.Name;
            }
            else if (!string.IsNullOrEmpty(this.ResourceGroupName))
            {
                resourceGroupName = this.ResourceGroupName;
            }
            else if (!string.IsNullOrEmpty(this.NextLink))
            {
                // Other parameters should be null or ignored if nextLink is specified.
                nextLink = this.NextLink;
            }

            if (!string.IsNullOrEmpty(nextLink))
            {
                // Get Next page of topics. Get the proper next API to be called based on the nextLink.
                Uri    uri  = new Uri(nextLink);
                string path = uri.AbsolutePath;

                if (path.IndexOf("/resourceGroups/", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    (topicsList, newNextLink) = this.Client.ListSystemTopicByResourceGroupNext(nextLink);
                }
                else
                {
                    (topicsList, newNextLink) = this.Client.ListSystemTopicBySubscriptionNext(nextLink);
                }

                PSSystemTopicListPagedInstance pSTopicListPagedInstance = new PSSystemTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName) && !string.IsNullOrEmpty(topicName))
            {
                // Get details of the Event Grid topic
                SystemTopic   topic   = this.Client.GetSystemTopic(resourceGroupName, topicName);
                PSSystemTopic psTopic = new PSSystemTopic(topic);
                this.WriteObject(psTopic);
            }
            else if (!string.IsNullOrEmpty(resourceGroupName) && string.IsNullOrEmpty(topicName))
            {
                // List all Event Grid topics in the given resource group
                (topicsList, newNextLink) = this.Client.ListSystemTopicByResourceGroup(resourceGroupName, this.ODataQuery, providedTop);
                PSSystemTopicListPagedInstance pSTopicListPagedInstance = new PSSystemTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
            else if (string.IsNullOrEmpty(resourceGroupName) && string.IsNullOrEmpty(topicName))
            {
                // List all Event Grid topics in the given subscription
                (topicsList, newNextLink) = this.Client.ListSystemTopicBySubscription(this.ODataQuery, providedTop);
                PSSystemTopicListPagedInstance pSTopicListPagedInstance = new PSSystemTopicListPagedInstance(topicsList, newNextLink);
                this.WriteObject(pSTopicListPagedInstance, true);
            }
        }