private async ValueTask <BlazorModuleManifest?> GetModuleManifestCoreAsync(ModuleIdentifier module, CancellationToken cancellation) { var moduleProperties = await _modulePropertiesLookup.LookupAsync(module, cancellation); if (moduleProperties == null) { _logger?.LogError($"Unable to load manifest for {module}. The module properties could not be fetched."); return(null); } foreach (var endPoint in moduleProperties.EndPoints) { var dispatchData = new DispatchDataDictionary <Query <BlazorModuleManifest> >(new Query <BlazorModuleManifest>()); var queryResult = await _messageDispatcher.DispatchAsync(dispatchData, publish : false, endPoint, cancellation); if (!queryResult.IsSuccessWithResult <BlazorModuleManifest>(out var manifest)) { _logger?.LogWarning($"Unable to load manifest for {module} from end-point {endPoint}."); continue; } _cache.TryAdd(module, manifest); _logger?.LogDebug($"Successfully loaded manifest for module {module}."); return(manifest); } if (moduleProperties.EndPoints.Any()) { _logger?.LogError($"Unable to load manifest for {module}. No end-point matched."); } else { _logger?.LogError($"Unable to load manifest for {module}. No end-points available."); } return(null); }
public async ValueTask <Assembly?> InstallAssemblyAsync(ModuleIdentifier module, string assemblyName, CancellationToken cancellation) { var result = GetAssembly(assemblyName); if (result != null) { _logger?.LogDebug($"Installing assembly {assemblyName} for module {module}: Already installed."); return(result); } _logger?.LogDebug($"Installing assembly {assemblyName} for module {module}."); var moduleProperties = await _modulePropertiesLookup.LookupAsync(module, cancellation); if (moduleProperties == null) { _logger?.LogError($"Unable to install assembly {assemblyName} for module {module}. The module properties could not be fetched."); return(null); } foreach (var prefix in moduleProperties.Prefixes) { var assemblyUri = GetAssemblyUri(prefix, assemblyName); HttpResponseMessage response; try { response = await _httpClient.GetAsync(assemblyUri, cancellation).ConfigureAwait(false); } catch (Exception exc) { _logger?.LogWarning(exc, $"Unable to load assembly {assemblyName} from source {assemblyUri}."); continue; } if (response.IsSuccessStatusCode) { var assemblyBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); try { result = Assembly.Load(assemblyBytes); } catch (Exception exc) { _logger?.LogWarning(exc, $"Unable to install loaded assembly {assemblyName}."); continue; } _logger?.LogDebug($"Successfully installed assembly {assemblyName}. Response status was: {response.StatusCode} {response?.ReasonPhrase ?? string.Empty}."); return(result); } _logger?.LogWarning($"Unable to load assembly {assemblyName} from source {assemblyUri}."); } if (moduleProperties.Prefixes.Any()) { _logger?.LogError($"Unable to load assembly {assemblyName}. No source successful."); } else { _logger?.LogError($"Unable to load assembly {assemblyName}. No sources available."); } return(null); }