Example #1
0
        static void Main(string[] args)
        {
            try
            {
                PortCoreRulesCli cli = new PortCoreRulesCli();
                cli.HandleCommand(args);
                Console.WriteLine(cli.FilePath);

                /* 1. Logger object */
                var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Debug).AddConsole());

                LogHelper.Logger = loggerFactory.CreateLogger("Translator");


                if (string.IsNullOrEmpty(cli.RulesPath))
                {
                    //TODO : Change the hard coded path to a constant
                    cli.RulesPath = Config.Constants.RulesDefaultPath;
                }

                string solutionDir  = Directory.GetParent(cli.FilePath).FullName;
                var    projectFiles = Directory.EnumerateFiles(solutionDir, "*.csproj", SearchOption.AllDirectories);

                List <PortCoreConfiguration> configs = new List <PortCoreConfiguration>();
                foreach (var proj in projectFiles)
                {
                    PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
                    {
                        ProjectPath     = proj,
                        RulesPath       = cli.RulesPath,
                        IsMockRun       = cli.IsMockRun,
                        UseDefaultRules = cli.DefaultRules,
                        TargetVersions  = new List <string> {
                            cli.Version
                        }
                    };

                    configs.Add(projectConfiguration);
                }

                //Solution Rewriter:
                SolutionPort solutionPort = new SolutionPort(cli.FilePath, configs);
                var          s            = solutionPort.AnalysisRun();
                foreach (var k in s.Keys)
                {
                    Console.WriteLine(k);
                    Console.WriteLine(s[k].ToString());
                }
                var portSolutionResult = solutionPort.Run();
            }
            catch (Exception ex)
            {
                LogHelper.LogError("Error while running solution rewriter: {0}", ex.Message);
            }
        }
Example #2
0
        public ProjectPort(AnalyzerResult analyzerResult, PortCoreConfiguration projectConfiguration, SolutionPort solutionPort, ILogger logger = null)
        {
            if (logger != null)
            {
                LogHelper.Logger = logger;
            }

            _solutionPort     = solutionPort;
            ProjectReferences = new HashSet <string>()
            {
                Constants.ProjectRecommendationFile
            };
            InitProjectRewriter(analyzerResult, projectConfiguration);
        }
Example #3
0
        static void Main(string[] args)
        {
            try
            {
                PortCoreRulesCli cli = new PortCoreRulesCli();

                cli.HandleCommand(args);

                Console.WriteLine(cli.FilePath);

                /* 1. Logger object */
                var loggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.Debug).AddConsole());

                LogHelper.Logger = loggerFactory.CreateLogger("Translator");


                if (string.IsNullOrEmpty(cli.RulesDir))
                {
                    //TODO : Change the hard coded path to a constant
                    cli.RulesDir = Config.Constants.RulesDefaultPath;
                }

                if (cli.CreateNew)
                {
                    cli.FilePath = Utils.CopySolutionToTemp(cli.FilePath);
                }

                var projectFiles = Utils.GetProjectPaths(cli.FilePath);

                var packageReferences = new Dictionary <string, Tuple <string, string> >
                {
                    { "Microsoft.EntityFrameworkCore", new Tuple <string, string>("0.0.0", "*") }
                };

                List <PortCoreConfiguration> configs = new List <PortCoreConfiguration>();
                foreach (var proj in projectFiles)
                {
                    PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
                    {
                        SolutionPath      = cli.FilePath,
                        ProjectPath       = proj,
                        RulesDir          = cli.RulesDir,
                        IsMockRun         = cli.IsMockRun,
                        UseDefaultRules   = cli.DefaultRules,
                        PackageReferences = packageReferences,
                        PortCode          = true,
                        PortProject       = true,
                        TargetVersions    = new List <string> {
                            cli.Version
                        }
                    };

                    configs.Add(projectConfiguration);
                }

                //Solution Rewriter:
                SolutionPort solutionPort = new SolutionPort(cli.FilePath, configs);
                var          s            = solutionPort.AnalysisRun();
                foreach (var k in s.ProjectResults)
                {
                    Console.WriteLine(k.ProjectFile);
                    Console.WriteLine(k.ProjectActions.ToString());
                }

                var portSolutionResult = solutionPort.Run();
            }
            catch (Exception ex)
            {
                LogHelper.LogError("Error while running solution rewriter: {0}", ex.Message);
            }
        }