本文整理汇总了C#中System.Web.Http.Controllers.HttpControllerSettings类的典型用法代码示例。如果您正苦于以下问题:C# HttpControllerSettings类的具体用法?C# HttpControllerSettings怎么用?C# HttpControllerSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpControllerSettings类属于System.Web.Http.Controllers命名空间,在下文中一共展示了HttpControllerSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public virtual void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor) {
var toRemove = settings.Formatters.Where(t => t is JsonMediaTypeFormatter || t is XmlMediaTypeFormatter).ToList();
foreach (var r in toRemove) {
settings.Formatters.Remove(r);
}
settings.Formatters.Add(new SkybrudJsonMediaTypeFormatter());
}
示例2: Initialize
/// <summary>
/// Callback invoked to set per-controller overrides for this controllerDescriptor.
/// </summary>
/// <param name="controllerSettings">The controller settings to initialize.</param>
/// <param name="controllerDescriptor">The controller descriptor. Note that the <see
/// cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> can be associated with the derived
/// controller type given that <see cref="T:System.Web.Http.Controllers.IControllerConfiguration" /> is
/// inherited.</param>
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
if (controllerSettings == null)
{
throw new ArgumentNullException("controllerSettings");
}
if (controllerDescriptor == null)
{
throw new ArgumentNullException("controllerDescriptor");
}
ServicesContainer services = controllerSettings.Services;
Contract.Assert(services != null);
IContainerMetadata containerMetadata = controllerDescriptor.GetContainerMetadata();
// Replace the action selector with one that is based on the OData routing conventions
IHttpActionSelector originalActionSelector = services.GetActionSelector();
IHttpActionSelector actionSelector;
if (containerMetadata != null)
{
// ContainerMetadata was stored with the HttpControllerDescriptor - so use our "special" ActionSelector
actionSelector = new EntityRepositoryActionSelector(containerMetadata, originalActionSelector);
}
else
{
// No ContainerMetadata stored with the HttpControllerDescriptor - so use the standard odata ActionSelector
actionSelector = new ODataActionSelector(originalActionSelector);
}
controllerSettings.Services.Replace(typeof(IHttpActionSelector), actionSelector);
}
示例3: Initialize
/// <inheritdoc />
public virtual void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
if (controllerSettings == null)
{
throw new ArgumentNullException("controllerSettings");
}
JsonMediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
JsonSerializerSettings serializerSettings = jsonFormatter.SerializerSettings;
// Set up date/time format to be ISO 8601 but with 3 digits and "Z" as UTC time indicator. This format
// is the JS-valid format accepted by most JS clients.
IsoDateTimeConverter dateTimeConverter = new IsoDateTimeConverter()
{
Culture = CultureInfo.InvariantCulture,
DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFZ",
DateTimeStyles = DateTimeStyles.AdjustToUniversal
};
// Ignoring default values while serializing was affecting offline scenarios as client sdk looks at first object in a batch for the properties.
// If first row in the server response did not include columns with default values, client sdk ignores these columns for the rest of the rows
serializerSettings.DefaultValueHandling = DefaultValueHandling.Include;
serializerSettings.NullValueHandling = NullValueHandling.Include;
serializerSettings.Converters.Add(new StringEnumConverter());
serializerSettings.Converters.Add(dateTimeConverter);
serializerSettings.MissingMemberHandling = MissingMemberHandling.Error;
serializerSettings.CheckAdditionalContent = true;
serializerSettings.ContractResolver = new ServiceContractResolver(jsonFormatter);
controllerSettings.Formatters.Remove(controllerSettings.Formatters.JsonFormatter);
controllerSettings.Formatters.Insert(0, jsonFormatter);
}
示例4: ConfigProvider_SettingsAreCorrect
public void ConfigProvider_SettingsAreCorrect()
{
// Arrange
var config = new HttpConfiguration();
var configProvider = new MobileAppControllerConfigProvider();
var settings = new HttpControllerSettings(config);
var descriptor = new HttpControllerDescriptor()
{
Configuration = config
};
// Act
configProvider.Configure(settings, descriptor);
// Assert
// Verify SerializerSettings are set up as we expect
var serializerSettings = settings.Formatters.JsonFormatter.SerializerSettings;
Assert.Equal(typeof(ServiceContractResolver), serializerSettings.ContractResolver.GetType());
Assert.Equal(DefaultValueHandling.Include, serializerSettings.DefaultValueHandling);
Assert.Equal(NullValueHandling.Include, serializerSettings.NullValueHandling);
Assert.Equal(MissingMemberHandling.Error, serializerSettings.MissingMemberHandling);
Assert.True(serializerSettings.CheckAdditionalContent);
// Verify Converters
var stringEnumConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(StringEnumConverter)) as StringEnumConverter;
Assert.False(stringEnumConverter.CamelCaseText);
var isoDateTimeConverter = serializerSettings.Converters.Single(c => c.GetType() == typeof(IsoDateTimeConverter)) as IsoDateTimeConverter;
Assert.Equal(DateTimeStyles.AdjustToUniversal, isoDateTimeConverter.DateTimeStyles);
Assert.Equal("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFZ", isoDateTimeConverter.DateTimeFormat);
Assert.Equal(CultureInfo.InvariantCulture, isoDateTimeConverter.Culture);
Assert.NotSame(config.Formatters.JsonFormatter.SerializerSettings.ContractResolver, settings.Formatters.JsonFormatter.SerializerSettings.ContractResolver);
Assert.Same(settings.Formatters.JsonFormatter, settings.Formatters[0]);
}
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:35,代码来源:MobileAppControllerConfigProviderTests.cs
示例5: Initialize_Calls_MobileAppControllerConfigProvider_Then_TableControllerConfigProvider
public void Initialize_Calls_MobileAppControllerConfigProvider_Then_TableControllerConfigProvider()
{
// Arrange
HttpConfiguration config = new HttpConfiguration();
HttpControllerSettings settings = new HttpControllerSettings(config);
HttpControllerDescriptor descriptor = new HttpControllerDescriptor()
{
Configuration = config
};
string output = string.Empty;
Mock<IMobileAppControllerConfigProvider> configProviderMock = new Mock<IMobileAppControllerConfigProvider>();
configProviderMock.Setup(p => p.Configure(settings, descriptor)).Callback(() => output += "1");
config.SetMobileAppControllerConfigProvider(configProviderMock.Object);
Mock<ITableControllerConfigProvider> tableConfigProviderMock = new Mock<ITableControllerConfigProvider>();
tableConfigProviderMock.Setup(p => p.Configure(settings, descriptor)).Callback(() => output += "2");
config.SetTableControllerConfigProvider(tableConfigProviderMock.Object);
// Act
new TableControllerConfigAttribute().Initialize(settings, descriptor);
// Assert
configProviderMock.VerifyAll();
tableConfigProviderMock.VerifyAll();
Assert.Equal("12", output);
}
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:28,代码来源:TableControllerConfigAttributeTests.cs
示例6: Initialize
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
// Add the LineItemFormatter to the associated ApiController. This formatter
// looks for the LineItemMediaType in the request Accept header and responds
// with the corresponding Content-Type.
controllerSettings.Formatters.Add(new LineItemFormatter());
}
示例7: HttpConfiguration
private HttpConfiguration(HttpConfiguration configuration, HttpControllerSettings settings)
{
_routes = configuration.Routes;
_filters = configuration.Filters;
_messageHandlers = configuration.MessageHandlers;
_properties = configuration.Properties;
_dependencyResolver = configuration.DependencyResolver;
IncludeErrorDetailPolicy = configuration.IncludeErrorDetailPolicy;
// per-controller settings
Services = settings.IsServiceCollectionInitialized ? settings.Services : configuration.Services;
_formatters = settings.IsFormatterCollectionInitialized ? settings.Formatters : configuration.Formatters;
ParameterBindingRules = settings.IsParameterBindingRuleCollectionInitialized ? settings.ParameterBindingRules : configuration.ParameterBindingRules;
// Use the original configuration's initializer so that its Initialize()
// will perform the same logic on this clone as on the original.
Initializer = configuration.Initializer;
// create a new validator cache if the validator providers have changed
if (settings.IsServiceCollectionInitialized &&
!settings.Services.GetModelValidatorProviders().SequenceEqual(configuration.Services.GetModelValidatorProviders()))
{
ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy<IEnumerable<ModelValidatorProvider>>(() => Services.GetModelValidatorProviders()));
RegisterForDispose(validatorCache);
settings.Services.Replace(typeof(IModelValidatorCache), validatorCache);
}
}
示例8: Initialize
public void Initialize(HttpControllerSettings controllerSettings,
HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.ParameterBindingRules.Insert(0,
new Func<HttpParameterDescriptor, HttpParameterBinding>(
d => new SimplePostVariableParameterBinding(d)));
}
示例9: Configure
/// <inheritdoc />
public void Configure(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
if (controllerSettings == null)
{
throw new ArgumentNullException("controllerSettings");
}
if (controllerDescriptor == null)
{
throw new ArgumentNullException("controllerDescriptor");
}
// We need to remove the xml formatter because it cannot handle the wrapped
// results this controller produces for inline count, etc.
controllerSettings.Formatters.Remove(controllerSettings.Formatters.XmlFormatter);
// Add additional query related filters for the same actions with a QueryableAttribute
// The Filter Provider ensures that the additional filters are always *after* the query filter as we
// want the IQueryable to have been set up before we do additional work on it.
controllerSettings.Services.Add(typeof(IFilterProvider), new TableFilterProvider());
// Register a ContractResolver with the JSON formatter that can handle Delta<T> correctly
JsonMediaTypeFormatter jsonFormatter = controllerSettings.Formatters.JsonFormatter;
jsonFormatter.SerializerSettings.ContractResolver = new TableContractResolver(jsonFormatter);
}
示例10: Initialize
public void Initialize(HttpControllerSettings controllerSettings,
HttpControllerDescriptor controllerDescriptor)
{
var xmlFormater = new XmlMediaTypeFormatter { UseXmlSerializer = true };
controllerSettings.Formatters.Clear();
controllerSettings.Formatters.Add(xmlFormater);
}
示例11: Initialize
public void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor)
{
foreach (var formatter in settings.Formatters.OfType<JsonMediaTypeFormatter>())
{
formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
formatter.SerializerSettings = Serializer.Settings;
}
}
示例12: Initialize
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
var jsonFormatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>();
foreach (var r in jsonFormatter)
{
r.SerializerSettings.Converters.Add(new CustomDateTimeConvertor(_format));
}
}
示例13: Initialize
public void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor)
{
// Clear the formatters list.
////settings.Formatters.Clear();
// Add a custom media-type formatter.
////settings.Formatters.Add(new Something());
settings.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
}
示例14: Initialize
public void Initialize(HttpControllerSettings settings,
HttpControllerDescriptor descriptor)
{
// Clear the formatters list.
settings.Formatters.Clear();
// Add a custom media-type formatter.
settings.Formatters.Add(new JsonMediaTypeFormatter());
}
示例15: Initialize
/// <summary>
/// Initialize the Breeze controller with a single <see cref="MediaTypeFormatter"/> for JSON
/// and a single <see cref="IFilterProvider"/> for Breeze OData support
/// </summary>
public void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor)
{
// replace the Web API's QueryActionFilterProvider with Breeze ODataActionFilter
settings.Services.Replace(typeof(IFilterProvider), BreezeFilterProvider());
// remove all formatters and add only the Breeze JsonFormatter
settings.Formatters.Clear();
settings.Formatters.Add(BreezeJsonFormatter());
}