Beispiel #1
0
        private void UrlMappingNameInUse(object sender, ConditionalEventArgs e)
        {
            string urlMappingName = this.GetBinding <string>("UrlMappingName");

            e.Result = LocalizationFacade.IsUrlMappingNameInUse(urlMappingName);
        }
Beispiel #2
0
        private void UrlMappingNameInUse(object sender, ConditionalEventArgs e)
        {
            ISystemActiveLocale systemActiveLocale = this.GetBinding <ISystemActiveLocale>("SystemActiveLocale");

            e.Result = LocalizationFacade.IsUrlMappingNameInUse(systemActiveLocale.CultureName, systemActiveLocale.UrlMappingName);
        }
Beispiel #3
0
        /// <exclude />
        public override IEnumerable <PackageFragmentValidationResult> Validate()
        {
            var validationResult = new List <PackageFragmentValidationResult>();

            if (this.Configuration.Count(f => f.Name == "Locales") > 1)
            {
                validationResult.AddFatal(Texts.PackageFragmentInstaller_OnlyOneElementAllowed("Locales"));
                return(validationResult);
            }

            XElement areasElement = this.Configuration.SingleOrDefault(f => f.Name == "Locales");

            _localesToInstall = new List <Tuple <CultureInfo, string, bool> >();

            if (areasElement != null)
            {
                foreach (XElement localeElement in areasElement.Elements("Locale"))
                {
                    XAttribute nameAttribute           = localeElement.Attribute("name");
                    XAttribute urlMappingNameAttribute = localeElement.Attribute("urlMappingName");
                    XAttribute defaultAttribute        = localeElement.Attribute("default");

                    if (nameAttribute == null)
                    {
                        // Missing attribute
                        validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), localeElement);
                        continue;
                    }

                    CultureInfo cultureInfo;
                    try
                    {
                        cultureInfo = CultureInfo.CreateSpecificCulture(nameAttribute.Value);
                    }
                    catch
                    {
                        // Name error
                        validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), nameAttribute);
                        continue;
                    }

                    if (LocalizationFacade.IsLocaleInstalled(cultureInfo))
                    {
                        continue; // Skip it, it is installed
                    }

                    if (_localesToInstall.Any(f => f.Item1.Equals(cultureInfo)))
                    {
                        // Already installed or going to be installed
                        validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("name"), nameAttribute);
                        continue;
                    }

                    string urlMappingName = cultureInfo.Name;
                    if (urlMappingNameAttribute != null)
                    {
                        urlMappingName = urlMappingNameAttribute.Value;
                    }

                    if (LocalizationFacade.IsUrlMappingNameInUse(urlMappingName) || _localesToInstall.Any(f => f.Item2 == urlMappingName))
                    {
                        // Url mapping name already used or going to be used
                        validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("urlMappingName"), urlMappingNameAttribute);
                        continue;
                    }

                    bool isDefault = false;
                    if (defaultAttribute != null)
                    {
                        if (!defaultAttribute.TryGetBoolValue(out isDefault))
                        {
                            // Wrong attribute value
                            validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("default"), defaultAttribute);
                            continue;
                        }
                    }

                    if (isDefault && _localesToInstall.Any(f => f.Item3))
                    {
                        // More than one is specified as default
                        validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("default"), defaultAttribute);
                        continue;
                    }

                    _localesToInstall.Add(new Tuple <CultureInfo, string, bool>(cultureInfo, urlMappingName, isDefault));

                    this.InstallerContext.AddPendingLocale(cultureInfo);
                }
            }


            if (validationResult.Count > 0)
            {
                _localesToInstall = null;
            }

            return(validationResult);
        }