/// <summary> /// Adds a locale to the system. Throws exception if the given locale has already been installed or /// if the given url mapping name has already been used. If the given locale is the first, its set /// to be the default locale. /// </summary> /// <param name="cultureInfo"></param> /// <param name="urlMappingName"></param> /// <param name="addAccessToAllUsers"></param> /// <param name="makeFlush"></param> /// <param name="isDefault"></param> internal static void AddLocale(CultureInfo cultureInfo, string urlMappingName, bool addAccessToAllUsers, bool makeFlush, bool isDefault) { using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope()) { Verify.That(!IsLocaleInstalled(cultureInfo), "The locale '{0}' has already been added to the system", cultureInfo); Verify.That(!IsUrlMappingNameInUse(urlMappingName), "The url mapping name '{0}' has already been used in the system", urlMappingName); if (!DataLocalizationFacade.ActiveLocalizationCultures.Any()) { addAccessToAllUsers = true; } var systemActiveLocale = DataFacade.BuildNew <ISystemActiveLocale>(); systemActiveLocale.Id = Guid.NewGuid(); systemActiveLocale.CultureName = cultureInfo.Name; systemActiveLocale.UrlMappingName = urlMappingName; systemActiveLocale.IsDefault = isDefault; DataFacade.AddNew(systemActiveLocale); if (addAccessToAllUsers) { List <string> usernames = (from u in DataFacade.GetData <IUser>() select u.Username).ToList(); foreach (string username in usernames) { UserSettings.AddActiveLocaleCultureInfo(username, cultureInfo); if (UserSettings.GetCurrentActiveLocaleCultureInfo(username) == null) { UserSettings.SetCurrentActiveLocaleCultureInfo(username, cultureInfo); UserSettings.SetForeignLocaleCultureInfo(username, cultureInfo); } } } if (DataLocalizationFacade.DefaultLocalizationCulture == null) { DataLocalizationFacade.DefaultLocalizationCulture = cultureInfo; } transactionScope.Complete(); } DynamicTypeManager.AddLocale(cultureInfo); if (makeFlush) { C1Console.Events.GlobalEventSystemFacade.FlushTheSystem(false); } }