public async Task <IActionResult> Post([FromBody] WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }

            InitializeCollections(webHook);

            try
            {
                // Validate the provided WebHook ID (or force one to be created on server side)
                var idValidator = HttpContext.RequestServices.GetIdValidator();
                await idValidator.ValidateIdAsync(Request, webHook);

                // Validate other parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
                _logger.LogInformation(message, ex);
                return(BadRequest(message));
            }

            try
            {
                // Add WebHook for this user.
                var result = await _registrationsManager.AddWebHookAsync(User, webHook, AddPrivateFilters);

                if (result == StoreResult.Success)
                {
                    var r = await _registrationsManager.LookupWebHookAsync(User, webHook.Id, RemovePrivateFilters);

                    return(CreatedAtAction(nameof(Lookup), new { id = webHook.Id }, r));
                }
                return(CreateHttpResult(result));
            }
            catch (InvalidOperationException ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
                _logger.LogInformation(message, ex);
                return(BadRequest(message));
            }
            catch (Exception ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
                _logger.LogError(message, ex);
                throw;
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Post(WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }

            try
            {
                // CustomServices.Reset();
                // Validate the provided WebHook ID (or force one to be created on server side)
                IWebHookIdValidator idValidator = Configuration.DependencyResolver.GetIdValidator();
                await idValidator.ValidateIdAsync(Request, webHook);

                // Validate other parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, BaladorResource.RegistrationController_RegistrationFailure, ex.Message);
                Configuration.DependencyResolver.GetLogger().Info(msg);
                HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
                return(ResponseMessage(error));
            }

            try
            {
                // Add WebHook for this user.
                StoreResult result = await _registrationsManager.AddWebHookAsync(User, webHook, AddPrivateFilters);

                if (result == StoreResult.Success)
                {
                    return(CreatedAtRoute(RegistrationLookupAction, new { id = webHook.Id }, webHook));
                }
                return(CreateHttpResult(result));
            }
            catch (Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, BaladorResource.RegistrationController_RegistrationFailure, ex.Message);
                Configuration.DependencyResolver.GetLogger().Error(msg, ex);
                HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
                return(ResponseMessage(error));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Post([FromBody] WebHook webHook)
        {
            if (webHook == null)
            {
                return(BadRequest());
            }

            try
            {
                // Validate the provided WebHook ID (or force one to be created on server side)
                await _idValidator.ValidateIdAsync(Request, webHook);

                // Validate other parts of WebHook
                await _registrationsManager.VerifySecretAsync(webHook);

                await _registrationsManager.VerifyFiltersAsync(webHook);

                await _registrationsManager.VerifyAddressAsync(webHook);
            }
            catch (Exception ex)
            {
                var message = $"Could not register WebHook due to error: {ex.Message}";
                _logger.LogInformation(ex.Message, ex);
                return(BadRequest(message));
            }

            try
            {
                // Add WebHook for this user.
                var result = await _registrationsManager.AddWebHookAsync(User, webHook, AddPrivateFilters);

                if (result == StoreResult.Success)
                {
                    return(CreatedAtRoute(WebHookRouteNames.RegistrationLookupAction, new { id = webHook.Id }, webHook));
                }
                return(CreateHttpResult(result));
            }
            catch (Exception ex)
            {
                var message = $"Could not register WebHook due to error: {ex.Message}";
                _logger.LogInformation(ex.Message, ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, message));
            }
        }