예제 #1
0
 /// <inheritdoc/>
 protected override void AddCustomTypeConverters()
 {
     base.AddCustomTypeConverters();
     if (!TypeConverterRegistrar.TryRegisterAttribute <Gdk.Point, GdkPointConverter>())
     {
         ApplicationLogger.RecordDebugTraceMessage($"Failed to register type converter for: {typeof(Gdk.Point)}");
     }
     if (!TypeConverterRegistrar.TryRegisterAttribute <Gdk.Size, GdkSizeConverter>())
     {
         ApplicationLogger.RecordDebugTraceMessage($"Failed to register type converter for: {typeof(Gdk.Size)}");
     }
     AddCustomTypeConverter(typeof(Gdk.WindowState), TypeDescriptor.GetConverter(typeof(Gdk.WindowState)));
     AddCustomTypeConverter(typeof(Gdk.Point), TypeDescriptor.GetConverter(typeof(Gdk.Point)));
     AddCustomTypeConverter(typeof(Gdk.Size), TypeDescriptor.GetConverter(typeof(Gdk.Size)));
     AddCustomTypeConverter(typeof(SearchDirectories), TypeDescriptor.GetConverter(typeof(SearchDirectories)));
 }
예제 #2
0
 public void BeforeTest()
 {
     TypeConverterRegistrar.Initialize();
 }
        /// <summary>
        /// Adds Localization services to the <see cref="IServiceCollection"/>. and AddAutoMapper
        /// </summary>
        /// <param name="services"></param>
        /// <param name="options"></param>
        /// <param name="configAction"></param>
        /// <param name="assemblies"></param>
        /// <returns></returns>
        public static IServiceCollection AddNopLocalization(this IServiceCollection services, Action <LocalizationOptions> configureOptions,
                                                            Action <IServiceProvider, IMapperConfigurationExpression> configAction, params Assembly[] assemblies)
        {
            var localizationOptions = new LocalizationOptions();

            configureOptions(localizationOptions);
            services.Configure(configureOptions);

            services.Configure <RequestLocalizationOptions>(options =>
            {
                localizationOptions.DefaultLanguage.NotNull(nameof(localizationOptions.DefaultLanguage));
                localizationOptions.OtherLanguages.NotNull(nameof(localizationOptions.OtherLanguages));

                var supportedCultures = localizationOptions.OtherLanguages.Concat(new[] { localizationOptions.DefaultLanguage })
                                        .Select(i => new CultureInfo(i)).ToList();

                options.DefaultRequestCulture = new RequestCulture(localizationOptions.DefaultLanguage);
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;

                //options.RequestCultureProviders.Clear();
                //var requestProvider = new RouteDataRequestCultureProvider() { Options = options };

                var requestProvider = new RouteSegmentRequestCultureProvider()
                {
                    Options = options, CultureSegmentIndex = localizationOptions.CultureSegmentIndex
                };
                options.RequestCultureProviders.Insert(0, requestProvider);

                localizationOptions.ConfigureRequestLocalizationOptions?.Invoke(options);
            });

            services.Configure <RouteOptions>(options =>
            {
                options.ConstraintMap.Add("culture", typeof(CultureRouteConstraint));
            });

            services.AddLocalization(opt => opt.ResourcesPath = "Resources");

            switch (localizationOptions.CacheMode)
            {
            case CacheMode.MemoryCache:
                services.AddMemoryCacheManager();
                break;

            case CacheMode.RedisCacheWithProtoBuf:
                services.AddRedisWithProtoBufCacheManager();
                break;
            }

            TypeConverterRegistrar.RegisterTypeConverters();

            services.AddServices();

            services.AddAutoMapper((serviceProvider, mapperConfigExpression) =>
            {
                mapperConfigExpression.AddProfile(new MappingProfile(assemblies));
                //mapperConfigExpression.ValidateInlineMaps = false;
                //mapperConfigExpression.CreateMissingTypeMaps = true;

                configAction?.Invoke(serviceProvider, mapperConfigExpression);
            }, assemblies);

            return(services);
        }