怎么在C#中写配置文件(20分) ( 积分: 20 )

  • 主题发起人 主题发起人 wujun510
  • 开始时间 开始时间
W

wujun510

Unregistered / Unconfirmed
GUEST, unregistred user!
我会写XML,但怎么在C#中写配置文件啊!.语法上有什么要求吗?大家能解释下面配置文件.主要格式为什么要这样写?配置文件格式有什么要求?
<xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Global" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="hbmSchemas" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="LocalDAO" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="PublishServer" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

<Global>
<add key="Global.isRemoting" value="true" />
<add key="Global.ChannelType" value="tcp" />
<add key="Global.RemotingUrl" value="tcp://127.0.0.1:6000/DataProvider" />
<add key="Global.Encrypt" value="true" />
<add key="Global.AppType" value="0" />
<add key="Global.Skin" value="Normal" />
<add key="Global.Landscape" value="false" />
</Global>

<system.runtime.remoting>
<channelSinkProviders>
<serverProviders>
<provider id="gzip" type="NTools.NetWork.CompressChannelSinkProvider,NTools" />
</serverProviders>
</channelSinkProviders>
<application>
<channels>
<channel ref="http" >
<serverProviders>
<provider ref="gzip" minDataSize="1024" />
<formatter ref="binary" />
</serverProviders>
</channel>
</channels>
<service>
<wellknown type="PTIAS.Data.Remoting.DataProvider, PTIAS.Data.Remoting" objectUri="DataProvider.rem" mode="SingleCall" />
<wellknown type="PTIAS.Data.Remoting.DataProvider, PTIAS.Data.Remoting" objectUri="DataProvider.soap" mode="SingleCall" />
</service>
</application>
</system.runtime.remoting>

<hbmSchemas>
<add key="hbmSchemas.hbmFileNamespace" value="PTIAS.Data.bo.hbm" />
<add key="hbmSchemas.hbmFileAssembly" value="PTIAS.Data.bo" />
<add
key="hbmSchemas.hbmList"
value="Agent.hbm.xml;
AgentReason.hbm.xml;
AgentInfoChangeReq.hbm.xml;
AuditAgentRequisitionView.hbm.xml;
AuditInfoChgRequisitionView.hbm.xml;
AuditLicenseOutRequisitionView.hbm.xml;
FiatNotice.hbm.xml;
AreaCodeList.hbm.xml;
Authority.hbm.xml;
Bail.hbm.xml;
BlackList.hbm.xml;
BlackListReason.hbm.xml;
CIRC.hbm.xml;
GroupTable.hbm.xml;
LicenseReqBroker.hbm.xml;
Broker.hbm.xml;
License.hbm.xml;
LicenseOperator.hbm.xml;
LicenseOutReq.hbm.xml;
PrintQueue.hbm.xml;
PaperPackage.hbm.xml;
Paper.hbm.xml;
InsuranceType.hbm.xml;
InsurerType.hbm.xml;
Insurer.hbm.xml;
Punishment.hbm.xml;
QualificationRequisition.hbm.xml;
ReportItem.hbm.xml;
ReportData.hbm.xml;
Relation.hbm.xml;
RelationView.hbm.xml;
Requisition.hbm.xml;
Examine.hbm.xml;
SystemLog.hbm.xml;
TradeCodeDict.hbm.xml;
Train.hbm.xml;
UserAuthority.hbm.xml;
UserGroupMap.hbm.xml;
UserAuthorityView.hbm.xml;
UserAuthorityInGroup.hbm.xml;
Unit.hbm.xml;
UserTable.hbm.xml;
Violation.hbm.xml;
Voucher.hbm.xml;
ZoneException.hbm.xml;
ZoneOrgException.hbm.xml"
/>
</hbmSchemas>

<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=developer;initial catalog=PTIAS30;Integrated Security=SSPI"
/>
</nhibernate>

<LocalDAO>
<add
key="LocalDAO.connection.connection_string"
value="Server=(local);initial catalog=IAI_GZDZ;Integrated Security=SSPI"
/>
</LocalDAO>

<PublishServer>
<add key="PublishServer.ChannelType" value="tcp"/>
<add key="PublishServer.RemotingUrl" value="tcp://zoumx:7000/DataProvider"/>
</PublishServer>

<!-- This section contains the log4net configuration settings -->
<log4net debug="true">
<appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
<param name="Threshold" value="DEBUG"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="..//data//Application.log" />
<param name="AppendToFile" value="true" />
<param name="Encoding" value="Unicode" />
<param name="Threshold" value="DEBUG"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="..//data//Application.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Size" />
<param name="MaxSizeRollBackups" value="3" />
<param name="MaximumFileSize" value="100KB" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="OutputDebugStringAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>

</configuration>
 
我会写XML,但怎么在C#中写配置文件啊!.语法上有什么要求吗?大家能解释下面配置文件.主要格式为什么要这样写?配置文件格式有什么要求?
<xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Global" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="hbmSchemas" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="LocalDAO" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="PublishServer" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>

<Global>
<add key="Global.isRemoting" value="true" />
<add key="Global.ChannelType" value="tcp" />
<add key="Global.RemotingUrl" value="tcp://127.0.0.1:6000/DataProvider" />
<add key="Global.Encrypt" value="true" />
<add key="Global.AppType" value="0" />
<add key="Global.Skin" value="Normal" />
<add key="Global.Landscape" value="false" />
</Global>

<system.runtime.remoting>
<channelSinkProviders>
<serverProviders>
<provider id="gzip" type="NTools.NetWork.CompressChannelSinkProvider,NTools" />
</serverProviders>
</channelSinkProviders>
<application>
<channels>
<channel ref="http" >
<serverProviders>
<provider ref="gzip" minDataSize="1024" />
<formatter ref="binary" />
</serverProviders>
</channel>
</channels>
<service>
<wellknown type="PTIAS.Data.Remoting.DataProvider, PTIAS.Data.Remoting" objectUri="DataProvider.rem" mode="SingleCall" />
<wellknown type="PTIAS.Data.Remoting.DataProvider, PTIAS.Data.Remoting" objectUri="DataProvider.soap" mode="SingleCall" />
</service>
</application>
</system.runtime.remoting>

<hbmSchemas>
<add key="hbmSchemas.hbmFileNamespace" value="PTIAS.Data.bo.hbm" />
<add key="hbmSchemas.hbmFileAssembly" value="PTIAS.Data.bo" />
<add
key="hbmSchemas.hbmList"
value="Agent.hbm.xml;
AgentReason.hbm.xml;
AgentInfoChangeReq.hbm.xml;
AuditAgentRequisitionView.hbm.xml;
AuditInfoChgRequisitionView.hbm.xml;
AuditLicenseOutRequisitionView.hbm.xml;
FiatNotice.hbm.xml;
AreaCodeList.hbm.xml;
Authority.hbm.xml;
Bail.hbm.xml;
BlackList.hbm.xml;
BlackListReason.hbm.xml;
CIRC.hbm.xml;
GroupTable.hbm.xml;
LicenseReqBroker.hbm.xml;
Broker.hbm.xml;
License.hbm.xml;
LicenseOperator.hbm.xml;
LicenseOutReq.hbm.xml;
PrintQueue.hbm.xml;
PaperPackage.hbm.xml;
Paper.hbm.xml;
InsuranceType.hbm.xml;
InsurerType.hbm.xml;
Insurer.hbm.xml;
Punishment.hbm.xml;
QualificationRequisition.hbm.xml;
ReportItem.hbm.xml;
ReportData.hbm.xml;
Relation.hbm.xml;
RelationView.hbm.xml;
Requisition.hbm.xml;
Examine.hbm.xml;
SystemLog.hbm.xml;
TradeCodeDict.hbm.xml;
Train.hbm.xml;
UserAuthority.hbm.xml;
UserGroupMap.hbm.xml;
UserAuthorityView.hbm.xml;
UserAuthorityInGroup.hbm.xml;
Unit.hbm.xml;
UserTable.hbm.xml;
Violation.hbm.xml;
Voucher.hbm.xml;
ZoneException.hbm.xml;
ZoneOrgException.hbm.xml"
/>
</hbmSchemas>

<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=developer;initial catalog=PTIAS30;Integrated Security=SSPI"
/>
</nhibernate>

<LocalDAO>
<add
key="LocalDAO.connection.connection_string"
value="Server=(local);initial catalog=IAI_GZDZ;Integrated Security=SSPI"
/>
</LocalDAO>

<PublishServer>
<add key="PublishServer.ChannelType" value="tcp"/>
<add key="PublishServer.RemotingUrl" value="tcp://zoumx:7000/DataProvider"/>
</PublishServer>

<!-- This section contains the log4net configuration settings -->
<log4net debug="true">
<appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
<param name="Threshold" value="DEBUG"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="..//data//Application.log" />
<param name="AppendToFile" value="true" />
<param name="Encoding" value="Unicode" />
<param name="Threshold" value="DEBUG"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="..//data//Application.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Size" />
<param name="MaxSizeRollBackups" value="3" />
<param name="MaximumFileSize" value="100KB" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="OutputDebugStringAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>

</configuration>
 
后退
顶部