Esempio n. 1
0
        /// <summary>
        /// Split upgrade scripts into batches of upgrade steps, the go token is
        /// considered as separation boundary of batches.
        /// </summary>
        /// <param name="parseLocal">Whether to parse ShardMapManagerLocal upgrade scripts, default = false</param>
        /// <returns></returns>
        private static IEnumerable <UpgradeSteps> ParseUpgradeScripts(bool parseLocal = false)
        {
            List <UpgradeSteps> upgradeSteps = new List <UpgradeSteps>();

            ResourceSet rs = Scripts.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);

            string upgradeFileNameFilter = @"^UpgradeShardMapManagerGlobalFrom(\d*).(\d*)";

            if (parseLocal)
            {
                upgradeFileNameFilter = upgradeFileNameFilter.Replace("Global", "Local");
            }

            Regex fileNameRegEx = new Regex(
                upgradeFileNameFilter,
                RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

            // Filter upgrade scripts based on file name and order by initial Major.Minor version
            var upgradeScriptObjects = from r in rs.Cast <DictionaryEntry>()
                                       let m = fileNameRegEx.Match(r.Key.ToString())
                                               where
                                               m.Success
                                               orderby new Version(Convert.ToInt32(m.Groups[1].Value), Convert.ToInt32(m.Groups[2].Value))
                                               select new
            {
                Key   = r.Key,
                Value = r.Value,
                initialMajorVersion = Convert.ToInt32(m.Groups[1].Value),
                initialMinorVersion = Convert.ToInt32(m.Groups[2].Value)
            };

            foreach (var entry in upgradeScriptObjects)
            {
                foreach (StringBuilder cmd in SplitScriptCommands(entry.Value.ToString()))
                {
                    upgradeSteps.Add(new UpgradeSteps(entry.initialMajorVersion, entry.initialMinorVersion, cmd));
                }
            }

            return(upgradeSteps);
        }
Esempio n. 2
0
        public void Resources_HasAllTranslations()
        {
            IEnumerable <Language> languages     = GlobalizationProviderFactory.CreateProvider().Languages;
            IEnumerable <Type>     resourceTypes = Assembly
                                                   .Load("MvcTemplate.Resources")
                                                   .GetTypes()
                                                   .Where(type => type.Namespace.StartsWith("MvcTemplate.Resources."));

            foreach (Type type in resourceTypes)
            {
                IEnumerable <String> resourceKeys = Enumerable.Empty <String>();
                ResourceManager      manager      = new ResourceManager(type);

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);
                    resourceKeys = resourceKeys.Union(set.Cast <DictionaryEntry>().Select(resource => resource.Key.ToString()));
                    resourceKeys = resourceKeys.Distinct();
                }

                foreach (Language language in languages)
                {
                    ResourceSet set = manager.GetResourceSet(language.Culture, true, true);

                    foreach (String key in resourceKeys)
                    {
                        Assert.IsNotNullOrEmpty(
                            set.GetString(key),
                            String.Format("{0}, does not have translation for '{1}' in {2} language.",
                                          type.FullName,
                                          key,
                                          language.Culture.EnglishName));
                    }
                }
            }
        }
Esempio n. 3
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (GlobalConfig.BackgroundGCPeriod > 0)
            {
                Hacks.EnableBackgroundGC(GlobalConfig.BackgroundGCPeriod);
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            if (CultureInfo.CurrentCulture.TwoLetterISOLanguageName.Equals("en"))
            {
                return;
            }

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));
                return;
            }

            HashSet <DictionaryEntry> defaultStringObjects = new HashSet <DictionaryEntry>(defaultResourceSet.Cast <DictionaryEntry>());

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));
                return;
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));
                return;
            }

            HashSet <DictionaryEntry> currentStringObjects = new HashSet <DictionaryEntry>(currentResourceSet.Cast <DictionaryEntry>());

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = new HashSet <DictionaryEntry>(currentStringObjects);
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
            }
        }
Esempio n. 4
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            ushort      defaultResourceSetCount = 0;
            ResourceSet defaultResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet != null)
            {
                defaultResourceSetCount = (ushort)defaultResourceSet.Cast <object>().Count();
            }

            if (defaultResourceSetCount == 0)
            {
                return;
            }

            ushort      currentResourceSetCount = 0;
            ResourceSet currentResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false);

            if (currentResourceSet != null)
            {
                currentResourceSetCount = (ushort)currentResourceSet.Cast <object>().Count();
            }

            if (currentResourceSetCount < defaultResourceSetCount)
            {
                // We don't want to report "en-AU" as 0.00% only because we don't have it as a dialect, if "en" is available and translated
                // This typically will work only for English, as e.g. "nl-BE" doesn't fallback to "nl-NL", but "nl", and "nl" will be empty
                ushort      neutralResourceSetCount = 0;
                ResourceSet neutralResourceSet      = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture.Parent, true, false);
                if (neutralResourceSet != null)
                {
                    neutralResourceSetCount = (ushort)neutralResourceSet.Cast <object>().Count();
                }

                if (neutralResourceSetCount < defaultResourceSetCount)
                {
                    float translationCompleteness = currentResourceSetCount / (float)defaultResourceSetCount;
                    ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
                }
            }
        }
Esempio n. 5
0
        private static async Task InitGlobalConfigAndLanguage()
        {
            string globalConfigFile = ASF.GetFilePath(ASF.EFileType.Config);

            if (string.IsNullOrEmpty(globalConfigFile))
            {
                ASF.ArchiLogger.LogNullError(nameof(globalConfigFile));

                return;
            }

            GlobalConfig globalConfig;

            if (File.Exists(globalConfigFile))
            {
                globalConfig = await GlobalConfig.Load(globalConfigFile).ConfigureAwait(false);

                if (globalConfig == null)
                {
                    ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                    await Task.Delay(5 * 1000).ConfigureAwait(false);
                    await Exit(1).ConfigureAwait(false);

                    return;
                }
            }
            else
            {
                globalConfig = GlobalConfig.Create();
            }

            ASF.InitGlobalConfig(globalConfig);

            if (Debugging.IsUserDebugging)
            {
                ASF.ArchiLogger.LogGenericDebug(globalConfigFile + ": " + JsonConvert.SerializeObject(ASF.GlobalConfig, Formatting.Indented));
            }

            if (!string.IsNullOrEmpty(ASF.GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(ASF.GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (Exception) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en"))
            {
                return;
            }

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.GetCultureInfo("en-US"), true, true);

            if (defaultResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultResourceSet));

                return;
            }

            HashSet <DictionaryEntry> defaultStringObjects = defaultResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (defaultStringObjects.Count == 0)
            {
                ASF.ArchiLogger.LogNullError(nameof(defaultStringObjects));

                return;
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            if (currentResourceSet == null)
            {
                ASF.ArchiLogger.LogNullError(nameof(currentResourceSet));

                return;
            }

            HashSet <DictionaryEntry> currentStringObjects = currentResourceSet.Cast <DictionaryEntry>().ToHashSet();

            if (currentStringObjects.Count >= defaultStringObjects.Count)
            {
                // Either we have 100% finished translation, or we're missing it entirely and using en-US
                HashSet <DictionaryEntry> testStringObjects = currentStringObjects.ToHashSet();
                testStringObjects.ExceptWith(defaultStringObjects);

                // If we got 0 as final result, this is the missing language
                // Otherwise it's just a small amount of strings that happen to be the same
                if (testStringObjects.Count == 0)
                {
                    currentStringObjects = testStringObjects;
                }
            }

            if (currentStringObjects.Count < defaultStringObjects.Count)
            {
                float translationCompleteness = currentStringObjects.Count / (float)defaultStringObjects.Count;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentUICulture.Name, translationCompleteness.ToString("P1")));
            }
        }
Esempio n. 6
0
        private static async Task InitServices()
        {
            string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

            GlobalConfig = GlobalConfig.Load(globalConfigFile);
            if (GlobalConfig == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorGlobalConfigNotLoaded, globalConfigFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);

                Exit(1);
                return;
            }

            if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture))
            {
                try {
                    // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"
                    CultureInfo culture = CultureInfo.CreateSpecificCulture(GlobalConfig.CurrentCulture);
                    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = culture;
                } catch (CultureNotFoundException) {
                    ASF.ArchiLogger.LogGenericError(Strings.ErrorInvalidCurrentCulture);
                }
            }

            int defaultResourceSetCount = 0;
            int currentResourceSetCount = 0;

            ResourceSet defaultResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CreateSpecificCulture("en-US"), true, true);

            if (defaultResourceSet != null)
            {
                defaultResourceSetCount = defaultResourceSet.Cast <object>().Count();
            }

            ResourceSet currentResourceSet = Strings.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, false);

            if (currentResourceSet != null)
            {
                currentResourceSetCount = currentResourceSet.Cast <object>().Count();
            }

            if (currentResourceSetCount < defaultResourceSetCount)
            {
                float translationCompleteness = currentResourceSetCount / (float)defaultResourceSetCount;
                ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.TranslationIncomplete, CultureInfo.CurrentCulture.Name, translationCompleteness.ToString("P1")));
            }

            string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);

            if (!File.Exists(globalDatabaseFile))
            {
                ASF.ArchiLogger.LogGenericInfo(Strings.Welcome);
                ASF.ArchiLogger.LogGenericWarning(Strings.WarningPrivacyPolicy);
                await Task.Delay(15 * 1000).ConfigureAwait(false);
            }

            GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile);
            if (GlobalDatabase == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);

                Exit(1);
                return;
            }

            ArchiWebHandler.Init();
            WebBrowser.Init();
            WCF.Init();

            WebBrowser = new WebBrowser(ASF.ArchiLogger);
        }