|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Reflection;
using System.IO;
using System.Windows.Forms;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using bsn.GoldParser.Grammar;
using bsn.GoldParser.Semantic;
using bsn.GoldParser.Parser;
using EntityMapper.CodeGen;
using EntityMapper.Semantic;
using EntityMapper.Model;
namespace EntityMapper
{
public partial class FormRuleTest : Form
{
EntityMapperGenerator _mapperGenerator;
public FormRuleTest()
{
InitializeComponent();
}
private void FormRuleTest_Load(object sender, EventArgs e)
{
textBoxInput.Text = Sampler.GetMappnigStatements();
buttonExecute.Enabled = false;
labelInstructions.Text = string.Format("Please enter business rules to map order to invoice entity ({0} -> {1}):", typeof(SalesOrder).Name, typeof(Invoice).Name);
_mapperGenerator = new EntityMapperGenerator();
}
private void buttonParse_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPageGenSource;
try
{
_mapperGenerator.Parse(typeof(SalesOrder), typeof(Invoice), textBoxInput.Text, new string[] { "System", "EntityMapper.Service" });
textBoxOutput.Text = _mapperGenerator.SourceCode;
buttonExecute.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
private void buttonExecute_Click(object sender, EventArgs e)
{
// Switch tagpage
tabControl1.SelectedTab = tabPageResult;
textBoxResult.Text = "";
StringBuilder sb = new StringBuilder();
Action<SalesOrder, Invoice> mapper = (Action<SalesOrder, Invoice>)_mapperGenerator.GetDelegate(new string[] { "System.dll", Path.GetFileName(this.GetType().Assembly.CodeBase) });
// Initialize entities
SalesOrder salesOrderObj = Sampler.GetOrder();
Invoice invoiceObj = Sampler.GetInvoice();
sb.AppendFormat("------ Sales Order ------", salesOrderObj);
sb.AppendLine();
sb.AppendFormat("{0}", salesOrderObj);
sb.AppendLine();
sb.AppendFormat("------ Invoice before calling method ------");
sb.AppendLine();
sb.AppendFormat("{0}", invoiceObj);
sb.AppendLine();
// Invoke method
mapper(salesOrderObj, invoiceObj);
sb.AppendFormat("------ Invoice after calling method ------");
sb.AppendLine();
sb.AppendFormat("{0}", invoiceObj);
// Capture result
textBoxResult.Text = sb.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am always interested in finding innovative ways for building better applications and founded a technology company since 2003. Welcome to exchange any idea with you and if I am not too busy before deadline of projects, I will reply your emails. Also, if you willing to pay for consulting works and customized software development, you can leave me message.