コード例 #1
0
        // NOT USED CURRENTLY
        public ActionResult SetCulture(string culture)
        {
            // Validate input
            culture = CultureHelpers.GetSupported(culture);

            // Save culture in a cookie
            HttpCookie cookie = Request.Cookies["accept-language"];

            if (cookie != null)
            {
                cookie.Value = culture;   // update cookie value
            }
            else
            {
                cookie = new HttpCookie("accept-language")
                {
                    Value   = culture,
                    Expires = DateTime.Now.AddYears(1),
                }
            };

            Response.Cookies.Add(cookie);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <ActionResult> Login(LoginUserViewModel details, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var jwtToken = await _authorizationServerManager.GetTokenAsync(details.Name, details.Password);

                if (jwtToken == string.Empty)
                {
                    ModelState.AddModelError(string.Empty, LanguageSummary.LoginError);
                }
                else
                {
                    var ident = _authorizationServerManager.GetClaimsIdentity(jwtToken);

                    GetAuthenticationManager().SignOut();
                    GetAuthenticationManager().SignIn(new AuthenticationProperties {
                        IsPersistent = false
                    }, ident);

                    if (returnUrl.IsEmpty())
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    var language = ident.FindFirst(ClaimTypes.Locality).Value;

                    returnUrl = CultureHelpers.ChangeCulture(returnUrl, language);

                    return(Redirect(returnUrl));
                }
            }

            ViewBag.returnUrl = returnUrl;
            return(View(details));
        }
コード例 #3
0
        public ActionResult ChangeCulture(string cultureValue)
        {
            var oldPath = Request.UrlReferrer?.PathAndQuery;
            var newPath = CultureHelpers.ChangeCulture(oldPath, cultureValue);

            return(Redirect(newPath));
        }
コード例 #4
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            string culture = null, uiCulture = null;

            // attempt to read the culture cookie from Request
            HttpCookie cultureCookie = Request.Cookies["accept-language"];

            if (cultureCookie != null)
            {
                string lang = cultureCookie.Value;
                if (CultureHelpers.IsValid(lang))
                {
                    culture = lang;
                }
                //uiCulture = CultureHelpers.GetSupported(lang);
                uiCulture = lang;
            }

            // fallback to browser preferred culture
            if ((culture == null || uiCulture == null) &&
                Request.UserLanguages != null &&
                Request.UserLanguages.Length > 0)
            {
                foreach (string lang in Request.UserLanguages)
                {
                    if (culture == null && CultureHelpers.IsValid(lang))
                    {
                        culture = lang;
                    }

                    if (uiCulture == null)
                    {
                        //uiCulture = CultureHelpers.GetSupported(lang);
                        uiCulture = lang;
                    }


                    if (culture != null && uiCulture != null)
                    {
                        break;
                    }
                }
            }

            // set current thread culture if any
            CultureHelpers.SetCurrentCulture(culture);       // locale
            CultureHelpers.SetCurrentUICulture(uiCulture);   // resource manager

            // execute controller
            return(base.BeginExecuteCore(callback, state));
        }
コード例 #5
0
        private IEnumerable <SelectListItem> GetAvailableLanguages(string cultureName)
        {
            var rm              = new ResourceManager(typeof(AppResource));
            var cultures        = CultureHelpers.GetImplementedCultures(rm);
            var selectedCulture = CultureHelpers.GetImplementedCulture(rm, cultureName);
            var result          = cultures.Select(i => new SelectListItem
            {
                Value    = i.Name,
                Text     = rm.GetLocalizeString("Language", i) ?? i.TextInfo.ToTitleCase(i.NativeName),
                Selected = i.Equals(selectedCulture)
            });

            return(result);
        }
コード例 #6
0
        public ActionResult ChangeLanguage(string language)
        {
            var result = new JsonResult();

            result.Data = new
            {
                status = "Success"
            };

            CultureHelpers.SetCurrentCulture(language);     // locale
            CultureHelpers.SetCurrentUICulture(language);   // resource manager

            HttpCookie cookie = new HttpCookie("accept-language", language);

            Response.Cookies.Add(cookie);

            return(Redirect(Request.UrlReferrer.ToString()));
        }
コード例 #7
0
        public HttpContext PostAction(XmlDbUpdateRecordedAction recordedAction, string backendUrl, int userId, bool useGuidSubstitution, IServiceProvider provider = null)
        {
            Ensure.NotNull(QPConnectionScope.Current.DbConnection, "QPConnection scope should be initialized to use fake mvc context");
            var urlParts = recordedAction.BackendAction.ControllerActionUrl.Split(@"/".ToCharArray())
                           .Where(n => !string.IsNullOrEmpty(n) && n != "~").ToArray();
            var controller = urlParts[0];
            var action     = urlParts[1];

            BackendActionContext.ResetCurrent();

            var cultureInfo = CultureHelpers.GetCultureByLcid(recordedAction.Lcid);

            CultureInfo.CurrentCulture = cultureInfo;

            var httpContext = XmlDbUpdateHttpContextHelpers.BuildHttpContext(recordedAction, backendUrl, userId, useGuidSubstitution);
            var routeData   = XmlDbUpdateHttpContextHelpers.GetRouteData(recordedAction, controller, action);

            httpContext.Features[typeof(IRoutingFeature)] = new RoutingFeature {
                RouteData = routeData
            };
            var routeContext = new RouteContext(httpContext)
            {
                RouteData = routeData
            };

            var serviceProvider = provider ?? new HttpContextAccessor().HttpContext.RequestServices;

            httpContext.RequestServices = serviceProvider;
            var m       = typeof(DynamicRouteValueTransformer).Assembly.GetType("Microsoft.AspNetCore.Mvc.Routing.MvcRouteHandler");
            var handler = (IRouter)serviceProvider.GetRequiredService(m);

            QPContext.CurrentUserId = userId;
            Task.Run(async() =>
            {
                await handler.RouteAsync(routeContext);
                await routeContext.Handler(routeContext.HttpContext);
            }).Wait();
            QPContext.CurrentUserId = 0;

            return(httpContext);
        }
コード例 #8
0
        protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
        {
            string cultureName = null;

            HttpCookie cultureCookie = Request.Cookies["_culture"];

            if (cultureCookie != null)
            {
                cultureName = cultureCookie.Value;
            }
            else
            {
                cultureName = Request.UserLanguages != null && Request.UserLanguages.Length > 0 ? Request.UserLanguages[0] : null;
            }

            var rm = new ResourceManager(typeof(AppResource));

            cultureName = CultureHelpers.GetImplementedCulture(rm, cultureName).Name;

            Thread.CurrentThread.CurrentCulture   = new CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            return(base.BeginExecuteCore(callback, state));
        }
コード例 #9
0
ファイル: BasePage.cs プロジェクト: usabox/MobileSystemApi
 protected string GetTranslation(string key, string fileName = "")
 {
     return(CultureHelpers.GetTranslation(key,
                                          string.IsNullOrEmpty(Language) ? LanguageHelpers.SelectedLanguage : Language,
                                          string.Format("contents/{0}", string.IsNullOrEmpty(fileName) ? "translations" : fileName)));
 }
コード例 #10
0
ファイル: Global.cs プロジェクト: QuantumArt/QP.Quantumart
        public static void RemoveContentIfExists(int contentId)
        {
            if (contentId > 0)
            {
                ReplayDynamicXml(
                    $@"<?xml version=""1.0"" encoding=""utf-8""?>
<actions backendUrl=""http://mscdev02:90/Backend/"" dbVersion=""7.9.9.0"">
  <action code=""simple_remove_content"" ids=""{contentId}"" parentId=""35"" lcid=""{Lcid}"" executed=""{DateTime.Now.ToString(CultureHelpers.GetCultureByLcid(Lcid))}"" executedBy=""AuthorProxy"" />
</actions>
");
            }
        }
コード例 #11
0
ファイル: Global.cs プロジェクト: QuantumArt/QP.Quantumart
        public static void RemoveArticlesIfExists(int[] articleIds, int contentId)
        {
            ReplayDynamicXml(
                $@"<?xml version=""1.0"" encoding=""utf-8""?>
<actions backendUrl=""http://mscdev02:90/Backend/"" dbVersion=""7.9.9.0"">
  <action code=""multiple_remove_article"" ids=""{string.Join(",", articleIds)}"" parentId=""{contentId}"" lcid=""{Lcid}"" executed=""{DateTime.Now.ToString(CultureHelpers.GetCultureByLcid(Lcid))}"" executedBy=""AuthorProxy"" />
</actions>
");
        }
コード例 #12
0
        internal static XDocument SerializeAction(XmlDbUpdateRecordedAction action, string currentDbVersion, string backendUrl, bool withoutRoot)
        {
            var actionAlement = new XElement(XmlDbUpdateXDocumentConstants.ActionElement,
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionCodeAttribute, action.Code),
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionIdsAttribute, string.Join(",", action.Ids)),
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionParentIdAttribute, action.ParentId),
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionLcidAttribute, action.Lcid),
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionExecutedAttribute, action.Executed.ToString(CultureHelpers.GetCultureByLcid(action.Lcid))),
                                             new XAttribute(XmlDbUpdateXDocumentConstants.ActionExecutedByAttribute, action.ExecutedBy),
                                             GetEntitySpecificAttributesForPersisting(action),
                                             GetActionChildElements(action.Form));

            if (!withoutRoot)
            {
                var root = GetOrCreateRoot(backendUrl, currentDbVersion);
                root.Add(actionAlement);
                return(root.Document);
            }

            return(new XDocument(actionAlement).Document);
        }
コード例 #13
0
        public HttpContextBase PostAction(XmlDbUpdateRecordedAction recordedAction, string backendUrl, int userId, bool useGuidSubstitution)
        {
            Ensure.NotNull(QPConnectionScope.Current.DbConnection, "QPConnection scope should be initialized to use fake mvc context");
            var urlParts         = recordedAction.BackendAction.ControllerActionUrl.Split(@"/".ToCharArray()).Where(n => !string.IsNullOrEmpty(n) && n != "~").ToArray();
            var controllerName   = urlParts[0];
            var controllerAction = urlParts[1];
            var requestContext   = new RequestContext(
                XmlDbUpdateHttpContextHelpers.BuildHttpContextBase(recordedAction, backendUrl, userId, useGuidSubstitution),
                XmlDbUpdateHttpContextHelpers.GetRouteData(recordedAction, controllerName, controllerAction)
                );

            BackendActionContext.ResetCurrent();
            XmlDbUpdateHttpContextHelpers.BuildController(requestContext, controllerName, CultureHelpers.GetCultureByLcid(recordedAction.Lcid)).Execute(requestContext);
            return(requestContext.HttpContext);
        }