private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken); ISystemActiveLocale systemActiveLocale = this.GetDataItemFromEntityToken <ISystemActiveLocale>(); var cultureName = systemActiveLocale.CultureName; var consolesToBeUpdated = (from consoleInformation in DataFacade.GetData <IUserConsoleInformation>() join userSettings in DataFacade.GetData <IUserSettings>() on consoleInformation.Username equals userSettings.Username where userSettings.CurrentActiveLocaleCultureName == cultureName || userSettings.ForeignLocaleCultureName == cultureName select consoleInformation.ConsoleId).ToList(); LocalizationFacade.RemoveLocale(cultureName); foreach (var consoleId in consolesToBeUpdated) { ConsoleMessageQueueFacade.Enqueue(new CollapseAndRefreshConsoleMessageQueueItem(), consoleId); } ConsoleMessageQueueFacade.Enqueue(new BroadcastMessageQueueItem { Name = "LocalesUpdated", Value = "" }, null); SelectElement(new LocalizationElementProviderRootEntityToken()); deleteTreeRefresher.PostRefreshMesseges(); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { string cultureName = this.GetBinding <string>("CultureName"); string urlMappingName = this.GetBinding <string>("UrlMappingName"); bool accessToAllUsers = this.GetBinding <bool>("AccessToAllUsers"); LocalizationFacade.AddLocale(cultureName, urlMappingName, accessToAllUsers); this.CloseCurrentView(); ConsoleMessageQueueFacade.Enqueue(new BroadcastMessageQueueItem { Name = "LocalesUpdated", Value = "" }, null); var specificTreeRefresher = this.CreateSpecificTreeRefresher(); specificTreeRefresher.PostRefreshMesseges(this.EntityToken); var newLocaleDataItem = DataFacade.GetData <ISystemActiveLocale>().FirstOrDefault(l => l.CultureName == cultureName); if (newLocaleDataItem != null) { SelectElement(newLocaleDataItem.GetDataEntityToken()); } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { List <PackageFragmentValidationResult> validationResults = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Locales") > 1) { validationResults.AddFatal(GetText("VirtualElementProviderNodePackageFragmentUninstaller.OnlyOneElement")); return(validationResults); } XElement localesElement = this.Configuration.SingleOrDefault(f => f.Name == "Locales"); _culturesToUninstall = new List <CultureInfo>(); if (localesElement != null) { XAttribute oldDefaultAttribute = localesElement.Attribute("oldDefault"); if (oldDefaultAttribute != null) { _oldDefaultCultureInfo = CultureInfo.CreateSpecificCulture(oldDefaultAttribute.Value); } foreach (XElement localeElement in localesElement.Elements("Locale").Reverse()) { CultureInfo locale = CultureInfo.CreateSpecificCulture(localeElement.Attribute("name").Value); if ((_oldDefaultCultureInfo == null) && (LocalizationFacade.IsDefaultLocale(locale))) { // Locale is default -> not possible to unintall validationResults.AddFatal(GetText("VirtualElementProviderNodePackageFragmentUninstaller.OnlyOneElement")); continue; } if (LocalizationFacade.IsOnlyActiveLocaleForSomeUsers(locale)) { // only active for the a user validationResults.AddFatal(GetText("VirtualElementProviderNodePackageFragmentUninstaller.OnlyOneElement")); continue; } if (LocalizationFacade.IsLocaleInstalled(locale)) { _culturesToUninstall.Add(locale); } } } if (validationResults.Count > 0) { _culturesToUninstall = null; _oldDefaultCultureInfo = null; } return(validationResults); }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken; ISystemActiveLocale systemActiveLocale = (ISystemActiveLocale)dataEntityToken.Data; CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(systemActiveLocale.CultureName); if (LocalizationFacade.SetDefaultLocale(cultureInfo)) { ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher(); parentTreeRefresher.PostRefreshMesseges(this.EntityToken); } }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken); ISystemActiveLocale systemActiveLocale = this.GetDataItemFromEntityToken <ISystemActiveLocale>(); LocalizationFacade.RemoveLocale(systemActiveLocale.CultureName); ConsoleMessageQueueFacade.Enqueue(new CollapseAndRefreshConsoleMessageQueueItem(), null); ConsoleMessageQueueFacade.Enqueue(new BroadcastMessageQueueItem { Name = "LocalesUpdated", Value = "" }, null); deleteTreeRefresher.PostRefreshMesseges(); }
/// <exclude /> public override void Uninstall() { if (_oldDefaultCultureInfo != null) { Log.LogVerbose("LocalePackageFragmentUninstaller", string.Format("Restoring default locale to '{0}'", _oldDefaultCultureInfo)); LocalizationFacade.SetDefaultLocale(_oldDefaultCultureInfo); } foreach (CultureInfo locale in _culturesToUninstall.Reverse <CultureInfo>()) { Log.LogVerbose("LocalePackageFragmentUninstaller", string.Format("Removing the locale '{0}'", locale)); LocalizationFacade.RemoveLocale(locale, false); } }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { string cultureName = this.GetBinding <string>("CultureName"); string urlMappingName = this.GetBinding <string>("UrlMappingName"); bool accessToAllUsers = this.GetBinding <bool>("AccessToAllUsers"); LocalizationFacade.AddLocale(cultureName, urlMappingName, accessToAllUsers); this.CloseCurrentView(); ConsoleMessageQueueFacade.Enqueue(new CollapseAndRefreshConsoleMessageQueueItem(), null); ConsoleMessageQueueFacade.Enqueue(new BroadcastMessageQueueItem { Name = "LocalesUpdated", Value = "" }, null); SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher(); specificTreeRefresher.PostRefreshMesseges(this.EntityToken); }
/// <exclude /> public override IEnumerable <XElement> Install() { Verify.IsNotNull(_localesToInstall, typeof(LocalePackageFragmentInstaller).Name + " has not been validated"); XAttribute oldDefaultAttribute = null; if (DataLocalizationFacade.DefaultLocalizationCulture != null) { oldDefaultAttribute = new XAttribute("oldDefault", DataLocalizationFacade.DefaultLocalizationCulture.Name); } var localeElements = new List <XElement>(); foreach (Tuple <CultureInfo, string, bool> tuple in _localesToInstall) { Log.LogVerbose(LogTitle, "Adding the locale '{0}'", tuple.Item1); LocalizationFacade.AddLocale(tuple.Item1, tuple.Item2, true, false); if (tuple.Item3) { Log.LogVerbose(LogTitle, "Setting new default locale to '{0}'", tuple.Item1); LocalizationFacade.SetDefaultLocale(tuple.Item1); } localeElements.Add(new XElement("Locale", new XAttribute("name", tuple.Item1.Name))); } var element = new XElement("Locales", localeElements); if (oldDefaultAttribute != null) { element.Add(oldDefaultAttribute); } yield return(element); }
private void IsCurrentDefaultLocale(object sender, ConditionalEventArgs e) { CultureInfo cultureInfo = CreateCultureInfo(); e.Result = LocalizationFacade.IsDefaultLocale(cultureInfo); }
private void IsOnlyActiveLocaleForSomeUsers(object sender, ConditionalEventArgs e) { CultureInfo cultureInfo = CreateCultureInfo(); e.Result = LocalizationFacade.IsOnlyActiveLocaleForSomeUsers(cultureInfo); }
private void IsTypesUsingLocalization(object sender, ConditionalEventArgs e) { e.Result = LocalizationFacade.IsTypesUsingLocalization(); }
private void IsLastLocale(object sender, ConditionalEventArgs e) { e.Result = LocalizationFacade.IsLastLocale(); }
/// <exclude /> public static bool SetUp(string setupDescriptionXml, string username, string password, string email, string language, string consoleLanguage, bool newsletter) { ApplicationOnlineHandlerFacade.TurnApplicationOffline(false); username = username.Trim().ToLowerInvariant(); XElement setupDescription = XElement.Parse(setupDescriptionXml); XElement setupRegistrationDescription = new XElement("registration", new XElement("user_email", email), new XElement("user_newsletter", newsletter), new XElement("user_consolelanguage", consoleLanguage), new XElement("user_websitelanguage", language), setupDescription); bool success = false; try { Log.LogInformation(VerboseLogTitle, "Downloading packages"); string[] packageUrls = GetPackageUrls(setupDescription).ToArray(); MemoryStream[] packages = new MemoryStream[packageUrls.Length]; Parallel.For(0, packageUrls.Length, i => { packages[i] = DownloadPackage(packageUrls[i]); }); Log.LogInformation(VerboseLogTitle, "Setting up the system for the first time"); CultureInfo locale = new CultureInfo(language); CultureInfo userCulture = new CultureInfo(consoleLanguage); ApplicationLevelEventHandlers.ApplicationStartInitialize(); Log.LogInformation(VerboseLogTitle, "Creating first locale: " + language); LocalizationFacade.AddLocale(locale, "", true, false, true); Log.LogInformation(VerboseLogTitle, "Creating first user: "******"Installing package from url " + packageUrls[i]); InstallPackage(packageUrls[i], packages[i]); // Releasing a reference to reduce memory usage packages[i].Dispose(); packages[i] = null; } } RegisterSetup(setupRegistrationDescription.ToString(), ""); Log.LogInformation(VerboseLogTitle, "Done setting up the system for the first time! Enjoy!"); success = true; } catch (Exception ex) { Log.LogCritical(LogTitle, ex); Log.LogWarning(LogTitle, "First time setup failed - could not download, install package or otherwise complete the setup."); RegisterSetup(setupRegistrationDescription.ToString(), ex.ToString()); if (RuntimeInformation.IsDebugBuild) { ApplicationOnlineHandlerFacade.TurnApplicationOnline(); throw; } } ApplicationOnlineHandlerFacade.TurnApplicationOnline(); return(success); }
private void UrlMappingNameInUse(object sender, ConditionalEventArgs e) { string urlMappingName = this.GetBinding <string>("UrlMappingName"); e.Result = LocalizationFacade.IsUrlMappingNameInUse(urlMappingName); }
/// <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); }
private void UrlMappingNameInUse(object sender, ConditionalEventArgs e) { ISystemActiveLocale systemActiveLocale = this.GetBinding <ISystemActiveLocale>("SystemActiveLocale"); e.Result = LocalizationFacade.IsUrlMappingNameInUse(systemActiveLocale.CultureName, systemActiveLocale.UrlMappingName); }
public IEnumerable <Element> GetChildren(EntityToken entityToken, SearchToken seachToken) { if ((entityToken is LocalizationElementProviderRootEntityToken) == false) { throw new InvalidOperationException(); } IEnumerable <ISystemActiveLocale> locales = DataFacade.GetData <ISystemActiveLocale>().ToList(); List <Element> elements = new List <Element>(); foreach (ISystemActiveLocale locale in locales) { bool isDefault = LocalizationFacade.IsDefaultLocale(locale.CultureName); ResourceHandle iconHandle = LocaleItemIcon; if (isDefault) { //lable = string.Format("{0} ({1})", lable, StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "ElementProvider.DefaultLabel")); iconHandle = DefaultLocaleItemIcon; } Element element = new Element(_context.CreateElementHandle(locale.GetDataEntityToken())); element.VisualData = new ElementVisualizedData { Label = DataLocalizationFacade.GetCultureTitle(new CultureInfo(locale.CultureName)), ToolTip = DataLocalizationFacade.GetCultureTitle(new CultureInfo(locale.CultureName)), HasChildren = false, Icon = iconHandle }; element.AddAction(new ElementAction(new ActionHandle( new WorkflowActionToken( WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.LocalizationElementProvider.EditSystemLocaleWorkflow"), new PermissionType[] { PermissionType.Administrate } ))) { VisualData = new ActionVisualizedData { Label = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "EditSystemLocaleWorkflow.EditElementActionLabel"), ToolTip = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "EditSystemLocaleWorkflow.EditElementActionToolTip"), Icon = EditSystemLocaleIcon, Disabled = false, ActionLocation = new ActionLocation { ActionType = ActionType.Edit, IsInFolder = false, IsInToolbar = true, ActionGroup = PrimaryActionGroup } } }); if (isDefault == false) { element.AddAction(new ElementAction(new ActionHandle( new WorkflowActionToken( WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.LocalizationElementProvider.DefineDefaultActiveLocaleWorkflow"), new PermissionType[] { PermissionType.Administrate } ))) { VisualData = new ActionVisualizedData { Label = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "DefineDefaultActiveLocaleWorkflow.ElementActionLabel"), ToolTip = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "DefineDefaultActiveLocaleWorkflow.ElementActionToolTip"), Icon = SetAsDefaultIcon, Disabled = false, ActionLocation = new ActionLocation { ActionType = ActionType.Edit, IsInFolder = false, IsInToolbar = true, ActionGroup = PrimaryActionGroup } } }); element.AddAction(new ElementAction(new ActionHandle( new WorkflowActionToken( WorkflowFacade.GetWorkflowType("Composite.Plugins.Elements.ElementProviders.LocalizationElementProvider.RemoveSystemLocaleWorkflow"), new PermissionType[] { PermissionType.Administrate } ))) { VisualData = new ActionVisualizedData { Label = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "RemoveSystemLocaleWorkflow.RemoveElementActionLabel"), ToolTip = StringResourceSystemFacade.GetString("Composite.Plugins.LocalizationElementProvider", "RemoveSystemLocaleWorkflow.RemoveElementActionToolTip"), Icon = RemoveSystemLocaleIcon, Disabled = false, ActionLocation = new ActionLocation { ActionType = ActionType.Delete, IsInFolder = false, IsInToolbar = true, ActionGroup = PrimaryActionGroup } } }); } elements.Add(element); } return(elements.OrderBy(f => f.VisualData.Label)); }