public Subscription CreateDeleteRMWebHooksSubscription()
        {
            // Get the project to create the subscription in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            // Get the list of publishers
            IList <VisualStudio.Services.ServiceHooks.WebApi.Publisher> publishers = serviceHooksClient.GetPublishersAsync().Result;

            // Find the Release Management publisher and get its ServiceInstanceType
            VisualStudio.Services.ServiceHooks.WebApi.Publisher rmPublisher = publishers.First(p => p.Id == "rm");
            Guid rmServiceInstance = Guid.Parse(rmPublisher.ServiceInstanceType);

            // Get a new client using the RM ServiceInstanceType
            ServiceHooksPublisherHttpClient rmServiceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>(rmServiceInstance);

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType       = "ms.vss-release.release-created-event",
                PublisherId     = "rm",
                PublisherInputs = new Dictionary <string, string>
                {
                    { "projectId", project.Id.ToString() }
                },
            };
            Subscription newSubscription = rmServiceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            rmServiceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = rmServiceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            }
            catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }
Esempio n. 2
0
        public NotificationProcessService(NotificationProcessChannel processingChannel, IOptions <AzureDevOpsConfig> azureOptions, IOptions <KestrelConfig> kestrelOptions, IOptions <JWTConfig> JWTOptions)
        {
            this.processingChannel = processingChannel;
            this.kestrelConfig     = kestrelOptions.Value;
            this.azureDevopsConfig = azureOptions.Value;
            this.JWTOptions        = JWTOptions.Value;

            var credentials = new VssBasicCredential("", azureDevopsConfig.PatToken);

            connection         = new VssConnection(new Uri(azureDevopsConfig.CollectionUri), credentials);
            subscriptionClient = connection.GetClient <ServiceHooksPublisherHttpClient>();
        }
        public IEnumerable <Subscription> ListSubscriptions()
        {
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            IList <Subscription> subscriptions = serviceHooksClient.QuerySubscriptionsAsync().Result;

            foreach (var subscription in subscriptions)
            {
                LogSubscription(subscription);
            }

            return(subscriptions);
        }
        public TFSClient(string url, string username, string passwordOrPAT)
        {
            _uri           = url;
            _username      = username;
            _passwordOrPAT = passwordOrPAT;
            VssBasicCredential credentials = new VssBasicCredential(_username, _passwordOrPAT);
            Uri uri = new Uri(_uri);

            _connection        = new VssConnection(uri, credentials);
            workItemClient     = _connection.GetClient <WorkItemTrackingHttpClient>();
            teamClient         = _connection.GetClient <TeamHttpClient>();
            projectClient      = _connection.GetClient <ProjectHttpClient>();
            serviceHooksClient = _connection.GetClient <ServiceHooksPublisherHttpClient>();
        }
        public Subscription CreateDeleteWebHooksSubscription()
        {
            // Get the project to create the subscription in
            TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);

            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType       = "workitem.created",
                PublisherId     = "tfs",
                PublisherInputs = new Dictionary <string, string>
                {
                    { "projectId", project.Id.ToString() }
                },
            };

            Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            } catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }
        public Subscription CreateDeleteAccountWideWebHooksSubscription()
        {
            // Get the client
            VssConnection connection = Context.Connection;
            ServiceHooksPublisherHttpClient serviceHooksClient = connection.GetClient <ServiceHooksPublisherHttpClient>();

            Subscription subscriptionParameters = new Subscription()
            {
                ConsumerId       = "webHooks",
                ConsumerActionId = "httpRequest",
                ConsumerInputs   = new Dictionary <string, string>
                {
                    { "url", "https://requestb.in/12h6lw21" }
                },
                EventType   = "workitem.updated",
                PublisherId = "tfs"
            };

            Subscription newSubscription = serviceHooksClient.CreateSubscriptionAsync(subscriptionParameters).Result;
            Guid         subscriptionId  = newSubscription.Id;

            LogSubscription(newSubscription);

            // Delete the subscription
            serviceHooksClient.DeleteSubscriptionAsync(subscriptionId).SyncResult();

            // Try to get the subscription (should result in an exception)
            try
            {
                newSubscription = serviceHooksClient.GetSubscriptionAsync(subscriptionId).Result;
            }
            catch (Exception e)
            {
                Context.Log("Unable to get the deleted subscription:" + e.Message);
            }

            return(newSubscription);
        }