Esempio n. 1
0
 public void Get(string path, Action<ConnectionStatus> callback)
 {
     ConnectionState state = new ConnectionState()
     {
         Callback = callback,
         Connection = this.CreateConnection(path)
     };
     this.BeginGetResponse(state);
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }