Exemplo n.º 1
0
        public void CSharpHelperConvertsCSharpTextsToApexDictionary()
        {
            var csharp = @"
                class Test1 { public Test1(int x) { } }
                class Test2 : Test1 { private int x = 10; }
                enum SomeEnum { None, Unknown, Default }";

            var apexClasses = ApexSharpParser.ConvertToApex(csharp);

            Assert.AreEqual(3, apexClasses.Count);

            CompareLineByLine(
                @"class Test1
                {
                    public Test1(Integer x)
                    {
                    }
                }", apexClasses["Test1"]);

            CompareLineByLine(
                @"class Test2 extends Test1
                {
                    private Integer x = 10;
                }", apexClasses["Test2"]);

            CompareLineByLine(
                @"enum SomeEnum
                {
                    None,
                    Unknown,
                    Default
                }", apexClasses["SomeEnum"]);
        }
Exemplo n.º 2
0
        public static void ConvertToApex(FileInfo cSharpFile, DirectoryInfo apexLocation, int version)
        {
            if (!apexLocation.Exists)
            {
                throw new DirectoryNotFoundException(apexLocation.FullName);
            }

            if (!cSharpFile.Exists)
            {
                throw new FileNotFoundException(cSharpFile.FullName);
            }

            // Convert C# to Apex
            var csharpCode = File.ReadAllText(cSharpFile.FullName);

            foreach (var convertedClass in ApexSharpParser.ConvertToApex(csharpCode))
            {
                var apexFileName = Path.ChangeExtension(convertedClass.Key, ".cls");
                var apexFile     = Path.Combine(apexLocation.FullName, apexFileName);
                File.WriteAllText(apexFile, convertedClass.Value);

                var metaFileName = Path.ChangeExtension(apexFile, ".cls-meta.xml");
                var metaFile     = new StringBuilder();

                metaFile.AppendLine("<?xml version = \"1.0\" encoding = \"UTF-8\"?>");
                metaFile.AppendLine("<ApexClass xmlns = \"http://soap.sforce.com/2006/04/metadata\">");
                metaFile.AppendLine($"<apiVersion>{version}.0</apiVersion>");
                metaFile.AppendLine("<status>Active</status>");
                metaFile.AppendLine("</ApexClass>");

                File.WriteAllText(metaFileName, metaFile.ToString());
                Console.WriteLine(metaFileName);
            }
        }
Exemplo n.º 3
0
        public static void ConvertToApex(DirectoryInfo cSharpLocation, DirectoryInfo apexLocation, int version)
        {
            if (!apexLocation.Exists)
            {
                throw new DirectoryNotFoundException(apexLocation.FullName);
            }

            if (!cSharpLocation.Exists)
            {
                throw new DirectoryNotFoundException(cSharpLocation.FullName);
            }

            // Convert C# to Apex
            ApexSharpParser.ConvertToApex(cSharpLocation.FullName, apexLocation.FullName, version);
        }
Exemplo n.º 4
0
        public static void ConvertToApex()
        {
            // Location of your APEX and C# Files that we will be converting
            DirectoryInfo apexLocation   = new DirectoryInfo(@"\ApexSharp\SalesForce\src\classes\");
            DirectoryInfo cSharpLocation = new DirectoryInfo(@"\ApexSharp\Demo\CSharpClasses\");

            //// Convert to C# to Apex
            if (apexLocation.Exists && cSharpLocation.Exists)
            {
                ApexSharpParser.ConvertToApex(cSharpLocation.FullName, apexLocation.FullName, 40);
            }
            else
            {
                Console.WriteLine("Missing Directory");
            }
        }