Beispiel #1
0
        private void GetLocalizationFiles(ConcurrentDictionary <string, LocalizedFileInfo> dictionaryCache, string parentFolder)
        {
            foreach (var directoryContent in _fileProvider.GetDirectoryContents(parentFolder))
            {
                if (!directoryContent.IsDirectory)
                {
                    var match = Regex.Match(directoryContent.Name, localizedFilesPattern);
                    if (match.Success)
                    {
                        var fileInfo = new LocalizedFileInfo(
                            $"{parentFolder}/{match.Groups["fileName"].Value}",
                            match.Groups["culture"].Value,
                            directoryContent);

                        var fileInfoKey = $"{fileInfo.FileName}|{fileInfo.Culture}";

                        LoadFile(fileInfoKey, fileInfo, dictionaryCache);
                    }
                }
                else if (_localizationOptions.RecurseSubfolders)
                {
                    GetLocalizationFiles(dictionaryCache, $"{parentFolder}/{directoryContent.Name}");
                }
            }
        }
Beispiel #2
0
        private void LoadFile(string fileInfoKey, LocalizedFileInfo fileInfo, ConcurrentDictionary <string, LocalizedFileInfo> dictionaryCache)
        {
            if (dictionaryCache.ContainsKey(fileInfoKey))
            {
                dictionaryCache.Remove(fileInfoKey, out fileInfo);
            }

            using (var reader = new StreamReader(fileInfo.CreateReadStream()))
            {
                var contents = JObject.Parse(reader.ReadToEnd()).ToObject(typeof(object));
                fileInfo.Items = FlatObject(contents);
            }

            fileInfo.InitialModified = DateTimeOffset.Now;
            dictionaryCache.TryAdd(fileInfoKey, fileInfo);
        }