本文整理汇总了C#中System.Web.Http.Controllers.HttpControllerSettings类的典型用法代码示例。如果您正苦于以下问题:C# HttpControllerSettings类的具体用法?C# HttpControllerSettings怎么用?C# HttpControllerSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpControllerSettings类属于System.Web.Http.Controllers命名空间,在下文中一共展示了HttpControllerSettings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:pjengaard,项目名称:Skybrud.WebApi.Json,代码行数:7,代码来源:JsonOnlyConfigurationAttribute.cs
示例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);
}
开发者ID:mdabbagh88,项目名称:ODataServer,代码行数:40,代码来源:UseEntityRepositoryActionSelectorAttribute.cs
示例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);
}
开发者ID:jwallra,项目名称:azure-mobile-apps-net-server-1,代码行数:32,代码来源:MobileAppControllerAttribute.cs
示例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());
}
开发者ID:easygenerator,项目名称:LtiLibrary,代码行数:7,代码来源:LineItemsControllerConfigAttribute.cs
示例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);
}
}
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:27,代码来源:HttpConfiguration.cs
示例8: Initialize
public void Initialize(HttpControllerSettings controllerSettings,
HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.ParameterBindingRules.Insert(0,
new Func<HttpParameterDescriptor, HttpParameterBinding>(
d => new SimplePostVariableParameterBinding(d)));
}
开发者ID:dahlbyk,项目名称:AspNetPersonaId,代码行数:7,代码来源:SimplePostVariableParameterBindingAttribute.cs
示例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);
}
开发者ID:huoxudong125,项目名称:azure-mobile-apps-net-server,代码行数:26,代码来源:TableControllerConfigProvider.cs
示例10: Initialize
public void Initialize(HttpControllerSettings controllerSettings,
HttpControllerDescriptor controllerDescriptor)
{
var xmlFormater = new XmlMediaTypeFormatter { UseXmlSerializer = true };
controllerSettings.Formatters.Clear();
controllerSettings.Formatters.Add(xmlFormater);
}
开发者ID:adwardliu,项目名称:vc-community,代码行数:8,代码来源:ControllerConfigurationAttribute.cs
示例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;
}
}
开发者ID:halakaraki,项目名称:Its.Cqrs,代码行数:8,代码来源:ServesJsonByDefaultAttribute.cs
示例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));
}
}
开发者ID:umbraco,项目名称:OurUmbraco,代码行数:8,代码来源:OutgoingDateTimeFormatAttribute.cs
示例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();
}
开发者ID:johnsmith9264,项目名称:Mvc4Application1,代码行数:8,代码来源:TodoConfigurationAttribute.cs
示例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());
}
开发者ID:Varno,项目名称:WebApiTest1,代码行数:9,代码来源:UseJsonFormatterAttribute.cs
示例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());
}
开发者ID:Mamanze,项目名称:Breeze,代码行数:13,代码来源:BreezeControllerAttribute.cs
示例16: Initialize
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.Formatters.Clear();
controllerSettings.Formatters.Add(new XmlMediaTypeFormatter());
controllerSettings.ParameterBindingRules.Clear();
controllerSettings.Services.Replace(typeof(IDocumentationProvider), new AttributeDocumentationProvider());
}
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:9,代码来源:SpecialConfigController.cs
示例17: Initialize
public void Initialize(
HttpControllerSettings controllerSettings,
HttpControllerDescriptor controllerDescriptor)
{
if (controllerSettings.Formatters.JsonFormatter != null)
{
controllerSettings.Formatters[controllerSettings.Formatters.IndexOf(controllerSettings.Formatters.JsonFormatter)] = new JsonMediaTypeFormatter();
}
}
开发者ID:wli3,项目名称:Its.Log,代码行数:9,代码来源:DefaultJsonFormatterAttribute.cs
示例18: Initialize
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
// Insert custom parameter binder as the first in line
controllerSettings.ParameterBindingRules.Insert(0,
parameterDescriptor => new MultipleParameterFromBodyParameterBinding(parameterDescriptor));
// Register an additional plain text media type formatter
controllerSettings.Formatters.Add(new PlainTextBufferedFormatter());
}
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:9,代码来源:CustomControllerConfigAttribute.cs
示例19: Initialize
public void Initialize(
HttpControllerSettings settings,
HttpControllerDescriptor descriptor) {
// Remove the existing JSON formatter.
var jsonFormatter = settings.Formatters.JsonFormatter;
settings.Formatters.Remove(jsonFormatter);
// Add the Web API Jsonformatter, configured for .NET
settings.Formatters.Add(JsonFormatter.Create());
}
开发者ID:jspuij,项目名称:breeze.server.net,代码行数:10,代码来源:BreezeJsonFormatterAttribute.cs
示例20: Initialize
/// <inheritdoc />
public virtual void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
if (controllerDescriptor == null)
{
throw new ArgumentNullException("controllerDescriptor");
}
IMobileAppControllerConfigProvider configurationProvider = controllerDescriptor.Configuration.GetMobileAppControllerConfigProvider();
configurationProvider.Configure(controllerSettings, controllerDescriptor);
}
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:11,代码来源:MobileAppControllerAttribute.cs
注:本文中的System.Web.Http.Controllers.HttpControllerSettings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论