public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); 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); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); // Configure the Azure Mobile Apps section new MobileAppConfiguration() .AddTables( new MobileAppTableConfiguration() .MapTableControllers() .AddEntityFramework()) .MapApiControllers() //.AddPushNotifications() .ApplyTo(config); // Initialize the database with EF Code First //Database.SetInitializer(new AzureMobileInitializer()); Database.SetInitializer <MyDbContext>(null); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } // Link the Web API into the configuration app.UseWebApi(config); }
public static void ConfigureMobileApp(IAppBuilder app) { var config = new HttpConfiguration(); config.EnableSystemDiagnosticsTracing(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; config.MapHttpAttributeRoutes(); #pragma warning disable 618 new MobileAppConfiguration() .UseDefaultConfiguration() .AddPushNotifications() .ApplyTo(config); #pragma warning restore 618 var cors = new EnableCorsAttribute("http://localhost:1076", "*", "*"); config.EnableCors(cors); IMobileAppSettingsProvider settingsProvider = config.GetMobileAppSettingsProvider(); MobileAppSettingsDictionary settings = settingsProvider.GetMobileAppSettings(); IDictionary environmentVariables = Environment.GetEnvironmentVariables(); foreach (var conKey in settings.Connections.Keys.ToArray()) { var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == conKey); if (!string.IsNullOrEmpty(envKey)) { settings.Connections[conKey].ConnectionString = (string)environmentVariables[envKey]; } } foreach (var setKey in settings.Keys.ToArray()) { var envKey = environmentVariables.Keys.OfType <string>().FirstOrDefault(p => p == setKey); if (!string.IsNullOrEmpty(envKey)) { settings[setKey] = (string)environmentVariables[envKey]; } } Mapper.Initialize(cfg => { cfg.CreateMap <IntIdRoundTripTableItem, IntIdRoundTripTableItemDto>() .ForMember(dto => dto.Id, map => map.MapFrom(db => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(db.Id)))); cfg.CreateMap <IntIdRoundTripTableItemDto, IntIdRoundTripTableItem>() .ForMember(db => db.Id, map => map.MapFrom(dto => MySqlFuncs.LongParse(dto.Id))); cfg.CreateMap <IntIdMovie, IntIdMovieDto>() .ForMember(dto => dto.Id, map => map.MapFrom(db => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(db.Id)))); cfg.CreateMap <IntIdMovieDto, IntIdMovie>() .ForMember(db => db.Id, map => map.MapFrom(dto => MySqlFuncs.LongParse(dto.Id))); }); Database.SetInitializer(new DbInitializer()); // Uncomment for local debugging // app.UseAppServiceAuthentication(config, AppServiceAuthenticationMode.LocalOnly); app.UseWebApi(config); app.UseStageMarker(PipelineStage.MapHandler); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration().UseDefaultConfiguration().ApplyTo(config); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); bool flag = string.IsNullOrEmpty(settings.HostName); if (flag) { app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new string[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new string[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } app.UseWebApi(config); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); Database.SetInitializer(new MigrateDatabaseToLatestVersion <telerikerpContext, telerikerpService.Migrations.Configuration>()); 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); }
public MobileAppSettingsDictionaryExtensionsTests() { this.settings = new MobileAppSettingsDictionary(); this.settingsProviderMock = new Mock<IMobileAppSettingsProvider>(); this.settingsProviderMock.Setup(p => p.GetMobileAppSettings()) .Returns(this.settings); }
public static void ConfigureMobileApp(IAppBuilder app, HttpConfiguration config) { new MobileAppConfiguration() .UseDefaultConfiguration() .MapApiControllers() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new DeviceSpecificAppServerInitializer()); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } app.UseWebApi(config); }
// POST tables/User public async Task <IHttpActionResult> PostUser(User item) { User current = await InsertAsync(item); HttpConfiguration config = this.Configuration; MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName, true); Dictionary <string, string> templateParams = new Dictionary <string, string>(); templateParams["messageParam"] = item.Username + " was added to the list."; try { // Send the push notification and log the results. var result = await hub.SendTemplateNotificationAsync(templateParams); // Write the success result to the logs. config.Services.GetTraceWriter().Info(result.State.ToString()); } catch (System.Exception ex) { // Write the failure result to the logs. config.Services.GetTraceWriter() .Error(ex.Message, null, "Push.SendAsync Error"); } return(CreatedAtRoute("Tables", new { id = current.Id }, current)); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; new MobileAppConfiguration() .AddTablesWithEntityFramework() .MapApiControllers() .ApplyTo(config); // Map routes by attribute config.MapHttpAttributeRoutes(); // 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 { 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) { var config = new HttpConfiguration(); new MobileAppConfiguration() .AddTablesWithEntityFramework() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new MobileServiceInitializer()); #if LOCAL_DEVELOPMENT // This is only used for local development environments that wish to validate tokens provided by // App Service Authentication. You don't need this code in production when running on Azure App Service. 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() }); } #endif app.UseWebApi(config); }
private async Task <IEnumerable <Device> > GetDevices() { MobileAppSettingsDictionary settings = Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); int maxDevices = int.Parse(settings["MaxDevices"]); return(await registryManager.GetDevicesAsync(maxDevices)); }
// POST tables/TodoItem public async Task <IHttpActionResult> PostTodoItem(TodoItem item) { TodoItem current = await InsertAsync(item); HttpConfiguration config = this.Configuration; MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); Dictionary <string, string> templateParams = new Dictionary <string, string>(); templateParams["messageParam"] = item.Text + " was added to the list"; try { var result = await hub.SendTemplateNotificationAsync(templateParams); config.Services.GetTraceWriter().Info(result.State.ToString()); } catch { } return(CreatedAtRoute("Tables", new { id = current.Id }, current)); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute("XamarinAuthProvider", ".auth/login/xamarin", new { controller = "XamarinAuth" }); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new UtahOpenSourceContextInitializer()); // To prevent Entity Framework from modifying your database schema, use a null database initializer // Database.SetInitializer(null); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); // 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. if (string.IsNullOrEmpty(settings.HostName)) { app.UseAppServiceAuthentication(new Microsoft.Azure.Mobile.Server.Authentication.AppServiceAuthenticationOptions { }); } app.UseWebApi(config); }
private async Task SentPushNotificationAsync(ToDoItem item) { HttpConfiguration config = this.Configuration; MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); Dictionary <string, string> templateParams = new Dictionary <string, string> { ["messageParam"] = item.TaskName + " was added to the list." }; try { // Send the push notification and log the results. var result = await hub.SendTemplateNotificationAsync(templateParams); // Write the success result to the logs. config.Services.GetTraceWriter().Info(result.State.ToString()); } catch (System.Exception ex) { // Write the failure result to the logs. config.Services.GetTraceWriter() .Error(ex.Message, null, "Push.SendAsync Error"); } }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); new MobileAppConfiguration() .AddTablesWithEntityFramework() .ApplyTo(config); config.MapHttpAttributeRoutes(); Database.SetInitializer(new MobileServiceInitializer()); #region Local Development Settings MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { SigningKey = ConfigurationManager.AppSettings["SigningKey"], ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, TokenHandler = config.GetAppServiceTokenHandler() }); } #endregion app.UseWebApi(config); }
// GET api/values public string Get() { MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); ITraceWriter traceWriter = this.Configuration.Services.GetTraceWriter(); string host = settings.HostName ?? "localhost"; string greeting = "Hello from " + host; EabcMobileAppContext context = new EabcMobileAppContext(); try { var item = context.PrayerRequestModels.FirstOrDefault(); if (item != null) { greeting = item.Request; } } catch (Exception e) { greeting = e.ToString(); } traceWriter.Info(greeting); return(greeting); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext //var migrator = new DbMigrator(new MyDiary.Migrations.Configuration()); //migrator.Update(); 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); config.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include; config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include; }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#custom-auth config.Routes.MapHttpRoute("SandboxAuthProvider", ".auth/login/sandbox", new { controller = "SandboxAuth" }); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .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); }
private void SetHubClient(out HttpConfiguration config, out NotificationHubClient hub) { string notificationHubName; string notificationHubConnection; // Get the settings for the server project. config = this.Configuration; MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { notificationHubName = "notification-hub-17"; notificationHubConnection = "Endpoint=sb://ns-notification-hub-17.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=7JgMPUZd4coxOv17V0gGQ5Pyd62adkc8Uw5Sa5Kc0XY="; } else { // Get the Notification Hubs credentials for the Mobile App. notificationHubName = settings.NotificationHubName; notificationHubConnection = settings .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; } // Create a new Notification Hub client. hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); }
// POST tables/TodoItem public async Task <IHttpActionResult> PostTodoItem(TodoItem item) { var asparams = new AzureStorageParams { ContainerName = item.ContainerName, ResourceName = item.ResourceName }; await SetTodoItemForImageUpload(asparams); item.SasQueryString = asparams.SasQueryString; item.AzureImageUri = asparams.AzureImageUri; item.ImageUploadPending = false; // Complete the insert operation. TodoItem current = await InsertAsync(item); // get Notification Hubs credentials associated with this Mobile App MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; // connect to notification hub NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); // windows payload var windowsToastPayload = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + item.Title + @"</text></binding></visual></toast>"; await Hub.SendWindowsNativeNotificationAsync(windowsToastPayload); return(CreatedAtRoute("Tables", new { id = current.Id }, current)); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new 20533D 0502MobileAppInitializer ()); // To prevent Entity Framework from modifying your database schema, use a null database initializer // Database.SetInitializer<20533D0502MobileAppContext>(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); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); config.MapHttpAttributeRoutes(); 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 config = new HttpConfiguration(); new MobileAppConfiguration() .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 config = new HttpConfiguration(); new MobileAppConfiguration() .AddTablesWithEntityFramework() .ApplyTo(config); // Map routes by attribute config.MapHttpAttributeRoutes(); // Automatic Code First Migrations var migrator = new DbMigrator(new Migrations.Configuration()); migrator.Update(); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); if (string.IsNullOrEmpty(settings.HostName)) { app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions { 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); }
/// <summary> /// Initializes the <see cref="MobileAppSettingsDictionary"/> provided in response to <see cref="M:GetMobileAppSettings"/>. /// </summary> /// <returns>A fully initialized <see cref="MobileAppSettingsDictionary"/>.</returns> protected virtual MobileAppSettingsDictionary InitializeSettings() { MobileAppSettingsDictionary settings = new MobileAppSettingsDictionary(); NameValueCollection appSettings = this.GetAppSettings(); foreach (string key in appSettings.AllKeys) { settings[key] = appSettings[key]; } string value = null; if (string.IsNullOrEmpty(settings.HostName)) { // Get the host name for the site from the Antares WEBSITE_HOSTNAME environment variable. value = Environment.GetEnvironmentVariable(WebsiteHostNameEnvironmentVariableName); if (!string.IsNullOrEmpty(value)) { settings.HostName = value.Trim(); } } ConnectionStringSettingsCollection connectionSettings = ConfigurationManager.ConnectionStrings; foreach (ConnectionStringSettings connectionSetting in connectionSettings) { settings.Connections.Add(connectionSetting.Name, new ConnectionSettings(connectionSetting.Name, connectionSetting.ConnectionString) { Provider = connectionSetting.ProviderName }); } if (string.IsNullOrEmpty(settings.SubscriptionId)) { // Parse the subscription ID out of the Antares WEBSITE_OWNER_NAME environment variable. // This value is of the form "de6db429-0822-4034-8456-fccf4deb3841+MyTestRG3-EastUSwebspace" value = Environment.GetEnvironmentVariable(WebsiteOwnerEnvironmentVariableName); if (!string.IsNullOrEmpty(value)) { int idx = value.IndexOf("+", StringComparison.OrdinalIgnoreCase); if (idx != -1) { string subscriptionId = value.Substring(0, idx); settings.SubscriptionId = subscriptionId; } } } if (string.IsNullOrEmpty(settings.SigningKey)) { // Parse the signing key from environment variables, since it was not found in app settings value = Environment.GetEnvironmentVariable(MobileAppSettingsKeys.WebsiteAuthSigningKey); if (!string.IsNullOrEmpty(value)) { settings.SigningKey = value.Trim(); } } return settings; }
public NotificationsProvider() { MobileAppSettingsDictionary settings = Startup.Config.GetMobileAppSettingsProvider().GetMobileAppSettings(); var notificationHubName = settings.NotificationHubName; var notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); }
public static void Configure(IAppBuilder app, HttpConfiguration config) { new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); }
// GET api/telemetry public string Get() { MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string host = settings.HostName ?? "localhost"; string greeting = $"Hello {host}. You are currently connected to Mission Control"; return(greeting); }
// GET api/values public string Get() { MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); //ITraceWriter traceWriter = this.Configuration.Services.GetTraceWriter(); //traceWriter.Info("Hello from " + settings.Name); return("Hello World!"); }
public static void ConfigureMobileApp(IAppBuilder app) { HttpConfiguration config = new HttpConfiguration(); //For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686 config.EnableSystemDiagnosticsTracing(); new MobileAppConfiguration() .UseDefaultConfiguration() .ApplyTo(config); // Use Entity Framework Code First to create database tables based on your DbContext Database.SetInitializer(new ZUMOAPPNAMEInitializer()); // To prevent Entity Framework from modifying your database schema, use a null database initializer Database.SetInitializer <ZUMOAPPNAMEContext>(null); //^^^THis used to be commented. Uncommenting it made the change of database fields work. See: /* * https://social.msdn.microsoft.com/Forums/en-US/186460c0-0bf4-41ed-989e-c5aa1b2c21f8/inserting-record-into-table-error-cannot-insert-the-value-null-into-column-createdat?forum=azuremobile * * To change data type: * * DROP TABLE [dbo].[TodoItems]; * CREATE TABLE [dbo].[TodoItems]( * Id nvarchar(4000) PRIMARY KEY, * Text nvarchar(4000) null, * Complete bit not null, * Version timestamp not null, * CreatedAt datetimeoffset not null, * UpdatedAt datetimeoffset null, * Deleted bit not null, * Name nvarchar(512) null * ); * DROP TABLE [dbo].[TodoItems]; * * Then uncomment the null line, change data type in TodoItem.cs and its all gucci. * * It worked on Android but added significant latency. */ 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); }
public static async Task <string> SaveBinaryToAzureStorage(MobileAppSettingsDictionary settings, string blobId, string blobData) { string storageAccountName; string storageAccountKey; // Try to get the Azure storage account token from app settings. if (!(settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) | settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey))) { return(string.Empty); } // Set the URI for the Blob Storage service. Uri blobEndpoint = new Uri(string.Format("https://{0}.blob.core.windows.net", storageAccountName)); // Create the BLOB service client. CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentials(storageAccountName, storageAccountKey)); string ContainerName = "beerdrinkinimages"; // Create a container, if it doesn't already exist. CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); await container.CreateIfNotExistsAsync(); // Create a shared access permission policy. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Enable anonymous read access to BLOBs. containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob; container.SetPermissions(containerPermissions); // Define a policy that gives write access to the container for 1 minute. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTime.UtcNow, SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1), Permissions = SharedAccessBlobPermissions.Write }; // Get the SAS as a string. var SasQueryString = container.GetSharedAccessSignature(sasPolicy); // Set the URL used to store the image. var avatarUri = string.Format("{0}{1}/{2}", blobEndpoint.ToString(), ContainerName, blobId.ToLower()); // Upload the new image as a BLOB from the string. CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(blobId.ToLower()); blobFromSASCredential.UploadTextAsync(blobData); return(avatarUri); }
public static async Task<string> SaveBinaryToAzureStorage(MobileAppSettingsDictionary settings, string blobId, string blobData ) { string storageAccountName; string storageAccountKey; // Try to get the Azure storage account token from app settings. if (!(settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) | settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey))) { return string.Empty; } // Set the URI for the Blob Storage service. Uri blobEndpoint = new Uri(string.Format("https://{0}.blob.core.windows.net", storageAccountName)); // Create the BLOB service client. CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentials(storageAccountName, storageAccountKey)); string ContainerName = "beerdrinkinimages"; // Create a container, if it doesn't already exist. CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); await container.CreateIfNotExistsAsync(); // Create a shared access permission policy. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Enable anonymous read access to BLOBs. containerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob; container.SetPermissions(containerPermissions); // Define a policy that gives write access to the container for 1 minute. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTime.UtcNow, SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1), Permissions = SharedAccessBlobPermissions.Write }; // Get the SAS as a string. var SasQueryString = container.GetSharedAccessSignature(sasPolicy); // Set the URL used to store the image. var avatarUri = string.Format("{0}{1}/{2}", blobEndpoint.ToString(), ContainerName, blobId.ToLower()); // Upload the new image as a BLOB from the string. CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(blobId.ToLower()); blobFromSASCredential.UploadTextAsync(blobData); return avatarUri; }
public PushClientTests() { this.settings = new MobileAppSettingsDictionary(); this.settingsProviderMock = new Mock<IMobileAppSettingsProvider>(); this.settingsProviderMock.Setup(p => p.GetMobileAppSettings()) .Returns(this.settings); this.config = new HttpConfiguration(); this.config.SetMobileAppSettingsProvider(this.settingsProviderMock.Object); this.clientMock = new Mock<PushClient>(this.config) { CallBase = true }; this.client = this.clientMock.Object; }
public MobileAppAppBuilderExtensionTests() { this.config = new HttpConfiguration(); this.settingsProviderMock = new Mock<IMobileAppSettingsProvider>(); this.settings = new MobileAppSettingsDictionary(); this.settingsProviderMock.Setup(s => s.GetMobileAppSettings()) .Returns(this.settings); this.config.SetMobileAppSettingsProvider(this.settingsProviderMock.Object); this.appBuilderMock = new Mock<IAppBuilder>(); this.appBuilder = this.appBuilderMock.Object; }
public static bool InsureBreweryDbIsInitialized(MobileAppSettingsDictionary appSettings, ITraceWriter logger) { settings = appSettings; tracer = logger; if (string.IsNullOrEmpty(BreweryDB.BreweryDBClient.ApplicationKey)) { string apiKey; // Try to get the BreweryDB API key app settings. if (!(settings.TryGetValue("BREWERYDB_API_KEY", out apiKey))) { tracer.Error("Could not retrieve BreweryDB API key."); return false; } tracer.Info($"BreweryDB API Key {apiKey}"); BreweryDB.BreweryDBClient.Initialize(apiKey); } return true; }
public BarcodeController() { settings = Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); tracer = Configuration.Services.GetTraceWriter(); }
public UserPrivateDataController() { settings = Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); tracer = Configuration.Services.GetTraceWriter(); }