Example #1
0
        public void TestToStringFunction()
        {
            Entity contact  = CreateContact("Test 1");
            Entity contact2 = CreateContact("Test 2");

            Entity payment = CreatePayment(contact);

            Entity paymentTask  = CreatePaymentTask(payment, contact);
            Entity paymentTask2 = CreatePaymentTask(payment, contact, contact2);

            ISyntacticParser syntacticParser = new SyntacticParser(new LexicalParser());
            ITextProcessor   textProcessor   = new TextProcessor(this.CrmOrganisationService);

            //Date Time
            Assert.AreEqual(((DateTime)payment["createdon"]).ToString("dd/MM/yyyy"), textProcessor.Process("{ToString(createdon,\"dd/MM/yyyy\")}", payment.ToEntityReference()));
            Assert.AreEqual(((DateTime)payment["createdon"]).ToString("dd/MM/yyyy"), textProcessor.Process("{ ToString(createdon , \"dd/MM/yyyy\") }", payment.ToEntityReference()));
            Assert.AreEqual(((DateTime)payment["createdon"]).ToString("dd/MM/yyyy"), textProcessor.Process("{ ToString ( createdon , \"dd/MM/yyyy\" ) }", payment.ToEntityReference()));

            //Test ActivityParty type
            string splitSeparator = ", ";

            Assert.AreEqual(contact["fullname"], textProcessor.Process("{ ToString ( customers ) }", paymentTask.ToEntityReference()));
            Assert.AreEqual(contact["fullname"], textProcessor.Process("{ ToString( customers, \"" + splitSeparator + "\") }", paymentTask.ToEntityReference()));
            Assert.AreEqual(contact["fullname"] + splitSeparator + contact2["fullname"], textProcessor.Process("{ToString(customers, \"" + splitSeparator + "\")}", paymentTask2.ToEntityReference()));

            //Test Money type
            Assert.AreEqual(((Money)payment["dxtools_amount"]).Value.ToString("0.00"), textProcessor.Process("{ToString(dxtools_amount,\"0.00\")}", payment.ToEntityReference()));
        }
Example #2
0
        public void TestTextprocessor_BasicTypes()
        {
            Entity contact = CreateContact();

            Entity payment = CreatePayment(contact);

            Entity paymentTask = CreatePaymentTask(payment, contact);

            ISyntacticParser syntacticParser = new SyntacticParser(new LexicalParser());
            ITextProcessor   textProcessor   = new TextProcessor(this.CrmOrganisationService);

            //Test DateTime type
            Assert.AreEqual(((DateTime)payment["createdon"]).ToString(), textProcessor.Process("{createdon}", payment.ToEntityReference()));

            //Test Owner type
            Assert.AreEqual(((EntityReference)payment["ownerid"]).Name.ToString(), textProcessor.Process("{ownerid}", payment.ToEntityReference()));
            Assert.AreEqual(((EntityReference)payment["ownerid"]).Name.ToString(), textProcessor.Process("{ownerid.Name}", payment.ToEntityReference()));
            Assert.AreEqual(((EntityReference)payment["ownerid"]).Id.ToString(), textProcessor.Process("{ownerid.Id}", payment.ToEntityReference()));

            //Test OptionSet type
            Assert.AreEqual(Enum.GetName(typeof(PaymentDirections), PaymentDirections.IN), textProcessor.Process("{dxtools_paymentdirection}", payment.ToEntityReference()));
            Assert.AreEqual(Enum.GetName(typeof(PaymentDirections), PaymentDirections.IN), textProcessor.Process("{dxtools_paymentdirection.Label}", payment.ToEntityReference()));
            Assert.AreEqual(((OptionSetValue)payment["dxtools_paymentdirection"]).Value.ToString(), textProcessor.Process("{dxtools_paymentdirection.Value}", payment.ToEntityReference()));

            //Test ActivityParty type
            Assert.AreEqual("Microsoft.Xrm.Sdk.EntityCollection", textProcessor.Process("{customers}", paymentTask.ToEntityReference()));

            //Test Money type
            Assert.AreEqual(((Money)payment["dxtools_amount"]).Value.ToString(), textProcessor.Process("{dxtools_amount}", payment.ToEntityReference()));

            //Test State (statecode) type
            Assert.AreEqual(Enum.GetName(typeof(State), State.Active), textProcessor.Process("{statecode}", payment.ToEntityReference()));
        }
Example #3
0
        static void Main()
        {
            string text;
            //var fileStream = new FileStream(@"C:\Users\IBARRA\Documents\Pascal\pascalTest.pas", FileMode.Open, FileAccess.Read);
            var fileStream = new FileStream(@"C:\Users\IBARRA\Documents\Pascal\Example2.pas", FileMode.Open, FileAccess.Read);

            using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
            {
                text = streamReader.ReadToEnd();
            }

            Console.WriteLine("Compile Pascal to Java...");
            Lexer.Lexer lexer = new Lexer.Lexer(new SourceCodeContent(text));
            Console.WriteLine("Lexer: Succeed.");
            var parser = new SyntacticParser(lexer);

            Console.WriteLine("Syntatic: Succeed.");
            try
            {
                var tree        = parser.Parse();
                var servletCode = "";
                foreach (var sentenceNode in tree)
                {
                    sentenceNode.ValidateNodeSemantic();
                    servletCode += sentenceNode.GenerateCode() + '\n';
                }
                Console.WriteLine("Semantic: Succeed.");

                using (StreamWriter writer = new StreamWriter("C:\\Users\\IBARRA\\Documents\\Pascal\\Servlet\\servlet.java", false))
                {
                    writer.WriteLine(GenerateServlet.InitServletCode(servletCode));
                }
                Console.WriteLine("Code Generation: Succeed.");
                System.Diagnostics.Process.Start("C:\\Users\\IBARRA\\Documents\\Pascal\\bat.bat");
            }
            catch (Exception e)
            {
                Console.WriteLine("\n\n Encountered Error.");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadLine();
            }
        }
        public void TestTextProcessor_OptionSet()
        {
            using (ShimsContext.Create())
            {
                Entity recordContext = new Entity("dxtools_payment");
                recordContext.Id = Guid.NewGuid();
                recordContext["dxtools_paymentdirection"] = new OptionSetValue(503530000);

                IOrganizationService stubOrganisationService = SetupIOrganisationService(recordContext, 503530000);

                ISyntacticParser syntacticParser  = new SyntacticParser(new LexicalParser());
                ITextProcessor   dynTextProcessor = new DXTools.CRM.Solutions.CustomEmails.Common.TextProcessing.TextProcessor(stubOrganisationService);

                string inputText = "Payment direction is {dxtools_PaymentDirection}. Other option to get the same is {dxtools_paymentdirection.Label}, and the value is {dxtools_paymentdirection.Value}";
                string expected  = "Payment direction is IN. Other option to get the same is IN, and the value is 503530000";

                string resultOuput = dynTextProcessor.Process(inputText, recordContext.ToEntityReference());

                Assert.AreEqual(expected, resultOuput);
            }
        }
Example #5
0
 public void GivenTheFollowingSourceCode(string p0)
 {
     _lexer  = new Lexer.Lexer(new SourceCodeContent(p0));
     _parser = new SyntacticParser(_lexer);
 }