Introduction
Continue of modds Drag and Drop Programming for C# Debugging (Part 4) if you want some functions of modds visual program to be used in your big existing project, the modds Class Library Template can help to create .NET DLL which can be used in exiting Visual Studio Projects. In this article, we will create two independent DLLs and combine them in a Visual Studio Project to develop a Stock Chart Program.
Project Requirements
- Modds C# Designer(from www.modds.org)
- Microsoft Visual Studio
- Windows 7 or above
- .NET Framework 4.5.2 OR above
DLL Function Control
The DLL Function Control is the control that creates function interface for a Class Library Template DLL. The control can be found at modds IDE Control Toolbox->modds Common Controls->Module->DLL Function. This control can only work for Class Library Template. It can create an interface function with any number of parameters and with or without a return value.
Stock Chart Program Example
In this example, we will create two independent DLLs (MarketDataYahoo.dll and MarketDataView.dll). The MarketDataYahoo.dll will have an interface function called “GetStockMarketData
”. This function will take three parameters (Stock Symbol, Start Data, and End Date) and it does not return any values, instead, it will broadcast the market data values to “StockMarketData
” message channel. Any other objects listening to the message channel can process it. The MarketDataView.dll will have an interface function called “CreateStockChartView
”. This function will not take any parameters and it will return a stock chart view object. This object will listen to “StockMarketData
” message channel. When there is a data updated, this object will display on its view. The object view can be data binded with a WPF ContentControl
for UI display.
MarketDataYahoo.dll
- Create a Class Library Project and name it “
MarketDataYahoo
”
- Add “MarketData.dll” from download source (LIB) to References/ProgramDLL. The MarketData.dll is code from the previous example that gets the market data from yahoo.
- Crate a message channel and name it “
StockMarketData
”
- Right click on->Solution->MarketDataYahoo->Channels select Add namespace and name it “
StockMarketData
”
- Right click on “
StockMarketData
” and select Add Broadcast
- Delete “DLLClass.xsml” and create new Schema and name it “DataServer.xsml”. Double click to open.
- Double click Solution->MarketDataYahoo->References->ProgramDLL->MarketData.dll to open it on .NET DLL toolbox.
- Drag the following controls to design board and connect them as following image:
- Control Toolbox->modds Common Controls->Module->DLL Function
- .NET DLL Toolbox->MarketData.dll->Class->YahooMarketData->YahooDailyMarketData
- Control Toolbox->modds Common Controls->Toolbox->Group Data
- Solution->MarketDataYahoo->Channels->StockMarketData->Broadcast
StockChartView.dll
- Create a Class Library Project and name it “
StockChartView
”
- Add “ChartConrol.dll” from download source (LIB) to References/ProgramDLL. The ChartControl.dll is WFP stock chart control from the previous example.
- Add “MarketDataView.xaml” from download source (LIB) to
SchemaView
. The MarketDataView.xaml is the stock chart view design.
- Crate a message channel “
StockMarketData
”.
- Right click on->Solution-> StockChartView ->Channels select Add namespace and name it “
StockMarketData
”
- Right click on “
StockMarketData
” and select Add Listener
- Delete “DLLClass.xsml” and create new Schema and name it “StockChartView.xsml”. Double click to open it.
- Drag the following controls to design board and connect them as following image:
- Solution->StockChartView->SchemaView->MarketDataView.xaml
- Solution->Channels->StockMarketData->Listener
- Control Toolbox->modds Common Controls->Toolbox->Group Data
- Control Toolbox->modds Common Controls->Toolbox->Ungroup Data
- .NET DLL Toolbox->CSharpCommonLibrary->Primitive Type->Double
- .NET DLL Toolbox->CSharpCommonLibrary->Class->DateTime
- .NET DLL Toolbox->CSharpCommonLibrary->Class->Object
- Properties->DataObjects(Data, Open, High, Low, and Last)
- Double click Solution-> StockChartView ->References->ProgramDLL->modds.LIB.dll to open it on .NET DLL toolbox.
- Create a new schema and name it “ObjectBuilder.xsml”. Double click to open it.
- Drag the following controls to design board and connect them as following image.
- Control Toolbox->modds Common Controls->Module->DLL Function
- Solution->StockChartView->Schema->StockChartView.xsml and select Module Id
- .NET DLL Toolbox->modds.LIB.dll->Class->GeneralObject->CreateGeneralObject(Guid)
- Return from DLL Function control
Visual Studio Project
Create new WPF Application Project and add (MarketDataYahoo.dll and StockChartView
) to References. Add the following code to complete the program.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
chartContent.DataContext = StockChartView.ObjectBuilder.CreateStockChartView();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string symbol = symbolBox.Text;
DateTime startDate = (DateTime)startDatePicker.SelectedDate;
DateTime endDate = (DateTime) endDatePicker.SelectedDate;
MarketDataYahoo.DataServer.GetMarketData(symbol, startDate, endDate);
}
}