in sdk/csharp/libraries/microsoft.bot.solutions/Responses/ResponseManager.cs [272:335]
private void LoadResponses(string resourceName, Assembly resourceAssembly, string locale = null)
{
var resources = new List<string>();
// if locale is not set, add resources under the default key.
var localeKey = _defaultLocaleKey;
if (locale != null)
{
localeKey = new CultureInfo(locale).TwoLetterISOLanguageName;
}
var jsonFile = $"{resourceName}.json";
resources = resourceAssembly
.GetManifestResourceNames()
.Where(x => x.Contains(jsonFile))
.ToList();
if (resources == null || resources.Count() == 0)
{
throw new FileNotFoundException($"Unable to find \"{jsonFile}\" in \"{resourceAssembly.FullName}\" assembly.");
}
foreach (var resource in resources)
{
try
{
string jsonData;
using (var sr = new StreamReader(resourceAssembly.GetManifestResourceStream(resource)))
{
jsonData = sr.ReadToEnd();
}
var responses = JsonConvert.DeserializeObject<Dictionary<string, ResponseTemplate>>(jsonData);
if (JsonResponses.ContainsKey(localeKey))
{
var localeResponses = JsonResponses[localeKey] ?? new Dictionary<string, ResponseTemplate>();
foreach (var item in responses)
{
if (!localeResponses.ContainsKey(item.Key))
{
localeResponses.Add(item.Key, item.Value);
}
}
JsonResponses[localeKey] = localeResponses;
}
else
{
JsonResponses.Add(localeKey, responses);
}
}
catch (JsonReaderException ex)
{
throw new JsonReaderException($"Error deserializing {resource}. {ex.Message}", ex);
}
catch (Exception ex)
{
throw ex;
}
}
}