Adsense_top

2009年8月19日水曜日

C# Twitter API ストリーム系.. その2

昨日の「C# Twitter API ストリーム系に挑戦してみる」の続きです。
先ずは、残りのメソッドや列挙型


受信イベントの発行



private void OnReciveded(string content)
{
if (Received != null)
Received(content);
}

メソッドで使用するデータを格納するオブジェクトの構造体



public struct ArgsObject
{
public string UserId;
public string Password;
public HttpMethod Method;
public string Url;
public int BufferSize;
public string[] Parameters;
public ArgsObject(string userId, string password,
string url, HttpMethod method,
string[] parameters, int bufferSize)
{
this.UserId = userId;
this.Password = password;
this.Url = url;
this.Method = method;
this.Parameters = parameters;
this.BufferSize = bufferSize;
}
}

受信待機を終了させるメソッド



private void Stop()
{
state.Request.Abort();
}

非同期要求で使用する状態オブジェクトのクラス



public class RequestState
{
public int BufferSize = 1024;
public StringBuilder StringValue = new StringBuilder
public byte[] Buffer
public HttpWebRequest Request = null;
public HttpWebResponse Response = null;
public Stream Stream
public RequestState(int bufferSize)
{
BufferSize = bufferSize;
Buffer = new byte[BufferSize];
}
public RequestState()
{
Buffer = new byte[BufferSize];
}
public void DataClear()
{
StringValue.Length = 0;
}
}

HTTP使用するメソッドを指定する列挙型



public enum HttpMethod
{
POST,
GET,
DELETE
}

Twitterから受信するファイル形式を指定する列挙型



public enum ResultFormat
{
json,
xml,
rss,
atom
}

まぁ、ここまでのソースを読めば大体の使い方は読めているとは思いますが...
そろそろ眠たくなってきましたので、使用方法などは次回にまわさせていただきます。


0 件のコメント:

コメントを投稿