/// 非同期でPOP3メールサーバーからのデータを受信します。 /// 受信データがまだある場合、再度BeginExecuteメソッドを呼び出し残りのデータを取得します。 /// <summary> /// Send a command with asynchronous and get response text by first parameter of callbackFunction. /// If there is more data to receive,continously call BeginExecuteCallback method and get response data. /// 非同期でPOP3メールサーバーからのデータを受信します。 /// 受信データがまだある場合、再度BeginExecuteメソッドを呼び出し残りのデータを取得します。 /// </summary> /// <param name="result"></param> private void BeginSendCallBack(IAsyncResult result) { DataReceiveContext cx = (DataReceiveContext)result.AsyncState; Boolean IsException = false; try { Int32 size = this.Stream.EndRead(result); if (cx.ReadBuffer(size) == true) { //まだデータが受信中の場合、再度レスポンスデータを受信します。 var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.BeginSendCallBack, cx); } else { cx.OnEndGetResponse(); cx.Dispose(); } } catch (Exception ex) { IsException = true; this.OnError(ex); } finally { if (IsException == true && cx != null) { cx.Dispose(); } } }
private void ExecuteIdleCallback(IAsyncResult result) { DataReceiveContext cx = null; try { cx = (DataReceiveContext)result.AsyncState; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } Int32 size = Stream.EndRead(result); if (cx.ReadBuffer(size) == true) { var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); } else { cx.Dispose(); } } catch (Exception ex) { cx.Exception = ex; this.OnError(ex); } finally { if (cx.Exception != null) { cx.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> protected void GetResponseStream(DataReceiveContext context) { if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } using (var cx = context) { var bb = cx.Buffer; this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); var bl = this.GetResponseDone.WaitOne(this.ReceiveTimeout); if (cx.Exception != null) { throw cx.Exception; } if (cx.Timeout == true || bl == false) { throw new SocketClientException("Response timeout"); } if (TraceSource.Listeners.Count > 0) { String text = this.ResponseEncoding.GetString(cx.GetData()); TraceSource.TraceInformation(String.Format("{0} Client Receive:{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), text)); } } }
/// <summary> /// /// </summary> /// <param name="result"></param> protected void GetResponseCallback(IAsyncResult result) { DataReceiveContext cx = null; try { cx = (DataReceiveContext)result.AsyncState; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } Int32 size = Stream.EndRead(result); TimeSpan ts = DateTime.Now - cx.StartTime; if (ts.TotalMilliseconds > this.ReceiveTimeout) { cx.Timeout = true; this.GetResponseDone.Set(); } if (cx.ReadBuffer(size) == true) { var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); } else { this.GetResponseDone.Set(); } } catch (Exception ex) { cx.Exception = ex; } if (cx.Exception != null) { try { this.GetResponseDone.Set(); } catch (ObjectDisposedException) { } } }
/// <summary> /// /// </summary> /// <param name="context"></param> protected void GetResponseStream(DataReceiveContext context) { if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } using (var cx = context) { var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); var bl = this.GetResponseDone.WaitOne(this.ReceiveTimeout); if (cx.Exception != null) { throw cx.Exception; } if (cx.Timeout == true || bl == false) { throw new SocketClientException("Response timeout"); } } }
protected void GetResponseStream(DataReceiveContext context) //Is stream laukia atsakymo { if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } using (var cx = context) { var bb = cx.GetByteArray(); //Grazina buferi this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); //Is stream i buferi nuskaito var bl = this.GetResponseDone.WaitOne(this.ReceiveTimeout); //Laukia nuskaitymo galo if (cx.Exception != null) { throw cx.Exception; } if (cx.Timeout == true || bl == false) { throw new SocketClientException("Response timeout"); } } }
/// 非同期でPOP3メールサーバーへコマンドを送信します。受信したレスポンスの文字列はcallbackFunctionの引数として取得できます。 /// <summary> /// Send a command with asynchronous and get response text by first parameter of callbackFunction. /// 非同期でPOP3メールサーバーへコマンドを送信します。受信したレスポンスの文字列はcallbackFunctionの引数として取得できます。 /// </summary> /// <param name="command"></param> /// <param name="context"></param> /// <param name="callbackFunction"></param> public void BeginSend(String command, DataReceiveContext context, Action <String> callbackFunction) { Boolean IsException = false; var cx = context; try { this.Send(command); var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.BeginSendCallBack, cx); } catch { IsException = true; throw; } finally { if (IsException == true && cx != null) { cx.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> protected Byte[] GetResponseBytes(DataReceiveContext context) { this.GetResponseStream(context); return(context.GetData()); }
protected Byte[] GetResponseBytes(DataReceiveContext context) //Laukia atsakymo is context streamo { this.GetResponseStream(context); //Is stream laukia atsakymo return(context.GetData()); //Is stream nuskaito duomenys i MemoryStream ir i Byte[] ideda }