Exemplo n.º 1
0
 public async Task WriteChunkAsync(ChunkSignature signature)
 {
     signaturebw.Write(signature.Length);
     signaturebw.Write(signature.RollingChecksum);
     await signaturebw.BaseStream.WriteAsync(signature.Hash, 0, signature.Hash.Length).ConfigureAwait(false);
 }
Exemplo n.º 2
0
 public void WriteChunk(ChunkSignature signature)
 {
     signaturebw.Write(signature.Length);
     signaturebw.Write(signature.RollingChecksum);
     signaturebw.Write(signature.Hash);
 }
        public void SerializePutChunkedFileRequestMessage()
        {
            PutChunkedFileRequestMessage request = new PutChunkedFileRequestMessage();
            ContentProperty contentProperty1     = new ContentProperty();

            contentProperty1.Name      = "Prop1";
            contentProperty1.Value     = "TestValue";
            contentProperty1.Retention = ContentPropertyRetention.KeepOnContentChange.ToString();

            ContentProperty contentProperty2 = new ContentProperty();

            contentProperty2.Name      = "last ocs save";
            contentProperty2.Value     = "TestValue2";
            contentProperty2.Retention = ContentPropertyRetention.DeleteOnContentChange.ToString();

            request.ContentProperties = new ContentProperty[] { contentProperty1, contentProperty2 };

            ChunkSignature chunk1 = new ChunkSignature();

            chunk1.ChunkId = "Chunk1";
            chunk1.Length  = 334;

            ChunkSignature chunk2 = new ChunkSignature();

            chunk2.ChunkId = "Chunk2";
            chunk2.Length  = 111334;

            ChunkSignature chunk3 = new ChunkSignature();

            chunk3.ChunkId = "Chunk3";
            chunk3.Length  = 4;

            ChunkSignature chunk4 = new ChunkSignature();

            chunk4.ChunkId = "Chunk4";
            chunk4.Length  = 554;


            StreamSignature signature = new StreamSignature();

            signature.ChunkingScheme  = ChunkingScheme.FullFile.ToString();
            signature.StreamId        = "AlternateStream1";
            signature.ChunkSignatures = new ChunkSignature[4] {
                chunk1, chunk2, chunk3, chunk4
            };
            StreamSignature[] streamSignatures = new StreamSignature[1] {
                signature
            };

            request.Signatures = streamSignatures;

            request.UploadSessionTokenToCommit = "3DFCF2D5 - DABA - 4BDD - 88EC - 69823EDCF585";

            using (MemoryStream ms = new MemoryStream())
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(PutChunkedFileRequestMessage));
                ser.WriteObject(ms, request);
                ms.Seek(0, SeekOrigin.Begin);
                PutChunkedFileRequestMessage requestNew = (PutChunkedFileRequestMessage)ser.ReadObject(ms);

                // Assert
                Assert.AreEqual(request.ToString(), requestNew.ToString());
            }
        }
        public void SerializeGetChunkedFileResponseMessage()
        {
            GetChunkedFileResponseMessage response = new GetChunkedFileResponseMessage();
            ContentProperty contentProperty1       = new ContentProperty();

            contentProperty1.Name      = "Prop1";
            contentProperty1.Value     = "TestValue";
            contentProperty1.Retention = ContentPropertyRetention.KeepOnContentChange.ToString();

            ContentProperty contentProperty2 = new ContentProperty();

            contentProperty2.Name      = "last ocs save";
            contentProperty2.Value     = "TestValue2";
            contentProperty2.Retention = ContentPropertyRetention.DeleteOnContentChange.ToString();

            response.ContentProperties = new ContentProperty[] { contentProperty1, contentProperty2 };

            ChunkSignature chunk1 = new ChunkSignature();

            chunk1.ChunkId = "Chunk1";
            chunk1.Length  = 334;

            ChunkSignature chunk2 = new ChunkSignature();

            chunk2.ChunkId = "Chunk2";
            chunk2.Length  = 111334;

            ChunkSignature chunk3 = new ChunkSignature();

            chunk3.ChunkId = "Chunk3";
            chunk3.Length  = 4;

            ChunkSignature chunk4 = new ChunkSignature();

            chunk4.ChunkId = "Chunk4";
            chunk4.Length  = Int64.MaxValue;


            StreamSignature signature = new StreamSignature();

            signature.ChunkingScheme  = ChunkingScheme.FullFile.ToString();
            signature.StreamId        = "AlternateStream1";
            signature.ChunkSignatures = new ChunkSignature[4] {
                chunk1, chunk2, chunk3, chunk4
            };
            StreamSignature[] streamSignatures = new StreamSignature[1] {
                signature
            };

            response.Signatures = streamSignatures;

            using (MemoryStream ms = new MemoryStream())
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(GetChunkedFileResponseMessage));
                ser.WriteObject(ms, response);
                ms.Seek(0, SeekOrigin.Begin);
                GetChunkedFileResponseMessage responseNew = (GetChunkedFileResponseMessage)ser.ReadObject(ms);

                // Assert
                Assert.AreEqual(response.ToString(), responseNew.ToString());
            }
        }
Exemplo n.º 5
0
        private void BuildChunkSignaturesAndDeltaBlobDictionary(
            string newContent,
            string lastKnownHostContent,
            string newContentResourceId,
            string lastKnownHostContentResourceId,
            IResourceManager resourceManager,
            ChunkingScheme chunkingScheme,
            Dictionary <string, IBlob> deltaBlobs,
            out ChunkSignature[] chunkSignatures)
        {
            string[] newContentBlobIds = new string[0];
            IReadOnlyDictionary <string, IBlob> newContentBlobs           = new Dictionary <string, IBlob>();
            IReadOnlyDictionary <string, IBlob> lastKnownHostContentBlobs = new Dictionary <string, IBlob>();

            if (chunkingScheme == ChunkingScheme.FullFile)
            {
                Stream newContentStream           = new MemoryStream(Encoding.UTF8.GetBytes(newContent));
                Stream lastKnownHostContentStream = new MemoryStream(Encoding.UTF8.GetBytes(lastKnownHostContent));

                IChunkProcessor chunkProcessor = ChunkProcessorFactory.Instance.CreateInstance(chunkingScheme);

                chunkProcessor.StreamToBlobs(
                    newContentStream,
                    new BlobAllocator(),
                    out newContentBlobIds,
                    out newContentBlobs
                    );
                chunkProcessor.StreamToBlobs(
                    lastKnownHostContentStream,
                    new BlobAllocator(),
                    out _,
                    out lastKnownHostContentBlobs
                    );
            }
            else if (chunkingScheme == ChunkingScheme.Zip)
            {
                IChunkProcessor chunkProcessor = ChunkProcessorFactory.Instance.CreateInstance(chunkingScheme);

                chunkProcessor.StreamToBlobs(
                    resourceManager,
                    newContentResourceId,
                    out newContentBlobIds,
                    out newContentBlobs
                    );
                chunkProcessor.StreamToBlobs(
                    resourceManager,
                    lastKnownHostContentResourceId,
                    out _,
                    out lastKnownHostContentBlobs
                    );
            }



            ChunkSignature[] chunkSignaturesToReturn = new ChunkSignature[newContentBlobIds.Length];
            for (int i = 0; i < newContentBlobIds.Length; i++)
            {
                string newContentBlobId = newContentBlobIds[i];
                IBlob  newContentBlob   = newContentBlobs[newContentBlobId];
                chunkSignaturesToReturn[i] = new ChunkSignature(ChunkId: newContentBlobId, Length: newContentBlob.Length);
                if (!lastKnownHostContentBlobs.ContainsKey(newContentBlobId) && !deltaBlobs.ContainsKey(newContentBlobId))
                {
                    deltaBlobs.Add(newContentBlobId, newContentBlob);
                }
            }

            chunkSignatures = chunkSignaturesToReturn;
        }