Exemplo n.º 1
0
        public void GetCultureTabFromValueTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("fr-CH", cultures.GetCultureTab("c=fr-CH|uic=en-GB"));
            Assert.Equal("fr-CH", cultures.GetCultureTab("culture=fr-CH&ui-culture=en-GB", false));
        }
Exemplo n.º 2
0
        private void InitialiseSettingsFromCookies()
        {
            var cookies = new MxCookies(_httpContextAccessor);

            SelectedCultureTab     = _supportedCultures.GetCultureTab(cookies.GetValue(MxSupportedCultures.CookieName));
            SelectedTimeZone       = _supportedTimeZones.GetTimeZoneAcronym(cookies.GetValue(MxSupportedTimeZones.CookieName));
            WithoutDaylightSavings = _supportedTimeZones.IsDaylightSavingAuto(cookies.GetValue(MxSupportedTimeZones.CookieName));
            SelectedTzDbName       = _supportedTimeZones.GetTzDbName(SelectedTimeZone);
        }
Exemplo n.º 3
0
        public void GetCultureTabFromValueFailTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("en-GB", cultures.GetCultureTab(""));
            Assert.Equal("en-GB", cultures.GetCultureTab(null));

            Assert.Equal("en-GB", cultures.GetCultureTab("cx=fr-CH£uic=en-GB"));
            Assert.Equal("en-GB", cultures.GetCultureTab("cx=fr-CH|uic=en-GB"));
            Assert.Equal("en-GB", cultures.GetCultureTab("c="));
            Assert.Equal("en-GB", cultures.GetCultureTab("c=fr-CH x|uic=en-GB"));
            Assert.Equal("en-GB", cultures.GetCultureTab("cx=fr-CH|uic=en-GB"));
            Assert.Equal("en-GB", cultures.GetCultureTab("uic=en-GB"));
        }
Exemplo n.º 4
0
        public IViewComponentResult Invoke()
        {
            string text;

            try
            {
                var cookies = new MxCookies(_httpContextAccessor);

                var value                 = cookies.GetValue(MxSupportedTimeZones.CookieName);
                var timeZoneAcronym       = _supportedTimeZones.GetTimeZoneAcronym(value);
                var withoutDaylightSaving = (!_supportedTimeZones.IsDaylightSavingAuto(value));
                if (withoutDaylightSaving)
                {
                    text = timeZoneAcronym;
                }
                else
                {
                    DateTimeZone zone = DateTimeZoneProviders.Tzdb[_supportedTimeZones.GetTzDbName(timeZoneAcronym)];
                    var          daylightSavingNow = zone.IsDaylightSavingsTime(SystemClock.Instance.GetCurrentInstant());
                    text = (daylightSavingNow) ? _supportedTimeZones.GetDaylightSavingAcronym(timeZoneAcronym) : timeZoneAcronym;
                }

                value = cookies.GetValue(MxSupportedCultures.CookieName);
                var culture   = _supportedCultures.GetCultureTab(value);
                var uiCulture = _supportedCultures.GetUiCultureTab(value);
                text += ",c=";
                text += culture;
                text += "|uic=";
                text += uiCulture;

                // Thread.CurrentThread.CurrentCulture = supportedCultures.GetCultureInfo(culture);
                // Thread.CurrentThread.CurrentUICulture = supportedCultures.GetCultureInfo(uiCulture);
            }
            catch (Exception e)
            {
                // ReSharper disable once RedundantAssignment
                text = e.Message;
                text = "[error]";
            }
            return(View("Default", text));
        }