예제 #1
0
파일: HttpAction.cs 프로젝트: h3mpti/Relax
        public virtual string GetResponse( CouchUri uri, string method, string body )
        {
            var request = WebRequest.Create( uri.ToString() );
            request.Method = method;
            request.Timeout = configuration.TimeOut;
            //request.PreAuthenticate = configuration.Preauthorize;

            if ( !string.IsNullOrEmpty( body ) )
            {
                var bytes = Encoding.UTF8.GetBytes( body );
                request.ContentType = "application/json; charset=utf-8";
                request.ContentLength = bytes.Length;

                var writer = request.GetRequestStream();
                writer.Write( bytes, 0, bytes.Length );
                writer.Close();
            }

            var result = "";
            var response = request.GetResponse();

            using( var reader = new StreamReader( response.GetResponseStream() ) )
            {
                result = reader.ReadToEnd();
                response.Close();
            }

            return result;
        }
예제 #2
0
 public static ReplicationCommand Once(CouchUri source, CouchUri target)
 {
     return(new ReplicationCommand
     {
         SourceUri = source.ToString(),
         TargetUri = target.ToString(),
         CreateTarget = true
     });
 }
예제 #3
0
 public static ReplicationCommand Once(CouchUri source, CouchUri target)
 {
     return new ReplicationCommand()
                {
                    SourceUri = source.ToString(),
                    TargetUri = target.ToString(),
                    CreateTarget = true
                };
 }
예제 #4
0
        public virtual void GetContinuousResponse(CouchUri uri, int since, Action<ChangeRecord> callback)
        {
            var baseUri = uri.Clone() as CouchUri;
            uri = uri.Changes(Feed.Continuous, since);
            var request = WebRequest.Create(uri.ToString());
            request.Method = "GET";
            request.Timeout = int.MaxValue;
            request.PreAuthenticate = _configuration.Preauthorize;
            var result = "";
            _pollForChanges = true;

            try
            {
                var response = request.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    while (_pollForChanges)
                    {
                        result = reader.ReadLine();
                        if (!string.IsNullOrEmpty(result))
                        {
                            var changeUri = baseUri.Clone() as CouchUri;
                            var change = result.FromJson<ChangeRecord>();
                            change.Document = GetResponse(changeUri.Key(change.Id), "GET", "");
                            callback.BeginInvoke(change, null, null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                "An exception occurred while receiving the change stream from {0}. \r\n\t {1}"
                    .ToError<IDocumentRepository>(uri.ToString(), ex);
                throw;
            }
            finally
            {
                callback = null;
            }
        }
예제 #5
0
파일: HttpAction.cs 프로젝트: h3mpti/Relax
 public virtual string SaveAttachment( CouchUri uri, string type, byte[] content )
 {
     using( var client = new WebClient() )
     {
         client.Headers.Add( "Content-Type", type );
         var bytes = client.UploadData( uri.ToString(), "PUT", content );
         return Encoding.UTF8.GetString( bytes );
     }
 }
예제 #6
0
파일: HttpAction.cs 프로젝트: h3mpti/Relax
        public virtual Tuple<string, byte[]> GetAttachment( CouchUri uri )
        {
            var request = WebRequest.Create( uri.ToString() );
            request.Method = "GET";
            request.Timeout = configuration.TimeOut;

            var response = request.GetResponse();
            int bytesRead = 0;
            var memoryStream = new MemoryStream();

            using( var stream = response.GetResponseStream() )
            {
                stream.CopyTo( memoryStream );
            }
            memoryStream.Position = 0;
            var result =
                Tuple.Create(
                    response.ContentType,
                    memoryStream.ToArray()
                    );

            response.Close();

            return result;
        }
 protected static CouchUri GetMockUri( CouchUri actualUri )
 {
     return Moq.It.Is<CouchUri>(u => u.ToString().Equals(actualUri.ToString()));
 }
예제 #8
0
 protected static CouchUri GetMockUri(CouchUri actualUri)
 {
     return(Moq.It.Is <CouchUri>(u => u.ToString().Equals(actualUri.ToString())));
 }