protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP002SendRoutingSlipGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP002SendRoutingSlipGenerator)); // Get all of the intermediaries and endpoints from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); var endpoints = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Endpoints); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the activating intermediaries (that are topic subscribers). foreach (var activatingIntermediary in targetApplication.Intermediaries.Where(i => i.Activator == true && i is MessageSubscriber && !string.IsNullOrEmpty(i.ResourceMapKey))) { // Get scenario name var scenarioName = activatingIntermediary.Properties[ModelConstants.ScenarioName].ToString(); // Walk the routing objects starting at the activating intermediary. var routingObjects = _routeWalker.WalkSendRoute(RuleName, scenarioName, activatingIntermediary, intermediaries, channels, endpoints); // Get the information from the endpoints and intermediaries into one list, filtering out any intermediaries or endpoints which dont have a scenario step. var configurationRoutingObjects = routingObjects.Where(r => r.RoutingObject is Intermediary) .Select(r => r.RoutingObject as Intermediary) .Where(i => i.Properties.ContainsKey(ModelConstants.ScenarioStepName) && i.Activator == false) .Select(i => new { ScenarioStepName = i.Properties[ModelConstants.ScenarioStepName].ToString(), Resources = i.Resources, }) .Union( routingObjects.Where(r => r.RoutingObject is Endpoint) .Select(r => r.RoutingObject as Endpoint) .Where(ep => ep.Properties.ContainsKey(ModelConstants.ScenarioStepName)) .Select(ep => new { ScenarioStepName = ep.Properties[ModelConstants.ScenarioStepName].ToString(), Resources = ep.Resources, })); // Initialise the JSON routing slip config. var routes = new JArray(); var routingSlipConfig = new JObject { ["routes"] = routes }; var buildRoutingSlipConfig = true; // Get all template resources in the route. var routeResources = routingObjects.SelectMany(i => i.RoutingObject.Resources); // Build the routes. foreach (var configurationRoutingObject in configurationRoutingObjects) { // Find the logic app resource under the routing object. var logicAppResource = FindLogicAppResource(routeResources, scenarioName, configurationRoutingObject.ScenarioStepName); if (logicAppResource == null) { // Find the logic app resource under the application. var applicationResources = targetApplication.Intermediaries.SelectMany(i => i.Resources).Union(targetApplication.Endpoints.SelectMany(e => e.Resources)); logicAppResource = FindLogicAppResource(applicationResources, targetApplication.Name, configurationRoutingObject.ScenarioStepName); if (logicAppResource == null) { // Find the logic app resource at the global level as this is a common resource. var messageBusResources = Model.FindAllTargetResourceTemplates(); logicAppResource = FindLogicAppResource(messageBusResources, Model.MigrationTarget.MessageBus.Name, configurationRoutingObject.ScenarioStepName); } } if (logicAppResource != null) { // Generate the routing config. routes.Add(BuildRoutingSlipConfig(configurationRoutingObject.ScenarioStepName, logicAppResource)); } else { // Log failure to parse the route. _logger.LogDebug(TraceMessages.UnableToFindResourceWithTypeInTargetModelForScenarioStepName, RuleName, ModelConstants.ResourceTypeAzureLogicApp, configurationRoutingObject.ScenarioStepName); buildRoutingSlipConfig = false; } } if (buildRoutingSlipConfig) { var conversionPath = Context.ConversionFolder; var appConfigResource = activatingIntermediary.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypeRoutingSlip); if (appConfigResource != null) { var fileName = $"{scenarioName}".ToLowerInvariant().Replace(" ", string.Empty);; var outputPath = new FileInfo(Path.Combine(conversionPath, Path.Combine(appConfigResource.OutputPath, $"{fileName}.routingslip.json"))); _fileRepository.WriteJsonFile(outputPath.FullName, routingSlipConfig); } else { _logger.LogError(ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingSlip, activatingIntermediary.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingSlip, activatingIntermediary.Name))); } } else { // Remove the resources to generate the routing slip as there is no valid route. var routingSlipResource = activatingIntermediary.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypeRoutingSlip); if (routingSlipResource != null) { var resourceName = routingSlipResource.ResourceName; var powerShellResource = activatingIntermediary.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypePowerShell && r.ResourceName == resourceName); if (powerShellResource != null) { activatingIntermediary.Resources.Remove(routingSlipResource); activatingIntermediary.Resources.Remove(powerShellResource); // Log. _logger.LogDebug(TraceMessages.RoutingSlipNotGeneratedForScenario, RuleName, activatingIntermediary.Properties[ModelConstants.ScenarioName]); // Add to report. activatingIntermediary.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Warning, Message = WarningMessages.RoutingSlipNotGeneratedForScenario }); } else { _logger.LogError(ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypePowerShell, activatingIntermediary.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypePowerShell, activatingIntermediary.Name))); } } else { _logger.LogError(ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingSlip, activatingIntermediary.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingSlip, activatingIntermediary.Name))); } } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP002SendRoutingSlipGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }
protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP004SendConfigurationEntryGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP004SendConfigurationEntryGenerator)); // Get all of the intermediaries and endpoints from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); var endpoints = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Endpoints); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the activatable intermediaries (that are topic subscribers), which have config. foreach (var activatingIntermediary in targetApplication.Intermediaries.Where(i => i.Activator == true && i is MessageSubscriber && !string.IsNullOrEmpty(i.ResourceMapKey))) { var appConfigResource = activatingIntermediary.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypeConfigurationEntry); if (appConfigResource != null) { // Get any global config from the resource. var globalConfig = new JObject( new JProperty("globalConfig", new JObject( from globalConfigSetting in appConfigResource.Parameters where globalConfigSetting.Key.StartsWith(ModelConstants.ResourceTemplateParamterGlobalConfigPrefix, StringComparison.OrdinalIgnoreCase) select new JProperty( globalConfigSetting.Key.Replace(ModelConstants.ResourceTemplateParamterGlobalConfigPrefix, string.Empty).Replace("_", " ").ConvertSnakeCaseToCamelCase(), globalConfigSetting.Value) ))); // Get scenario name var scenarioName = activatingIntermediary.Properties[ModelConstants.ScenarioName].ToString(); // Walk the routing objects starting at the activating intermediary. var routingObjects = _routeWalker.WalkSendRoute(RuleName, scenarioName, activatingIntermediary, intermediaries, channels, endpoints); // Get the information from the routing objects into one list, filtering out any routing objects which dont have a scenario step. var configurationObjects = from routingObject in routingObjects where routingObject.RoutingObject.Properties.ContainsKey(ModelConstants.ScenarioStepName) select new { ScenarioStepName = routingObject.RoutingObject.Properties[ModelConstants.ScenarioStepName].ToString(), Configuration = routingObject.RoutingObject.Properties.TryGetValue(ModelConstants.ConfigurationEntry, out var value) ? value as Dictionary <string, object> : new Dictionary <string, object>() }; // Generate the JSON configuration. var configurationEntry = new JObject( from configurationObject in configurationObjects where configurationObject.Configuration != null select new JProperty(configurationObject.ScenarioStepName, new JObject( from configurationProperty in configurationObject.Configuration.AsEnumerable() select new JProperty(configurationProperty.Key, configurationProperty.Value != null ? JToken.FromObject(configurationProperty.Value) : null) )) ); // Merge in the global config. configurationEntry.Merge(globalConfig, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union }); var fileName = $"{scenarioName}".ToLowerInvariant().Replace(" ", string.Empty);; var conversionPath = Context.ConversionFolder; var outputPath = new FileInfo(Path.Combine(conversionPath, Path.Combine(appConfigResource.OutputPath, $"{fileName}.configurationentry.json"))); _fileRepository.WriteJsonFile(outputPath.FullName, configurationEntry); } else { _logger.LogError(ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeConfigurationEntry, activatingIntermediary.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeConfigurationEntry, activatingIntermediary.Name))); } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP004SendConfigurationEntryGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }
protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP005SendRoutingPropertyGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP005SendRoutingPropertyGenerator)); // Get all of the intermediaries, channels and endpoints from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); var endpoints = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Endpoints); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the activating intermediaries (that are topic subscribers). foreach (var activatingIntermediary in targetApplication.Intermediaries.Where(i => i.Activator == true && i is MessageSubscriber && !string.IsNullOrEmpty(i.ResourceMapKey))) { // Get the scenario name. var scenarioName = activatingIntermediary.Properties[ModelConstants.ScenarioName].ToString(); // Walk the routing objects starting at the activating intermediary. var routingObjects = _routeWalker.WalkSendRoute(RuleName, scenarioName, activatingIntermediary, intermediaries, channels, endpoints); // Get the information from the endpoints and intermediaries into one list, filtering out any intermediaries or endpoints which don't have routing properties. var scenarioStepRoutes = routingObjects.Where(r => r.RoutingObject is Intermediary) .Select(r => r.RoutingObject as Intermediary) .Where(i => i.Properties.ContainsKey(ModelConstants.RoutingProperties)) .Select(i => new { RoutingProperties = i.Properties[ModelConstants.RoutingProperties] as Dictionary <string, object> }) .Union( routingObjects.Where(r => r.RoutingObject is Endpoint) .Select(r => r.RoutingObject as Endpoint) .Where(ep => ep.Properties.ContainsKey(ModelConstants.RoutingProperties)) .Select(ep => new { RoutingProperties = ep.Properties[ModelConstants.RoutingProperties] as Dictionary <string, object> })); // Generate the routing property config as JSON. var routingConfig = new JObject( new JProperty("routingProperties", new JArray( from scenarioStepRoute in scenarioStepRoutes from routingProperty in scenarioStepRoute.RoutingProperties select new JObject( new JProperty("propertyName", routingProperty.Key), new JProperty("propertyType", "property"), new JProperty("propertyValue", routingProperty.Value) ) ) )); var conversionPath = Context.ConversionFolder; var appConfigResource = activatingIntermediary.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypeRoutingProperties); if (appConfigResource != null) { var fileName = $"{scenarioName}".ToLowerInvariant().Replace(" ", string.Empty); var outputPath = new FileInfo(Path.Combine(conversionPath, Path.Combine(appConfigResource.OutputPath, $"{fileName}.routingproperties.json"))); _fileRepository.WriteJsonFile(outputPath.FullName, routingConfig); } else { _logger.LogError(ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.RoutingProperties, activatingIntermediary.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingProperties, activatingIntermediary.Name))); } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP005SendRoutingPropertyGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }