示例#1
0
 public void HandleEvent(IRequestHandler requestHandler, Form form)
 {
     foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
     {
         requestHandler.HttpContext.RequestServices.GetService <ICache>().RemoveFormViewComponentResult(form.Code, culture.Code);
     }
 }
示例#2
0
        public void HandleEvent(IRequestHandler requestHandler, Object @object)
        {
            string urlPropertyStringValue = string.Format("/{0}", new ObjectManager(requestHandler).GetUrlPropertyStringValue(@object));

            foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
            {
                requestHandler.HttpContext.RequestServices.GetService <ICache>().RemovePageActionResult(urlPropertyStringValue, culture.Code);
            }
        }
        private bool CheckCulture(string cultureCode)
        {
            IStorage storage = this.serviceProvider.GetService <IStorage>();

            if (CultureManager.GetNotNeutralCultures(storage).Count() == 0)
            {
                return(cultureCode == DefaultCulture.Code);
            }

            return(CultureManager.GetNotNeutralCultures(storage).Any(c => c.Code == cultureCode));
        }
示例#4
0
        public void Execute(IApplicationBuilder applicationBuilder, IServiceProvider serviceProvider)
        {
            RequestLocalizationOptions requestLocalizationOptions = new RequestLocalizationOptions();
            IStorage storage = serviceProvider.GetService <IStorage>();

            if (storage == null)
            {
                requestLocalizationOptions.DefaultRequestCulture = new RequestCulture(DefaultCulture.Code);
                requestLocalizationOptions.SupportedCultures     = requestLocalizationOptions.SupportedUICultures =
                    new CultureInfo[] { new CultureInfo(DefaultCulture.Code) }.ToList();
            }

            else
            {
                Culture defaultCulture = CultureManager.GetDefaultCulture(storage);

                if (defaultCulture == null)
                {
                    requestLocalizationOptions.DefaultRequestCulture = new RequestCulture(DefaultCulture.Code);
                }

                else
                {
                    requestLocalizationOptions.DefaultRequestCulture = new RequestCulture(defaultCulture.Code);
                }

                if (CultureManager.GetNotNeutralCultures(storage).Count() == 0)
                {
                    requestLocalizationOptions.SupportedCultures = requestLocalizationOptions.SupportedUICultures =
                        new CultureInfo[] { new CultureInfo(DefaultCulture.Code) }.ToList();
                }

                else
                {
                    requestLocalizationOptions.SupportedCultures = requestLocalizationOptions.SupportedUICultures =
                        CultureManager.GetNotNeutralCultures(storage).Select(c => new CultureInfo(c.Code)).ToList();
                }

                if (this.MustSpecifyCultureInUrl(storage))
                {
                    requestLocalizationOptions.RequestCultureProviders.Insert(0, new RouteValueRequestCultureProvider(serviceProvider));
                }
            }

            applicationBuilder.UseWhen(
                context => !context.Request.Path.StartsWithSegments(new PathString("/backend")),
                frontendApplicationBuilder =>
            {
                frontendApplicationBuilder.UseRequestLocalization(requestLocalizationOptions);
            }
                );
        }
示例#5
0
        private void CreateLocalizations(int dictionaryId, IDictionary <string, string> valuesByCultureCodes)
        {
            foreach (Culture culture in CultureManager.GetNotNeutralCultures(this.requestHandler.Storage))
            {
                Localization localization = new Localization();

                localization.DictionaryId = dictionaryId;
                localization.CultureId    = culture.Id;
                localization.Value        = valuesByCultureCodes[culture.Code];
                this.requestHandler.Storage.GetRepository <ILocalizationRepository>().Create(localization);
            }

            this.requestHandler.Storage.Save();
        }
        public void HandleEvent(IRequestHandler requestHandler, Form oldForm, Form newForm)
        {
            new SerializationManager(requestHandler).SerializeForm(newForm);

            if (oldForm != null)
            {
                foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
                {
                    requestHandler.HttpContext.RequestServices.GetService <ICache>().RemoveFormViewComponentResult(oldForm.Code, culture.Code);
                }
            }

            foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
            {
                requestHandler.HttpContext.RequestServices.GetService <ICache>().RemoveFormViewComponentResult(newForm.Code, culture.Code);
            }
        }
        public void HandleEvent(IRequestHandler requestHandler, Menu oldMenu, Menu newMenu)
        {
            new SerializationManager(requestHandler).SerializeMenu(newMenu);

            if (oldMenu != null)
            {
                foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
                {
                    requestHandler.HttpContext.RequestServices.GetService <ICache>().RemoveMenuViewComponentResult(oldMenu.Code, culture.Code);
                }
            }

            foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
            {
                requestHandler.HttpContext.RequestServices.GetService <ICache>().RemoveMenuViewComponentResult(newMenu.Code, culture.Code);
            }
        }
示例#8
0
        private void CreateLocalizations(PropertyInfo propertyInfo, Dictionary dictionary)
        {
            foreach (Culture culture in CultureManager.GetNotNeutralCultures(this.Storage))
            {
                Localization localization = new Localization();

                localization.DictionaryId = dictionary.Id;
                localization.CultureId    = culture.Id;

                string identity = propertyInfo.Name + culture.Code;
                string value    = this.Request.Form[identity];

                localization.Value = value;
                this.Storage.GetRepository <ILocalizationRepository>().Create(localization);
            }

            this.Storage.Save();
        }
示例#9
0
        private void HandleViewModelMultilingualProperties(ActionExecutingContext actionExecutingContext)
        {
            ViewModelBase viewModel = this.GetViewModelFromActionExecutingContext(actionExecutingContext);

            if (viewModel == null)
            {
                return;
            }

            try
            {
                foreach (PropertyInfo propertyInfo in this.GetMultilingualPropertiesFromViewModel(viewModel))
                {
                    this.ModelState.Remove(propertyInfo.Name);

                    bool hasRequiredAttribute = propertyInfo.CustomAttributes.Any(ca => ca.AttributeType == typeof(RequiredAttribute));

                    foreach (Culture culture in CultureManager.GetNotNeutralCultures(this.Storage))
                    {
                        string identity = propertyInfo.Name + culture.Code;
                        string value    = this.Request.Form[identity];

                        this.ModelState.SetModelValue(identity, value, value);

                        if (hasRequiredAttribute && string.IsNullOrEmpty(value))
                        {
                            this.ModelState[identity].ValidationState = ModelValidationState.Invalid;
                            this.ModelState[identity].Errors.Add(string.Empty);
                        }

                        else
                        {
                            this.ModelState[identity].ValidationState = ModelValidationState.Valid;
                        }
                    }
                }
            }

            catch { }
        }
示例#10
0
        public void SerializeObject(Object @object)
        {
            foreach (Culture culture in CultureManager.GetNotNeutralCultures(this.requestHandler.Storage))
            {
                SerializedObject serializedObject = this.requestHandler.Storage.GetRepository <ISerializedObjectRepository>().WithKey(culture.Id, @object.Id);

                if (serializedObject == null)
                {
                    this.requestHandler.Storage.GetRepository <ISerializedObjectRepository>().Create(this.SerializeObject(culture, @object));
                }

                else
                {
                    SerializedObject temp = this.SerializeObject(culture, @object);

                    serializedObject.UrlPropertyStringValue = temp.UrlPropertyStringValue;
                    serializedObject.SerializedProperties   = temp.SerializedProperties;
                    this.requestHandler.Storage.GetRepository <ISerializedObjectRepository>().Edit(serializedObject);
                }
            }

            this.requestHandler.Storage.Save();
        }
        public void HandleEvent(IRequestHandler requestHandler, Object oldObject, Object newObject)
        {
            new SerializationManager(requestHandler).SerializeObject(newObject);

            if (oldObject != null)
            {
                string urlPropertyStringValue = new ObjectManager(requestHandler).GetUrlPropertyStringValue(oldObject);

                foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
                {
                    requestHandler.HttpContext.RequestServices.GetService <ICache>().RemovePageActionResult(urlPropertyStringValue, culture.Code);
                }
            }

            {
                string urlPropertyStringValue = new ObjectManager(requestHandler).GetUrlPropertyStringValue(newObject);

                foreach (Culture culture in CultureManager.GetNotNeutralCultures(requestHandler.Storage))
                {
                    requestHandler.HttpContext.RequestServices.GetService <ICache>().RemovePageActionResult(urlPropertyStringValue, culture.Code);
                }
            }
        }