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());
 }
		/// <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);
		}
        /// <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);
        }
        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]);
        }
        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);
        }
 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());
 }
        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);
            }
        }
 public void Initialize(HttpControllerSettings controllerSettings,
                         HttpControllerDescriptor controllerDescriptor)
 {
     controllerSettings.ParameterBindingRules.Insert(0,
         new Func<HttpParameterDescriptor, HttpParameterBinding>(
             d => new SimplePostVariableParameterBinding(d)));
 }
        /// <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);
        }
 public void Initialize(HttpControllerSettings controllerSettings,
                        HttpControllerDescriptor controllerDescriptor)
 {
     var xmlFormater = new XmlMediaTypeFormatter { UseXmlSerializer = true };
     
     controllerSettings.Formatters.Clear();
     controllerSettings.Formatters.Add(xmlFormater);
 }
 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;
     }
 }
 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));
     }
 }
 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();
 }
Ejemplo n.º 14
0
        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());
        }
Ejemplo n.º 15
0
        /// <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());
        }
            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());
            }
Ejemplo n.º 17
0
 public void Initialize(
     HttpControllerSettings controllerSettings,
     HttpControllerDescriptor controllerDescriptor)
 {
     if (controllerSettings.Formatters.JsonFormatter != null)
     {
         controllerSettings.Formatters[controllerSettings.Formatters.IndexOf(controllerSettings.Formatters.JsonFormatter)] = new JsonMediaTypeFormatter();
     }
 }
        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());
        }
    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());
    }
        /// <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);
        }
Ejemplo n.º 21
0
        public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
        {
            controllerSettings.Formatters.Clear();

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new LowerCasePropertyNamesContractResolver()
            };
            controllerSettings.Formatters.Add(new JsonMediaTypeFormatter { SerializerSettings = settings });
        }
        public void Initialize_RegistersActionSelector()
        {
            var config = new HttpConfiguration();
            var controllerSettings = new HttpControllerSettings(config);
            var controllerDescriptor = new HttpControllerDescriptor();
            controllerDescriptor.Configuration = config;

            new ODataRoutingAttribute().Initialize(controllerSettings, controllerDescriptor);

            Assert.IsType<ODataActionSelector>(controllerSettings.Services.GetActionSelector());
        }
        public void Initialize(HttpControllerSettings config,
                               HttpControllerDescriptor controllerDescriptor)
        {
            var formatter = config.Formatters.OfType<JsonMediaTypeFormatter>().Single();
            config.Formatters.Remove(formatter);

            formatter = new JsonMediaTypeFormatter();
            formatter.SerializerSettings.ContractResolver = new DefaultContractResolver();

            config.Formatters.Add(formatter);
        }
 public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
 {
     controllerSettings.Formatters.Clear();
     controllerSettings.Formatters.Add(new JsonMediaTypeFormatter
     {
         SerializerSettings = new JsonSerializerSettings
         {
             DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
         }
     });
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes the controller.
        /// </summary>
        /// <param name="controllerSettings">
        /// The controller settings.
        /// </param>
        /// <param name="controllerDescriptor">
        /// The controller descriptor.
        /// </param>
        public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
        {
            controllerSettings.Formatters.Clear();

            var formatter = new JsonMediaTypeFormatter
            {
                SerializerSettings = { ContractResolver = new CamelCasePropertyNamesContractResolver() }
            };

            controllerSettings.Formatters.Add(formatter);
        }
        public void Initialize_RegistersContentNegotiator()
        {
            var config = new HttpConfiguration();
            var controllerSettings = new HttpControllerSettings(config);
            var controllerDescriptor = new HttpControllerDescriptor();
            controllerDescriptor.Configuration = config;

            new ODataFormattingAttribute().Initialize(controllerSettings, controllerDescriptor);

            Assert.IsType<PerRequestContentNegotiator>(controllerSettings.Services.GetContentNegotiator());
        }
Ejemplo n.º 27
0
        public void Initialize(HttpControllerSettings controllerSettings,
            HttpControllerDescriptor controllerDescriptor)
        {
            var traceWriter =
                new SystemDiagnosticsTraceWriter()
                {
                    MinimumLevel = TraceLevel.Info,
                    IsVerbose = false
                };

            controllerSettings.Services.Replace(typeof(ITraceWriter), traceWriter);
        }
        /// <inheritdoc />
        public override void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
        {
            if (controllerDescriptor == null)
            {
                throw new ArgumentNullException("controllerDescriptor");
            }

            base.Initialize(controllerSettings, controllerDescriptor);

            ITableControllerConfigProvider tableConfigurationProvider = controllerDescriptor.Configuration.GetTableControllerConfigProvider();
            tableConfigurationProvider.Configure(controllerSettings, controllerDescriptor);
        }
 public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
 {
     controllerSettings.Formatters.Clear();
     controllerSettings.Formatters.Add(new JsonMediaTypeFormatter
     {
         SerializerSettings = new JsonSerializerSettings
         {
             DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
             ContractResolver = new SkipEmptyCollectionsContractResolver()
         }
     });
 }
Ejemplo n.º 30
0
        public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
        {
            var formatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>().Single();
            controllerSettings.Formatters.Remove(formatter);

            formatter = new JsonMediaTypeFormatter
            {
                SerializerSettings = { ContractResolver = new CamelCasePropertyNamesContractResolver() }
            };

            controllerSettings.Formatters.Add(formatter);
        }