示例#1
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);
                }
            }
        }
        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);
                }
            }
        }
示例#3
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));
 }