daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    public class ConfigurableResponseProcessor : IResponseProcessor
  2.     {
  3.         private Func<MediaRange, object, NancyContext, ProcessorMatch> canProcess = (media, model, context) => new ProcessorMatch();
  4.         private Func<MediaRange, object, NancyContext, Response> process = (media, model, context) => 200;
  5.         private IList<Tuple<string, MediaRange>> extensionMappings = new List<Tuple<string, MediaRange>>();
  6.  
  7.         public ConfigurableResponseProcessor()
  8.         {
  9.         }
  10.  
  11.         public ConfigurableResponseProcessor(Action<ConfigurableResponseProcessorConfigurator> action)
  12.         {
  13.             var configurator =
  14.                 new ConfigurableResponseProcessorConfigurator(this);
  15.  
  16.             action.Invoke(configurator);
  17.         }
  18.  
  19.         public IEnumerable<Tuple<string, MediaRange>> ExtensionMappings
  20.         {
  21.             get { return this.extensionMappings; }
  22.         }
  23.  
  24.         public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
  25.         {
  26.             return this.canProcess.Invoke(requestedMediaRange, model, context);
  27.         }
  28.  
  29.         public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
  30.         {
  31.             return this.process.Invoke(requestedMediaRange, model, context);
  32.         }
  33.  
  34.         public class ConfigurableResponseProcessorConfigurator
  35.         {
  36.             private readonly ConfigurableResponseProcessor processor;
  37.  
  38.             public ConfigurableResponseProcessorConfigurator(ConfigurableResponseProcessor processor)
  39.             {
  40.                 this.processor = processor;
  41.             }
  42.  
  43.             public ConfigurableResponseProcessorConfigurator Extension(string extension, MediaRange range)
  44.             {
  45.                 this.processor.extensionMappings.Add(new Tuple<string, MediaRange>(extension, range));
  46.                 return this;
  47.             }
  48.  
  49.             public ConfigurableResponseProcessorConfigurator Extension(Tuple<string, MediaRange> mapping)
  50.             {
  51.                 this.processor.extensionMappings.Add(mapping);
  52.                 return this;
  53.             }
  54.  
  55.             public ConfigurableResponseProcessorConfigurator Extension(IEnumerable<Tuple<string, MediaRange>> mappings)
  56.             {
  57.                 this.processor.extensionMappings = mappings.ToList();
  58.                 return this;
  59.             }
  60.  
  61.             public ConfigurableResponseProcessorConfigurator CanProcess(Func<MediaRange, object, NancyContext, ProcessorMatch> action)
  62.             {
  63.                 this.processor.canProcess = action;
  64.                 return this;
  65.             }
  66.  
  67.             public ConfigurableResponseProcessorConfigurator Process(Func<MediaRange, object, NancyContext, Response> action)
  68.             {
  69.                 this.processor.process = action;
  70.                 return this;
  71.             }
  72.         }
  73.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top