static void Main(string[] args)
        {
            var client = new RoslynCodeConverter.Client.Proxies.RoslynCodeConverter();

            //ConvertResponse result = client.Converter.Post(new ConvertRequest()
            //{
            //    Code = "public class Test {}",
            //    RequestedConversion = SupportedConversions.CSharp2Vb
            //});

            ConvertResponse result = client.Converter.Post(new ConvertRequest()
            {
                Code = "Public Class Test\r\nEnd Class",
                RequestedConversion = SupportedConversions.Vb2CSharp
            });

            if (true == result.ConversionOk)
            {
                Console.WriteLine("Conversion succeeded");
                Console.WriteLine(result.ConvertedCode);
            }
            else
            {
                Console.WriteLine("Error converting: " + result.ErrorMessage);
            }

            Console.Read();
        }
Exemple #2
0
        private async void runConversion_Click(object sender, RoutedEventArgs e)
        {
            outputCode.Text = "";
            string conversionType = SupportedConversions.CSharp2Vb;

            if (cs2vbnetRbtn.IsChecked == true)
            {
                outputCode.SyntaxHighlighting = vbDefinition;
            }
            else
            {
                outputCode.SyntaxHighlighting = csharpDefinition;
                conversionType = SupportedConversions.Vb2CSharp;
            }

            string code = inputCode.Text;

            converterCallInflight.Visibility = Visibility.Visible;
            runConversion.IsEnabled          = false;

            try
            {
                var client = new RoslynCodeConverter.Client.Proxies.RoslynCodeConverter();

                ConvertResponse result = await client.Converter.PostAsync(new ConvertRequest()
                {
                    Code = code,
                    RequestedConversion = conversionType
                });

                if (true == result.ConversionOk)
                {
                    outputCode.Text = result.ConvertedCode;
                }
                else
                {
                    outputCode.SyntaxHighlighting = null;
                    outputCode.Text = result.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                outputCode.SyntaxHighlighting = null;
                outputCode.Text = ex.Message;
            }

            converterCallInflight.Visibility = Visibility.Collapsed;
            runConversion.IsEnabled          = true;
        }
Exemple #3
0
        static bool FileConvertedOk(string file, RoslynCodeConverter.Client.Proxies.RoslynCodeConverter client)
        {
            string code = System.IO.File.ReadAllText(file);

            if (String.IsNullOrWhiteSpace(code))
            {
                return(false);
            }

            ConvertResponse result = client.Converter.Post(new ConvertRequest()
            {
                Code = code,
                RequestedConversion = "cs2vbnet"
            });

            if (true != result.ConversionOk)
            {
                Console.WriteLine("ERROR:" + file);
                Console.WriteLine(result.ErrorMessage);
                return(false);
            }

            return(true);
        }
Exemple #4
0
        // Adapted from: https://msdn.microsoft.com/en-us/library/bb513869.aspx
        public static int TraverseTree(string root)
        {
            var client  = new RoslynCodeConverter.Client.Proxies.RoslynCodeConverter();
            var dirs    = new Stack <string>(20);
            int okFiles = 0;

            if (!System.IO.Directory.Exists(root))
            {
                Console.Write("Directory does not exist");
                return(okFiles);
            }

            dirs.Push(root);

            while (dirs.Count > 0)
            {
                string   currentDir = dirs.Pop();
                string[] subDirs;

                try
                {
                    subDirs = System.IO.Directory.GetDirectories(currentDir);
                }
                catch (Exception)
                {
                    continue;
                }

                string[] files = null;
                try
                {
                    files = System.IO.Directory.GetFiles(currentDir, "*.cs");
                }
                catch (Exception)
                {
                    continue;
                }

                foreach (string file in files)
                {
                    try
                    {
                        if (FileConvertedOk(file, client))
                        {
                            okFiles++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"INFO: Exception when trying to run conversion for {file}, {ex.Message}");
                        continue;
                    }
                }

                // Push the subdirectories onto the stack for traversal.
                foreach (string str in subDirs)
                {
                    dirs.Push(str);
                }
            }

            return(okFiles);
        }