Beispiel #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;
        }
Beispiel #2
0
 public override void ExecuteConfiguration(IApplicationConfigurationService service)
 {
     service.ExposeDelegate(_currentApi, this, _delegate);
 }