Created
November 24, 2010 04:14
-
-
Save noqisofon/713100 to your computer and use it in GitHub Desktop.
MSDN の BBS にはられたリモート関連の基本名前空間のちょっとだけ改変。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace moa.test.remote { | |
/// <summary> | |
/// メッセージを送信するイベントハンドラを定義します。 | |
/// </summary> | |
public delegate void SendMessageEventHandler(); | |
/// <summary> | |
/// メッセージを送信するインターフェイスを表します。 | |
/// </summary> | |
public interface IRemoteObject { | |
/// <summary> | |
/// メッセージを送信したときに発生します。 | |
/// </summary> | |
event SendMessageEventHandler sendMessage; | |
/// <summary> | |
/// SendMessage イベントを発生させます。 | |
/// </summary> | |
void onMessageSend(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.Remoting.Messaging; | |
// やりたいこと。 | |
// ## ■リモートオブジェクトとして用意したイベントを発生させる! | |
// | |
// ### 手順 | |
// 1. イベントを持ったリモートオブジェクトを用意します。 | |
// 2. リモートオブジェクトをアクティベートします。 | |
// 3. アクティベートしたリモートオブジェクトのイベントハンドラに登録します。 | |
// 4. アクティベートしたリモートオブジェクトのイベントを発生させます。 | |
// 5. イベントハンドラに登録したメソッドが呼ばれていることを確認します。 | |
// | |
// ### 用意するもの | |
// *. リモートオブジェクト | |
// *. クライアント | |
// *. サーバ | |
// [[リモーティングでサーバのイベントに登録>http://social.msdn.microsoft.com/forums/ja-JP/vsgeneralja/thread/22000da9-58c3-4572-9f46-49dbbf23360e/]] | |
namespace moa.test.remote { | |
/// <summary> | |
/// 大元となるメッセージ送信イベントを発生させる機能を提供します。 | |
/// </summary> | |
public class RemoteObject : MarshalByRefObject, IRemoteObject { | |
/// <summary> | |
/// メッセージイベントです。 | |
/// </summary> | |
public event SendMessageEventHandler sendMessage; | |
/// <summary> | |
/// メッセージイベントを発生させます。 | |
/// </summary> | |
[OneWay] | |
public void onMessageSend() { | |
if ( sendMessage != null ) { | |
sendMessage(); | |
} | |
} | |
} | |
/// <summary> | |
/// メッセージ送信イベントをチェインさせる為の機能を提供します。 | |
/// </summary> | |
public class ChainRemoteObject : MarshalByRefObject, IRemoteObject { | |
/// <summary> | |
/// チェインするメッセージイベントです。 | |
/// </summary> | |
public event SendMessageEventHandler sendMessage; | |
/// <summary> | |
/// チェインメッセージを発生させます。 | |
/// </summary> | |
[OneWay] | |
public void onMessageSend() { | |
if ( sendMessage != null ) { | |
sendMessage(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment