Example #1
0
        public void ExecuteConfiguration(IApplicationConfigurationService service)
        {
            BaseAssetProvider assetProvider = null;
            Delegate          handler;

            if (File.Exists(_fileSystemPath))
            {
                assetProvider = new FileAssetProvider(
                    _currentApiInformation.ServiceProvider.GetService <IFileAssetCache>(),
                    _currentApiInformation.ServiceProvider.GetService <FileExtensionContentTypeProvider>(),
                    _fileSystemPath
                    );

                handler = (Func <HttpContext, Task>)(context => assetProvider.ProvideAsset(context, _urlPath));

                var delegateConfig = new DelegateInstanceConfiguration(_currentApiInformation, handler)
                {
                    Method = HttpMethods.Get,
                    Path   = _urlPath
                };

                service.ExposeDelegate(_currentApiInformation, delegateConfig, handler);
            }
            else if (Directory.Exists(_fileSystemPath))
            {
                assetProvider = new DirectoryAssetProvider(
                    _currentApiInformation.ServiceProvider.GetService <IFileAssetCache>(),
                    _currentApiInformation.ServiceProvider.GetService <FileExtensionContentTypeProvider>(),
                    _fileSystemPath,
                    _fallback);

                handler = new Func <HttpContext, string, Task>((context, filePath) => assetProvider.ProvideAsset(context, filePath));

                var delegateConfig = new DelegateInstanceConfiguration(_currentApiInformation, handler)
                {
                    Method = HttpMethods.Get,
                    Path   = _urlPath + "{filePath}"
                };

                service.ExposeDelegate(_currentApiInformation, delegateConfig, handler);
            }
            else
            {
                throw new Exception($"Could not find asset path {_fileSystemPath}");
            }

            assetProvider.CacheMaxAge   = _cacheMaxAge;
            assetProvider.NoCache       = _noCache;
            assetProvider.InMemoryCache = _inMemoryCache;
        }
Example #2
0
        /// <summary>
        /// Register a delegate to handle a specific method/path combination
        /// </summary>
        /// <param name="method"></param>
        /// <param name="path"></param>
        /// <param name="func"></param>
        /// <param name="hasBody"></param>
        /// <returns></returns>
        protected virtual IExposureDelegateConfiguration RegisterDelegateHandler(string method, string path, Delegate func,
                                                                                 bool?hasBody)
        {
            var delegateConfiguration =
                new DelegateInstanceConfiguration(_internalApiConfiguration.GetCurrentApiInformation(), func)
            {
                Method         = method,
                Path           = path,
                HasRequestBody = hasBody
            };

            _internalApiConfiguration.ApplicationConfigurationService.AddConfigurationObject(delegateConfiguration);

            return(delegateConfiguration);
        }
 /// <inheritdoc />
 public void ExposeDelegate(ICurrentApiInformation currentApi, DelegateInstanceConfiguration delegateInstanceConfiguration, Delegate @delegate)
 {
     RegisterDelegate(currentApi, delegateInstanceConfiguration, @delegate);
 }