-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGenericControllerSelector.cs
87 lines (76 loc) · 2.95 KB
/
GenericControllerSelector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace DynamicPowerShellApi
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using Configuration;
using Controllers;
/// <summary>
/// The generic controller selector.
/// </summary>
public class GenericControllerSelector : IHttpControllerSelector
{
/// <summary>
/// The current configuration from the http server.
/// </summary>
private readonly HttpConfiguration _currentConfiguration;
/// <summary>
/// Gets the generic descriptor.
/// </summary>
private HttpControllerDescriptor GenericDescriptor
{
get
{
return
new HttpControllerDescriptor(
_currentConfiguration,
"generic",
typeof(GenericController));
}
}
/// <summary>
/// Initializes a new instance of the <see cref="GenericControllerSelector" /> class.
/// </summary>
/// <param name="configuration">The configuration of the http channel.</param>
public GenericControllerSelector(HttpConfiguration configuration)
{
if (configuration == null)
throw new ArgumentNullException("configuration", "Argument cannot be null.");
_currentConfiguration = configuration;
}
/// <summary>
/// Selects a <see cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> for the given <see cref="T:System.Net.Http.HttpRequestMessage" />.
/// </summary>
/// <param name="request">The request message.</param>
/// <returns>
/// An <see cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> instance.
/// </returns>
public HttpControllerDescriptor SelectController(HttpRequestMessage request)
{
if (request == null)
throw new ArgumentNullException("request", "Argument cannot be null.");
DynamicPowershellApiEvents.Raise.VerboseMessaging(String.Format("Received Request {0}", request.RequestUri));
return GenericDescriptor;
}
/// <summary>
/// Returns a map, keyed by controller string, of all <see cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> that the selector can select. This is primarily called by <see cref="T:System.Web.Http.Description.IApiExplorer" /> to discover all the possible controllers in the system.
/// </summary>
/// <returns>
/// A map of all <see cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> that the selector can select, or null if the selector does not have a well-defined mapping of <see cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" />.
/// </returns>
public IDictionary<string, HttpControllerDescriptor> GetControllerMapping()
{
// Exercised only by ASP.NET Web API’s API explorer feature
var dic = new Dictionary<string, HttpControllerDescriptor>();
foreach (WebApi api in WebApiConfiguration.Instance.Apis)
{
dic.Add(api.Name, new HttpControllerDescriptor(_currentConfiguration, api.Name, typeof(GenericController)));
}
dic.Add("generic", GenericDescriptor);
return dic;
}
}
}