예제 #1
0
        public Task<ConnectionStatus> Delete(string path, string data)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.DELETE;
            restRequest.Uri = path;

            if (!string.IsNullOrEmpty(data))
            {
                restRequest.Body = Encoding.UTF8.GetBytes(data);
            }
            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return Task.Factory.StartNew<ConnectionStatus>(() =>
            {
                return this.Execute(restRequest);
            });
        }
예제 #2
0
        public ConnectionStatus PutSync(string path, string data)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.PUT;
            restRequest.Uri = path;

            if (!string.IsNullOrEmpty(data))
            {
                restRequest.Body = Encoding.UTF8.GetBytes(data);
            }
            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            RestResponse result = GetClient().execute(restRequest);
            return new ConnectionStatus(DecodeStr(result.Body));
        }
예제 #3
0
        public Task<ConnectionStatus> Post(string path, string data)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.POST;
            restRequest.Uri = path;

            if (!string.IsNullOrEmpty(data))
            {
                restRequest.Body = Encoding.UTF8.GetBytes(data);
            }
            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return Task.Factory.StartNew<ConnectionStatus>(() =>
            {
                var result = GetClient().execute(restRequest);
                return new ConnectionStatus(DecodeStr(result.Body));
            });
        }
예제 #4
0
        public ConnectionStatus HeadSync(string path)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.HEAD;
            restRequest.Uri = path;

            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            RestResponse result = GetClient().execute(restRequest);
            return new ConnectionStatus(DecodeStr(result.Body));
        }
예제 #5
0
        public Task<ConnectionStatus> Head(string path)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.HEAD;
            restRequest.Uri = path;

            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return Task.Factory.StartNew<ConnectionStatus>(()=>
            {
                var result = GetClient().execute(restRequest);
                return new ConnectionStatus(DecodeStr(result.Body));
            });
        }
예제 #6
0
        public Task<ConnectionStatus> Delete(string path)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.DELETE;
            restRequest.Uri = path;

            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return Task.Factory.StartNew<ConnectionStatus>(() =>
            {
                return this.Execute(restRequest);
            });
        }
예제 #7
0
        private ConnectionStatus Execute(RestRequest restRequest)
        {
            //RestResponse result = GetClient().execute(restRequest);
            //

            if (!this._resourceLock.WaitOne(this._timeout))
            {
                var m = "Could not start the thrift operation before the timeout of " + this._timeout + "ms completed while waiting for the semaphore";
                return new ConnectionStatus(this._connectionSettings, new TimeoutException(m));
            }
            try
            {
                Rest.Client client = null;
                if (!this._clients.TryDequeue(out client))
                {
                    var m = string.Format("Could dequeue a thrift client from internal socket pool of size {0}", this._poolSize);
                    var status = new ConnectionStatus(this._connectionSettings, new Exception(m));
                    return status;
                }
                try
                {
                    if (!client.InputProtocol.Transport.IsOpen)
                        client.InputProtocol.Transport.Open();

                    var result = client.execute(restRequest);
                    if (result.Status == Status.OK || result.Status == Status.CREATED || result.Status == Status.ACCEPTED)
                        return new ConnectionStatus(this._connectionSettings, DecodeStr(result.Body));
                    else
                    {
                        var connectionException = new ConnectionException(
                            msg: Enum.GetName(typeof (Status), result.Status),
                            statusCode: (int)result.Status,
                            response: DecodeStr(result.Body)
                        );
                        return new ConnectionStatus(this._connectionSettings, connectionException);
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    //make sure we make the client available again.
                    this._clients.Enqueue(client);
                }

            }
            catch (Exception e)
            {
                return new ConnectionStatus(this._connectionSettings, e);
            }
            finally
            {
                this._resourceLock.Release();
            }
        }
예제 #8
0
        public ConnectionStatus HeadSync(string path)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.HEAD;
            restRequest.Uri = path;

            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return this.Execute(restRequest);
        }
예제 #9
0
        public ConnectionStatus PostSync(string path, string data)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.POST;
            restRequest.Uri = path;

            if (!string.IsNullOrEmpty(data))
            {
                restRequest.Body = Encoding.UTF8.GetBytes(data);
            }
            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            return this.Execute(restRequest);
        }
예제 #10
0
        public void Delete(string path, string data, Action<ConnectionStatus> callback)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.DELETE;
            restRequest.Uri = path;

            if (!string.IsNullOrEmpty(data))
            {
                restRequest.Body = Encoding.UTF8.GetBytes(data);
            }
            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            GetClient().execute(restRequest);
        }
예제 #11
0
        public void Head(string path, Action<ConnectionStatus> callback)
        {
            var restRequest = new RestRequest();
            restRequest.Method = Method.HEAD;
            restRequest.Uri = path;

            restRequest.Headers = new Dictionary<string, string>();
            restRequest.Headers.Add("Content-Type", "application/json");
            GetClient().execute(restRequest);
        }
예제 #12
0
파일: Rest.cs 프로젝트: romankor/NEST
 public RestResponse execute(RestRequest request)
 {
     send_execute(request);
     return recv_execute();
 }
예제 #13
0
파일: Rest.cs 프로젝트: romankor/NEST
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
         field = iprot.ReadFieldBegin();
         if (field.Type == TType.Stop)
         {
             break;
         }
         switch (field.ID)
         {
             case 1:
                 if (field.Type == TType.Struct)
                 {
                     request = new RestRequest();
                     request.Read(iprot);
                     __isset.request = true;
                 }
                 else
                 {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             default:
                 TProtocolUtil.Skip(iprot, field.Type);
                 break;
         }
         iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }
예제 #14
0
파일: Rest.cs 프로젝트: romankor/NEST
 public void send_execute(RestRequest request)
 {
     oprot_.WriteMessageBegin(new TMessage("execute", TMessageType.Call, seqid_));
     var args = new execute_args();
     args.Request = request;
     args.Write(oprot_);
     oprot_.WriteMessageEnd();
     oprot_.Transport.Flush();
 }