Example #1
0
        internal HttpWebRequest WR(CouchUrl c)
        {
            var req = WebRequest.Create(c.Uri);

            req = c.RunFilters(req);

            return((HttpWebRequest)req);
        }
Example #2
0
        public async Task <CouchResponse> Get(CouchUrl couchUrl)
        {
            try
            {
                var req = WR(couchUrl);
                req.Method = "GET";
                var resp = await req.GetResponseAsync();

                return(this.MakeResponse(couchUrl.couchRepo, resp));
            }
            catch (WebException ex)
            {
                ex.RethrowBunkException();
                throw;
            }
        }
Example #3
0
        private CouchRepo(ConnectionConfig config)
        {
            this.config   = config;
            this.couchUrl = CouchUrl.Create(this, null, null, null);

            //By default set application/json
            this.couchUrl = this.couchUrl.Filter((req) =>
            {
                req.ContentType = "application/json";
                return(req);
            });

            foreach (var f in config.DefaultFilters)
            {
                this.couchUrl = this.couchUrl.Filter(f);
            }
        }
Example #4
0
        public async Task <CouchResponse> Put(CouchUrl couchUrl, Action <System.IO.Stream> writeData)
        {
            try
            {
                var req = WR(couchUrl);
                req.Method = "PUT";
                if (writeData != null)
                {
                    writeData(req.GetRequestStream());
                }
                var resp = await req.GetResponseAsync();

                return(this.MakeResponse(couchUrl.couchRepo, resp));
            }
            catch (WebException ex)
            {
                ex.RethrowBunkException();
                throw;
            }
        }
Example #5
0
File: DB.cs Project: dedels/Bunk
        public async Task <T> Get <T>(CouchUrl url)
        {
            var response = await couchRepo.HttpClient.Get(url);

            return(couchRepo.Deserialize <T>(response));
        }
Example #6
0
File: DB.cs Project: dedels/Bunk
        internal async Task <T> Post <T>(CouchUrl couchUrl, Action <System.IO.Stream> action)
        {
            var response = await couchRepo.HttpClient.Post(couchUrl, action);

            return(couchRepo.Deserialize <T>(response));
        }
Example #7
0
        public Continuous(DB db,
                          int?timeout            = null,
                          int?heartbeat          = null,
                          bool?conflicts         = null,
                          bool?descending        = null,
                          string filter          = null,
                          bool?include_docs      = null,
                          bool?attachments       = null,
                          bool?att_encoding_info = null,
                          int?last_event_id      = null,
                          int?limit    = null,
                          string since = null,
                          string style = null,
                          string view  = null)
        {
            this.db       = db;
            this.couchUrl = this.db.couchUrl.Add("_changes").QueryString("feed", "continuous");
            this.cancellationTokenSource = new System.Threading.CancellationTokenSource();
            this.couchUrl = this.couchUrl.Filter((wr) => //Default to 30 second timeout
            {
                var tcp_timeout = (timeout.HasValue ? timeout.Value : 60000) / 2;
                ((HttpWebRequest)wr).ServicePoint.SetTcpKeepAlive(true, tcp_timeout, tcp_timeout);
                return(wr);
            });


            if (timeout.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("timeout", timeout.Value);
            }
            if (heartbeat.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("heartbeat", heartbeat.Value);
            }

            if (conflicts.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("conflicts", conflicts.Value);
            }

            if (descending.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("descending", descending.Value);
            }
            if (filter != null)
            {
                this.couchUrl = this.couchUrl.QueryString("filter", filter);
            }
            if (include_docs.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("include_docs", include_docs.Value);
            }
            if (attachments.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("attachments", attachments.Value);
            }
            if (att_encoding_info.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("att_encoding_info", att_encoding_info.Value);
            }
            if (last_event_id.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("last-event-id", last_event_id.Value);
            }
            if (limit.HasValue)
            {
                this.couchUrl = this.couchUrl.QueryString("limit", limit.Value);
            }
            if (since != null)
            {
                this.couchUrl = this.couchUrl.QueryString("since", since);
            }
            if (style != null)
            {
                this.couchUrl = this.couchUrl.QueryString("style", style);
            }
            if (view != null)
            {
                this.couchUrl = this.couchUrl.QueryString("view", view);
            }
        }
Example #8
0
 public Task <CouchResponse> Put(CouchUrl couchUrl)
 {
     return(Put(couchUrl, null));
 }
Example #9
0
 public Task <CouchResponse> Delete(CouchUrl couchUrl)
 {
     return(Delete(couchUrl, null));
 }