示例#1
0
        /// <summary>
        /// Rewrites the assemblies specified in the configuration.
        /// </summary>
        private static void RewriteAssemblies(Configuration configuration, RewritingOptions options)
        {
            try
            {
                if (options.AssemblyPaths.Count is 1)
                {
                    Console.WriteLine($". Rewriting {options.AssemblyPaths.First()}");
                }
                else
                {
                    Console.WriteLine($". Rewriting the assemblies specified in {options.AssembliesDirectory}");
                }

                var profiler = new Profiler();
                RewritingEngine.Run(options, configuration, profiler);
                Console.WriteLine($". Done rewriting in {profiler.Results()} sec");
            }
            catch (Exception ex)
            {
                if (ex is AggregateException aex)
                {
                    ex = aex.Flatten().InnerException;
                }

                Error.ReportAndExit(configuration.IsDebugVerbosityEnabled ? ex.ToString() : ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// Rewrites the assemblies specified in the configuration.
        /// </summary>
        private static void RewriteAssemblies(Configuration configuration, RewritingOptions options)
        {
            try
            {
                string assemblyDir = null;
                var    fileList    = new HashSet <string>();
                if (!string.IsNullOrEmpty(configuration.AssemblyToBeAnalyzed))
                {
                    var fullPath = Path.GetFullPath(configuration.AssemblyToBeAnalyzed);
                    Console.WriteLine($". Rewriting {fullPath}");
                    assemblyDir = Path.GetDirectoryName(fullPath);
                    fileList.Add(fullPath);
                }
                else if (Directory.Exists(configuration.RewritingOptionsPath))
                {
                    assemblyDir = Path.GetFullPath(configuration.RewritingOptionsPath);
                    Console.WriteLine($". Rewriting the assemblies specified in {assemblyDir}");
                }

                RewritingOptions config = options;

                if (!string.IsNullOrEmpty(assemblyDir))
                {
                    // Create a new RewritingOptions object from command line args only.
                    config.AssembliesDirectory = assemblyDir;
                    config.OutputDirectory     = assemblyDir;
                    config.AssemblyPaths       = fileList;
                }
                else
                {
                    // Load options from JSON file.
                    config = RewritingOptions.ParseFromJSON(configuration.RewritingOptionsPath);
                    Console.WriteLine($". Rewriting the assemblies specified in {configuration.RewritingOptionsPath}");
                    config.PlatformVersion = configuration.PlatformVersion;

                    // Allow command line options to override the JSON configuration file options.
                    config.Merge(options);
                }

                RewritingEngine.Run(configuration, config);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
                Error.ReportAndExit(ex.Message);
            }
        }