public void RenderTemplateAsyncWithResourceTemplateWithSuccess(ITemplateRenderer renderer, AzureIntegrationServicesModel model, MessagingObject messagingObject, TargetResourceTemplate resourceTemplate, string templateContent, string renderedContent, Exception e) { "Given a template renderer" .x(() => renderer = new LiquidTemplateRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a messaging object" .x(() => messagingObject = model.FindMessagingObject("ContosoMessageBus:System:FtpReceive").messagingObject); "And a resource template object" .x(() => resourceTemplate = new TargetResourceTemplate() { ResourceName = "endpointFtpReceiveLogicAppConsumption" }); "And a template content" .x(() => templateContent = _templateResourceTemplateContent); "When rendering the template" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderTemplateAsync(templateContent, model, null, resourceTemplate))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.ContainAny("endpointFtpReceiveLogicAppConsumption").And.NotContainAny("{{").And.NotContainAny("}}"); }); }
/// <summary> /// Generates a template file by loading, rendering and saving the file to the conversion path /// if it is a .liquid file, otherwise just copy the file. /// </summary> /// <param name="messagingObject">The messaging object associated with the list of resource templates.</param> /// <param name="resourceTemplate">The resource template for this render.</param> /// <param name="templatePaths">The list of source template paths.</param> /// <param name="templateFile">The template file.</param> /// <param name="templateOutputPath">The output path for template files.</param> /// <param name="conversionPathRoot">The root path for all converted files.</param> /// <returns></returns> private async Task<bool> GenerateFileAsync(MessagingObject messagingObject, TargetResourceTemplate resourceTemplate, IEnumerable<DirectoryInfo> templatePaths, string templateFile, string templateOutputPath, DirectoryInfo conversionPathRoot) { var foundTemplate = false; foreach (var templatePath in templatePaths) { var templateFilePath = new FileInfo(Path.Combine(templatePath.FullName, templateFile)); if (_fileRepository.DoesFileExist(templateFilePath.FullName)) { // Check extension if (templateFilePath.Extension.ToUpperInvariant() == ".liquid".ToUpperInvariant()) { _logger.LogTrace(TraceMessages.LoadingTemplate, templateFilePath.FullName); // Load template var templateContent = await _repository.LoadTemplateAsync(templateFilePath.FullName).ConfigureAwait(false); _logger.LogDebug(TraceMessages.RenderingTemplate, templateFilePath.FullName); // Render template var renderedContent = await _renderer.RenderTemplateAsync(templateContent, Model, messagingObject, resourceTemplate).ConfigureAwait(false); // Set output file path var outputFilePath = new FileInfo(Path.Combine(conversionPathRoot.FullName, templateOutputPath, Path.GetFileNameWithoutExtension(templateFilePath.Name))); _logger.LogTrace(TraceMessages.SavingTemplate, outputFilePath.FullName); // Save rendered template await _repository.SaveTemplateAsync(outputFilePath.FullName, renderedContent).ConfigureAwait(false); } else { // Set output file path var outputFilePath = new FileInfo(Path.Combine(conversionPathRoot.FullName, templateOutputPath, templateFilePath.Name)); _logger.LogDebug(TraceMessages.CopyingTemplate, templateFilePath.FullName, outputFilePath.FullName); // Create output path if some directories don't exist if (!_fileRepository.DoesDirectoryExist(outputFilePath.FullName)) { _fileRepository.CreateDirectory(outputFilePath.DirectoryName); } // Just a normal file, copy it to output path _fileRepository.CopyFile(templateFilePath.FullName, outputFilePath.FullName); } foundTemplate = true; } } return foundTemplate; }
/// <summary> /// Build the routing slip config in JSON. /// </summary> /// <param name="scenarioStepName">The name of the scenario step.</param> /// <param name="resource">The resource containing the routing slip information.</param> /// <returns>The routing slip config.</returns> private static JObject BuildRoutingSlipConfig(string scenarioStepName, TargetResourceTemplate resource) { var resourceGroup = resource.Parameters.TryGetValue(ModelConstants.ResourceTemplateParameterAzureResourceGroupName, out var value) ? value as string : string.Empty; switch (resource.ResourceType) { case ModelConstants.ResourceTypeAzureLogicAppConsumption: { return(JObject.FromObject(new { name = scenarioStepName, routingSteps = new { channelType = ModelConstants.TriggerChannelAzureApim }, routingParameters = new { messageReceiverType = resource.ResourceType, parameters = new { resourceId = $"/{resourceGroup}/{resource?.ResourceName}" } } })); } case ModelConstants.ResourceTypeAzureLogicAppStandard: { return(JObject.FromObject(new { name = scenarioStepName, routingSteps = new { channelType = ModelConstants.TriggerChannelAzureApim }, routingParameters = new { messageReceiverType = resource.ResourceType, parameters = new { resourceId = $"/{resourceGroup}/{resource?.Parameters[ModelConstants.ResourceTemplateParameterAzureLogicAppName]}/{resource?.ResourceName}" } } })); } default: { return(new JObject()); } } }
/// <summary> /// Sorts messaging objects by their name. /// </summary> /// <param name="x">The first item to be compared.</param> /// <param name="y">The second item to be compared.</param> /// <returns>An integer indicating the comparison between x and y.</returns> public static int SortTargetResourceTemplatesByTypeAndName(TargetResourceTemplate x, TargetResourceTemplate y) { _ = x ?? throw new ArgumentNullException(nameof(x)); _ = y ?? throw new ArgumentNullException(nameof(y)); if (x.ResourceType == y.ResourceType) { // Equal on type - sort on name return(string.Compare(x.ResourceName, y.ResourceName, true, CultureInfo.CurrentCulture)); } ; return(string.Compare(ResourceFormatter.GetTargetResourceFriendlyName(x.ResourceType), ResourceFormatter.GetTargetResourceFriendlyName(y.ResourceType), true, CultureInfo.CurrentCulture)); }
/// <summary> /// Build the routing slip config in JSON. /// </summary> /// <param name="scenarioStepName">The name of the scenario step.</param> /// <param name="resource">The resource containing the routing slip information.</param> /// <returns>The routing slip config.</returns> private static JObject BuildRoutingSlipConfig(string scenarioStepName, TargetResourceTemplate resource) { return(JObject.FromObject(new { name = scenarioStepName, routingSteps = new { channelType = ModelConstants.TriggerChannelAzureApim }, routingParameters = new { messageReceiverType = resource.ResourceType, parameters = new { resourceId = $"/{resource?.Parameters[ModelConstants.ResourceTemplateParameterAzureResourceGroupName]}/{resource?.ResourceName}" } } })); }
public void RenderTemplateAsyncWithSnippetContentNullError(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a process manager" .x(() => { var messagingObject = model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); }); "And a workflow object" .x(() => { workflowObject = processManager.WorkflowModel.Activities.First(); }); "And null snippet content" .x(() => snippetContent = null); "When rendering the template" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, processManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should error" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("snippetContent")); "And the rendered content should not have a value" .x(() => renderedContent.Should().BeNull()); }
public void RenderSnippetAsyncWithMissingMessagingObjectWithWarning(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, ProcessManager missingProcessManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a missing process manager" .x(() => { missingProcessManager = new ProcessManager("MissingProcessManager") { Key = "MissingProcessManager" }; }); "And a workflow object" .x(() => { var messagingObject = model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); workflowObject = processManager.WorkflowModel.Activities.First(); }); "And a snippet content" .x(() => snippetContent = _missingProcessManagerSnippet); "When rendering the snippet" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, missingProcessManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should not have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.Be("").And.NotContainAny("{{").And.NotContainAny("}}"); // Verify warning was raised _mockLogger.Verify(l => l.Log( It.Is <LogLevel>(l => l == LogLevel.Warning), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => v.ToString().Contains("does not appear in the target model", StringComparison.CurrentCultureIgnoreCase)), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.Once); }); }
public void RenderSnippetAsyncWithSuccess(ISnippetRenderer renderer, AzureIntegrationServicesModel model, ProcessManager processManager, TargetResourceTemplate resourceTemplate, TargetResourceSnippet resourceSnippet, WorkflowObject workflowObject, string snippetContent, string renderedContent, Exception e) { "Given a snippet renderer" .x(() => renderer = new LiquidSnippetRenderer(_mockLogger.Object)); "And a model" .x(() => model = _model); "And a process manager" .x(() => { var messagingObject = model.FindMessagingObject("ContosoMessageBus:AppA:FtpTransformWorkflow"); messagingObject.messagingObject.Should().NotBeNull().And.BeOfType(typeof(ProcessManager)); processManager = (ProcessManager)messagingObject.messagingObject; resourceTemplate = processManager.Resources.First(); resourceSnippet = processManager.Snippets.First(); }); "And a workflow object" .x(() => { workflowObject = processManager.WorkflowModel.Activities.First(); }); "And a snippet content" .x(() => snippetContent = _snippetContent); "When rendering the snippet" .x(async() => e = await Record.ExceptionAsync(async() => renderedContent = await renderer.RenderSnippetAsync(snippetContent, model, processManager, resourceTemplate, resourceSnippet, workflowObject))); "Then the render should succeed" .x(() => e.Should().BeNull()); "And the rendered content should have expected values from the model" .x(() => { renderedContent.Should().NotBeNull().And.ContainAny($"StepName:_{workflowObject.Name.Replace(" ", "_", StringComparison.InvariantCulture)}").And.NotContainAny("{{").And.NotContainAny("}}"); }); }
/// <summary> /// Creates a target resource for the template. /// </summary> /// <param name="model">The model.</param> /// <param name="templateKey">The key of the template.</param> /// <param name="templateNode">The template from configuration.</param> /// <returns></returns> private TargetResourceTemplate CreateTargetResourceTemplate(AzureIntegrationServicesModel model, YamlScalarNode templateKey, YamlMappingNode templateNode) { // Mandatory fields var targetResource = new TargetResourceTemplate() { TemplateKey = ((YamlScalarNode)templateNode.Children["template"]).Value, TemplateType = ((YamlScalarNode)templateNode.Children["templateType"]).Value, ResourceName = ((YamlScalarNode)templateNode.Children["resourceName"]).Value, ResourceType = ((YamlScalarNode)templateNode.Children["resourceType"]).Value }; // Optional fields if (templateNode.Children.ContainsKey("outputPath")) { targetResource.OutputPath = ((YamlScalarNode)templateNode.Children["outputPath"]).Value; } // Tags if (templateNode.Children.ContainsKey("tags")) { var templateTags = templateNode.Children["tags"] as YamlSequenceNode; if (templateTags != null) { foreach (var tag in templateTags) { var tagNode = ((YamlMappingNode)tag).Children.SingleOrDefault(); targetResource.Tags.Add(((YamlScalarNode)tagNode.Key).Value, ((YamlScalarNode)tagNode.Value).Value); } } } // Parameters if (templateNode.Children.ContainsKey("parameters")) { var templateParams = templateNode.Children["parameters"] as YamlSequenceNode; if (templateParams != null) { foreach (var param in templateParams) { var paramNode = ((YamlMappingNode)param).Children.SingleOrDefault(); targetResource.Parameters.Add(((YamlScalarNode)paramNode.Key).Value, ((YamlScalarNode)paramNode.Value).Value); } } } // Files if (templateNode.Children.ContainsKey("files")) { var templateFiles = templateNode.Children["files"] as YamlSequenceNode; if (templateFiles != null) { _logger.LogTrace(TraceMessages.FilteringTemplatesByEnvironment, model.MigrationTarget.DeploymentEnvironment, templateKey.Value); foreach (var templateFileNode in templateFiles) { var templateFile = (YamlMappingNode)templateFileNode; // Filter by deployment environment var envNameNode = templateFile.Children["env"] as YamlSequenceNode; if (envNameNode != null) { var envNames = envNameNode.Select(t => ((YamlScalarNode)t).Value.ToUpperInvariant()); if (envNames.Contains(model.MigrationTarget.DeploymentEnvironment.ToUpperInvariant())) { _logger.LogTrace(TraceMessages.FoundFilesForEnvironment, model.MigrationTarget.DeploymentEnvironment, templateKey.Value); // Get paths - note that if there are no paths defined, then this node is a YamlScalarNode. var pathsList = templateFile.Children["paths"] as YamlSequenceNode; if (pathsList != null) { foreach (var path in pathsList) { targetResource.ResourceTemplateFiles.Add(((YamlScalarNode)path).Value); } } } } } } } return(targetResource); }
/// <summary> /// Builds a target model. /// </summary> /// <param name="model">The model.</param> private static void BuildTargetModel(AzureIntegrationServicesModel model) { model.MigrationTarget.TargetEnvironment = AzureIntegrationServicesTargetEnvironment.Consumption; model.MigrationTarget.DeploymentEnvironment = "dev"; model.MigrationTarget.AzurePrimaryRegion = "UK South"; model.MigrationTarget.AzureSecondaryRegion = "West US"; model.MigrationTarget.UniqueDeploymentId = "unit-test"; model.MigrationTarget.MessageBus = new MessageBus() { Name = "Message Bus", Key = "MessageBus", Type = MessagingObjectType.MessageBus, Description = "Azure Integration Services Message Bus", ResourceMapKey = "messageBus", Rating = ConversionRating.NotSupported }; // Message Bus resources var resource1 = new TargetResourceTemplate() { TemplateKey = "deployResources", TemplateType = "microsoft.template.powershell", ResourceName = "deploy-resources", ResourceType = "microsoft.scripts.powershell", OutputPath = "" }; resource1.ResourceTemplateFiles.Add("Deploy-All.ps1.liquid"); resource1.ResourceTemplateFiles.Add("TearDown-All.ps1.liquid"); model.MigrationTarget.MessageBus.Resources.Add(resource1); var resource2 = new TargetResourceTemplate() { TemplateKey = "messageBusAzureResourceGroup", TemplateType = "microsoft.template.arm", ResourceName = "arrg-aimmsgbus-dev-uksouth", ResourceType = "microsoft.groups.azureresourcegroup", OutputPath = "messagebus/messagebusgroup", }; resource2.Tags.Add("ApplicationName", "AIM-MessageBus"); resource2.Tags.Add("Env", "dev"); resource2.Parameters.Add("azure_primary_region", "UK South"); resource2.Parameters.Add("azure_secondary_region", "West US"); resource2.Parameters.Add("azure_subscription_id", ""); resource2.ResourceTemplateFiles.Add("messagebus/messagebusgroup/messagebusgroup.dev.parameters.json.liquid"); resource2.ResourceTemplateFiles.Add("messagebus/messagebusgroup/messagebusgroup.json.liquid"); model.MigrationTarget.MessageBus.Resources.Add(resource2); var resource3 = new TargetResourceTemplate() { TemplateKey = "deployMessageBusGroup", TemplateType = "microsoft.template.powershell", ResourceName = "arrg-aimmsgbus-dev-uksouth", ResourceType = "microsoft.scripts.powershell", OutputPath = "messagebus/messagebusgroup", }; resource3.Parameters.Add("azure_primary_region", "UK South"); resource3.Parameters.Add("azure_secondary_region", "West US"); resource3.Parameters.Add("azure_subscription_id", ""); resource3.ResourceTemplateFiles.Add("messagebus/messagebusgroup/Deploy-10-MessageBusGroup.ps1.liquid"); resource3.ResourceTemplateFiles.Add("messagebus/messagebusgroup/New-MessageBusGroup.ps1.liquid"); resource3.ResourceTemplateFiles.Add("messagebus/messagebusgroup/TearDown-10-MessageBusGroup.ps1.liquid"); resource3.ResourceTemplateFiles.Add("messagebus/messagebusgroup/Remove-MessageBusGroup.ps1.liquid"); model.MigrationTarget.MessageBus.Resources.Add(resource3); var resource4 = new TargetResourceTemplate() { TemplateKey = "messageBusServiceAzureRole", TemplateType = "microsoft.template.json", ResourceName = "arapim-aimmsgbussvc-dev", ResourceType = "microsoft.security.azurerole", OutputPath = "messagebus/messagebusservice" }; resource4.ResourceTemplateFiles.Add("messagebus/messagebusservice/messagebusservice.logicappsrole.json"); model.MigrationTarget.MessageBus.Resources.Add(resource4); // Applications var application1 = new Application() { Name = "BTS2010FlatFilePipelineSample", Key = "MessageBus:BTS2010FlatFilePipelineSample", Type = MessagingObjectType.Application, Description = "Azure Integration Application", ResourceMapKey = "applicationBTS2010FlatFilePipelineSample", Rating = ConversionRating.NoRating, }; model.MigrationTarget.MessageBus.Applications.Add(application1); var appresource1 = new TargetResourceTemplate() { TemplateKey = "applicationAzureResourceGroupBTS2010FlatFilePipelineSample", TemplateType = "microsoft.template.arm", ResourceName = "arrg-aimapp-bts2010flatfilepipelinesample-dev-uksouth", ResourceType = "microsoft.groups.azureresourcegroup", OutputPath = "applications/bts2010flatfilepipelinesample/bts2010flatfilepipelinesamplegroup", }; appresource1.Tags.Add("ApplicationName", "BTS2010FlatFilePipelineSample"); appresource1.Tags.Add("Env", "dev"); appresource1.Parameters.Add("azure_primary_region", "UK South"); appresource1.Parameters.Add("azure_secondary_region", "West US"); appresource1.Parameters.Add("azure_subscription_id", ""); appresource1.ResourceTemplateFiles.Add("application/applicationgroup/applicationgroup.json.liquid"); appresource1.ResourceTemplateFiles.Add("application/applicationgroup/applicationgroup.dev.parameters.json.liquid"); application1.Resources.Add(appresource1); var appresource2 = new TargetResourceTemplate() { TemplateKey = "deployApplicationGroupBTS2010FlatFilePipelineSample", TemplateType = "microsoft.template.powershell", ResourceName = "arrg-aimapp-bts2010flatfilepipelinesample-dev-uksouth", ResourceType = "microsoft.scripts.powershell", OutputPath = "applications/bts2010flatfilepipelinesample/bts2010flatfilepipelinesamplegroup", }; appresource2.Parameters.Add("azure_primary_region", "UK South"); appresource2.Parameters.Add("azure_secondary_region", "West US"); appresource2.Parameters.Add("azure_subscription_id", ""); appresource2.ResourceTemplateFiles.Add("application/applicationgroup/Deploy-10-ApplicationGroup.ps1.liquid"); appresource2.ResourceTemplateFiles.Add("application/applicationgroup/New-ApplicationGroup.ps1.liquid"); appresource2.ResourceTemplateFiles.Add("application/applicationgroup/TearDown-10-ApplicationGroup.ps1.liquid"); appresource2.ResourceTemplateFiles.Add("application/applicationgroup/Remove-ApplicationGroup.ps1.liquid"); application1.Resources.Add(appresource2); // Messages in the application var documentmessage1 = new DocumentMessage() { MessageType = MessageType.Document, ContentType = MessageContentType.Xml, MessageSchema = new MessageSchema() { Name = "NewOrder", ResourceKeyRef = "BTS2010FlatFilePipelineSample:ITEM~0:BTS2010FlatFilePipelineSample:NewOrder:schema:Order" }, Name = "NewOrder", Key = "MessageBus:BTS2010FlatFilePipelineSample:NewOrder", Type = MessagingObjectType.Message, Description = "Azure Integration Application Schema", ResourceMapKey = "applicationMessageBTS2010FlatFilePipelineSampleNewOrder", Rating = ConversionRating.NoRating }; application1.Messages.Add(documentmessage1); var messageresource1 = new TargetResourceTemplate() { TemplateKey = "deploySchemaBTS2010FlatFilePipelineSampleNewOrder", TemplateType = "microsoft.template.powershell", ResourceName = "NewOrder", ResourceType = "microsoft.scripts.powershell", OutputPath = "applications/BTS2010FlatFilePipelineSample/messages/neworder", }; messageresource1.Parameters.Add("azure_primary_region", "UK South"); messageresource1.Parameters.Add("azure_secondary_region", "West US"); messageresource1.Parameters.Add("azure_subscription_id", ""); messageresource1.Parameters.Add("azure_resource_group_name", "arrg-aimmsgbus-dev-uksouth"); messageresource1.Parameters.Add("azure_integration_account_name", "arintacc-aimartifactstore-dev-uksouth"); messageresource1.Parameters.Add("azure_message_schema_name", "BTS2010FlatFilePipelineSample.NewOrder"); messageresource1.ResourceTemplateFiles.Add("messages/schemas/Deploy-100-Schema.ps1.liquid"); messageresource1.ResourceTemplateFiles.Add("messages/schemas/New-Schema.ps1.liquid"); messageresource1.ResourceTemplateFiles.Add("messages/schemas/Remove-Schema.ps1.liquid"); messageresource1.ResourceTemplateFiles.Add("messages/schemas/TearDown-100-Schema.ps1.liquid"); documentmessage1.Resources.Add(messageresource1); var messageresource2 = new TargetResourceTemplate() { TemplateKey = "messagesAzureIntegrationAccountSchemaBTS2010FlatFilePipelineSampleNewOrder", TemplateType = "microsoft.template.json", ResourceName = "NewOrder", ResourceType = "microsoft.schemas.xml", OutputPath = "applications/BTS2010FlatFilePipelineSample/messages/neworder", }; messageresource2.Tags.Add("Application", "BTS2010FlatFilePipelineSample"); messageresource2.Tags.Add("Env", "dev"); messageresource2.Parameters.Add("azure_primary_region", "UK South"); messageresource2.Parameters.Add("azure_secondary_region", "West US"); messageresource2.Parameters.Add("azure_subscription_id", ""); messageresource2.Parameters.Add("azure_resource_group_name", "arrg-aimmsgbus-dev-uksouth"); messageresource2.Parameters.Add("azure_integration_account_name", "arintacc-aimartifactstore-dev-uksouth"); messageresource2.Parameters.Add("azure_message_schema_name", "BTS2010FlatFilePipelineSample.NewOrder"); messageresource2.ResourceTemplateFiles.Add("messages/schemas/requestbody.dev.json.liquid"); documentmessage1.Resources.Add(messageresource2); // Endpoints var ftpadapter1 = new AdapterEndpoint() { Type = MessagingObjectType.Endpoint, AdapterProtocol = "FTP", MessageExchangePattern = MessageExchangePattern.Receive, Name = "FTP Receive", Description = "FTP Receive Adapter", EndpointType = EndpointType.Adapter, MessageDeliveryGuarantee = MessageDeliveryGuarantee.AtLeastOnce, Activator = true, }; ftpadapter1.MessageKeyRefs.Add("MessageBus:BTS2010FlatFilePipelineSample:NewOrder"); ftpadapter1.OutputChannelKeyRef = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RcvFile.FTP-RoutingSlipRouter"; ftpadapter1.Properties.Add("scenario", "Aim.BizTalk.FTPPassthru.RcvFile.RcvFile.FTP"); ftpadapter1.Properties.Add("scenarioStep", "ftpReceiveAdapter"); ftpadapter1.Properties.Add("configuration", new Dictionary <string, object> { { "btsReceivePortName", "RcvFile" } }); ftpadapter1.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Error, Message = ModelResources.ExampleErrorMessage }); ftpadapter1.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Warning, Message = ModelResources.ExampleWarningMessage }); ftpadapter1.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Information, Message = ModelResources.ExampleInformationMessage }); application1.Endpoints.Add(ftpadapter1); var adapterresource1 = new TargetResourceTemplate() { TemplateKey = "deploySchemaBTS2010FlatFilePipelineSampleNewOrder", TemplateType = "microsoft.template.powershell", ResourceName = "NewOrder", ResourceType = "microsoft.scripts.powershell", OutputPath = "applications/BTS2010FlatFilePipelineSample/messages/neworder", }; adapterresource1.Parameters.Add("azure_primary_region", "UK South"); adapterresource1.Parameters.Add("azure_secondary_region", "West US"); adapterresource1.Parameters.Add("azure_subscription_id", ""); adapterresource1.Parameters.Add("azure_resource_group_name", "arrg-aimmsgbus-dev-uksouth"); adapterresource1.Parameters.Add("azure_integration_account_name", "arintacc-aimartifactstore-dev-uksouth"); adapterresource1.Parameters.Add("azure_message_schema_name", "BTS2010FlatFilePipelineSample.NewOrder"); adapterresource1.ResourceTemplateFiles.Add("messages/schemas/Deploy-100-Schema.ps1.liquid"); adapterresource1.ResourceTemplateFiles.Add("messages/schemas/New-Schema.ps1.liquid"); adapterresource1.ResourceTemplateFiles.Add("messages/schemas/Remove-Schema.ps1.liquid"); adapterresource1.ResourceTemplateFiles.Add("messages/schemas/TearDown-100-Schema.ps1.liquid"); ftpadapter1.Resources.Add(adapterresource1); var adapterresource2 = new TargetResourceTemplate() { TemplateKey = "messagesAzureIntegrationAccountSchemaBTS2010FlatFilePipelineSampleNewOrder", TemplateType = "microsoft.template.json", ResourceName = "NewOrder", ResourceType = "microsoft.schemas.xml", OutputPath = "applications/BTS2010FlatFilePipelineSample/messages/neworder", }; adapterresource2.Tags.Add("Application", "BTS2010FlatFilePipelineSample"); adapterresource2.Tags.Add("Env", "dev"); adapterresource2.Parameters.Add("azure_primary_region", "UK South"); adapterresource2.Parameters.Add("azure_secondary_region", "West US"); adapterresource2.Parameters.Add("azure_subscription_id", ""); adapterresource2.Parameters.Add("azure_resource_group_name", "arrg-aimmsgbus-dev-uksouth"); adapterresource2.Parameters.Add("azure_integration_account_name", "arintacc-aimartifactstore-dev-uksouth"); adapterresource2.Parameters.Add("azure_message_schema_name", "BTS2010FlatFilePipelineSample.NewOrder"); adapterresource2.ResourceTemplateFiles.Add("messages/schemas/requestbody.dev.json.liquid"); ftpadapter1.Resources.Add(adapterresource2); // Create the channel for the FTP adapter var channel1 = new TriggerChannel() { Type = MessagingObjectType.Channel, ChannelType = ChannelType.PointToPoint, Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RcvFile.FTP-RoutingSlipRouter", Name = "Trigger Channel", Description = "The trigger channel sends a message to a URL endpoint which triggers the Microsoft.AzureIntegrationMigration.ApplicationModel.Target.Intermediaries.RoutingSlipRouter intermediary.", }; application1.Channels.Add(channel1); var routingSlipRouter = new RoutingSlipRouter() { Type = MessagingObjectType.Intermediary, IntermediaryType = IntermediaryType.MessageRouter, MessageRouterType = MessageRouterType.ContentBasedRouter, Name = "Routing Slip Router", Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:RoutingSlipRouter:RcvFile.FTP-ContentPromoter", Description = "The routing slip router calls the next step in the route which is Content Promoter.", }; routingSlipRouter.InputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RcvFile.FTP-RoutingSlipRouter"); routingSlipRouter.OutputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); application1.Intermediaries.Add(routingSlipRouter); var channel2 = new TriggerChannel() { Type = MessagingObjectType.Channel, ChannelType = ChannelType.PointToPoint, Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter", Name = "Trigger Channel", Description = "The trigger channel sends a message to a URL endpoint which triggers the Microsoft.AzureIntegrationMigration.ApplicationModel.Target.Intermediaries.ContentPromoter intermediary.", TriggerUrl = "/routingManager/route/contentPromoter" }; application1.Channels.Add(channel2); var contentPromoter = new ContentPromoter() { Type = MessagingObjectType.Intermediary, IntermediaryType = IntermediaryType.MessageProcessor, MessageProcessorType = MessageProcessorType.ContentPromoter, }; contentPromoter.InputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); contentPromoter.OutputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:ContentPromoter-RoutingSlipRouter"); application1.Intermediaries.Add(contentPromoter); var channel3 = new TriggerChannel() { Type = MessagingObjectType.Channel, ChannelType = ChannelType.PointToPoint, Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:ContentPromoter-RoutingSlipRouter", Name = "Trigger Channel", Description = "The trigger channel sends a message to a URL endpoint which triggers the Microsoft.AzureIntegrationMigration.ApplicationModel.Target.Intermediaries.RoutingSlipRouter intermediary.", }; application1.Channels.Add(channel3); var routingSlipRouter2 = new RoutingSlipRouter() { Type = MessagingObjectType.Intermediary, IntermediaryType = IntermediaryType.MessageRouter, MessageRouterType = MessageRouterType.ContentBasedRouter, Name = "Routing Slip Router", Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:ContentPromoter", Description = "The routing slip router calls the next step in the route which is Content Promoter.", }; routingSlipRouter2.InputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); routingSlipRouter2.OutputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); application1.Intermediaries.Add(routingSlipRouter2); var channel4 = new TriggerChannel() { Type = MessagingObjectType.Channel, ChannelType = ChannelType.PointToPoint, Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter", Name = "Trigger Channel", Description = "The trigger channel sends a message to a URL endpoint which triggers the Microsoft.AzureIntegrationMigration.ApplicationModel.Target.Intermediaries.ContentPromoter intermediary.", TriggerUrl = "/routingManager/route/contentPromoter" }; application1.Channels.Add(channel4); var contentPromoter2 = new ContentPromoter() { Type = MessagingObjectType.Intermediary, IntermediaryType = IntermediaryType.MessageProcessor, MessageProcessorType = MessageProcessorType.ContentPromoter, Name = "Content Promoter", Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:ContentPromoter", }; contentPromoter2.InputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); contentPromoter2.OutputChannelKeyRefs.Add("MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter"); application1.Intermediaries.Add(contentPromoter2); var channel5 = new TriggerChannel() { Type = MessagingObjectType.Channel, ChannelType = ChannelType.PointToPoint, Key = "MessageBus:Aim.BizTalk.FTPPassthru:RcvFile:RcvFile.FTP:TriggerChannel:RoutingSlipRouter-ContentPromoter", Name = "Trigger Channel", Description = "The trigger channel sends a message to a URL endpoint which triggers the Microsoft.AzureIntegrationMigration.ApplicationModel.Target.Intermediaries.ContentPromoter intermediary.", TriggerUrl = "/routingManager/route/contentPromoter" }; application1.Channels.Add(channel5); // System application var systemapp = new Application() { Name = "System Application", Key = "MessageBus:SystemApplication", Type = MessagingObjectType.Application, Description = "Azure Integration System Application", ResourceMapKey = "applicationSystemApplication", Rating = ConversionRating.NoRating, }; model.MigrationTarget.MessageBus.Applications.Add(systemapp); // Channels in the system application var topicchannel1 = new TopicChannel() { ChannelType = ChannelType.PublishSubscribe, Name = "Message Box", Key = "MessageBus:SystemApplication:MessageBox", Type = MessagingObjectType.Channel, Description = "Azure Integration Message Box", ResourceMapKey = "messageBox", Rating = ConversionRating.NotSupported }; systemapp.Channels.Add(topicchannel1); }
/// <summary> /// Renders a template using a Liquid template engine. /// </summary> /// <param name="templateContent">The template content to render.</param> /// <param name="model">The model used to provide properties to Liquid templates.</param> /// <param name="messagingObject">An optional messaging object to add to the variable context, accessible to templates.</param> /// <param name="resourceTemplate">An optional resource template object to add to the variable context, accessible to templates.</param> /// <returns>The rendered template content.</returns> public async Task <string> RenderTemplateAsync(string templateContent, AzureIntegrationServicesModel model, MessagingObject messagingObject = null, TargetResourceTemplate resourceTemplate = null) { _ = model ?? throw new ArgumentNullException(nameof(model)); _ = templateContent ?? throw new ArgumentNullException(nameof(templateContent)); // Create variables on script object, to be accessible to Liquid templates var scriptObject = new ScriptObject { ["model"] = model }; // Is there a messaging object? if (messagingObject != null) { var messagingObjects = model.FindMessagingObject(messagingObject.Key); if (messagingObjects.messageBus != null) { scriptObject["message_bus"] = messagingObjects.messageBus; if (messagingObjects.application != null) { scriptObject["application"] = messagingObjects.application; } if (messagingObjects.messagingObject != null) { scriptObject["messaging_object"] = messagingObjects.messagingObject; switch (messagingObjects.messagingObject.Type) { case MessagingObjectType.Message: scriptObject["message"] = (Message)messagingObjects.messagingObject; break; case MessagingObjectType.Channel: scriptObject["channel"] = (Channel)messagingObjects.messagingObject; break; case MessagingObjectType.Intermediary: scriptObject["intermediary"] = (Intermediary)messagingObjects.messagingObject; break; case MessagingObjectType.Endpoint: scriptObject["endpoint"] = (Endpoint)messagingObjects.messagingObject; break; } } } else { // Should never happen, unless the messaging object is not attached to the target model _logger.LogWarning(WarningMessages.MessagingObjectMissingInModel, messagingObject.Key); } } // Is there a resource template? if (resourceTemplate != null) { scriptObject["resource_template"] = resourceTemplate; } // Push variables onto the context _context.PushGlobal(scriptObject); try { // Render template var template = Template.ParseLiquid(templateContent); var renderedContent = await template.RenderAsync(_context).ConfigureAwait(false); return(renderedContent); } finally { // Pop model from context stack _context.PopGlobal(); } }
public void FindChannelMissingResourceWithSuccess(AzureIntegrationServicesModel model, string templateKey, TargetResourceTemplate resource, Exception e) { "Given a model" .x(() => model = _model); "And a template key for a resource that doesn't exist" .x(() => templateKey = "missingChannel"); "When finding the resource template" .x(() => e = Record.Exception(() => resource = CustomLiquidFunctions.FindResourceTemplate(model, templateKey))); "Then the find should succeed" .x(() => e.Should().BeNull()); "And the target resource should be null" .x(() => resource.Should().BeNull()); }
public void FindChannelResourceWithSuccess(AzureIntegrationServicesModel model, string templateKey, TargetResourceTemplate resource, Exception e) { "Given a model" .x(() => model = _model); "And a template key" .x(() => templateKey = "topicChannelAzureServiceBusStandard"); "When finding the resource template" .x(() => e = Record.Exception(() => resource = CustomLiquidFunctions.FindResourceTemplate(model, templateKey))); "Then the find should succeed" .x(() => e.Should().BeNull()); "And the target resource should be the expected value from the model" .x(() => { resource.Should().NotBeNull(); resource.TemplateKey.Should().Be("topicChannelAzureServiceBusStandard"); }); }
public void FindChannelResourceWithTemplateKeyNullError(AzureIntegrationServicesModel model, string templateKey, TargetResourceTemplate resource, Exception e) { "Given a model" .x(() => model = _model); "And a null template key" .x(() => templateKey.Should().BeNull()); "When finding the resource template" .x(() => e = Record.Exception(() => resource = CustomLiquidFunctions.FindResourceTemplate(model, templateKey))); "Then the find should succeed" .x(() => e.Should().BeNull()); "And the target resource should be null" .x(() => resource.Should().BeNull()); }
/// <summary> /// Creates a default object model for converting. /// </summary> /// <returns></returns> public static AzureIntegrationServicesModel CreateDefaultModelForConverting() { var model = new AzureIntegrationServicesModel(); // Create a report node with a resource container and resource definitions var resourceContainer = new ResourceContainer() { Name = "TestApp1.msi", Description = "This is the description of the MSI.", Type = ModelConstants.ResourceContainerMsi, Key = "test-app-1-container-key" }; model.MigrationSource.ResourceContainers.Add(resourceContainer); var appResourceDefinition1 = new ResourceDefinition() { Name = "App 1 Resource Definition", Key = "app-1", Description = "App 1 Description", Type = ModelConstants.ResourceDefinitionApplicationDefinition }; resourceContainer.ResourceDefinitions.Add(appResourceDefinition1); var appResource1 = new ResourceItem { Name = "App 1 Resource Definition Application", Key = "app-resource-1", Description = "App 1 Resource Description", Type = ModelConstants.ResourceApplication }; appResourceDefinition1.Resources.Add(appResource1); var appResourceDefinition2 = new ResourceDefinition() { Name = "App 2 Resource Definition", Key = "app-2", Description = "App 2 Description", Type = ModelConstants.ResourceDefinitionApplicationDefinition }; resourceContainer.ResourceDefinitions.Add(appResourceDefinition2); var appResource2 = new ResourceItem { Name = "App 2 Resource Definition Application", Key = "app-resource-2", Description = "App 1 Resource Description", Type = ModelConstants.ResourceApplication }; appResourceDefinition2.Resources.Add(appResource2); var appResourceDefinition3 = new ResourceDefinition() { Name = "App 3 Resource Definition", Key = "app-3", Description = "App 3 Description", Type = ModelConstants.ResourceDefinitionApplicationDefinition }; resourceContainer.ResourceDefinitions.Add(appResourceDefinition3); var appResource3 = new ResourceItem { Name = "App 3 Resource Definition Application", Key = "app-resource-3", Description = "App 3 Resource Description", Type = ModelConstants.ResourceApplication }; appResourceDefinition3.Resources.Add(appResource3); var schemaResourceDefinition1 = new ResourceDefinition() { Name = "DocumentSchema1", Description = "This is document schema 1.", Type = ModelConstants.ResourceDefinitionSchema, Key = "document-schema-1", ResourceContent = "<some xml>" }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition1); var schemaResource1 = new ResourceItem() { Name = "DocumentSchema1", Description = "This is document schema 1.", Type = ModelConstants.ResourceDocumentSchema, Key = "document-schema-1:schema1", ParentRefId = schemaResourceDefinition1.RefId }; schemaResourceDefinition1.Resources.Add(schemaResource1); var messageResource1 = new ResourceItem() { Name = "Message1", Description = "This is message 1.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-1:schema1:message1", ParentRefId = schemaResource1.RefId }; schemaResource1.Resources.Add(messageResource1); var schemaResourceDefinition2 = new ResourceDefinition() { Name = "DocumentSchema2", Description = "This is document schema 2.", Type = ModelConstants.ResourceDefinitionSchema, Key = "document-schema-2", ParentRefId = resourceContainer.RefId }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition2); var schemaResource2 = new ResourceItem() { Name = "DocumentSchema2", Description = "This is document schema 2.", Type = ModelConstants.ResourceDocumentSchema, Key = "document-schema-2:schema2", ParentRefId = schemaResourceDefinition2.RefId }; schemaResourceDefinition2.Resources.Add(schemaResource2); var messageResource2 = new ResourceItem() { Name = "Message2", Description = "This is message 2.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-2:schema2:message2", ParentRefId = schemaResource2.RefId }; schemaResource2.Resources.Add(messageResource2); var schemaResourceDefinition3 = new ResourceDefinition() { Name = "PropertySchema1", Description = "This is property schema 1.", Type = ModelConstants.ResourceDefinitionSchema, Key = "property-schema-1", ParentRefId = resourceContainer.RefId }; resourceContainer.ResourceDefinitions.Add(schemaResourceDefinition3); var schemaResource3 = new ResourceItem() { Name = "PropertySchema1", Description = "This is property schema 2.", Type = ModelConstants.ResourceDocumentSchema, Key = "property-schema-1:schema", ParentRefId = schemaResourceDefinition3.RefId }; schemaResourceDefinition3.Resources.Add(schemaResource3); var messageResource3 = new ResourceItem() { Name = "Message3", Description = "This is message 3.", Type = ModelConstants.ResourceMessageType, Key = "document-schema-3:schema3:message3", ParentRefId = schemaResource3.RefId }; schemaResource3.Resources.Add(messageResource3); var schemaResource3Property1 = new ResourceItem() { Name = "Property1", Description = "This is property 2", Key = "property-schema-1:schema:Property1", Type = ModelConstants.ResourcePropertySchema, ParentRefId = schemaResourceDefinition3.RefId }; schemaResourceDefinition3.Resources.Add(schemaResource3Property1); var schemaResource3Property2 = new ResourceItem() { Name = "Property2", Description = "This is property 2", Key = "property-schema-1:schema:Property2", Type = ModelConstants.ResourcePropertySchema, ParentRefId = schemaResourceDefinition3.RefId }; schemaResourceDefinition3.Resources.Add(schemaResource3Property2); var transformResourceDefinition1 = new ResourceDefinition() { Name = "Transform1", Description = "This is transform 1.", Type = ModelConstants.ResourceDefinitionMap, Key = "transform-1", ParentRefId = resourceContainer.RefId, ResourceContent = "<some xml>" }; resourceContainer.ResourceDefinitions.Add(transformResourceDefinition1); var transformResource1 = new ResourceItem() { Name = "Transform1", Description = "This is the transform 1, resource", Type = ModelConstants.ResourceMap, Key = "transform-1-resource", ParentRefId = transformResourceDefinition1.RefId }; transformResourceDefinition1.Resources.Add(transformResource1); var bindingResourceDefinition1 = new ResourceDefinition() { Name = "Binding1", Description = "This is binding 1.", Type = ModelConstants.ResourceDefinitionBindings, Key = "binding-1", ParentRefId = resourceContainer.RefId }; resourceContainer.ResourceDefinitions.Add(bindingResourceDefinition1); var sendPortResource1 = new ResourceItem() { Name = "SendPort1", Description = "This is sendport 1.", Type = ModelConstants.ResourceSendPort, Key = "sendport-1", ParentRefId = bindingResourceDefinition1.RefId }; bindingResourceDefinition1.Resources.Add(sendPortResource1); var sendPortFilterResource1 = new ResourceItem() { Name = "SendPort1-Filter", Description = "This is sendport 1, filter expression", Type = ModelConstants.ResourceFilterExpression, Key = "sendport-1-filter", ParentRefId = sendPortResource1.RefId }; sendPortResource1.Resources.Add(sendPortFilterResource1); var receivePortResource1 = new ResourceItem() { Name = "ReceivePort1", Description = "This is receive port 1.", Type = ModelConstants.ResourceReceivePort, Key = "receiveport-1", ParentRefId = bindingResourceDefinition1.RefId }; bindingResourceDefinition1.Resources.Add(receivePortResource1); var receiveLocation1 = new ResourceItem() { Name = "ReceiveLocation1", Description = "This is receive location 1.", Type = ModelConstants.ResourceReceiveLocation, Key = "receivelocation-1", ParentRefId = receivePortResource1.RefId }; receivePortResource1.Resources.Add(receiveLocation1); var distributionListResource1 = new ResourceItem { Name = "DistributionList1", Description = "This is distributionlist 1.", Type = ModelConstants.ResourceDistributionList, Key = "distributionlist-1", ParentRefId = bindingResourceDefinition1.RefId }; bindingResourceDefinition1.Resources.Add(distributionListResource1); var distributionListFilterResource1 = new ResourceItem { Name = "DistributionListFilter1", Description = "This is distribution list filer 1.", Type = ModelConstants.ResourceFilterExpression, Key = "distributionlistfilter-1", ParentRefId = distributionListResource1.RefId }; distributionListResource1.Resources.Add(distributionListFilterResource1); // Create a parsed BizTalk Application Group var applicationGroup = new ParsedBizTalkApplicationGroup(); model.MigrationSource.MigrationSourceModel = applicationGroup; // Create applications var application1 = new ParsedBizTalkApplication(); application1.Application.Name = "Test App 1"; applicationGroup.Applications.Add(application1); var application2 = new ParsedBizTalkApplication(); application2.Application.Name = "Test App 2"; application2.Application.Bindings = new BindingFile { BindingInfo = new BindingInfo() }; applicationGroup.Applications.Add(application2); var application3 = new ParsedBizTalkApplication(); application3.Application.Name = "Test App 3"; applicationGroup.Applications.Add(application3); application3.Application.Bindings = new BindingFile { BindingInfo = new BindingInfo() }; // Create application definitions application1.Application.ApplicationDefinition = new ApplicationDefinitionFile() { ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = appResourceDefinition1.Key, ResourceKey = appResource1.Key, ApplicationDefinition = new ApplicationDefinition() { Properties = new List <ApplicationDefinitionProperty>() { new ApplicationDefinitionProperty() { Name = "DisplayName", Value = application1.Application.Name }, new ApplicationDefinitionProperty() { Name = "ApplicationDescription", Value = application1.Application.Name + " Description" } }.ToArray() } }; application2.Application.ApplicationDefinition = new ApplicationDefinitionFile() { ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = appResourceDefinition2.Key, ResourceKey = appResource2.Key, ApplicationDefinition = new ApplicationDefinition() { References = new List <ApplicationDefinitionReference>() { new ApplicationDefinitionReference() { Name = application3.Application.Name } }.ToArray(), Properties = new List <ApplicationDefinitionProperty>() { new ApplicationDefinitionProperty() { Name = "DisplayName", Value = application2.Application.Name }, new ApplicationDefinitionProperty() { Name = "ApplicationDescription", Value = application2.Application.Name + " Description" } }.ToArray() } }; application3.Application.ApplicationDefinition = new ApplicationDefinitionFile() { ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = appResourceDefinition3.Key, ResourceKey = appResource3.Key, ApplicationDefinition = new ApplicationDefinition() { Properties = new List <ApplicationDefinitionProperty>() { new ApplicationDefinitionProperty() { Name = "DisplayName", Value = application3.Application.Name }, new ApplicationDefinitionProperty() { Name = "ApplicationDescription", Value = application3.Application.Name + " Description" } }.ToArray() } }; // Create schemas var documentSchema1 = new Types.Entities.Schema() { Name = "DocumentSchema1", Namespace = "Test.Schemas", FullName = "Test.Schemas.DocumentSchema1", XmlNamespace = "http://schemas.test.com/DocumentSchema1", RootNodeName = "Root", ResourceDefinitionKey = schemaResourceDefinition1.Key, ResourceKey = schemaResource1.Key, SchemaType = BizTalkSchemaType.Document }; documentSchema1.MessageDefinitions.Add(new MessageDefinition(documentSchema1.RootNodeName, documentSchema1.XmlNamespace, "Test.Schemas.DocumentSchema1", "DocumentSchema1", "document-schema-1:schema:Root")); documentSchema1.PromotedProperties.Add(new PromotedProperty() { PropertyType = "Test.Schemas.PropertySchema1.Property1", XPath = "some xpath" }); application1.Application.Schemas.Add(documentSchema1); var documentSchema2 = new Types.Entities.Schema() { Name = "DocumentSchema2", Namespace = "Test.Schemas", FullName = "Test.Schemas.DocumentSchema2", XmlNamespace = "http://schemas.test.com/DocumentSchema2", RootNodeName = "Root", ResourceDefinitionKey = schemaResourceDefinition2.Key, ResourceKey = schemaResource2.Key, SchemaType = BizTalkSchemaType.Document }; documentSchema2.MessageDefinitions.Add(new MessageDefinition(documentSchema2.RootNodeName, documentSchema2.XmlNamespace, "Test.Schemas.DocumentSchema2", "DocumentSchema2", "document-schema-2:schema:Root")); application1.Application.Schemas.Add(documentSchema2); var propertySchema = new Types.Entities.Schema() { Name = "PropertySchema1", Namespace = "Test.Schemas", FullName = "Test.Schemas.PropertySchema1", XmlNamespace = "http://schemas.test.com/PropertySchema1", RootNodeName = "Root", ResourceDefinitionKey = schemaResourceDefinition3.Key, ResourceKey = schemaResource3.Key, SchemaType = BizTalkSchemaType.Property }; propertySchema.ContextProperties.Add(new ContextProperty() { DataType = "xs:string", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property1", PropertyName = schemaResource3Property1.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = schemaResource3Property1.Key }); propertySchema.ContextProperties.Add(new ContextProperty() { DataType = "xs:int", FullyQualifiedName = "Test.Schemas.PropertySchema1.Property2", PropertyName = schemaResource3Property2.Name, Namespace = "Test.Schemas.PropertySchema1", ResourceKey = schemaResource3Property2.Key }); application1.Application.Schemas.Add(propertySchema); // Create transforms var map = new Types.Entities.Transform() { Name = "Transform1", FullName = "Test.Maps.Transform1", ModuleName = "Test.Maps, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", Namespace = "Test.Maps", ResourceContainerKey = resourceContainer.Key, ResourceDefinitionKey = transformResourceDefinition1.Key }; map.SourceSchemaTypeNames.Add("Test.Schemas.DocumentSchema1"); map.TargetSchemaTypeNames.Add("Test.Schemas.DocumentSchema2"); application1.Application.Transforms.Add(map); // Create send ports. var sendPort = new SendPort { ResourceKey = sendPortResource1.Key, Description = "This is a send port description.", Name = "Test.SendPorts.SendPort1", FilterExpression = new Types.Entities.Filters.Filter { Group = new Types.Entities.Filters.Group[] { new Types.Entities.Filters.Group { Statement = new Types.Entities.Filters.Statement[] { new Types.Entities.Filters.Statement() } } } } }; /// Create receive ports. var receivePort = new ReceivePort { ResourceKey = receivePortResource1.Key, Description = receivePortResource1.Description, Name = receivePortResource1.Name, ReceiveLocations = new ReceiveLocation[] { new ReceiveLocation { ResourceKey = receiveLocation1.Key, Name = receiveLocation1.Name, Description = receiveLocation1.Name } } }; // Create distribution lists. var distributionList = new DistributionList { ResourceKey = distributionListResource1.Key, Description = distributionListResource1.Description, Name = distributionListResource1.Name, FilterExpression = new Types.Entities.Filters.Filter { ResourceKey = distributionListFilterResource1.Key, Group = new Types.Entities.Filters.Group[] { new Types.Entities.Filters.Group() } } }; application1.Application.Bindings = new BindingFile { BindingInfo = new BindingInfo { SendPortCollection = new SendPort[] { sendPort }, ReceivePortCollection = new ReceivePort[] { receivePort }, DistributionListCollection = new DistributionList[] { distributionList } } }; // Target model model.MigrationTarget.TargetEnvironment = AzureIntegrationServicesTargetEnvironment.Consumption; model.MigrationTarget.DeploymentEnvironment = "dev"; model.MigrationTarget.AzureSubscriptionId = "azure-subs-id"; model.MigrationTarget.AzurePrimaryRegion = "UK South"; model.MigrationTarget.AzureSecondaryRegion = "UK West"; // Add a message bus model.MigrationTarget.MessageBus = new MessageBus() { Name = "ContosoMessageBus", Key = "ContosoMessageBus", ResourceMapKey = "messageBus", }; var messageBusResourceTemplate = new TargetResourceTemplate() { OutputPath = "output" }; messageBusResourceTemplate.ResourceTemplateFiles.Add("path/to/file.json.liquid"); messageBusResourceTemplate.ResourceTemplateFiles.Add("path/to/file2.json"); model.MigrationTarget.MessageBus.Resources.Add(messageBusResourceTemplate); // Add an application var systemApp = new Application() { Name = "System", Key = "ContosoMessageBus:System" }; model.MigrationTarget.MessageBus.Applications.Add(systemApp); var app = new Application() { Name = "AppA", Key = "ContosoMessageBus:AppA", ResourceMapKey = "application" }; model.MigrationTarget.MessageBus.Applications.Add(app); // Add an application message var appMessage = new DocumentMessage() { Name = "PurchaseOrderFlatFile", MessageSchema = new MessageSchema { ResourceKeyRef = messageResource1.Key, Name = messageResource2.Name }, Key = "ContosoMessageBus:AppA:PurchaseOrderFlatFile", ContentType = MessageContentType.Xml, ResourceMapKey = "applicationMessage" }; app.Messages.Add(appMessage); var appMessageResource1 = new TargetResourceTemplate() { OutputPath = "OutputPath", ResourceType = ModelConstants.ResourceTypeXml }; appMessage.Resources.Add(appMessageResource1); var transform = new MessageTransform { Name = "MessageTransform", ResourceKeyRef = "transform-1-resource", }; appMessage.MessageTransforms.Add(transform); var appMessageResource2 = new TargetResourceTemplate() { OutputPath = "OutputPath", ResourceType = ModelConstants.ResourceTypeXslt }; appMessage.Resources.Add(appMessageResource2); // Add a message box var messageBox = new TopicChannel() { Name = "MessageBox", Key = "ContosoMessageBus:System:MessageBox", ResourceMapKey = "messageBox" }; systemApp.Channels.Add(messageBox); // Add a message agent var messageAgent = new ContentBasedRouter() { Name = "MessageAgent", Key = "ContosoMessageBus:System:MessageAgent", ResourceMapKey = "messageAgent" }; systemApp.Intermediaries.Add(messageAgent); // Add an FTP endpoint var ftpReceive = new AdapterEndpoint() { Name = "FtpReceive", Key = "ContosoMessageBus:System:FtpReceive", ResourceMapKey = "ftpReceive" }; systemApp.Endpoints.Add(ftpReceive); return(model); }