Esempio n. 1
0
        private Task OnChanged(LocalizedStringCacheResetEventData data)
        {
            if (string.Equals(_resourceName, data.ResourceName))
            {
                if (!_dictionaries.ContainsKey(data.CultureName))
                {
                    // TODO: 需要处理 data.Key data.Value 空引用
                    var dictionary = new Dictionary <string, LocalizedString>();
                    dictionary.Add(data.Key, new LocalizedString(data.Key, data.Value.NormalizeLineEndings()));
                    var newLocalizationDictionary = new StaticLocalizationDictionary(data.CultureName, dictionary);

                    _dictionaries.Add(data.CultureName, newLocalizationDictionary);
                }
                else
                {
                    // 取出当前的缓存写入到新字典进行处理
                    var nowLocalizationDictionary = _dictionaries[data.CultureName];
                    var dictionary = new Dictionary <string, LocalizedString>();
                    nowLocalizationDictionary.Fill(dictionary);

                    var existsKey = dictionary.ContainsKey(data.Key);
                    if (!existsKey)
                    {
                        // 如果不存在,则新增
                        dictionary.Add(data.Key, new LocalizedString(data.Key, data.Value.NormalizeLineEndings()));
                    }
                    else if (existsKey && data.IsDeleted)
                    {
                        // 如果删掉了本地化的节点,删掉当前的缓存
                        dictionary.Remove(data.Key);
                    }

                    var newLocalizationDictionary = new StaticLocalizationDictionary(data.CultureName, dictionary);

                    if (newLocalizationDictionary != null)
                    {
                        // 重新赋值变更过的缓存
                        _dictionaries[data.CultureName] = newLocalizationDictionary;
                    }
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
 public virtual async Task DispatchAsync(LocalizedStringCacheResetEventData data)
 {
     await _handler(data);
 }