Bloom.Api.EnhancedImageServer.RegisterEndpointHandler C# (CSharp) Method

RegisterEndpointHandler() public method

Get called when a client (i.e. javascript) does an HTTP api call
public RegisterEndpointHandler ( string pattern, EndpointHandler handler, bool handleOnUiThread = true ) : void
pattern string Simple string or regex to match APIs that this can handle. This must match what comes after the ".../api/" of the URL
handler EndpointHandler The method to call
handleOnUiThread bool For safety, this defaults to true, but that can kill performance if you don't need it (BL-3452)
return void
        public void RegisterEndpointHandler(string pattern, EndpointHandler handler, bool handleOnUiThread = true)
        {
            _endpointRegistrations[pattern.ToLowerInvariant().Trim(new char[] {'/'})] = new EndpointRegistration()
            {
                Handler = handler,
                HandleOnUIThread = handleOnUiThread
            };
        }

Usage Example

Example #1
0
        public void RegisterWithServer(EnhancedImageServer server)
        {
            server.RegisterEndpointHandler(kBrandingImageUrlPart, request =>
            {
#if DEBUG
                // The book templates are allowed to use the branding api.  All real books
                // should not use this facility.
                if (request.CurrentBook == null || request.CurrentBook.FolderPath == null ||
                    !Book.BookStorage.IsStaticContent(request.CurrentBook.FolderPath))
                {
                    //Debug.Fail("Books should no longer have branding api urls");
                }
#endif
                var fileName = request.RequiredFileNameOrPath("id");
                var path     = FindBrandingImageFileIfPossible(_collectionSettings.BrandingProjectKey, fileName.NotEncoded, request.CurrentBook.GetLayout());

                // And this is perfectly normal, to not have a branding image at all, for a particular page:
                if (string.IsNullOrEmpty(path))
                {
                    request.Failed("");
                    // the HTML will need to be able to handle this invisibly... see http://stackoverflow.com/questions/22051573/how-to-hide-image-broken-icon-using-only-css-html-without-js
                    return;
                }
                request.ReplyWithImage(path);
            }, false);
        }
All Usage Examples Of Bloom.Api.EnhancedImageServer::RegisterEndpointHandler