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);
            }
        }
        /// <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);
            }
        }
Exemple #3
0
        /// <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);
        }
        /// <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);
                LocalizationFacade.SetDefaultLocale(locale);


                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);
        }