protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP006ReceiveRoutingPropertyGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP006ReceiveRoutingPropertyGenerator)); // Get all of the intermediaries and channels from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the receive endpoints and request/reply send points, which have config. foreach (var initiatingEndpoint in targetApplication.Endpoints.Where( ep => (ep.Activator || ep.MessageExchangePattern == ApplicationModel.Target.Endpoints.MessageExchangePattern.RequestReply) && !string.IsNullOrEmpty(ep.ResourceMapKey)) ) { // Get the scenario name. var scenarioName = initiatingEndpoint.Properties[ModelConstants.ScenarioName].ToString(); // Walk the routing objects starting at the initiating endpoint. var routingObjects = _routeWalker.WalkReceiveRoute(RuleName, scenarioName, initiatingEndpoint, intermediaries, channels); // 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 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> }) .Union( 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> })); // 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 = initiatingEndpoint.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, initiatingEndpoint.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingProperties, initiatingEndpoint.Name))); } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP006ReceiveRoutingPropertyGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }
protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP003ReceiveConfigurationEntryGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP003ReceiveConfigurationEntryGenerator)); // Get all of the intermediaries and channels from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the receive endpoints and request/reply send points, which have config. foreach (var initiatingEndpoint in targetApplication.Endpoints.Where( ep => (ep.Activator || ep.MessageExchangePattern == ApplicationModel.Target.Endpoints.MessageExchangePattern.RequestReply) && !string.IsNullOrEmpty(ep.ResourceMapKey)) ) { var scenarioName = initiatingEndpoint.Properties[ModelConstants.ScenarioName].ToString(); var scenarioStepName = initiatingEndpoint.Properties[ModelConstants.ScenarioStepName].ToString(); var appConfigResource = initiatingEndpoint.Resources.SingleOrDefault(r => r.ResourceType == ModelConstants.ResourceTypeConfigurationEntry); if (appConfigResource != null) { // Walk the intermediaries starting at the receive endpoint. var routingObjects = _routeWalker.WalkReceiveRoute(RuleName, scenarioName, initiatingEndpoint, intermediaries, channels); // 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 the configuration object. 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 conversionPath = Context.ConversionFolder; var fileName = $"{initiatingEndpoint.Properties[ModelConstants.ScenarioName]}".ToLowerInvariant().Replace(" ", string.Empty);; 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, initiatingEndpoint.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeConfigurationEntry, initiatingEndpoint.Name))); } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP003ReceiveConfigurationEntryGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }
protected override async Task ConvertInternalAsync(CancellationToken token) { if (Model.MigrationTarget.MessageBus?.Applications == null) { _logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(AP001ReceiveRoutingSlipGenerator)); } else { _logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(AP001ReceiveRoutingSlipGenerator)); // Get all of the intermediaries and channels from the migration target. var intermediaries = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Intermediaries); var channels = Model.MigrationTarget.MessageBus.Applications.SelectMany(a => a.Channels); foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications) { // Loop through all of the receive endpoints and request/reply send points, which have config. foreach (var initiatingEndpoint in targetApplication.Endpoints.Where( ep => (ep.Activator || ep.MessageExchangePattern == ApplicationModel.Target.Endpoints.MessageExchangePattern.RequestReply) && !string.IsNullOrEmpty(ep.ResourceMapKey)) ) { // Get scenario name var scenarioName = initiatingEndpoint.Properties[ModelConstants.ScenarioName].ToString(); // Walk the intermediaries starting at the receive endpoint. var routingObjects = _routeWalker.WalkReceiveRoute(RuleName, scenarioName, initiatingEndpoint, intermediaries, channels); // Get the messaging objects in the route which are intermediaries. var routingIntermediaries = from routingObject in routingObjects where routingObject.RoutingObject is Intermediary select new { Intermediary = (Intermediary)routingObject.RoutingObject, Channel = routingObject.InputChannel }; // Filter out the intermediaries which don't have a scenario step. var configurationIntermediaries = routingIntermediaries.Where(i => i.Intermediary.Properties.ContainsKey(ModelConstants.ScenarioStepName)); // Initialise the JSON routing slip config. var routes = new JArray(); var routingSlipConfig = new JObject { ["routes"] = routes }; // Get all template resources in the route. var routeResources = routingIntermediaries.Select(i => i.Intermediary).SelectMany(i => i.Resources); // Build the routes. foreach (var configurationIntermediary in configurationIntermediaries) { var scenarioStepName = configurationIntermediary.Intermediary.Properties[ModelConstants.ScenarioStepName].ToString(); // Find the logic app resource in the route. var logicAppResource = FindLogicAppResource(routeResources, scenarioName, scenarioStepName); if (logicAppResource == null) { // Find the logic app resource under the application. var applicationResources = targetApplication.Intermediaries.SelectMany(i => i.Resources); logicAppResource = FindLogicAppResource(applicationResources, targetApplication.Name, 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, scenarioStepName); } } if (logicAppResource != null) { // Generate the routing conig. routes.Add(BuildRoutingSlipConfig(scenarioStepName, logicAppResource)); } else { _logger.LogError(ErrorMessages.UnableToFindResourceWithTypeInTargetModelForScenarioStepName, ModelConstants.ResourceTypeAzureLogicApp, scenarioStepName); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceWithTypeInTargetModelForScenarioStepName, ModelConstants.ResourceTypeAzureLogicApp, scenarioStepName))); } } var conversionPath = Context.ConversionFolder; var appConfigResource = initiatingEndpoint.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, initiatingEndpoint.Name); Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeRoutingSlip, initiatingEndpoint.Name))); } } } _logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(AP001ReceiveRoutingSlipGenerator)); } await Task.CompletedTask.ConfigureAwait(false); }