Monday, April 27, 2009

修改 connection string during install process

public bool modifyConnectionString(string ServerName, string DBName, string AdminName, string AdminPwd, string targetSite)
{

string connectionString = string.Empty;

if (AdminName != string.Empty && AdminPwd != string.Empty)
connectionString = String.Format("Data Source={0};initial catalog={1};id={2};password={3}", ServerName, DBName, AdminName, AdminPwd);
else
connectionString = String.Format("Integrated Security=true;Data Source={0};initial catalog={1}", ServerName, DBName);
try
{
// Get the configuration object for a Web application
// running on the local server.
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetSite)
as System.Configuration.Configuration;

// Get the appSettings.
ConnectionStringSettings settings = new ConnectionStringSettings();
settings.Name = "connectionString1";
settings.ConnectionString = connectionString;
MessageBox.Show(connectionString);
config.ConnectionStrings.ConnectionStrings.Clear();
config.ConnectionStrings.ConnectionStrings.Add(settings);
config.Save();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}

}

run Sql generate from sql 2005

need:
Microsoft.sqlServer.ConnectionInfo
Microsoft.SqlServer.Smo
Microsoft.SqlServer.SmoEnum

c#
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

private void ExecuteSqlfile(string sqlstring)
{
if (ConnectDatabase())
{
try
{
Server server = new Server(new ServerConnection(sqlConn));
server.ConnectionContext.ExecuteNonQuery(sqlstring);

}
finally
{
Command.Connection.Close();
}
}
}

install/uninstall windows service and start it.

install.bat file (%1 --parameter 1, e.g. install.bat c:\Program Files\)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i
cd %1
InstallUtil.exe winservice.exe
NET START "your win services display name"
Pause

uninstall.bat file
cd %1
InstallUtil.exe -u winservice.exe
Pause

c# to run the install.bat file
ProgramFilesx86() run the system program file folder path (e.g. "c:\Program File")
using System.Diagnostics;
System.Diagnostics.Process.Start("\"" + ProgramFilesx86() + "\\path\\install.bat\"", parameter1);

使用VS2005部署带有数据库的Web站点

1. 在“新建项目”对话框的左侧树状图中选择“Other Project Types”->“Setup and Deployment”节点,在右侧选择“Web Setup Project”。

2. 在Solution Explorer中在Solution上点右键,选择“Add”->“Existing Web Site”,将存放编译好的Web网站的文件夹加入Solution中。

如果添加使用aspnet_compiler编译好的网站,有可能会出现下面的提示框,点击“是”就行。


3. 再添加一个新的“Class Library”,名称“CreateDB”,用以创建数据库的操作。


删除默认生成的“class1.cs”,在这个项目上点右键,选择“Add”->“New Item”,在弹出的对话框中选择“Installer Class”,点击OK。

在类中添加如下代码:
private void ExecuteSql(string connectionString, string databaseName, string sql)
{
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
try
{
sqlCommand.Connection.Open();
sqlCommand.Connection.ChangeDatabase(databaseName);
sqlCommand.ExecuteNonQuery();
}
catch (Exception exception)
{
throw exception;
}
finally
{
sqlCommand.Connection.Close();
}
}

public override void Install(System.Collections.IDictionary stateSaver)
{
string server = this.Context.Parameters["server"];
string database = this.Context.Parameters["dbname"];
string user = this.Context.Parameters["user"];
string password = this.Context.Parameters["pwd"];
string targetDir = this.Context.Parameters["targetdir"];

try
{
string connectionString = String.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096",
server, user, password);

//create db
ExecuteSql(connectionString, "master", "CREATE DATABASE " + database);

//set user
string setUserString = "sp_addlogin 'PrinteryERP', 'PrinteryERP', 'PrinteryERP'";
string setAccessString = "sp_grantdbaccess 'PrinteryERP'";
string setRole = "sp_addrolemember 'db_owner', 'PrinteryERP'";

//create new user login
try
{
ExecuteSql(connectionString, "master", setUserString);
}
catch { }

//set default database
try
{
ExecuteSql(connectionString, "PrinteryERP", setAccessString);
}
catch { }

//set read role
try
{
ExecuteSql(connectionString, "PrinteryERP", setRole);
}
catch { }

//create table,store produce......
Process osqlProcess = new Process();
osqlProcess.StartInfo.FileName = targetDir + "osql.exe";
osqlProcess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -S {2} -d {3} -i {4}createdb.sql",
user, password, server, database, targetDir);
osqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
osqlProcess.Start();
osqlProcess.WaitForExit();
osqlProcess.Close();

//add data
osqlProcess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -S {2} -d {3} -i {4}insertdata.sql",
user, password, server, database, targetDir);
osqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
osqlProcess.Start();
osqlProcess.WaitForExit();
osqlProcess.Close();
}
catch (Exception exception)
{
throw exception;
}

try
{
string configFile = targetDir + "/Web.config";
if (!File.Exists(configFile))
{
throw new InstallException("没有找到配置文件。");
}

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(configFile);

GC.Collect();
File.Delete(configFile);
GC.Collect();

foreach (XmlNode xmlNode in xmlDoc["configuration"]["connectionStrings"].ChildNodes)
{
if (xmlNode.Name == "add")
{
if (xmlNode.Attributes["name"].Value == "DBConnection")
{
xmlNode.Attributes["connectionString"].Value = String.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID=PrinteryERP;Password=PrinteryERP",
server, database);
}
if (xmlNode.Attributes["name"].Value == "UserManageServicesConnection")
{
xmlNode.Attributes["connectionString"].Value = String.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID=PrinteryERP;Password=PrinteryERP",
server, database);
}
}
}
xmlDoc.Save(configFile);
}
catch (Exception exception)
{
throw exception;
}
}
4. 在“Web Setup Project”项目上点右键,选择“Add”->“Project Output”,选择Project“CreateDB”,选择“Primary Output”,点击OK。重复上述动作,将选择刚才添加的Web Site,选择“Content Files”,点击OK。


5. 在“Web Setup Project”项目上点右键,选择“Add”->“File”,将创建数据库表、存储过程和视图的脚本createdb.sql加入。重复,将向 数据表中添加基础数据的脚本insertdata.sql加入。重复,将程序osql.exe加入。
6. 在“Web Setup Project”项目上点右键,选择“Add”->“Merge Module”,在弹出的对话框中选择“VC_User_CRT71_RTL_X86_---.msm”,点击OK。添加这个VC运行库是因为在一台干净 的机器上测试的时候发现osql.exe这个程序需要这个库。
7. 在“Web Setup Project”项目上点右键,选择“Properties”,在弹出的对话框中可以设置一些安装程序的属性。点击按钮“Prerequisites”, 在弹出的对话框中选中“.NET Framework 2.0”和“Windows Installer 3.1”,选中“Download prerequisites from the same location as my application”。这样就可以把这些组件和应用程序打包在一起,安装的时候自动检测并安装了。如果需要部署的计算机如果没有打过最新的补丁的话, 是没有“Windows Installer 3.1”的,如果没有这个组件,“.NET Framework 2.0”是不能安装的。

8.在“Web Setup Project”项目上点右键,选择“View”->“Custom Actions”,在出现的树状图的节点“Install”上点右键,选择“Add Custom Actions”。在弹出的对话框中“Look in”中选择“Web Application Folders”,在下面选择“Primary output from CreateDB (Active)”,点击OK。


9. 在“Web Setup Project”项目上点右键,选择“View”->“User Interface”,在出现的树状图节点“Install”的子节点“Start”上点击右键,选择“Add Dialog”,在弹出的对话框中选择“TextBoxes(A)”。

在新添加的节点“TextBoxes (A)”上点击右键,选择“Properites Window”,依次设置Edit*Property属性为“CUSTOMTEXTA1”,“CUSTOMTEXTA2”,“CUSTOMTEXTA3” 和“CUSTOMTEXTA4”。

10. 在刚刚建立的“Primary output from CreateDB (Active)”节点上点右键,选择“Properties Window”,设置“CustomActionData”属性为“/dbname=[CUSTOMTEXTA1] /server=[CUSTOMTEXTA2] /user=[CUSTOMTEXTA3] /pwd=[CUSTOMTEXTA4] /targetdir="[TARGETDIR]\"”。

接下来对整个解决方案进行编译,会在输出目录下生成两个文件夹和两个文件。
两个文件夹中分别包含了.NET Framework 2.0和Windows Installer3.1的安装包。另外的两个文件分别是(项目名称).msi和setup.exe。如果要进行安装,请执行setup.exe。

Bootstrap Manifest Generator - How To Setup Custom Pre-Requisites (VS 2005 Web setup project)

Bootstrap Manifest Generator - How To Setup Custom Pre-Requisites (VS 2005 Web setup project)

From: http://jcrawfor74.wordpress.com/2008/02/27/bootstrap-manifest-generator-how-to-custom-pre-requisites/

Recently I was attempting to create a deployment package that has customised pre-requisites i.e I wanted my installer to detect if AJAX Extensions 1.0 was installed and if not ask the user to install it.

I found this link talking about how to do it..

http://www.codeplex.com/MSAjax10SetupPrereq

Which lead me to download the Bootstapper Manifest generator from http://www.codeplex.com/bmg

http://www.davidguyer.us/BMG/publish.htm

I was a bit lost with what to do so hopefully this will save you the pain I went though.

(Note: the BMG is really buggy. Most of the system checks don’t work, and once you add a file system check and save your project you can no longer open your bootstrap project. But given it is free it’s better than attempting to write the XML by hand)

As an example to create a pre-requisite for AJAX follow these steps:
  1. Run the BMG tool.
  2. Create a new Package Manifest. Give it a name, AJAX
  3. Add a file, choose the AJAX Extension installer .msi.
  4. Give it a name, this will be the name that appears in your installer so make it something nice like “Microsoft ASP .Net 2.0 AJAX Extensions 1.0″
  5. Build it.
Now if it builds have a look at the location that it is written to, it is a visual studio directory, so I thought to myself it must integrate with VS2005.
So open your Setup Project in visual studio, (in my case, a Web Setup Project). Right Click — Properties on the solution. There in the bottom right is the pre-requisite button.
Click on it and you should now see AJAX as an option.
Traps for young players
1. Copy paste
Inside the BGM copy and paste does not appear to work. The trick, is right click in the field and choose paste.
2. Download from web Option
If you want to download from the web enter the url for the .exe. I setup my own publically available spot to allow downloading these pre-requesites (rather than relying on the microsoft download site), as they migth change things. So I have a known static location to go download the AJAX Extensions msi.
3. System Checks
You should include a check to see whether AJAX is already installed.
In your manifest click on the file you added, and go to the “System Checks” tab. I found that most of the system checks did not work properly.
I found the one that did work was a file check, so I added a file check for System.Web.Extensions.dll in the default location
  • Add a File check. Set the file name to System.Web.Extensions.dll, turn off the search, and enter the default path to the ASP Net folder.
  • Switch to the “Install Conditions” tab and add a line that says:
    • Type - By Pass If
    • Property - AJAX (or the name you gave your system check
    • Comparison - Exists

Cheers and goodluck

Sunday, November 16, 2008

接口(Interface)的作用

接口(Interface)的作用

继承"基类"跟继承"接口"都能实现某些相同的功能,但有些接口能够完成的功能是只用基类无法实现的

1.接口用于描述一组类的公共方法/公共属性. 它不实现任何的方法或属性,只是告诉继承它的类
《至少》要实现哪些功能,继承它的类可以增加自己的方法.

2.使用接口可以使继承它的类: 命名统一/规范,易于维护.比如: 两个类 "狗"和"猫",如果它
们都继承了接口"动物",其中动物里面有个方法Behavior(),那么狗和猫必须得实现Behavior()方法,
并且都命名为Behavior这样就不会出现命名太杂乱的现象.如果命名不是Behavior(),接口会约束
即不按接口约束命名编译不会通过.

3.提供永远的接口。 当类增加时,现有接口方法能够满足继承类中的大多数方法,没必要
重新给新类设计一组方法,也节省了代码,提高了开发效率.
举个代码示例:

//公共接口: "动物"
public Interface IAnimal
{
int EyeNumber;
private void Behavior(); //行为方法,描述各种动物的特性
}

//类: 狗
public Dog : IAnimal
{
string ActiveTime = "白天";
private void Behavior()
{ {
Console.Write("我晚上睡觉,白天活动");
}
}

//类: 猫
public Cat: IAnimal
{
string ActiveTime = "夜晚";
private void Behavior()
{ {
Console.Write("我白天睡觉,晚上活动");
}
}


//简单的应用:
public static Main()
{
Dog myDog = new Dog();
myDog.Behavior(); //输出: "我晚上睡觉,白天活动"
Cat myCat = new Cat();
myCat.Behavior(); //输出: "我白天睡觉,晚上活动"
}
以上调用不同的类的相同名方法,会输出不同的东东,也就是说每个类里面的同名方法完成的
功能可以是完全不同的.

更进一步,不是用上面Main方法这样一个一个调用类的方法,用多态性实现其调用.
看一下下面这个方法:
public Behavior(IAnimal myIanimal)
{
myIanimal.Behavior();
}

其参数是<<接口类型>>,任何继承它的类都可以调用此方法,此方法能根据类的不同调用不同的类
中的方法. 也即能够自己根据不同的类,完成不同的类的功能.
多态性代码示例:
Dog myDog = new Dog();
Cat myCat = new Cat();
Behavior(myDog); //Behavior接受“狗”类实例
Behavior(myCat); //Behavior接受“狗”类实例

这样Behavior方法写一次就能完成所有继承它的类中的相同名方法的不同功能. 非常方便,

同样,由于“动物软件”功能需求,需要再增加一个"龟"类:
//类: 龟
public Tortoise: IAnimal
{
string ActiveTime = "很难说";
private void Behavior()
{ {
Console.Write("我可以不活动,一睡就睡五千年!");
}
}
那么也可以调用上面多态方法,所以说接口使方法具有较好扩展性.
如果继承它的类很多的话,有多少好处是可想而知的!

另外, 也有抽象类能够实现但接口不能实现的情况:

1. 在抽象类中可以加代码逻辑,但接口不能.

2. 如果要在接口中增加一个方法, 所有实现它的类都强制重载一遍此方法, 如果重载类很多时, 会增大工作量.

总之, 一般在仅实现单继承用途时, 尽量用抽象类, 功能也更强些!
Abstract class VS Interface
来自:ITPUB devilbaby [原作]

abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。 abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进行抽象类定义时对于 abstract class和interface的选择显得比较随意。其实,两者之间还是有很大的区别的,对于它们的选择甚至反映出对于问题领域本质的理解、对于设计意图 的理解是否正确、合理。本文将对它们之间的区别进行一番剖析,试图给开发者提供一个在二者之间进行选择的依据。
理解抽象类

abstract class和interface在Java语言中都是用来进行抽象类(本文中的抽象类并非从abstract class翻译而来,它表示的是一个抽象体,而abstract class为Java语言中用于定义抽象类的一种方法,请读者注意区分)定义的,那么什么是抽象类,使用抽象类能为我们带来什么好处呢?

在 面向对象的概念中,我们知道所有的对象都是通过类来描绘的,但是反过来却不是这样。并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来 描绘一个具体的对象,这样的类就是抽象类。抽象类往往用来表征我们在对问题领域进行分析、设计中得出的抽象概念,是对一系列看上去不同,但是本质上相同的 具体概念的抽象。比如:如果我们进行一个图形编辑软件的开发,就会发现问题领域存在着圆、三角形这样一些具体概念,它们是不同的,但是它们又都属于形状这 样一个概念,形状这个概念在问题领域是不存在的,它就是一个抽象概念。正是因为抽象的概念在问题领域没有对应的具体概念,所以用以表征抽象概念的抽象类是 不能够实例化的。

在面向对象 领域,抽象类主要用来进行类型隐藏。我们可以构造出一个固定的一组行为的抽象描述,但是这组行为却能够有任意个可能的具体实现方式。这个抽象描述就是抽象 类,而这一组任意个可能的具体实现则表现为所有可能的派生类。模块可以操作一个抽象体。由于模块依赖于一个固定的抽象体,因此它可以是不允许修改的;同 时,通过从这个抽象体派生,也可扩展此模块的行为功能。熟悉OCP的读者一定知道,为了能够实现面向对象设计的一个最核心的原则OCP(Open- Closed Principle),抽象类是其中的关键所在。

从语法定义层面看abstract class和interface

在语法层面,Java语言对于abstract class和interface给出了不同的定义方式,下面以定义一个名为Demo的抽象类为例来说明这种不同。

使用abstract class的方式定义Demo抽象类的方式如下:

abstract class Demo {
abstract void method1();
abstract void method2();

使用interface的方式定义Demo抽象类的方式如下:

interface Demo {
void method1();
void method2();

}

在abstract class方式中,Demo可以有自己的数据成员,也可以有非abstarct的成员方法,而在interface方式的实现中,Demo只能够有静态的不能被修改的数据成员(也就是必须是static final的,不过在interface中一般不定义数据成员),所有的成员方法都是abstract的。从某种意义上说,interface是一种特殊形式的abstract class。

对于abstract class和interface在语法定义层面更多的细节问题,不是本文的重点,不再赘述,读者可以参阅参考文献〔1〕获得更多的相关内容。

从编程层面看abstract class和interface

从编程的角度来看,abstract class和interface都可以用来实现"design by contract"的思想。但是在具体的使用上面还是有一些区别的。

首先,abstract class在Java语言中表示的是一种继承关系,一个类只能使用一次继承关系。但是,一个类却可以实现多个interface。也许,这是Java语言的设计者在考虑Java对于多重继承的支持方面的一种折中考虑吧。

其次,在abstract class的定义中,我们可以赋予方法的默认行为。但是在interface的定义中,方法却不能拥有默认行为,为了绕过这个限制,必须使用委托,但是这会 增加一些复杂性,有时会造成很大的麻烦。

在 抽象类中不能定义默认行为还存在另一个比较严重的问题,那就是可能会造成维护上的麻烦。因为如果后来想修改类的界面(一般通过abstract class或者interface来表示)以适应新的情况(比如,添加新的方法或者给已用的方法中添加新的参数)时,就会非常的麻烦,可能要花费很多的时 间(对于派生类很多的情况,尤为如此)。但是如果界面是通过abstract class来实现的,那么可能就只需要修改定义在abstract class中的默认行为就可以了。

同样,如果不能在抽象类中定义默认行为,就会导致同样的方法实现出现在该抽象类的每一个派生类中,违反了"one rule,one place"原则,造成代码重复,同样不利于以后的维护。因此,在abstract class和interface间进行选择时要非常的小心。

从设计理念层面看abstract class和interface

上面主要从语法定义和编程的角度论述了abstract class和interface的区别,这些层面的区别是比较低层次的、非本质的。本小节将从另一个层面:abstract class和interface所反映出的设计理念,来分析一下二者的区别。作者认为,从这个层面进行分析才能理解二者概念的本质所在。

前面已经提到过,abstarct class在Java语言中体现了一种继承关系,要想使得继承关系合理,父类和派生类之间必须存在"is a"关系,即父类和派生类在概念本质上应该是相同的(参考文献〔3〕中有关于"is a"关系的大篇幅深入的论述,有兴趣的读者可以参考)。对于interface 来说则不然,并不要求interface的实现者和interface定义在概念本质上是一致的,仅仅是实现了interface定义的契约而已。为了使论述便于理解,下面将通过一个简单的实例进行说明。

考虑这样一个例子,假设在我们的问题领域中有一个关于Door的抽象概念,该Door具有执行两个动作open和close,此时我们可以通过abstract class或者interface来定义一个表示该抽象概念的类型,定义方式分别如下所示:

使用abstract class方式定义Door:

abstract class Door {
abstract void open();
abstract void close();
}

使用interface方式定义Door:

interface Door {
void open();
void close();
}

其他具体的Door类型可以extends使用abstract class方式定义的Door或者implements使用interface方式定义的Door。看起来好像使用abstract class和interface没有大的区别。

如果现在要求Door还要具有报警的功能。我们该如何设计针对该例子的类结构呢(在本例中,主要是为了展示abstract class和interface反映在设计理念上的区别,其他方面无关的问题都做了简化或者忽略)?下面将罗列出可能的解决方案,并从设计理念层面对这些不同的方案进行分析。

解决方案一:

简单的在Door的定义中增加一个alarm方法,如下:

abstract class Door {
abstract void open();
abstract void close();
abstract void alarm();
}

或者

interface Door {
void open();
void close();
void alarm();
}

那么具有报警功能的AlarmDoor的定义方式如下:

class AlarmDoor extends Door {
void open() { … }
void close() { … }
void alarm() { … }
}

或者

class AlarmDoor implements Door {
void open() { … }
void close() { … }
void alarm() { … }

这 种方法违反了面向对象设计中的一个核心原则ISP(Interface Segregation Priciple),在Door的定义中把Door概念本身固有的行为方法和另外一个概念"报警器"的行为方法混在了一起。这样引起的一个问题是那些仅仅 依赖于Door这个概念的模块会因为"报警器"这个概念的改变(比如:修改alarm方法的参数)而改变,反之依然。

解决方案二:

既然open、close和alarm属于两个不同的概念,根据ISP原则应该把它们分别定义在代表这两个概念的抽象类中。定义方式有:这两个概念都使用abstract class方式定义;两个概念都使用interface方式定义;一个概念使用abstract class方式定义,另一个概念使用interface方式定义。

显然,由于Java语言不支持多重继承,所以两个概念都使用abstract class方式定义是不可行的。后面两种方式都是可行的,但是对于它们的选择却反映出对于问题领域中的概念本质的理解、对于设计意图的反映是否正确、合理。我们一一来分析、说明。

如 果两个概念都使用interface方式来定义,那么就反映出两个问题:1、我们可能没有理解清楚问题领域,AlarmDoor在概念本质上到底是 Door还是报警器?2、如果我们对于问题领域的理解没有问题,比如:我们通过对于问题领域的分析发现AlarmDoor在概念本质上和Door是一致 的,那么我们在实现时就没有能够正确的揭示我们的设计意图,因为在这两个概念的定义上(均使用interface方式定义)反映不出上述含义。

如果我们对于问题领域的理解是:AlarmDoor在概念本质上是Door,同时它有具有报警的功能。我们该如何来设计、实现来明确的反映出我们的意思呢?前面已经说过,abstract class在Java语言中表示一种继承关系,而继承关系在本质上是"is a"关系。所以对于Door这个概念,我们应该使用abstarct class方式来定义。另外,AlarmDoor又具有报警功能,说明它又能够完成报警概念中定义的行为,所以报警概念可以通过interface方式定义。如下所示:

abstract class Door {
abstract void open();
abstract void close();
}
interface Alarm {
void alarm();
}
class AlarmDoor extends Door implements Alarm {
void open() { … }
void close() { … }
void alarm() { … }
}

这 种实现方式基本上能够明确的反映出我们对于问题领域的理解,正确的揭示我们的设计意图。其实abstract class表示的是"is a"关系,interface表示的是"like a"关系,大家在选择时可以作为一个依据,当然这是建立在对问题领域的理解上的,比如:如果我们认为AlarmDoor在概念本质上是报警器,同时又具有 Door的功能,那么上述的定义方式就要反过来了。

结论

abstract class和interface是Java语言中的两种定义抽象类的方式,它们之间有很大的相似性。但是对于它们的选择却又往往反映出对于问题领域中的概 念本质的理解、对于设计意图的反映是否正确、合理,因为它们表现了概念间的不同的关系(虽然都能够实现需求的功能)。这其实也是语言的一种的惯用法,希望 读者朋友能够细细体会。