Skip to content

Tutorial_Template_development

daisuke nishino edited this page Oct 17, 2018 · 2 revisions

Open Touryo Tutorial (Template Development edition)

November 27th, 2014

Introduction

Objective of this document

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.

Scope of this document

This tutorial targets the architects who understand the architectures of Open Touryo. (That is, the architects who can understand Open Touryo user guide.)

Overview of this document

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.

Use of copyrights and trademarks of other companies

The company names and product names used in this document are the trademarks or registered trademarks of the respective companies.

License

This document can use Creative commons CC BY 2.1 JP license.

Table of Contents

1. Overview of Open Touryo framework

2. Set up the environment

3. Exercises in this tutorial

4. Exercises

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

2. Set up the environment

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
  • Runtime environment
    • Runtime
      • .NET Framework 4.6
    • DB
      • Oracle Database Express Edition 11g Release 2
  • Others
    • OS
      • Windows 7
    • Programming language
      • C#

Install Visual Studio referring to Microsoft homepage beforehand.

Next, set up Open Touryo Template Base and database.

  1. Click [Download ZIP] button on GitHub and obtain OpenTouryoTemplates.zip. Unzip this zip file and obtain Open Touryo Template Base for Visual Studio 2015.

  2. Set up Open Touryo Template Base according to Readme.md in root_VS2015 folder.

  3. Install Oracle Database Express Edition as a sample database. (The installation procedure of Oracle database is omitted in this tutorial.)

  4. Run the sql in C:\root\files\resource\Sql\oracle\テストテーブル.txt on installed Oracle Database to create test table.

3. Exercises in this tutorial

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.

4. Exercises

The following section describes development flow of Open Touryo template.

4.1 Change data provider (Framework)

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.)

4.1.1 Install Oracle Data Access Components (ODAC)

Install Oracle Data Access Components (ODAC). (The installation procedure of ODAC is omitted in this tutorial.)

4.1.2 Replace Open Touryo data access part (Open Touryo Framework)

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.

  1. Open C:\root\programs\C#\Frameworks\Infrastructure\AllComponent.sln.

  2. Right-click AllComponent solution in the Solution Explorer, and select Add -> Existing project.

  3. 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.

  4. Remove References -> Oracle.DataAccess in DamOraOdp project in the Solution Explorer.

  5. Right-click DamOraOdp project in the Solution Explorer and select Add reference.

  6. In Select files dialog, select Oracle.DataAccess.dll in ODAC installation folder and click Add.

  7. Confirm that Oracle.DataAccess.dll is checked and click OK.

  8. Right-click Business project in the Solution Explorer and select Add reference.

  9. In Reference Manager dialog, select Solution and check DamOraOdp. Click OK.

  10. Open Business\MyFcBaseLogic.cs in Business project in the Solution Explorer.

  11. Modify the データ プロバイダ選択 region in MyFcBaseLogic.cs as follows.

    #region データ プロバイダ選択
    
    // Oracle / ODP.NET用のDamを生成
    dam = new DamOraOdp();
    
    // 接続文字列をロード(Instant Client)
    connstring = GetConfigParameter.GetConnectionString("ConnectionString_ODP2");
    
    #endregion
  12. Remove Business\MyBaseLogic.cs in Business 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 remove MyBaseLogic class.

  13. Click Save All icon to save changes.

  14. Build Open Touryo framework.

    1. Run C:\root\programs\C#\1_DeleteDir.bat to remove the folders for storing the assemblies of Open Touryo framework.

    2. Run C:\root\programs\C#\2_DeleteFile.bat to remove temp files.

    3. 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.

4.1.3 Replace Open Touryo data access part (Rich Client Framework)

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.

  1. Open C:\root\programs\C#\Frameworks\Infrastructure\RichClient.sln.

  2. Right-click Business.RichClient project in the Solution Explorer and select Add references.

  3. Add C:\root\programs\C#\Frameworks\Infrastructure\Build\DamOraOdp.dll in Reference Manager dialog.

  4. In the same way to section 4.1.2, rewrite データ プロバイダ選択 region in Business\MyFcBaseLogicTEMPLATE.cs in Business.RichClient project to use the data provider using Oracle.

  5. Remove Business\MyBaseLogicTEMPLATE.cs in Business.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.

  6. Click Save All icon in toolbar to save changes.

  7. 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.

4.1.4 Replace Open Touryo data access part (Dynamic Parameterized Query Analytical Tool)

Next, replace the data access part that is used by the tools bundled in Open Touryo.

  1. Open C:\root\programs\C#\Frameworks\Tools\DPQuery_Tool\DPQuery_Tool.sln.

  2. Right-click DPQuery_Tool project in the Solution Explorer, select Add references.

  3. Add Oracle.DataAccess.dll and DamOraOdp.dll in Reference Manager dialog.

  4. Open DummyDaps.cs in the Solution Explorer and comment out or remove DamOraOdp class part and Oracle.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.

  1. Click Save All icon to save changes.

4.1.5 Open Replace Open Touryo data access part (D layer auto generation tool)

  1. Open C:\root\programs\C#\Frameworks\Tools\DaoGen_Tool\DaoGen_Tool.sln.

  2. In the same way to section 4.1.4, add references to Oracle.DataAccess.dll and DamOraOdp.dll to DaoGen_Tool project.

  3. Click Save All icon to save changes.

  4. Run C:\root\programs\C#\4_Build_Framework_Tool.bat to build the tools bundled in Open Touryo.

4.2 Add logic to run commonly in the project

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.)

4.2.1 Add common logic to presentation tier

  1. Open C:\root\programs\C#\Frameworks\Infrastructure\AllComponent.sln.

  2. Open Presentation\MyBaseController.cs in Business project in the Solution Explorer.

  3. 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");
}

4.2.2 Add common logic to business logic tier

  1. Open Business\MyFcBaseLogic.cs in Business project in the Solution Explorer.

  2. 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)
}

4.2.3 Add common logic to data access tier

  1. Open Dao\MyBaseDao.cs in Business project in the Solution Explorer.

  2. 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)
}

4.2.4 Build framework and tools

When finishing implementing common logic, build framework and tools.

  1. Click Save All icon to save changes.

  2. Run C:\root\programs\C#\3_Build_Framework.bat to build Open Touryo framework.

  3. Run C:\root\programs\C#\4_Build_Framework_Tool.bat to build the tools bundled in Open Touryo.

4.3 Change the construction of template base

4.3.1 Remove unnecessary features

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.

  1. 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.

  2. 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).

4.3.2 Change folder construction

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.

  1. 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
  2. Replace the folder construction. The tools like Flexible Renamer are useful to replace file name or folder name.

  3. Replace the contents of files. The tools like GrepReplace are useful to replace the contents of files.

  4. Click Save All icon to save changes.

  5. Run C:\root\programs\C#\10_Build_WebApp_sample.bat to build sample program.

4.4 Change data provider (Sample program)

Change the data provider that is used in original sample program to ODP.NET.

  1. Run C:\root\programs\C#\Frameworks\DaoGen_Tool\bin\Debug\DaoGen_Tool.exe to launch D layer auto generation tool.

  2. Set properties as follows and click Acquire.

    • Data provider: Oracle ODP.NET
    • Connection string: Connection string to Oracle database
    • Drop down list: Summary
  3. 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.

  1. Click Get Table List.

    In the Note? (prerequisites) dialog box, click OK.

  2. Select tables except SHIPPERS, click Delete button.

  3. Confirm whether Table List contains only SHIPPERS table, and click Load.

  4. 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.

  5. Click OK in the dialog box displaying the message Completion of generation of the D-layer definition information!.

  6. Click Go to STEP 2.

  7. 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.

  8. Click OK in the dialog box displaying the message Automatic Generation Completed!.

  9. 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)

  10. To add generated data access class to sample program, select Dao folder in Solution Explorer, and click Project -> Add Existing File in toolbar.

  11. In the Add Existing Item screen, select DaoSHIPPERS.cs and DaoOrder_Details.cs in C:\root folder. Click Add.

  12. Open App_Code\sample\Business\LayerB.cs in the Solution Explorer.

  13. 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
  14. Click Save All icon to save changes.

  15. Run C:\root\programs\C#\10_Build_WebApp_sample.bat to build sample program.

  16. Copy the generated SQL and XML files in C:\root to C:\root\files\resource\Sql folder.

  17. Close D layer auto generation tool.

4.5 Confirm the setting of application configuration file

Set properties in application configuration file (web.config or app.config) according to the architectures of the individual projects.

  1. Open C:\root\programs\C#\App\WebApp\ProjectX\ProjectX.sln.

  2. Open web.config in the Solution Explorer.

  3. Set the properties in web.config.

    1. 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>
    2. Set other properties in system.web tag in web.config according to the architectures of the individual project.

  4. Open app.config in the Solution Explorer.

  5. 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.

  6. Run C:\root\programs\C#\10_Build_WebApp_sample.bat to build sample program.

4.6 Check operation of sample program

  1. Debug sample program with Visual Studio.

  2. 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
  3. Since menu screen is shown, click ノーマル (Normal in Japanese).

  4. Click 件数取得 (Get record count in Japanese) button in sample screen.

  5. Confirm that the record count is shown in message area and sample program accesses to Oracle database successfully.

  6. Open log file - C:\root\files\resource\Log\ACCESS.yyyy-mm-dd.log (where, yyyy-mm-dd is executed date) in Notepad.

  7. 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
Clone this wiki locally