-
Notifications
You must be signed in to change notification settings - Fork 55
Tutorial_Template_development
November 27th, 2014
Open Touryo supports various architectures such as client-server system and web system etc., and DBMS such as SQL Server and Oracle. And the programs that customized Open Touryo according to the architectures of the individual projects are called Template. This tutorial explains how to develop template.
This tutorial targets the architects who understand the architectures of Open Touryo. (That is, the architects who can understand Open Touryo user guide.)
Open Touryo provides Template Base, that is the matrix for developing template. This tutorial explains how to customize this Template Base and develop template according to the architectures of the individual projects.
As we are pressed for time, some images are only displayed in Japanese.
The company names and product names used in this document are the trademarks or registered trademarks of the respective companies.
This document can use Creative commons CC BY 2.1 JP license.
1. Overview of Open Touryo framework
Open Touryo framework is an application framework for .NET. Open Touryo framework targets .NET Framework 4.6 and above and can be used in various applications like C/S (Windows Forms, WPF), Web (ASP.NET) and RIA (Silverlight).
Figure 1-1 shows the class configuration of Open Touryo framework. Open Touryo is implemented with three-tier architectures, that is presentation tier, business logic tier, and data access tier. And Open Touryo provides the parent class for each tiers. By implementing the common logic for application in the parent class, developers can focus their attention on implementing the individual business logic. Therefore, Open Touryo reduces the coding quantity and suppress variation in coding quality due to the skills of the developers.
Figure 1-1 Class diagram of Open Touryo framework
The developers can customize Open Touryo for each projects, that is remove unnecessary features or add the features that are specific to each projects. The Open Touryo classes that customized according to the architectures of each projects, that is shown as The classes provided by Open Touryo in Figure 1-1, are called Template.
The developers can also implement the business logic to the classes that inherit the parent class, that is shown as The classes should be implemented by developers in Figure 1-1.
Open Touryo provides the template base, the matrix of the template. This tutorial how to customize this template base supposing the following architectures.
- DBMS
- Oracle
- Application forms
- Web application(ASP.NET)
- Two-tier architecture
The followings are the prerequisites for this tutorial.
- Development environment
- IDE
- Visual Studio 2015 (Express Edition is also available)
- Application framework
- Open Touryo Template Base for Visual Studio 2015
- IDE
- Runtime environment
- Runtime
- .NET Framework 4.6
- DB
- Oracle Database Express Edition 11g Release 2
- Runtime
- Others
- OS
- Windows 7
- Programming language
- C#
- OS
Install Visual Studio referring to Microsoft homepage beforehand.
Next, set up Open Touryo Template Base and database.
-
Click [Download ZIP] button on GitHub and obtain OpenTouryoTemplates.zip. Unzip this zip file and obtain Open Touryo Template Base for Visual Studio 2015.
-
Set up Open Touryo Template Base according to Readme.md in root_VS2015 folder.
-
Install Oracle Database Express Edition as a sample database. (The installation procedure of Oracle database is omitted in this tutorial.)
-
Run the sql in
C:\root\files\resource\Sql\oracle\テストテーブル.txt
on installed Oracle Database to create test table.
As shown in figure 3-1, this tutorial describes how to customize template base and develop the template for the project that is ASP.NET two-tier application and uses Oracle database. Table 3-1 shows the development procedure of the template.
Figure 3-1 Original template base and template that will be developed in this tutorial (Each numbers in this figure correspond to the numbers in table 3-1)
Table 3-1 The development procedure of Open Touryo template
No. | Category | Work | Descriptioin | Remarks |
---|---|---|---|---|
1 | Framework | Change data provider | Change the data provider that is used in template base to the data provider that is used in the project. | See section 4.1. |
2 | Framework | Add logic to run commonly in the project | Implement the logic to run commonly in the project to Open Touryo parent class 2. | See section 4.2. |
3 | Common | Change the construction of template base | Remove the unnecessary features or change folder construction according to the architectures or the development rules of the project. | See section 4.3. |
4 | Sample Program | Change data provider | Change the data provider that is used in sample program to the data provider that is used in the project. | See section 4.4. |
5 | Sample Program | Set the application configuration file | Set the parameters in application configuration file according to the architectures of the project. | See section 4.5. |
6 | Common | Check operation of sample program | Run the sample program and check operation. | See section 4.6. |
The following section describes development flow of Open Touryo template.
Change the data provider that is used in template base to ODP.NET. (Open Touryo does not support ODP.NET Managed Driver at the time of this writing.)
Install Oracle Data Access Components (ODAC). (The installation procedure of ODAC is omitted in this tutorial.)
Open Touryo provides the data access parts using various DBMS, such as SQL Server, Oracle. Original template base uses the data access parts using SQL Server. Therefore, replace this to the data access parts using Oracle.
-
Open
C:\root\programs\C#\Frameworks\Infrastructure\AllComponent.sln
. -
Right-click
AllComponent
solution in the Solution Explorer, and select Add -> Existing project. -
Select
C:\root\programs\C#\Frameworks\Infrastructure\Public\Db\DamOraOdp\DamOraOdp.csproj
in Add existing project dialog to add the data access part using Oracle to solution. -
Remove References -> Oracle.DataAccess in
DamOraOdp
project in the Solution Explorer. -
Right-click
DamOraOdp
project in the Solution Explorer and select Add reference. -
In Select files dialog, select
Oracle.DataAccess.dll
in ODAC installation folder and click Add. -
Confirm that
Oracle.DataAccess.dll
is checked and click OK. -
Right-click
Business
project in the Solution Explorer and select Add reference. -
In Reference Manager dialog, select Solution and check
DamOraOdp
. Click OK. -
Open
Business\MyFcBaseLogic.cs
inBusiness
project in the Solution Explorer. -
Modify the データ プロバイダ選択 region in
MyFcBaseLogic.cs
as follows.#region データ プロバイダ選択 // Oracle / ODP.NET用のDamを生成 dam = new DamOraOdp(); // 接続文字列をロード(Instant Client) connstring = GetConfigParameter.GetConnectionString("ConnectionString_ODP2"); #endregion
-
Remove
Business\MyBaseLogic.cs
inBusiness
project.Note:
MyBaseLogic
class is left for backward compatibility to Open Touryo of previous version. In new application development,MyFcBaseLogic
class, that supports new features, is useful. So, developers can removeMyBaseLogic
class. -
Click
Save All
icon to save changes. -
Build Open Touryo framework.
-
Run
C:\root\programs\C#\1_DeleteDir.bat
to remove the folders for storing the assemblies of Open Touryo framework. -
Run
C:\root\programs\C#\2_DeleteFile.bat
to remove temp files. -
Run
C:\root\programs\C#\3_Build_Framework.bat
to build Open Touryo framework.Note:
3_Build_Framework.bat
is a batch file for building Open Touryo framework and Open Touryo rich client framework. Because we have not modified rich client framework, errors occur when building rich client framework. Ignore the errors and confirm that the build of Open Touryo framework finishes successfully.
-
Next, replace the data access part that is used by rich client framework to the data access part using Oracle. Although this tutorial targets ASP.NET application, it is necessary to do this because the tools bundled in Open Touryo use rich client framework.
-
Open
C:\root\programs\C#\Frameworks\Infrastructure\RichClient.sln
. -
Right-click
Business.RichClient
project in the Solution Explorer and select Add references. -
Add
C:\root\programs\C#\Frameworks\Infrastructure\Build\DamOraOdp.dll
in Reference Manager dialog. -
In the same way to section 4.1.2, rewrite データ プロバイダ選択 region in
Business\MyFcBaseLogicTEMPLATE.cs
inBusiness.RichClient
project to use the data provider using Oracle. -
Remove
Business\MyBaseLogicTEMPLATE.cs
inBusiness.RichClient
project.Note:
Same as Open Touryo framework,MyBaseLogicTEMPLATE
class is left for backward compatibility to rich client framework of previous version. So, developers can remove this class. -
Click Save All icon in toolbar to save changes.
-
Run
C:\root\programs\C#\3_Build_Framework.bat
again to build rich client framework. Confirm that the builds of Open Touryo framework and rich client framework finish successfully.
Next, replace the data access part that is used by the tools bundled in Open Touryo.
-
Open
C:\root\programs\C#\Frameworks\Tools\DPQuery_Tool\DPQuery_Tool.sln
. -
Right-click
DPQuery_Tool
project in the Solution Explorer, select Add references. -
Add
Oracle.DataAccess.dll
andDamOraOdp.dll
in Reference Manager dialog. -
Open
DummyDaps.cs
in the Solution Explorer and comment out or removeDamOraOdp
class part andOracle.DataAccess.Client
namespace part.
Note:
Open Touryo supports the various DBMSs, such as SQL Server and Oracle. So Open Touryo references the data providers for the DBMSs. In actual development, template should reference the data provider that is used in the project only, and should not reference other data providers. DummyDaps.cs
is stub object for the data providers that is not referenced by the project. In this tutorial, we use actual ODP.NET and DamOraOdp
project. So because the stub object for Oracle becomes unnecessary, the corresponding part can be removed.
-
Click Save All icon to save changes.
-
Open
C:\root\programs\C#\Frameworks\Tools\DaoGen_Tool\DaoGen_Tool.sln
. -
In the same way to section 4.1.4, add references to
Oracle.DataAccess.dll
andDamOraOdp.dll
toDaoGen_Tool
project. -
Click Save All icon to save changes.
-
Run
C:\root\programs\C#\4_Build_Framework_Tool.bat
to build the tools bundled in Open Touryo.
As shown in fiture 1-1, Open Touryo is composed of Parent Class 1, Parent Class 2, and subclass. Common logic can be run by add the logic to Parent Class 2. (For details, refer Open Touryo user guide (Leader Edition) and カスタマイズ sheet and 参考資料_フレームワーク要件 sheet in Atypical_work_list.xlsx.)
-
Open
C:\root\programs\C#\Frameworks\Infrastructure\AllComponent.sln
. -
Open
Presentation\MyBaseController.cs
inBusiness
project in the Solution Explorer. -
Add common logic to the methods in
MyBaseController
class. Use Open Touryo user guide (Common Edition) as reference, add common logic to the following methods according to timing of executing the logic.
- When the screen is loaded
- MyBaseController.UOC_CMNFormInit
- Postback
- MyBaseController.UOC_CMNFormInit_PostBack
- Before running event handler
- MyBaseController.UOC_PreAction
- After running event handler
- MyBaseController.UOC_AfterAction
- When the error is occurred
- MyBaseController.UOC_ABEND
- At the end of all events
- MyBaseController.UOC_Finally
For example, to output log when the screen is loaded, implement to UOC_CMNFormInit
method as follows.
protected override void UOC_CMNFormInit()
{
// Implement common logic to run when the screen is loaded.
LogIF.InfoLog("ACCESS", "P 層共通処理サンプル");
// フォーム初期化共通処理
this.CMN_FormInit("init");
}
-
Open
Business\MyFcBaseLogic.cs
inBusiness
project in the Solution Explorer. -
Add common logic to the methods in
MyFcBaseLogic
class. Use Open Touryo user guide (Common Edition) as reference, add common logic to the following methods according to timing of executing the logic.
- Before running business logic
- MyFcBaseLogic.UOC_PreAction
- After running business logic
- MyFcBaseLogic.UOC_AfterAction
- After finishing transaction
- MyFcBaseLogic.UOC_AfterTransaction
- When the error is occurred
- MyFcBaseLogic.UOC_ABEND
For example, to output log before running business logic, implement to UOC_PreAction
method as follows.
protected override void UOC_PreAction(BaseParameterValue parameterValue)
{
LogIF.InfoLog("ACCESS", "B 層共通処理サンプル");
// ACCESSログ出力-----------------------------------------------
(omit)
}
-
Open
Dao\MyBaseDao.cs
inBusiness
project in the Solution Explorer. -
Add common logic to the methods in
MyBaseDao
class. Use Open Touryo user guide (Common Edition) as reference, add common logic to the following methods according to timing of executing the logic.
- Before running sql
- MyBaseDao.UOC_PreQuery
- After running sql
- MyBaseDao.UOC_AfterQuery
For example, to output log after running sql, implement to UOC_AfterQuery
method as follows.
protected override void UOC_AfterQuery(string sql)
{
LogIF.InfoLog("ACCESS", "D 層共通処理サンプル: " + sql);
// 性能測定終了
(omit)
}
When finishing implementing common logic, build framework and tools.
-
Click Save All icon to save changes.
-
Run
C:\root\programs\C#\3_Build_Framework.bat
to build Open Touryo framework. -
Run
C:\root\programs\C#\4_Build_Framework_Tool.bat
to build the tools bundled in Open Touryo.
Open Touryo framework and sample programs provide features for each architectures, such as web or client-server system. Remove unnecessary features based on the architecture of project.
-
Remove folders that store unnecessary features or samples for project.
For examples:
- Because we want to develop ASP.NET application, remove sample programs for client-server system.
- Because we want to develop ASP.NET application, remove sample program for Universal Windows Platform(UWP).
- Because we want to develop two-tier application, remove communication control part (service interface).
- Because we want to develop two-tier application, remove sample programs implemented with three-tier architecture.
- Because we want to use C#, remove sample programs implemented with VB.
Note:
Although we want to develop ASP.NET application, do not remove rich client framework because the tools bundled in Open Touryo use rich client framework. -
Remove unnecessary batch files for project in
C:\root\programs\C#
folder.For examples:
- Because we want to develop ASP.NET application, remove batch file to build two-tier client-server sample program (5_Build_TEMPLATE_sample.bat).
- Because we want to develop ASP.NET application, remove batch file to build uwp sample program (11_Build_UWP_sample.bat).
- Because we want to develop two-tier application, remove batch files to build three-tier sample program (6_Build_WSSrv_sample.bat, 7_Build_Framework_WS.bat, 8_Build_WSClnt_sample.bat, 9_Build_WSClnt_sample.bat).
As mentioned in section 1, in the development using Open Touryo, developers progress the development by adding individual features to the sample program in template. So, it is necessary to correspond the project name, folder construction, and more of the sample program to actual development rules. When performing this step, we recommend using text replacement tools to prevent the correction leakage.
-
Decide the project name and folder construction. By default, ASP.NET sample program is implemented in
C:\root\programs\C#\Samples\WebApp_sample\WebForms_Sample\WebForms_Sample.sln
and project name is WebForms_Sample. Here, change project name and folder construction as follows.- Samples folder -> App folder
- Remove _sample from folder name and project name
-
Replace the folder construction. The tools like Flexible Renamer are useful to replace file name or folder name.
-
Replace the contents of files. The tools like GrepReplace are useful to replace the contents of files.
-
Click Save All icon to save changes.
-
Run
C:\root\programs\C#\10_Build_WebApp_sample.bat
to build sample program.
Change the data provider that is used in original sample program to ODP.NET.
-
Run
C:\root\programs\C#\Frameworks\DaoGen_Tool\bin\Debug\DaoGen_Tool.exe
to launch D layer auto generation tool. -
Set properties as follows and click Acquire.
- Data provider: Oracle ODP.NET
- Connection string: Connection string to Oracle database
- Drop down list: Summary
-
If database information, such as connection string, are correct, Display (Summary Information) dialog of schema information of DBMS screen is shown.
Click Close to close the dialog box.
-
Click Get Table List.
In the Note? (prerequisites) dialog box, click OK.
-
Select tables except SHIPPERS, click Delete button.
-
Confirm whether Table List contains only SHIPPERS table, and click Load.
-
The Generate D layer definition file button is activated. Select utf-8 as file encoding and click Generate D layer definition file.
Save as
C:\root\Info.csv
. -
Click OK in the dialog box displaying the message Completion of generation of the D-layer definition information!.
-
Click Go to STEP 2.
-
In the STEP2 screen, enter input / output settings as follows:
- D layer definition file: C:\root\Info.csv
- Source Template Folder: C:\root\files\tools\DGenTemplates
- Output File: C:\root
- Leave the other fields as default.
Click Generate Program.
-
Click OK in the dialog box displaying the message Automatic Generation Completed!.
-
Confirm that data access classes and SQL files are generated in
C:\root
folder.Note:
In the Open Touryo framework, the files with extensions.sql
and.xml
are SQL files. (For more details, refer to the Open Touryo framework user guide) -
To add generated data access class to sample program, select
Dao
folder in Solution Explorer, and click Project -> Add Existing File in toolbar. -
In the Add Existing Item screen, select
DaoSHIPPERS.cs
andDaoOrder_Details.cs
inC:\root
folder. Click Add. -
Open
App_Code\sample\Business\LayerB.cs
in the Solution Explorer. -
In case of using Oracle, table name part or column name part of generated class or properties are written in capital letters. So, replace the following string with Visual Studio.
- DaoShippers -> DaoSHIPPERS
- genDao.PK_ShipperID -> genDao.PK_SHIPPERID
- genDao.CompanyName -> genDao.COMPANYNAME
- genDao.Phone -> genDao.PHONE
- genDao.Set_CompanyName_forUPD -> genDao.Set_COMPANYNAME_forUPD
- genDao.Set_Phone_forUPD -> genDao.Set_PHONE_forUPD
-
Click Save All icon to save changes.
-
Run
C:\root\programs\C#\10_Build_WebApp_sample.bat
to build sample program. -
Copy the generated SQL and XML files in
C:\root
toC:\root\files\resource\Sql
folder. -
Close D layer auto generation tool.
Set properties in application configuration file (web.config or app.config) according to the architectures of the individual projects.
-
Open
C:\root\programs\C#\App\WebApp\ProjectX\ProjectX.sln
. -
Open
web.config
in the Solution Explorer. -
Set the properties in
web.config
.-
Set the connection string to database in
connectionStrings
tag.<connectionStrings> <!-- For Oracle --> <add name="ConnectionString_ODP2" connectionString="Data Source=localhost/XE;User Id=scott;Password=tiger;"/> </connectionStrings>
-
Set other properties in
system.web
tag inweb.config
according to the architectures of the individual project.
-
-
Open
app.config
in the Solution Explorer. -
Set the properties in
app.config
according to the architectures of the individual project.Note:
For the setting items and the value should be set, refer Open Touryo user guide. -
Run
C:\root\programs\C#\10_Build_WebApp_sample.bat
to build sample program.
-
Debug sample program with Visual Studio.
-
Since the browser is launched and login form is shown, input the value as follows and click ログイン (Login in Japanese).
- ユーザID (User Id in Japanese): Arbitrary string, NOT allowed empty string
- パスワード (Password in Japanese): Arbitrary string, allowed empty string
-
Since menu screen is shown, click ノーマル (Normal in Japanese).
-
Click 件数取得 (Get record count in Japanese) button in sample screen.
-
Confirm that the record count is shown in message area and sample program accesses to Oracle database successfully.
-
Open log file -
C:\root\files\resource\Log\ACCESS.yyyy-mm-dd.log
(where, yyyy-mm-dd is executed date) in Notepad. -
Confirm that the access to
sampleScreen
is logged and implemented common logics in section 4.2 are run.[2013/08/08 15:04:19,263],[DEBUG],[10],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:19,310],[INFO ],[10],P 層共通処理サンプル [2013/08/08 15:04:19,326],[INFO ],[10],,未認証,127.0.0.1,init,login [2013/08/08 15:04:19,373],[DEBUG],[10],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,102,78 [2013/08/08 15:04:19,592],[DEBUG],[9],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:19,592],[INFO ],[9],P 層共通処理サンプル [2013/08/08 15:04:19,592],[INFO ],[9],,未認証,127.0.0.1,init,login [2013/08/08 15:04:19,592],[DEBUG],[9],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,2,0 [2013/08/08 15:04:21,814],[DEBUG],[9],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:21,814],[INFO ],[9],,未認証,127.0.0.1,postback,login [2013/08/08 15:04:21,814],[INFO ],[9],,未認証,127.0.0.1,----->,login,btnButton1 [2013/08/08 15:04:21,830],[INFO ],[9],,user01,127.0.0.1,<-----,login,btnButton1,,10,0 [2013/08/08 15:04:21,830],[DEBUG],[9],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,17,0 [2013/08/08 15:04:21,892],[DEBUG],[10],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:21,908],[INFO ],[10],P 層共通処理サンプル [2013/08/08 15:04:21,908],[INFO ],[10],,user01,127.0.0.1,init,menu [2013/08/08 15:04:21,908],[DEBUG],[10],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,18,16 [2013/08/08 15:04:21,955],[DEBUG],[5],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:21,955],[DEBUG],[5],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,0,0 [2013/08/08 15:04:24,799],[DEBUG],[9],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:24,845],[INFO ],[9],P 層共通処理サンプル [2013/08/08 15:04:24,845],[INFO ],[9],,user01,127.0.0.1,init,sampleScreen [2013/08/08 15:04:24,845],[DEBUG],[9],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,55,47 [2013/08/08 15:04:27,541],[DEBUG],[10],,-,127.0.0.1,-----↓,Global.asax,Application_OnPreRequest [2013/08/08 15:04:27,556],[INFO ],[10],,user01,127.0.0.1,postback,sampleScreen [2013/08/08 15:04:27,556],[INFO ],[10],,user01,127.0.0.1,----->,sampleScreen,btnMButton1 [2013/08/08 15:04:27,978],[INFO ],[10],B 層共通処理サンプル [2013/08/08 15:04:27,978],[INFO ],[10],,user01,127.0.0.1,----->>,sampleScreen,btnMButton1,SelectCount,SQL%individual%static%- [2013/08/08 15:04:27,994],[INFO ],[10],D 層共通処理サンプル: [commandText]:SELECT COUNT(*) FROM Shippers [commandParameter]: [2013/08/08 15:04:28,010],[INFO ],[10],,user01,127.0.0.1,<<-----,sampleScreen,btnMButton1,SelectCount,SQL%individual%static%-,30,31 [2013/08/08 15:04:28,010],[INFO ],[10],,user01,127.0.0.1,<-----,sampleScreen,btnMButton1,,461,47 [2013/08/08 15:04:28,010],[DEBUG],[10],,-,127.0.0.1,-----↑,Global.asax,Application_OnPostRequest,-,-,467,63