Exemplo n.º 1
0
        public EventSubscription CreateEventSubscription(
            string scope,
            string eventSubscriptionName,
            string endpoint,
            string endpointType,
            string subjectBeginsWith,
            string subjectEndsWith,
            bool isSubjectCaseSensitive,
            string[] includedEventTypes,
            string[] labels)
        {
            EventSubscription            eventSubscription    = new EventSubscription();
            EventSubscriptionDestination destination          = null;
            const string WebHookEventSubscriptionDestination  = "webhook";
            const string EventHubEventSubscriptionDestination = "eventhub";

            if (string.IsNullOrEmpty(endpointType) ||
                string.Equals(endpointType, WebHookEventSubscriptionDestination, StringComparison.OrdinalIgnoreCase))
            {
                destination = new WebHookEventSubscriptionDestination()
                {
                    EndpointUrl = endpoint
                };
            }
            else if (string.Equals(endpointType, EventHubEventSubscriptionDestination, StringComparison.OrdinalIgnoreCase))
            {
                destination = new EventHubEventSubscriptionDestination()
                {
                    ResourceId = endpoint
                };
            }
            else
            {
                throw new ArgumentNullException(nameof(endpointType), "EndpointType should be WebHook or EventHub");
            }

            if (includedEventTypes == null)
            {
                includedEventTypes    = new string[1];
                includedEventTypes[0] = "All";
            }

            var filter = new EventSubscriptionFilter()
            {
                SubjectBeginsWith      = subjectBeginsWith,
                SubjectEndsWith        = subjectEndsWith,
                IsSubjectCaseSensitive = isSubjectCaseSensitive,
                IncludedEventTypes     = new List <string>(includedEventTypes)
            };

            eventSubscription.Destination = destination;
            eventSubscription.Filter      = filter;

            if (labels != null)
            {
                eventSubscription.Labels = new List <string>(labels);
            }

            return(this.Client.EventSubscriptions.Create(scope, eventSubscriptionName, eventSubscription));
        }
Exemplo n.º 2
0
        public EventSubscription CreateEventSubscription(
            string scope,
            string eventSubscriptionName,
            string endpoint,
            string endpointType,
            string subjectBeginsWith,
            string subjectEndsWith,
            bool isSubjectCaseSensitive,
            string[] includedEventTypes,
            string[] labels,
            RetryPolicy retryPolicy,
            string deadLetterEndpoint)
        {
            EventSubscription            eventSubscription = new EventSubscription();
            EventSubscriptionDestination destination       = null;

            if (string.IsNullOrEmpty(endpointType) ||
                string.Equals(endpointType, EventGridConstants.Webhook, StringComparison.OrdinalIgnoreCase))
            {
                destination = new WebHookEventSubscriptionDestination()
                {
                    EndpointUrl = endpoint
                };
            }
            else if (string.Equals(endpointType, EventGridConstants.EventHub, StringComparison.OrdinalIgnoreCase))
            {
                destination = new EventHubEventSubscriptionDestination()
                {
                    ResourceId = endpoint
                };
            }
            else if (string.Equals(endpointType, EventGridConstants.StorageQueue, StringComparison.OrdinalIgnoreCase))
            {
                destination = this.GetStorageQueueEventSubscriptionDestinationFromEndpoint(endpoint);
            }
            else if (string.Equals(endpointType, EventGridConstants.HybridConnection, StringComparison.OrdinalIgnoreCase))
            {
                destination = new HybridConnectionEventSubscriptionDestination()
                {
                    ResourceId = endpoint
                };
            }
            else
            {
                throw new ArgumentNullException(nameof(endpointType), "Invalid EndpointType. Allowed values are WebHook, EventHub, StorageQueue or HybridConnection");
            }

            if (includedEventTypes == null)
            {
                includedEventTypes    = new string[1];
                includedEventTypes[0] = "All";
            }

            eventSubscription.Destination = destination;

            var filter = new EventSubscriptionFilter()
            {
                SubjectBeginsWith      = subjectBeginsWith,
                SubjectEndsWith        = subjectEndsWith,
                IsSubjectCaseSensitive = isSubjectCaseSensitive,
                IncludedEventTypes     = new List <string>(includedEventTypes)
            };

            eventSubscription.Filter = filter;

            if (labels != null)
            {
                eventSubscription.Labels = new List <string>(labels);
            }

            if (retryPolicy != null)
            {
                eventSubscription.RetryPolicy = retryPolicy;
            }

            if (!string.IsNullOrEmpty(deadLetterEndpoint))
            {
                eventSubscription.DeadLetterDestination = this.GetStorageBlobDeadLetterDestinationFromEndPoint(deadLetterEndpoint);
            }

            return(this.Client.EventSubscriptions.CreateOrUpdate(scope, eventSubscriptionName, eventSubscription));
        }