public ProjectConverter(
     ILogger logger,
     ITransformationSet transformationSet,
     ConversionOptions conversionOptions = null)
 {
     this.logger            = logger;
     this.conversionOptions = conversionOptions ?? new ConversionOptions();
     this.transformationSet = transformationSet ?? BasicReadTransformationSet.Instance;
     projectReader          = new ProjectReader(logger, this.conversionOptions);
 }
示例#2
0
        public static IReadOnlyCollection <ITransformation> IterateTransformations(this ITransformationSet set,
                                                                                   ILogger logger, ConversionOptions conversionOptions)
        {
            var all = set.Transformations(logger, conversionOptions);

            var(normal, others) = all.Split(FilterTargetNormalTransformations);
            var(early, late)    = others.Split(x =>
                                               ((ITransformationWithTargetMoment)x).ExecutionMoment == TargetTransformationExecutionMoment.Early);
            var res = new List <ITransformation>(all.Count);

            TopologicalSort(early, res, logger);
            TopologicalSort(normal, res, logger);
            TopologicalSort(late, res, logger);
            return(res);
        }
示例#3
0
        private void WizardModernize(IReadOnlyCollection <Project> projects, ITransformationSet transformationSet,
                                     ConversionOptions conversionOptions)
        {
            var transformations = transformationSet.CollectAndOrderTransformations(facility.Logger, conversionOptions);

            var doBackups = AskBinaryChoice("Would you like to create backups?");

            var writer = new ProjectWriter(facility.Logger, new ProjectWriteOptions {
                MakeBackups = doBackups
            });

            foreach (var project in projects)
            {
                using (facility.Logger.BeginScope(project.FilePath))
                {
                    var projectName = Path.GetFileNameWithoutExtension(project.FilePath.Name);
                    Log.Information("Modernizing {ProjectName}...", projectName);

                    if (!project.Valid)
                    {
                        Log.Error("Project {ProjectName} is marked as invalid, skipping...", projectName);
                        continue;
                    }

                    foreach (var transformation in transformations.WhereSuitable(project, conversionOptions))
                    {
                        try
                        {
                            transformation.Transform(project);
                        }
                        catch (Exception e)
                        {
                            Log.Error(e, "Transformation {Item} has thrown an exception, skipping...",
                                      transformation.GetType().Name);
                        }
                    }

                    if (!writer.TryWrite(project))
                    {
                        continue;
                    }
                    Log.Information("Project {ProjectName} has been modernized", projectName);
                }
            }
        }
示例#4
0
        public IReadOnlyCollection <Project> ParseProjects(
            IEnumerable <string> items,
            ITransformationSet transformationSet,
            ConversionOptions conversionOptions)
        {
            var convertedProjects = new List <Project>();

            foreach (var file in items)
            {
                var projects = new ProjectConverter(genericLogger, transformationSet, conversionOptions)
                               .Convert(file)
                               .Where(x => x != null)
                               .ToList();
                convertedProjects.AddRange(projects);
            }

            return(convertedProjects);
        }
        private void WizardModernCleanUp(IReadOnlyList <Project> modern, ITransformationSet transformationSet,
                                         ConversionOptions conversionOptions)
        {
            var transformations = transformationSet.CollectAndOrderTransformations(facility.Logger, conversionOptions);

            var writer = new ProjectWriter(facility.Logger, new ProjectWriteOptions());

            foreach (var project in modern)
            {
                using (facility.Logger.BeginScope(project.FilePath))
                {
                    var projectName = Path.GetFileNameWithoutExtension(project.FilePath.Name);
                    Log.Information("Processing {ProjectName}...", projectName);

                    if (!project.Valid)
                    {
                        Log.Error("Project {ProjectName} is marked as invalid, skipping...", projectName);
                        continue;
                    }

                    foreach (var transformation in transformations.WhereSuitable(project, conversionOptions))
                    {
                        try
                        {
                            transformation.Transform(project);
                        }
                        catch (Exception e)
                        {
                            Log.Error(e, "Transformation {Item} has thrown an exception, skipping...",
                                      transformation.GetType().Name);
                        }
                    }

                    if (!writer.TryWrite(project))
                    {
                        continue;
                    }
                    Log.Information("Project {ProjectName} has been processed", projectName);
                }
            }
        }
示例#6
0
 /// <summary>
 /// Choose and order all transformations from set that are suitable for the project type.
 /// </summary>
 /// <param name="set">Transformation set to choose from</param>
 /// <param name="project">Project to be based upon when determining suitability</param>
 /// <param name="logger">Logger for transformations to use</param>
 /// <param name="conversionOptions">Conversion options for transformations to use, or to override suitability choice</param>
 /// <returns></returns>
 public static IEnumerable <ITransformation> IterateSuitableTransformations(this ITransformationSet set,
                                                                            Project project, ILogger logger, ConversionOptions conversionOptions)
 {
     return(set.CollectAndOrderTransformations(logger, conversionOptions).WhereSuitable(project, conversionOptions));
 }
示例#7
0
        public static IReadOnlyCollection <ITransformation> CollectAndOrderTransformations(this ITransformationSet set,
                                                                                           ILogger logger, ConversionOptions conversionOptions)
        {
            var all = set.Transformations(logger, conversionOptions);

            var(normal, others) = all.Split(FilterTargetNormalTransformations);
            var(early, late)    = others.Split(x =>
                                               ((ITransformationWithTargetMoment)x).ExecutionMoment == TargetTransformationExecutionMoment.Early);
            var res = new List <ITransformation>(all.Count);

            TopologicalSort(early, res, logger);
            TopologicalSort(normal, res, logger);
            TopologicalSort(late, res, logger);

            foreach (var(transformation, index) in res.Select((x, i) => (x, i)))
            {
                logger.LogTrace("{Index}: {TransformName}", index + 1, transformation.GetType().Name);
            }

            return(res);
        }