コード例 #1
0
        public static void Register()
        {
            ConfigOptions options = new ConfigOptions
            {
                PushAuthorization        = AuthorizationLevel.Application,
                DiagnosticsAuthorization = AuthorizationLevel.Anonymous,
            };

            options.LoginProviders.Remove(typeof(AzureActiveDirectoryLoginProvider));
            options.LoginProviders.Add(typeof(AzureActiveDirectoryExtendedLoginProvider));

            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            // Now add any missing connection strings and app settings from the environment.
            // Any envrionment variables found with names that match existing connection
            // string and app setting names will be used to replace the value.
            // This allows the Web.config (which typically would contain secrets) to be
            // checked in, but requires people running the tests to config their environment.
            IServiceSettingsProvider  settingsProvider = config.DependencyResolver.GetServiceSettingsProvider();
            ServiceSettingsDictionary settings         = settingsProvider.GetServiceSettings();
            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];
                }
            }

            // Emulate the auth behavior of the server: default is application unless explicitly set.
            config.Properties["MS_IsHosted"] = true;

            config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;

            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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static void Register()
        {
            // Use this class to set configuration options for your mobile service
            ConfigOptions options = new ConfigOptions();

            // Use this class to set WebAPI configuration options
            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            config.SetIsHosted(true);

            Database.SetInitializer(new alltheairgeadInitializer());

            // Configure automapper to map class elements between EntityFramework model and model used in database
            AutoMapper.Mapper.Initialize(cfg =>
            {
                /*********************************************/
                /* Mapping from database type to client type */
                /*********************************************/
                // Map ExpenseId from database to Id for EntityData
                cfg.CreateMap <Expense, ExpenseDto>()
                .ForMember(dst => dst.Id, map => map.MapFrom(src => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(src.ExpenseId))));
                // Map priority stored as a short in the database to byte in the mobile service
                cfg.CreateMap <Expense, ExpenseDto>()
                .ForMember(dst => dst.Priority, map => map.MapFrom(src => (short)src.Priority));
                // Map category name used in database to id string from EntityFramework
                cfg.CreateMap <Catagory, CategoryDto>()
                .ForMember(dst => dst.Id, map => map.MapFrom(src => src.CategoryName));

                /*********************************************/
                /* Mapping from client type to database type */
                /*********************************************/
                // Map Id from EntityData to ExpenseId for database
                cfg.CreateMap <ExpenseDto, Expense>()
                .ForMember(dst => dst.ExpenseId, map => map.MapFrom(src => MySqlFuncs.LongParse(src.Id)));
                // Map to minimum date for smalldatetime SQL type
                cfg.CreateMap <ExpenseDto, Expense>()
                .ForMember(dst => dst.Time, map => map.MapFrom(src => new DateTime(1900, 1, 1) + ((DateTime)src.Time).TimeOfDay));
                // Map priority stored as a byte in the mobile service to a short in the database
                cfg.CreateMap <ExpenseDto, Expense>()
                .ForMember(dst => dst.Priority, map => map.MapFrom(src => (Byte)src.Priority));
                // Map category id string from EntityFramework to category name used in database
                cfg.CreateMap <CategoryDto, Catagory>()
                .ForMember(dst => dst.CategoryName, map => map.MapFrom(src => src.Id));
            });
        }
コード例 #4
0
        public static void Register()
        {
            // Use this class to set configuration options for your mobile service
            ConfigOptions options = new ConfigOptions();

            // Use this class to set WebAPI configuration options
            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));



            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <UserProfile, UserProfileDTO>()
                .ForMember(up => up.InterestedIn,
                           map => map.MapFrom(y => y.InterestedIn));

                cfg.CreateMap <UserProfileDTO, UserProfile>()
                .ForMember(up => up.InterestedIn,
                           map => map.MapFrom(y => y.InterestedIn));

                cfg.CreateMap <Technology, TechnologyDTO>()
                .ForMember(technologyDTO => technologyDTO.Id,
                           map => map.MapFrom(technology => MySqlFuncs.LTRIM(MySqlFuncs.StringConvert(technology.Id))));



                cfg.CreateMap <TechnologyDTO, Technology>()
                .ForMember(technology => technology.Id, map => map.MapFrom(
                               technologyDTO => MySqlFuncs.IntParse(technologyDTO.Id)));
            });


            // To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            // config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            Database.SetInitializer(new MobileServiceInitializer());
        }