예제 #1
0
파일: RiakObject.cs 프로젝트: bubbafat/Hebo
        public static RiakObject Load(Bucket bucket, string keyName, Document part)
        {
            RiakObject ro = new RiakObject
                                {
                                    Bucket = bucket, 
                                    KeyName = keyName
                                };

            ro.LoadDocumentHeaders(part);
            ro._cachedData = part.Content;

            return ro;
        }
예제 #2
0
        protected static Document Load(Stream stream, Dictionary<string,string> headers, Document parent)
        {
            // if the header indicated a content length then respect that otherwise
            // read everything left over.
            long contentLength = headers.ContainsKey(HttpWellKnownHeader.ContentLength)
                                     ? long.Parse(headers[HttpWellKnownHeader.ContentLength])
                                     : Math.Max(0, stream.Length - stream.Position);

            byte[] content = new byte[contentLength];

            Util.CopyStream(stream, content);

            Document doc = Util.IsMultiPart(headers[HttpWellKnownHeader.ContentType])
                               ? new MultiPartDocument(headers, content, parent)
                               : new Document(headers, content, parent);

            return doc;
        }
예제 #3
0
 public MultiPartDocument(Dictionary<string,string> headers, byte[] content, Document parent)
     : base(headers, content, parent)
 {
     _content = content;
     _boundary = LoadBoundary();
     _boundaryBytes = Encoding.GetEncoding(28591).GetBytes(BoundaryPrefix + _boundary);
     LoadParts();
 }
예제 #4
0
 protected Document(Dictionary<string,string> headers, byte[] content, Document parent)
 {
     Headers = headers;
     Content = content;
     Parent = parent;
 }
예제 #5
0
 protected static Document Load(Stream stream, Document parent)
 {
     Dictionary<string, string> headers = LoadHeadersFromStream(stream);
     return Load(stream, headers, parent);
 }
예제 #6
0
파일: RiakObject.cs 프로젝트: bubbafat/Hebo
        protected virtual void LoadDocumentHeaders(Document document)
        {
            MultiPartDocument mpParent = document.Parent as MultiPartDocument;
            HasSiblings = (mpParent != null && mpParent.Parts.Count > 1);

            VClock = document.GetLocalOrParentHeader(HttpWellKnownHeader.RiakVClock);

            ContentType = document.Headers[HttpWellKnownHeader.ContentType];
            ETag = document.Headers[HttpWellKnownHeader.ETag];
            if (document.Headers.ContainsKey(HttpWellKnownHeader.LastModified))
            {
                LastModified = DateTime.Parse(document.Headers[HttpWellKnownHeader.LastModified]);
            }
            ContentLength = document.Content.Length;
            Links = LinkCollection.Create(document.Headers[HttpWellKnownHeader.Link]);
        }
예제 #7
0
        private static void CheckData(Document document, string expectedString)
        {
            byte[] expected = Encoding.GetEncoding(28591).GetBytes(expectedString);
            Assert.AreEqual(expected.Length, document.Content.Length);

            for(int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], document.Content[i]);
            }
        }