Merge pull request #4575 from babrekel/babrekel/resource-explorer-declarative-types
Allow resource explorer to accept the set of declarative type registrations
This commit is contained in:
Коммит
1a49139d32
|
@ -30,6 +30,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources
|
||||||
private readonly ConcurrentDictionary<string, Type> kindToType = new ConcurrentDictionary<string, Type>();
|
private readonly ConcurrentDictionary<string, Type> kindToType = new ConcurrentDictionary<string, Type>();
|
||||||
private readonly ConcurrentDictionary<Type, List<string>> typeToKinds = new ConcurrentDictionary<Type, List<string>>();
|
private readonly ConcurrentDictionary<Type, List<string>> typeToKinds = new ConcurrentDictionary<Type, List<string>>();
|
||||||
private List<ResourceProvider> resourceProviders = new List<ResourceProvider>();
|
private List<ResourceProvider> resourceProviders = new List<ResourceProvider>();
|
||||||
|
private List<IComponentDeclarativeTypes> declarativeTypes;
|
||||||
private CancellationTokenSource cancelReloadToken = new CancellationTokenSource();
|
private CancellationTokenSource cancelReloadToken = new CancellationTokenSource();
|
||||||
private ConcurrentBag<Resource> changedResources = new ConcurrentBag<Resource>();
|
private ConcurrentBag<Resource> changedResources = new ConcurrentBag<Resource>();
|
||||||
private bool typesLoaded = false;
|
private bool typesLoaded = false;
|
||||||
|
@ -49,9 +50,19 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="providers">The list of resource providers to initialize the current instance.</param>
|
/// <param name="providers">The list of resource providers to initialize the current instance.</param>
|
||||||
public ResourceExplorer(IEnumerable<ResourceProvider> providers)
|
public ResourceExplorer(IEnumerable<ResourceProvider> providers)
|
||||||
: this()
|
: this(providers, null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ResourceExplorer"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="providers">The list of resource providers to initialize the current instance.</param>
|
||||||
|
/// <param name="declarativeTypes">A list of declarative types to use. Falls back to <see cref="ComponentRegistration.Components" /> if set to null.</param>
|
||||||
|
public ResourceExplorer(IEnumerable<ResourceProvider> providers, IEnumerable<IComponentDeclarativeTypes> declarativeTypes)
|
||||||
{
|
{
|
||||||
this.resourceProviders = providers.ToList();
|
this.resourceProviders = providers.ToList();
|
||||||
|
this.declarativeTypes = declarativeTypes?.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -495,6 +506,11 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources
|
||||||
Changed?.Invoke(this, resources);
|
Changed?.Invoke(this, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<IComponentDeclarativeTypes> GetComponentRegistrations()
|
||||||
|
{
|
||||||
|
return this.declarativeTypes ?? ComponentRegistration.Components.OfType<IComponentDeclarativeTypes>();
|
||||||
|
}
|
||||||
|
|
||||||
private void RegisterTypeInternal(string kind, Type type, ICustomDeserializer loader = null)
|
private void RegisterTypeInternal(string kind, Type type, ICustomDeserializer loader = null)
|
||||||
{
|
{
|
||||||
// Default loader if none specified
|
// Default loader if none specified
|
||||||
|
@ -543,7 +559,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Declarative.Resources
|
||||||
// this can be reentrant, and we only want to do once.
|
// this can be reentrant, and we only want to do once.
|
||||||
this.typesLoaded = true;
|
this.typesLoaded = true;
|
||||||
|
|
||||||
foreach (var component in ComponentRegistration.Components.OfType<IComponentDeclarativeTypes>())
|
foreach (var component in GetComponentRegistrations())
|
||||||
{
|
{
|
||||||
if (component != null)
|
if (component != null)
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче