/// <summary>
 /// Create a NotificationEndpoint in the specified project in the given region using the parameters that are included in the request.
 /// </summary>
 /// <param name="project">
 /// Project ID for this request.
 /// </param>
 /// <param name="region">
 /// Name of the region scoping this request.
 /// </param>
 /// <param name="notificationEndpointResource">
 /// The body resource for this request
 /// </param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public virtual Operation Insert(string project, string region, NotificationEndpoint notificationEndpointResource, gaxgrpc::CallSettings callSettings = null) =>
 Insert(new InsertRegionNotificationEndpointRequest
 {
     NotificationEndpointResource = gax::GaxPreconditions.CheckNotNull(notificationEndpointResource, nameof(notificationEndpointResource)),
     Project = gax::GaxPreconditions.CheckNotNullOrEmpty(project, nameof(project)),
     Region  = gax::GaxPreconditions.CheckNotNullOrEmpty(region, nameof(region)),
 }, callSettings);
        /// <summary>
        /// Add a label to a notification endpoint.
        /// </summary>
        /// <param name="label">label to add</param>
        /// <param name="endpoint">the notification endpoint</param>
        /// <returns></returns>
        public async Task <Label> AddLabelAsync(Label label, NotificationEndpoint endpoint)
        {
            Arguments.CheckNotNull(endpoint, nameof(endpoint));
            Arguments.CheckNotNull(label, nameof(label));

            return(await AddLabelAsync(label.Id, endpoint.Id));
        }
        /// <summary>
        /// Delete label from a notification endpoint.
        /// </summary>
        /// <param name="label">the label to delete</param>
        /// <param name="endpoint">the notification endpoint</param>
        /// <returns></returns>
        public async Task DeleteLabelAsync(Label label, NotificationEndpoint endpoint)
        {
            Arguments.CheckNotNull(endpoint, nameof(endpoint));
            Arguments.CheckNotNull(label, nameof(label));

            await DeleteLabelAsync(label.Id, endpoint.Id);
        }
Exemple #4
0
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, string, NotificationEndpoint, CallSettings)
            // Additional: InsertAsync(string, string, NotificationEndpoint, CancellationToken)
            // Create client
            RegionNotificationEndpointsClient regionNotificationEndpointsClient = await RegionNotificationEndpointsClient.CreateAsync();

            // Initialize request argument(s)
            string project = "";
            string region  = "";
            NotificationEndpoint notificationEndpointResource = new NotificationEndpoint();
            // Make the request
            lro::Operation <Operation, Operation> response = await regionNotificationEndpointsClient.InsertAsync(project, region, notificationEndpointResource);

            // Poll until the returned long-running operation is complete
            lro::Operation <Operation, Operation> completedResponse = await response.PollUntilCompletedAsync();

            // Retrieve the operation result
            Operation result = completedResponse.Result;

            // Or get the name of the operation
            string operationName = response.Name;
            // This name can be stored, then the long-running operation retrieved later by name
            lro::Operation <Operation, Operation> retrievedResponse = await regionNotificationEndpointsClient.PollOnceInsertAsync(operationName);

            // Check if the retrieved long-running operation has completed
            if (retrievedResponse.IsCompleted)
            {
                // If it has completed, then access the result
                Operation retrievedResult = retrievedResponse.Result;
            }
            // End snippet
        }
        private async Task <NotificationEndpoint> CloneEndpointAsync(string name, NotificationEndpoint toCloneEndpoint,
                                                                     NotificationEndpoint clonedEndpoint)
        {
            clonedEndpoint.OrgID       = toCloneEndpoint.OrgID;
            clonedEndpoint.Description = toCloneEndpoint.Description;
            clonedEndpoint.Status      = toCloneEndpoint.Status;
            clonedEndpoint.Type        = toCloneEndpoint.Type;

            return(await CreateEndpointAsync(clonedEndpoint).ContinueWith(created =>
            {
                //
                // Add labels
                //
                return GetLabelsAsync(toCloneEndpoint)
                .ContinueWith(labels =>
                {
                    return labels.Result.Select(label => AddLabelAsync(label, created.Result));
                })
                .ContinueWith(async tasks =>
                {
                    await Task.WhenAll(tasks.Result);
                    return created.Result;
                })
                .Unwrap();
            }).Unwrap());
        }
Exemple #6
0
        public void GetRequestObject()
        {
            moq::Mock <RegionNotificationEndpoints.RegionNotificationEndpointsClient> mockGrpcClient = new moq::Mock <RegionNotificationEndpoints.RegionNotificationEndpointsClient>(moq::MockBehavior.Strict);
            GetRegionNotificationEndpointRequest request = new GetRegionNotificationEndpointRequest
            {
                Region  = "regionedb20d96",
                Project = "projectaa6ff846",
                NotificationEndpoint = "notification_endpointbe78db22",
            };
            NotificationEndpoint expectedResponse = new NotificationEndpoint
            {
                Id   = "id74b70bb8",
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                CreationTimestamp = "creation_timestamp235e59a1",
                Region            = "regionedb20d96",
                Description       = "description2cf9da67",
                GrpcSettings      = new NotificationEndpointGrpcSettings(),
                SelfLink          = "self_link7e87f12d",
            };

            mockGrpcClient.Setup(x => x.Get(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            RegionNotificationEndpointsClient client = new RegionNotificationEndpointsClientImpl(mockGrpcClient.Object, null);
            NotificationEndpoint response            = client.Get(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #7
0
        public async stt::Task GetAsync()
        {
            moq::Mock <RegionNotificationEndpoints.RegionNotificationEndpointsClient> mockGrpcClient = new moq::Mock <RegionNotificationEndpoints.RegionNotificationEndpointsClient>(moq::MockBehavior.Strict);
            GetRegionNotificationEndpointRequest request = new GetRegionNotificationEndpointRequest
            {
                Region  = "regionedb20d96",
                Project = "projectaa6ff846",
                NotificationEndpoint = "notification_endpointbe78db22",
            };
            NotificationEndpoint expectedResponse = new NotificationEndpoint
            {
                Id   = "id74b70bb8",
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                CreationTimestamp = "creation_timestamp235e59a1",
                Region            = "regionedb20d96",
                Description       = "description2cf9da67",
                GrpcSettings      = new NotificationEndpointGrpcSettings(),
                SelfLink          = "self_link7e87f12d",
            };

            mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <NotificationEndpoint>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            RegionNotificationEndpointsClient client  = new RegionNotificationEndpointsClientImpl(mockGrpcClient.Object, null);
            NotificationEndpoint responseCallSettings = await client.GetAsync(request.Project, request.Region, request.NotificationEndpoint, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            NotificationEndpoint responseCancellationToken = await client.GetAsync(request.Project, request.Region, request.NotificationEndpoint, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Update a notification endpoint. The updates is used for fields from <see cref="NotificationEndpointUpdate"/>.
        /// </summary>
        /// <param name="notificationEndpoint">update to apply</param>
        /// <returns>An updated notification endpoint</returns>
        public async Task <NotificationEndpoint> UpdateEndpointAsync(NotificationEndpoint notificationEndpoint)
        {
            Arguments.CheckNotNull(notificationEndpoint, nameof(notificationEndpoint));

            Enum.TryParse(notificationEndpoint.Status.ToString(), true,
                          out NotificationEndpointUpdate.StatusEnum status);

            return(await UpdateEndpointAsync(notificationEndpoint.Id,
                                             new NotificationEndpointUpdate(notificationEndpoint.Name,
                                                                            notificationEndpoint.Description, status)));
        }
Exemple #9
0
 /// <summary>Snippet for Get</summary>
 public void Get()
 {
     // Snippet: Get(string, string, string, CallSettings)
     // Create client
     RegionNotificationEndpointsClient regionNotificationEndpointsClient = RegionNotificationEndpointsClient.Create();
     // Initialize request argument(s)
     string project = "";
     string region  = "";
     string notificationEndpoint = "";
     // Make the request
     NotificationEndpoint response = regionNotificationEndpointsClient.Get(project, region, notificationEndpoint);
     // End snippet
 }
Exemple #10
0
 /// <summary>Snippet for Insert</summary>
 public void Insert()
 {
     // Snippet: Insert(string, string, NotificationEndpoint, CallSettings)
     // Create client
     RegionNotificationEndpointsClient regionNotificationEndpointsClient = RegionNotificationEndpointsClient.Create();
     // Initialize request argument(s)
     string project = "";
     string region  = "";
     NotificationEndpoint notificationEndpointResource = new NotificationEndpoint();
     // Make the request
     Operation response = regionNotificationEndpointsClient.Insert(project, region, notificationEndpointResource);
     // End snippet
 }
        public async Task GetNotificationsAsync_OAuth2Null_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new NotificationEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() => await endpoint.GetNotificationsAsync().ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task MarkNotificationViewedAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new NotificationEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() => await endpoint.MarkNotificationViewedAsync(null).ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task MarkNotificationsViewedAsync_True()
        {
            var mockUrl      = "https://api.imgur.com/3/notification/12345";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockNotificationEndpointResponses.MarkNotificationViewed)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new NotificationEndpoint(client,
                                                    new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var marked = await endpoint.MarkNotificationViewedAsync("12345").ConfigureAwait(false);

            Assert.True(marked);
        }
Exemple #14
0
        /// <summary>
        /// Initializes the notification.
        /// </summary>
        private void InitializeNotification()
        {
            NotificationPort = 45520;

            //initilize the notification nedpoint
            notificationEndpoint = new NotificationEndpoint(NotificationPort);

            //add the right connector to the endpoint to enable xml communication
            notificationEndpoint.AddNetworkConnector(new XmlNotificationNetworkConnector());

            //forward the notification event
            notificationEndpoint.NotificationOccured += (message) => NotificationReceivedHandler(message);

            //start the endpoint - listen to the port
            notificationEndpoint.StartNotificationEndpoint();
        }
Exemple #15
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetRegionNotificationEndpointRequest, CallSettings)
     // Create client
     RegionNotificationEndpointsClient regionNotificationEndpointsClient = RegionNotificationEndpointsClient.Create();
     // Initialize request argument(s)
     GetRegionNotificationEndpointRequest request = new GetRegionNotificationEndpointRequest
     {
         Region  = "",
         Project = "",
         NotificationEndpoint = "",
     };
     // Make the request
     NotificationEndpoint response = regionNotificationEndpointsClient.Get(request);
     // End snippet
 }
Exemple #16
0
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, string, NotificationEndpoint, CallSettings)
            // Additional: InsertAsync(string, string, NotificationEndpoint, CancellationToken)
            // Create client
            RegionNotificationEndpointsClient regionNotificationEndpointsClient = await RegionNotificationEndpointsClient.CreateAsync();

            // Initialize request argument(s)
            string project = "";
            string region  = "";
            NotificationEndpoint notificationEndpointResource = new NotificationEndpoint();
            // Make the request
            Operation response = await regionNotificationEndpointsClient.InsertAsync(project, region, notificationEndpointResource);

            // End snippet
        }
Exemple #17
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetAsync()
        {
            // Snippet: GetAsync(string, string, string, CallSettings)
            // Additional: GetAsync(string, string, string, CancellationToken)
            // Create client
            RegionNotificationEndpointsClient regionNotificationEndpointsClient = await RegionNotificationEndpointsClient.CreateAsync();

            // Initialize request argument(s)
            string project = "";
            string region  = "";
            string notificationEndpoint = "";
            // Make the request
            NotificationEndpoint response = await regionNotificationEndpointsClient.GetAsync(project, region, notificationEndpoint);

            // End snippet
        }
        public async Task MarkNotificationsViewedAsync_WithOAuth2Null_ThrowsArgumentNullException()
        {
            var client   = new ImgurClient("123", "1234");
            var endpoint = new NotificationEndpoint(client);

            var exception =
                await
                Record.ExceptionAsync(
                    async() =>
                    await endpoint.MarkNotificationsViewedAsync(new List <string> {
                "456"
            }).ConfigureAwait(false))
                .ConfigureAwait(false);

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task GetNotificationsAsync_NotNull()
        {
            var mockUrl      = "https://api.imgur.com/3/notification?new=false";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockNotificationEndpointResponses.GetNotifications)
            };

            var client   = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new NotificationEndpoint(client,
                                                    new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var notifications = await endpoint.GetNotificationsAsync(false).ConfigureAwait(false);

            Assert.NotNull(notifications);
            Assert.NotNull(notifications.Messages);
            Assert.NotNull(notifications.Replies);
        }
        private Task <NotificationRule> CreateRuleAsync(string name, string every, RuleStatusLevel status,
                                                        List <TagRule> tagRules, NotificationEndpoint notificationEndpoint, string orgId, NotificationRule rule)
        {
            Arguments.CheckNotNull(rule, "rule");

            rule.Name        = name;
            rule.Every       = every;
            rule.OrgID       = orgId;
            rule.TagRules    = tagRules;
            rule.StatusRules = new List <StatusRule> {
                new StatusRule(status)
            };
            rule.EndpointID = notificationEndpoint.Id;
            rule.Status     = TaskStatusType.Active;

            return(CreateRuleAsync(rule));
        }
Exemple #21
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetRegionNotificationEndpointRequest, CallSettings)
            // Additional: GetAsync(GetRegionNotificationEndpointRequest, CancellationToken)
            // Create client
            RegionNotificationEndpointsClient regionNotificationEndpointsClient = await RegionNotificationEndpointsClient.CreateAsync();

            // Initialize request argument(s)
            GetRegionNotificationEndpointRequest request = new GetRegionNotificationEndpointRequest
            {
                Region  = "",
                Project = "",
                NotificationEndpoint = "",
            };
            // Make the request
            NotificationEndpoint response = await regionNotificationEndpointsClient.GetAsync(request);

            // End snippet
        }
        private async Task <NotificationEndpoint> CloneEndpointAsync(string name, NotificationEndpoint toCloneEndpoint,
                                                                     NotificationEndpoint clonedEndpoint)
        {
            clonedEndpoint.OrgID       = toCloneEndpoint.OrgID;
            clonedEndpoint.Description = toCloneEndpoint.Description;
            clonedEndpoint.Status      = toCloneEndpoint.Status;
            clonedEndpoint.Type        = toCloneEndpoint.Type;

            var created = await CreateEndpointAsync(clonedEndpoint).ConfigureAwait(false);

            var labels = await GetLabelsAsync(toCloneEndpoint).ConfigureAwait(false);

            foreach (var label in labels)
            {
                await AddLabelAsync(label, created).ConfigureAwait(false);
            }

            return(created);
        }
Exemple #23
0
        public async Task <Result> AddNotificationEndpoint(NotificationEndpoint notificationEndpoint, CancellationToken cancellationToken)
        {
            try
            {
                if (!await NotificationEndpointExists(notificationEndpoint.Identifier, cancellationToken))
                {
                    await _dbContext.AddAsync(notificationEndpoint, cancellationToken);

                    await _dbContext.SaveChangesAsync(cancellationToken);
                }

                return(Result.Success());
            }
            catch (Exception e)
            {
                _logger.LogInformation("Adding notificationEndpoint with identifier {identifier} failed due to: {exceptionMessage}. ",
                                       notificationEndpoint.Identifier,
                                       e.Message);
                return(Result.Failure("Adding the notificationEndpoint to the database failed."));
            }
        }
 /// <summary>
 /// Create a NotificationEndpoint in the specified project in the given region using the parameters that are included in the request.
 /// </summary>
 /// <param name="project">
 /// Project ID for this request.
 /// </param>
 /// <param name="region">
 /// Name of the region scoping this request.
 /// </param>
 /// <param name="notificationEndpointResource">
 /// The body resource for this request
 /// </param>
 /// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Operation> InsertAsync(string project, string region, NotificationEndpoint notificationEndpointResource, st::CancellationToken cancellationToken) =>
 InsertAsync(project, region, notificationEndpointResource, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
Exemple #25
0
 public Subscription(BO.Subscription subscription)
 {
     Media = new Media(subscription.Media);
     NotificationEndpoint = new NotificationEndpoint(subscription.NotificationEndpoint);
 }
        public async Task <Result> AddNotificationEndpoint(NotificationEndpoint notificationEndpoint)
        {
            var notificationEndpointDao = new DAO.NotificationEndpoint(notificationEndpoint);

            return(await _notificationDataStore.AddNotificationEndpoint(notificationEndpointDao));
        }
        /// <summary>
        /// List all labels for a notification endpoint.
        /// </summary>
        /// <param name="endpoint">the notification endpoint</param>
        /// <returns>a list of all labels for a notification endpoint</returns>
        public async Task <List <Label> > GetLabelsAsync(NotificationEndpoint endpoint)
        {
            Arguments.CheckNotNull(endpoint, nameof(endpoint));

            return(await GetLabelsAsync(endpoint.Id));
        }
        /// <summary>
        /// Delete a notification endpoint.
        /// </summary>
        /// <param name="notificationEndpoint">notification endpoint</param>
        /// <returns>delete has been accepted></returns>
        public async Task DeleteNotificationEndpointAsync(NotificationEndpoint notificationEndpoint)
        {
            Arguments.CheckNotNull(notificationEndpoint, nameof(notificationEndpoint));

            await DeleteNotificationEndpointAsync(notificationEndpoint.Id);
        }
        /// <summary>
        /// Add new notification endpoint.
        /// </summary>
        /// <param name="notificationEndpoint">notificationEndpoint to create</param>
        /// <returns>Notification endpoint created</returns>
        public async Task <NotificationEndpoint> CreateEndpointAsync(NotificationEndpoint notificationEndpoint)
        {
            Arguments.CheckNotNull(notificationEndpoint, nameof(notificationEndpoint));

            return(await _service.CreateNotificationEndpointAsync(notificationEndpoint));
        }
        /// <summary>
        /// Delete a notification endpoint.
        /// </summary>
        /// <param name="notificationEndpoint">notification endpoint</param>
        /// <returns>delete has been accepted></returns>
        public Task DeleteNotificationEndpointAsync(NotificationEndpoint notificationEndpoint)
        {
            Arguments.CheckNotNull(notificationEndpoint, nameof(notificationEndpoint));

            return(DeleteNotificationEndpointAsync(notificationEndpoint.Id));
        }