public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (this.domains != null)
            {
                config.SetCrossDomainOrigins(this.domains);
            }

            // register the controller as an exclusion so it does not map to /api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            mobileAppConfig.AddBaseRouteExclusion(CrossDomainControllerName);

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainBridgeRouteName,
                routeTemplate: "crossdomain/bridge",
                defaults: new { controller = CrossDomainControllerName });

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainLoginReceiverRouteName,
                routeTemplate: "crossdomain/loginreceiver",
                defaults: new { controller = CrossDomainControllerName });
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            var mobileConfig         = new MobileAppConfiguration();

            //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
            config.EnableSystemDiagnosticsTracing();

            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new OlyfauntInitializer());

            // To prevent Entity Framework from modifying your database schema, use a null database initializer
            // Database.SetInitializer<OlyfauntContext>(null);

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                // This middleware is intended to be used locally for debugging. By default, HostName will
                // only have a value when running in an App Service application.
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = config.GetAppServiceTokenHandler()
                });
            }
            app.UseWebApi(config);
        }
Exemple #3
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            var mobileConfig         = new MobileAppConfiguration();

            mobileConfig
            .UseDefaultConfiguration()
            .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new MobileServiceInitializer());

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration httpConfig = new HttpConfiguration();
            var mobileConfig             = new MobileAppConfiguration();

            mobileConfig
            .AddTablesWithEntityFramework()
            .MapApiControllers()
            .ApplyTo(httpConfig);

            //httpConfig.MapHttpAttributeRoutes();

            // Automatic Code First Migrations
            var migrator = new DbMigrator(new Migrations.Configuration());

            migrator.Update();

            MobileAppSettingsDictionary settings = httpConfig.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = httpConfig.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(httpConfig);
        }
Exemple #5
0
        public void GetMobileAppConfigOptions_ReturnsNullByDefault()
        {
            // Act
            MobileAppConfiguration actual = this.config.GetMobileAppConfiguration();

            // Assert
            Assert.Null(actual);
        }
Exemple #6
0
        /// <summary>
        /// Registers a <see cref="Microsoft.Azure.Mobile.Server.Config.MobileAppConfiguration"/> with the current <see cref="System.Web.Http.HttpConfiguration" />.
        /// </summary>
        /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param>
        /// <param name="options">The instance to register.</param>
        public static void SetMobileAppConfiguration(this HttpConfiguration config, MobileAppConfiguration options)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.Properties[MobileAppOptionsKey] = options;
        }
Exemple #7
0
        public void GetMobileAppConfiguration_ReturnsNullByDefault()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            MobileAppConfiguration actual = config.GetMobileAppConfiguration();

            // Assert
            Assert.Null(actual);
        }
        /// <summary>
        /// Configures the mobile app.
        /// </summary>
        /// <param name="app">App.</param>
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var config       = new HttpConfiguration();
            var mobileConfig = new MobileAppConfiguration();

            mobileConfig.AddTablesWithEntityFramework().ApplyTo(config);

            Database.SetInitializer(new MobileServiceInitializer());

            app.UseWebApi((config));
        }
Exemple #9
0
        public void SetMobileAppConfigOptions_Roundtrips()
        {
            // Arrange
            MobileAppConfiguration options = new MobileAppConfiguration();

            // Act
            this.config.SetMobileAppConfiguration(options);
            MobileAppConfiguration actual = this.config.GetMobileAppConfiguration();

            // Assert
            Assert.Same(options, actual);
        }
Exemple #10
0
        public void SetMobileAppConfiguration_ReturnsNull_IfSetToNull()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.SetMobileAppConfiguration(null);
            MobileAppConfiguration actual = config.GetMobileAppConfiguration();

            // Assert
            Assert.Null(actual);
        }
Exemple #11
0
        public void SetMobileAppConfiguration_Roundtrips()
        {
            // Arrange
            HttpConfiguration      config  = new HttpConfiguration();
            MobileAppConfiguration options = new MobileAppConfiguration();

            // Act
            config.SetMobileAppConfiguration(options);
            MobileAppConfiguration actual = config.GetMobileAppConfiguration();

            // Assert
            Assert.Same(options, actual);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            var mobileConfig = new MobileAppConfiguration();

            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(config);

            app.UseWebApi(config);
        }
Exemple #13
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var httpConfig   = new HttpConfiguration();
            var mobileConfig = new MobileAppConfiguration();

            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(httpConfig);

            // Automatic Code First Migrations
            //var migrator = new DbMigrator(new Migrations.Configuration());
            //migrator.Update();

            app.UseWebApi(httpConfig);
        }
Exemple #14
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            var mobileConfig = new MobileAppConfiguration();

            mobileConfig.AddTablesWithEntityFramework()
            .ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            var migrator = new DbMigrator(new Migrations.Configuration());

            migrator.Update();

            app.UseWebApi(config);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var httpConfig   = new HttpConfiguration();
            var mobileConfig = new MobileAppConfiguration();

            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(httpConfig);

            // Map Routes via attribute
            httpConfig.MapHttpAttributeRoutes();

            Database.SetInitializer(new MobileServiceInitializer());

            app.UseWebApi(httpConfig);
        }
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            //register the controller as an exclusion so it does not map to / api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            mobileAppConfig.AddBaseRouteExclusion(PushControllerName);

            //HttpRouteCollectionExtensions.MapHttpRoute(
            //    config.Routes,
            //    name: NotificationInstallationsRouteName,
            //    routeTemplate: PushRoutePrefix + "{installationId}",
            //    defaults: new { controller = PushControllerName });
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();
            config.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger());
            config.EnableSystemDiagnosticsTracing();
#if DEBUG
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
#endif
            var mobileConfig = new MobileAppConfiguration();

            mobileConfig.AddTablesWithEntityFramework().ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            Database.SetInitializer(new MobileServiceInitializer());

            app.UseWebApi(config);
        }
Exemple #18
0
        /// <summary>
        /// </summary>
        /// <param name="config">HttpConfiguration</param>
        public void Initialize(HttpConfiguration config)
        {
            HashSet <string>            tableControllerNames      = config.GetTableControllerNames();
            SetRouteConstraint <string> tableControllerConstraint = new SetRouteConstraint <string>(tableControllerNames, matchOnExcluded: false);

            // register all TableControllers as exclusions so they do not map to /api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            foreach (string controllerName in tableControllerNames)
            {
                mobileAppConfig.AddBaseRouteExclusion(controllerName);
            }

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: TablesRouteName,
                routeTemplate: "tables/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { controller = tableControllerConstraint });
        }
Exemple #19
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();   // enable attribute routing

            var mobileConfig = new MobileAppConfiguration();

            mobileConfig
            .AddTablesWithEntityFramework()         /* /tables endpoints */
            .MapApiControllers()                    /* /api endpoints */
            //.UseDefaultConfiguration()
            .ApplyTo(config);

            // Automatic Code First Migrations
            var migrator = new DbMigrator(new Migrations.Configuration());

            migrator.Update();

            //// Use Entity Framework Code First to create database tables based on your DbContext
            //Database.SetInitializer(new MobileServiceInitializer());

            //MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            //if (string.IsNullOrEmpty(settings.HostName))
            //{
            //    app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
            //    {
            //        // This middleware is intended to be used locally for debugging. By default, HostName will
            //        // only have a value when running in an App Service application.
            //        SigningKey = ConfigurationManager.AppSettings["SigningKey"],
            //        ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
            //        ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
            //        TokenHandler = config.GetAppServiceTokenHandler()
            //    });
            //}

            app.UseWebApi(config);

            ConfigureSwagger(config);
        }
        private TestServer CreateTestServer(IEnumerable <string> origins)
        {
            HttpConfiguration      config       = new HttpConfiguration();
            MobileAppConfiguration mobileConfig = new MobileAppConfiguration();

            if (origins == null)
            {
                mobileConfig = mobileConfig.MapLegacyCrossDomainController();
            }
            else
            {
                mobileConfig = mobileConfig.MapLegacyCrossDomainController(origins);
            }

            mobileConfig.ApplyTo(config);

            return(TestServer.Create(appBuilder =>
            {
                appBuilder.UseWebApi(config);
            }));
        }
Exemple #21
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var config       = new HttpConfiguration();
            var mobileConfig = new MobileAppConfiguration();

            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(config);


            //Database.SetInitializer(new MobileServiceInitializer());
            //Database.SetInitializer(new MigrateDatabaseToLatestVersion<MobileServiceContext, Migrations.Configuration>());

            var migrator = new DbMigrator(new Migrations.Configuration());

            migrator.Update();


            app.UseWebApi(config);
        }
Exemple #22
0
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            var httpConfig   = new HttpConfiguration();
            var mobileConfig = new MobileAppConfiguration();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            mobileConfig
            .AddTablesWithEntityFramework()
            .ApplyTo(httpConfig);

            httpConfig.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
#if DEBUG
            Database.SetInitializer(new MobileServiceInitializer());
#else
            var migrator = new DbMigrator(new Migrations.Configuration());
            migrator.Update();
#endif

            MobileAppSettingsDictionary settings = httpConfig.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = httpConfig.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(httpConfig);
        }
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            //var container = new UnityContainer();
            //container.RegisterType<DbContext, EShopeMobileServiceContext>(new HierarchicalLifetimeManager());
            //container.RegisterType<IRepository<Order>, EFRepository<Order>>(new HierarchicalLifetimeManager());

            HttpConfiguration config = new HttpConfiguration();
            //config.DependencyResolver = new UnityResolver(container);
            //config.Formatters.JsonFormatter.SupportedMediaTypes
            //config.EnableSystemDiagnosticsTracing();

            //config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional });

            //config.Routes.MapHttpRoute(
            //name: "ActionApi",
            //routeTemplate: "api/{controller}/{action}/{id}",
            //defaults: new { id = RouteParameter.Optional });

            //config.Services
            //app.Use
            // Swagger
            //SwaggerConfig.Register(config);

            var mobileAppConfiguration = new MobileAppConfiguration();

            mobileAppConfiguration.UseDefaultConfiguration();
            //.AddMobileAppHomeController()             // from the Home package
            //.MapApiControllers()
            //.AddTables(                               // from the Tables package
            //    new MobileAppTableConfiguration()
            //        .MapTableControllers()
            //        .AddEntityFramework()             // from the Entity package
            //    )
            ////.AddPushNotifications()                   // from the Notifications package
            //.MapLegacyCrossDomainController()         // from the CrossDomain package

            //.AddTablesWithEntityFramework()
            //mobileAppConfiguration.MapApiControllers();
            mobileAppConfiguration.ApplyTo(config);

            // Use Entity Framework Code First to create database tables based on your DbContext
            //Database.SetInitializer(new MobileServiceInitializer());

            //var migrator = new DbMigrator(new Migrations.Configuration());
            //migrator.Update();

            MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

            if (string.IsNullOrEmpty(settings.HostName))
            {
                app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
                {
                    // This middleware is intended to be used locally for debugging. By default, HostName will
                    // only have a value when running in an App Service application.
                    SigningKey     = ConfigurationManager.AppSettings["SigningKey"],
                    ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                    ValidIssuers   = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                    TokenHandler   = config.GetAppServiceTokenHandler()
                });
            }

            app.UseWebApi(config);
            SwaggerConfig.Register(config);
        }
Exemple #24
0
        /// <summary>
        /// Configurations the specified application.
        /// </summary>
        /// <param name="app">The application.</param>
        public void Configuration(IAppBuilder app)
        {
            // Create HTTP configuration object
            var httpConfig =
                new HttpConfiguration
            {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
            };

            httpConfig.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            httpConfig.Formatters.JsonFormatter.SerializerSettings.ContractResolver  = new CamelCasePropertyNamesContractResolver();
            httpConfig.Formatters.JsonFormatter.SerializerSettings.Formatting        = Formatting.Indented;
            JsonConvert.DefaultSettings =
                () =>
                new JsonSerializerSettings
            {
                ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
            };

            // Enable swagger support
            SwaggerConfig.Register(httpConfig);

            // Create autofac container (it may need to update the HTTP configuration)
            var builder = new ContainerBuilder();

            builder.RegisterModule(new IocModule(httpConfig));
            var container = builder.Build();

            // Get telemetry client and log
            var telemetryClient = container.Resolve <TelemetryClient>();

            telemetryClient.TrackEvent("Service startup");

            // Setup WEBAPI dependency resolver
            httpConfig.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // Setup mobile application app settings
            var provider = httpConfig.GetMobileAppSettingsProvider();
            var options  = provider.GetMobileAppSettings();

            // Setup mobile app configuration settings
            var mobileAppConfig = new MobileAppConfiguration()
                                  //.MapApiControllers()
                                  .AddMobileAppHomeController()
                                  .AddPushNotifications()
                                  .AddTables(
                new MobileAppTableConfiguration()
                .MapTableControllers()
                .AddEntityFramework());

            mobileAppConfig.ApplyTo(httpConfig);

            // Enable attribute routing for everything else we expose
            httpConfig.MapHttpAttributeRoutes();

            // Hook up autofac webapi controller dependency injection
            app.UseAutofacWebApi(httpConfig);
            app.UseWebApi(httpConfig);

            // Initialise database (including execution of any pending schema migrations)
            Database.SetInitializer(new MobileServiceInitializer());
        }