2009-07-21 31 views
6

電子メール通知を処理するためのカスタム構成セクションを作成する必要があります。カスタムASP.NET構成セクション

<configSections> 
    <sectionGroup name="notifications"> 
     <section name="notification" type="NotificationConfiguration" allowLocation="true" allowDefinition="Everywhere" /> 
    </sectionGroup> 
</configSections> 
... 
<notifications> 
    <notification name="..." enabled="..." delayInMinutes="..."> 
     <recipients> 
      <add email="..." /> 
      <add email="..." /> 
      <add email="..." /> 
     </recipients> 
    </notification> 
    <notification name="..." enabled="..." delayInMinutes="..."> 
     <recipients> 
      <add email="..." /> 
      <add email="..." /> 
      <add email="..." /> 
     </recipients> 
    </notification> 
</notifications> 
... 

は、私は、これは罰金NotificationConfiguration config = (NotificationConfiguration) ConfigurationManager.GetSection("notifications\notification")を使用して仕事を得ることができますが、これは一個の<notification>要素の食料調達:設定は、次の形式である必要があります。複数の通知を受け取るために複数の要素を達成するにはどうすればよいですか?

これを処理するクラスは、非常に長いので、私はここに貼り付けていないだろうが、それは、ここからダウンロードできます。

http://files.getdropbox.com/u/288235/NotificationConfiguration.cs

感謝。

+0

外部要素を作成し、すべての通知要素をそのグループに入れることができます。このようにして、達成したいことを達成することができます。 – Kirtan

+0

更新された回答を確認してください。 – Kirtan

答えて

1

ConfigurationElementCollection Classを使用できます。

これを使用する方法のリファレンスはCodeProjectにあります。

編集:<NotificationsGroup />外部要素を作成し、すべての通知要素をそのグループに入れることができます。このようにして、達成したいことを達成することができます。

EDIT 2:

<configSections> 
    <sectionGroup name="NotificationsGroup"> 
     <section name="NotificationsGroup" type="NotificationGroupConfiguration" allowLocation="true" allowDefinition="Everywhere" /> 
    </sectionGroup> 
</configSections> 

<NotificationsGroup> 
    <Notifications> 
    </Notifications> 
    ... Multiple notifications go here, instead of one. 
    <Notifications> 
    </Notifications> 
</NotificationsGroup> 

これはNotificationsGroupは、通知の要素のコレクションが含まれていることを意味します。

+0

こんにちはKirtan ConfigurationElementCollectionクラスは、セクションではなく要素のコレクションに使用されています。そのクラスをタグに使用しますが、タグはweb.configファイルの最上部にある設定セクションとして定義されていますので、セクション内の要素のコレクションではなく、セクションのコレクションを達成するにはどうすればよいですかセクション? – staterium

+0

web.configの上部では、私は自分のカスタム設定を次のように定義します:

私のタグのように、一群の通知を意味しますか? – staterium

+1

あなたの助けてくれてありがとうKirtran。下のツールは結局も多くの助けになりました! http://www.codeplex.com/csd/ – staterium

関連する問題