private static bool IsProcessed(CalculationComponent component, string[] journeyBreadcrumbs) { if (journeyBreadcrumbs == null) { return(false); } return(Array.IndexOf(journeyBreadcrumbs, JourneyUtils.ToBreadCrumb(component)) >= 0); }
public async Task Run( [QueueTrigger("munt-component-queue", Connection = "AzureWebJobsStorage")] string message, [Queue("munt-journey-queue"), StorageAccount("AzureWebJobsStorage")] ICollector <string> journeyQueue, ILogger log) { var componentMessage = Deserialize(message); var componentType = componentMessage.ComponentType; var componentVersion = componentMessage.ComponentVersion; log.LogInformation( $"Component {componentType} received context {componentMessage.MuntContext} and {componentMessage.ComponentContext}"); var nugetComponentVersions = await this.nugetServerService.GetPackageVersions(componentType); if (!nugetComponentVersions.Any()) { throw new ArgumentException($"Component {componentType} does not have any versions on NuGet"); } var nugetComponent = nugetComponentVersions.FirstOrDefault(c => c.Version.Equals(new Version(componentVersion))); if (nugetComponent == null) { throw new ArgumentException( $"Component {componentType} with version {componentVersion} does not exist on NuGet"); } var packageName = $"{componentType}.{componentVersion}.nupkg"; var packageLocation = Path.GetFullPath(packageName); // Results to bin/Debug/netcoreapp3.1/package.version.nupkg if (IsRunningOnAzure()) { packageLocation = Path.Combine(Path.GetTempPath(), packageName); // Results to the TEMP directory of the Azure Functions (App Service) on Azure } // Download from NuGet server if file with specific version does not exist if (!File.Exists(packageLocation)) { var package = await this.nugetServerService.DownloadPackage(componentType, componentVersion); await File.WriteAllBytesAsync(packageLocation, package); } var pathToPackage = Path.GetDirectoryName( packageLocation); // Returns the root execution directory, where all nupkg's are downloaded // Scanning for nupkg's also extracts all available packages var pluginScanResults = await this.pluginLoader.FindPlugins <IMuntCalculationComponent>(pathToPackage); // We're looking for the nupkg with the correct name and version var pluginScanResult = pluginScanResults.FirstOrDefault(p => p.AssemblyPath.Contains(componentType) && p.AssemblyPath.Contains(componentVersion)); if (pluginScanResult == null) { throw new NotSupportedException( $"Could not find extracted plugin with name {componentType} and version {componentVersion}"); } var plugin = await this.pluginLoader.LoadPlugin <IMuntCalculationComponent>(pluginScanResult, configure : (ctx) => { // Share the IConfigurationService ctx.AddHostService <IConfigurationService>(this.configurationService); }); var componentBreadCrumb = JourneyUtils.ToBreadCrumb(componentType, componentVersion); var results = await plugin.Calculate(componentMessage.MuntContext, componentMessage.ComponentContext); var journey = componentMessage.Journey; var journeyMessage = new JourneyMessage { AmountForCalculationArea = componentMessage.ComponentContext.AmountForCalculationArea, Context = componentMessage.MuntContext, Journey = AddBreadCrumb(journey, componentBreadCrumb), CalculationResults = AddResults(componentMessage.ComponentContext.CalculationResults, results) }; var newMessage = JsonConvert.SerializeObject(journeyMessage); log.LogInformation($"Component {componentBreadCrumb} created new context {newMessage}"); journeyQueue.Add(newMessage); }