public void Get(string path, Action<ConnectionStatus> callback) { ConnectionState state = new ConnectionState() { Callback = callback, Connection = this.CreateConnection(path) }; this.BeginGetResponse(state); }
public void Delete(string path, Action<ConnectionStatus> callback) { Thread deleteThread = new Thread(() => { this._ResourceLock.WaitOne(); ConnectionState state = new ConnectionState { Callback = (c) => { this._ResourceLock.Release(); if (callback != null) callback(c); }, Connection = this.CreateConnection(path, "DELETE") }; this.BeginGetResponse(state); }); deleteThread.Start(); }
private void _PutOrPost(string method, string path,string data, Action<ConnectionStatus> callback) { ConnectionState state = new ConnectionState() { Callback = callback, Connection = this.CreateConnection(path), PostData = data }; state.Connection.Method = method; state.Connection.BeginGetRequestStream(this.PostStreamOpened, state); }
private void BeginGetResponse(ConnectionState state) { try { IAsyncResult result = (IAsyncResult)state.Connection.BeginGetResponse( new AsyncCallback(GetResponseHandle), state ); ThreadPool.RegisterWaitForSingleObject( result.AsyncWaitHandle, new WaitOrTimerCallback(ThreadTimeoutCallback), state.Connection, this._ConnectionSettings.TimeOut, true ); } catch (WebException e) { state.RaiseCallBack(e); } catch (Exception e) { state.RaiseCallBack(e); } }
private void PostDataUsingMethod(string method, string path,string data, Action<ConnectionStatus> callback) { if (method != "PUT" && method != "POST" && method != "DELETE") { throw new ArgumentException("Valid methods that can post a body are PUT, POST, DELETE", "method"); } ConnectionState state = new ConnectionState() { Callback = callback, Connection = this.CreateConnection(path, method), PostData = data }; state.Connection.BeginGetRequestStream(this.PostStreamOpened, state); }
private void _PutOrPost(string method, string path,string data, Action<ConnectionStatus> callback) { if (method != "PUT" && method != "POST") { throw new ArgumentException("Valid values contain only PUT or POST", "method"); } ConnectionState state = new ConnectionState() { Callback = callback, Connection = this.CreateConnection(path, method), PostData = data }; state.Connection.BeginGetRequestStream(this.PostStreamOpened, state); }