Пример #1
0
        protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
        {
            var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>();

            if (group?.Applications == null)
            {
                _logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(ApplicationDefinitionParser));
            }
            else
            {
                _logger.LogDebug(TraceMessages.RunningParser, nameof(ApplicationDefinitionParser));

                foreach (var application in group.Applications)
                {
                    try
                    {
                        // Defensive check
                        if (application.Application.ApplicationDefinition == null)
                        {
                            _logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
                            continue;
                        }

                        _logger.LogDebug(TraceMessages.ParsingBizTalkApplicationDefinitionFileFromResourceContainer, application.Application.ApplicationDefinition.ResourceContainerKey);

                        var adf = from resourceContainer in model.MigrationSource.ResourceContainers
                                  from resourceDefinition in resourceContainer.ResourceDefinitions
                                  where resourceContainer.Key == application.ResourceContainerKey &&
                                  application.Application.ApplicationDefinition.ResourceContainerKey == resourceContainer.Key &&
                                  application.Application.ApplicationDefinition.ResourceDefinitionKey == resourceDefinition.Key &&
                                  resourceDefinition.Type == ModelConstants.ResourceDefinitionApplicationDefinition
                                  select resourceDefinition;

                        var adfResourceDefinition = adf.Single();
                        var applicationDefinition = ApplicationDefinition.FromXml((string)adfResourceDefinition.ResourceContent);
                        application.Application.ApplicationDefinition.ApplicationDefinition = applicationDefinition;
                    }
                    catch (Exception ex)
                    {
                        var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorReadingApplicationDefinition, application.Application.Name, ex.Message);
                        context.Errors.Add(new ErrorMessage(message));
                        _logger.LogError(message);
                    }
                }

                _logger.LogDebug(TraceMessages.CompletedParser, nameof(ApplicationDefinitionParser));
            }
        }
Пример #2
0
        protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
        {
            var group = model.GetSourceModel <ParsedBizTalkApplicationGroup>();

            if (group?.Applications == null)
            {
                _logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(BizTalkApplicationParser));
            }
            else
            {
                _logger.LogDebug(TraceMessages.RunningParser, nameof(BizTalkApplicationParser));

                foreach (var application in group.Applications)
                {
                    try
                    {
                        // Defensive check
                        if (application.Application.ApplicationDefinition == null)
                        {
                            _logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
                            continue;
                        }

                        _logger.LogDebug(TraceMessages.ParsingBizTalkApplicationFromResourceContainer, application.Application.ApplicationDefinition.ResourceContainerKey);

                        var adf = from resourceContainer in model.MigrationSource.ResourceContainers
                                  from resourceDefinition in resourceContainer.ResourceDefinitions
                                  where resourceContainer.Key == application.ResourceContainerKey &&
                                  application.Application.ApplicationDefinition.ResourceContainerKey == resourceContainer.Key &&
                                  application.Application.ApplicationDefinition.ResourceDefinitionKey == resourceDefinition.Key &&
                                  resourceDefinition.Type == ModelConstants.ResourceDefinitionApplicationDefinition
                                  select resourceDefinition;

                        var applicationResourceDefinition = adf.SingleOrDefault();
                        if (applicationResourceDefinition == null)
                        {
                            _logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
                            continue;
                        }

                        var applicationDefinition = application.Application.ApplicationDefinition.ApplicationDefinition ?? ApplicationDefinition.FromXml((string)applicationResourceDefinition.ResourceContent); // Only parse if not already deserialized.
                        var applicationName       = applicationDefinition.Properties.Where(p => p.Name == BizTalkApplicationParser.ApplicationDisplayNameProperty).SingleOrDefault();

                        if (applicationName != null && !string.IsNullOrWhiteSpace(applicationName.Value))
                        {
                            // Check to see if there is already an application in the source with this name (duplicate names can occur is passing multiple unrelated
                            // MSI files).
                            var duplicateApplication = model.FindResourcesByType(ModelConstants.ResourceApplication).Any(a => a.Name == applicationName.Value);

                            // Set application name
                            application.Application.Name = applicationName.Value;
                            if (duplicateApplication)
                            {
                                application.Application.Name = $"{application.Application.Name} {ResourceItemProperties.Duplicate}";
                            }

                            // Define resource key for application.
                            var resourceKey = string.Concat(applicationResourceDefinition.Key, ":", applicationName);
                            application.Application.ApplicationDefinition.ResourceKey = resourceKey;

                            // Create the application resource under the application definition resource.
                            var applicationResource = new ResourceItem
                            {
                                Name        = applicationName.Value,
                                Description = applicationDefinition.Properties.Where(p => p.Name == BizTalkApplicationParser.ApplicationDescriptionProperty).SingleOrDefault()?.Value,
                                Key         = resourceKey,
                                Type        = ModelConstants.ResourceApplication,
                                ParentRefId = applicationResourceDefinition.RefId,
                                Rating      = ConversionRating.NotSupported
                            };

                            application.Application.ApplicationDefinition.Resource = applicationResource; // Maintain pointer to the resource.
                            applicationResource.SourceObject = applicationDefinition;                     // Maintain backward pointer.
                            applicationResourceDefinition.Resources.Add(applicationResource);

                            _logger.LogTrace(TraceMessages.ResourceCreated, nameof(BizTalkApplicationParser), applicationResource.Key, applicationResource.Name, applicationResource.Type, applicationResource.Key);

                            // If this does not exist then update on the source model.
                            if (application.Application.ApplicationDefinition.ApplicationDefinition == null)
                            {
                                application.Application.ApplicationDefinition.ApplicationDefinition = applicationDefinition;
                            }

                            _logger.LogDebug(TraceMessages.ParsedTheBizTalkApplicationWithName, application.Application.Name);

                            // Raise an error if this was a duplicate application
                            if (duplicateApplication)
                            {
                                // Raise an error that there is already an application with this name
                                var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.DuplicateApplicationFound, applicationName.Value);
                                context.Errors.Add(new ErrorMessage(message));
                                _logger.LogError(message);
                            }
                        }
                        else
                        {
                            var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ApplicationNameNotFound, applicationResourceDefinition.Key);
                            context.Errors.Add(new ErrorMessage(message));
                            _logger.LogError(message);
                        }
                    }
                    catch (Exception ex)
                    {
                        var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorReadingApplicationFromAdf, application.Application.ApplicationDefinition.ResourceDefinitionKey, ex.Message);
                        context.Errors.Add(new ErrorMessage(message));
                        _logger.LogError(message);
                    }
                }

                _logger.LogDebug(TraceMessages.CompletedParser, nameof(BizTalkApplicationParser));
            }
        }