コード例 #1
0
        public WebFormsToRazorConverter(DirectoryHandler directoryHandler)
        {
            DirectoryHandler = directoryHandler;
            var catalog   = new AssemblyCatalog(typeof(IWebFormsParser).Assembly);
            var container = new CompositionContainer(catalog);

            container.ComposeParts(this);
        }
コード例 #2
0
        public void Run(string[] args)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            if (args.Length < 1)
            {
                DisplayUsage();
                return;
            }

            var outputDirectory  = (args.Length >= 2 && !args[1].StartsWith("-")) ? args[1] : "";
            var directoryHandler = new DirectoryHandler(args[0], outputDirectory);
            var Errors           = new List <string>();
            var recursive        = args.Contains("-r", StringComparer.InvariantCultureIgnoreCase);
            var files            = directoryHandler.GetFiles(recursive);

            foreach (var file in files)
            {
                try
                {
                    Console.WriteLine("Converting {0}", file);

                    var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                    var webFormsDocument   = Parser.Parse(webFormsPageSource);
                    var razorDom           = Converter.Convert(webFormsDocument);
                    var razorPage          = Renderer.Render(razorDom);

                    var outputFileName = ReplaceExtension(directoryHandler.GetOutputFileName(file), ".cshtml");
                    Console.WriteLine("Writing    {0}", outputFileName);
                    EnsureDirectory(Path.GetDirectoryName(outputFileName));
                    File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);

                    Console.WriteLine("Done\n");
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e);
                    Console.ForegroundColor = ConsoleColor.White;
                    Errors.Add(file + ":" + e.Message);
                }
            }

            foreach (var error in Errors)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(error);
                Console.ForegroundColor = ConsoleColor.White;
            }

            var elapsed = stopwatch.Elapsed;

            Console.WriteLine();
            Console.WriteLine("{0} files converted", files.Length);
            Console.WriteLine("Elapsed: {0} seconds", elapsed.TotalSeconds);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ashwingdl/razor-converter
        public void Run(string[] args)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            if (args.Length < 1)
            {
                DisplayUsage();
                return;
            }

            var outputDirectory = (args.Length >= 2 && !args[1].StartsWith("-")) ? args[1] : "";
            var directoryHandler = new DirectoryHandler(args[0], outputDirectory);

            var recursive = args.Contains("-r", StringComparer.InvariantCultureIgnoreCase);
            var files = directoryHandler.GetFiles(recursive);
            foreach (var file in files)
            {
                Console.WriteLine("Converting {0}", file);

                var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                var webFormsDocument = Parser.Parse(webFormsPageSource);
                var razorDom = Converter.Convert(webFormsDocument);
                var razorPage = Renderer.Render(razorDom);

                var outputFileName = ReplaceExtension(directoryHandler.GetOutputFileName(file), ".cshtml");
                Console.WriteLine("Writing    {0}", outputFileName);
                EnsureDirectory(Path.GetDirectoryName(outputFileName));
                File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);

                Console.WriteLine("Done\n");
            }

            var elapsed = stopwatch.Elapsed;
            Console.WriteLine();
            Console.WriteLine("{0} files converted", files.Length);
            Console.WriteLine("Elapsed: {0} seconds", elapsed.TotalSeconds);
        }
コード例 #4
0
        public (int successCount, IList <string> fails) Convert(IEnumerable <string> files)
        {
            int successCount = 0;
            var fails        = new List <string>();

            foreach (var file in files)
            {
                Console.WriteLine("Converting {0}", file);

                try
                {
                    var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                    var webFormsDocument   = Parser.Parse(webFormsPageSource);
                    var razorDom           = Converter.Convert(webFormsDocument);
                    var razorPage          = Renderer.Render(razorDom);

                    var outputFileName = ReplaceExtension(DirectoryHandler.GetOutputFileName(file), ".cshtml");
                    Console.WriteLine("Writing    {0}", outputFileName);
                    EnsureDirectory(Path.GetDirectoryName(outputFileName));
                    File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);

                    Console.WriteLine("Done");
                    successCount++;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception Thrown!");
                    AddFail(file, ex.Message, fails);
                }
                finally
                {
                    Console.WriteLine();
                }
            }
            return(successCount, fails);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: sebnilsson/razor-converter
        public void Run(string[] args)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            if(args.Length < 1) {
                DisplayUsage();
                return;
            }

            var failList = new List<string>();
            int successCount = 0;

            var outputDirectory = (args.Length >= 2 && !args[1].StartsWith("-")) ? args[1] : "";

            DirectoryHandler directoryHandler;
            try {
                directoryHandler = new DirectoryHandler(args[0], outputDirectory);
            }
            catch(ArgumentException ex) {
                Console.WriteLine("The given directories were not valid: {0}", ex.Message);
                return;
            }

            var recursive = args.Contains("-r", StringComparer.InvariantCultureIgnoreCase);
            var files = directoryHandler.GetFiles(recursive);
            foreach(var file in files) {
                Console.WriteLine("Converting {0}", file);

                try {
                    var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                    var webFormsDocument = Parser.Parse(webFormsPageSource);
                    var razorDom = Converter.Convert(webFormsDocument);
                    var razorPage = Renderer.Render(razorDom);

                    var outputFileName = ReplaceExtension(directoryHandler.GetOutputFileName(file), ".cshtml");
                    Console.WriteLine("Writing    {0}", outputFileName);
                    EnsureDirectory(Path.GetDirectoryName(outputFileName));
                    File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);

                    Console.WriteLine("Done");
                    successCount++;
                }
                catch(Exception ex) {
                    Console.WriteLine("Exception Thrown!");
                    AddFail(file, ex.Message, failList);
                }
                finally {
                    Console.WriteLine();
                }
            }

            var elapsed = stopwatch.Elapsed;
            Console.WriteLine();
            Console.WriteLine("{0} files converted", successCount);

            if(failList.Any()) {
                Console.WriteLine();
                Console.WriteLine("{0} files failed:", failList.Count);
                failList.ForEach(fail => Console.WriteLine(fail));
                Console.WriteLine();
            }

            Console.WriteLine("Elapsed: {0} seconds", elapsed.TotalSeconds);
        }
コード例 #6
0
        public void Run(string[] args)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            if (args.Length < 1)
            {
                DisplayUsage();
                return;
            }

            var failList     = new List <string>();
            int successCount = 0;

            var outputDirectory = (args.Length >= 2 && !args[1].StartsWith("-")) ? args[1] : "";

            DirectoryHandler directoryHandler;

            try {
                directoryHandler = new DirectoryHandler(args[0], outputDirectory);
            }
            catch (ArgumentException ex) {
                Console.WriteLine("The given directories were not valid: {0}", ex.Message);
                return;
            }

            var recursive = args.Contains("-r", StringComparer.InvariantCultureIgnoreCase);
            var files     = directoryHandler.GetFiles(recursive);

            foreach (var file in files)
            {
                Console.WriteLine("Converting {0}", file);

                try {
                    var webFormsPageSource = File.ReadAllText(file, Encoding.UTF8);
                    var webFormsDocument   = Parser.Parse(webFormsPageSource);
                    var razorDom           = Converter.Convert(webFormsDocument);
                    var razorPage          = Renderer.Render(razorDom);

                    var outputFileName = ReplaceExtension(directoryHandler.GetOutputFileName(file), ".cshtml");
                    Console.WriteLine("Writing    {0}", outputFileName);
                    EnsureDirectory(Path.GetDirectoryName(outputFileName));
                    File.WriteAllText(outputFileName, razorPage, Encoding.UTF8);

                    Console.WriteLine("Done");
                    successCount++;
                }
                catch (Exception ex) {
                    Console.WriteLine("Exception Thrown!");
                    AddFail(file, ex.Message, failList);
                }
                finally {
                    Console.WriteLine();
                }
            }

            var elapsed = stopwatch.Elapsed;

            Console.WriteLine();
            Console.WriteLine("{0} files converted", successCount);

            if (failList.Any())
            {
                Console.WriteLine();
                Console.WriteLine("{0} files failed:", failList.Count);
                failList.ForEach(fail => Console.WriteLine(fail));
                Console.WriteLine();
            }

            Console.WriteLine("Elapsed: {0} seconds", elapsed.TotalSeconds);
        }