示例#1
0
        private async Task LoadLabels(int languageId, string module, string type)
        {
            using (var persistence = new PersistenceLayer())
            {
                var translationLabelDefinition = await persistence
                                                 .Get <TranslationLabelDefinition>()
                                                 .Include(x => x.TranslationLabels)
                                                 .Where(x => x.Module == module && x.Type == type)
                                                 .ToListAsync();

                var definitions = translationLabelDefinition
                                  .Select(x => new
                {
                    TranslationLabelDefinition = x,
                    TranslationLabel           = x.TranslationLabels
                                                 .FirstOrDefault(y => y.Language_Id == languageId)
                });

                var dictionary = new StringValueDictionary <string>(DefaultLabelValue);

                foreach (var definition in definitions)
                {
                    var transDef = definition.TranslationLabelDefinition;

                    dictionary.Add($"{transDef.Module}:{transDef.Type}:{transDef.Key}", definition?.TranslationLabel?.Label ?? DefaultLabelValue);
                }

                lock (DictionaryLanguagesLock)
                {
                    if (!DictionaryLanguages.ContainsKey(languageId))
                    {
                        DictionaryLanguages.Add(languageId, new StringValueDictionary <StringValueDictionary <StringValueDictionary <string> > >());
                    }

                    if (!DictionaryLanguages[languageId].ContainsKey(module))
                    {
                        DictionaryLanguages[languageId].Add(module, new StringValueDictionary <StringValueDictionary <string> >());
                    }

                    if (!DictionaryLanguages[languageId][module].ContainsKey(type))
                    {
                        DictionaryLanguages[languageId][module].Add(type, new StringValueDictionary <string>(DefaultLabelValue));
                    }

                    DictionaryLanguages[languageId][module][type] = dictionary;
                }
            }
        }