Exemplo n.º 1
0
        private StreamSignature[] BuildSignatures(IResourceManager resourceManager, out Dictionary <string, IBlob> deltaBlobs)
        {
            var streamSignatures = new List <StreamSignature>();
            Dictionary <string, IBlob> deltaBlobsToReturn = new Dictionary <string, IBlob>();

            foreach (var contentStream in this.ContentStreams)
            {
                string newContent                     = contentStream.NewContent;
                string lastKnownHostContent           = contentStream.LastKnownHostContent;
                string newContentResourceId           = contentStream.NewContentResourceId;
                string lastKnownHostContentResourceId = contentStream.LastKnownHostContentResourceId;

                ChunkingScheme chunkingScheme = contentStream.ChunkingScheme;

                BuildChunkSignaturesAndDeltaBlobDictionary(
                    newContent,
                    lastKnownHostContent,
                    newContentResourceId,
                    lastKnownHostContentResourceId,
                    resourceManager,
                    chunkingScheme,
                    deltaBlobsToReturn,
                    out ChunkSignature[] chunkSignatures);

                streamSignatures.Add(new StreamSignature(
                                         StreamId: contentStream.StreamId,
                                         ChunkingScheme: contentStream.ChunkingScheme.ToString(),
                                         ChunkSignatures: chunkSignatures));
            }

            deltaBlobs = deltaBlobsToReturn;
            return(streamSignatures.ToArray());
        }
Exemplo n.º 2
0
        public IChunkProcessor CreateInstance(ChunkingScheme chunkingScheme)
        {
            switch (chunkingScheme)
            {
            case ChunkingScheme.FullFile:
                return(new FullFileChunkProcessor());

            case ChunkingScheme.Zip:
                return(new ZipChunkProcessor());

            default:
                throw new ArgumentException($"No IChunkProcessor implementation defined for ChunkingScheme: {chunkingScheme}");
            }
        }
        private ContentFilter[] BuildContentFilters(IResourceManager resourceManager)
        {
            var contentFilters = new List <ContentFilter>();

            foreach (var contentFilter in this.ContentFilters)
            {
                ChunkingScheme chunkingScheme = contentFilter.ChunkingScheme;
                IReadOnlyDictionary <string, IBlob> alreadyExistingContentBlobs = new Dictionary <string, IBlob>();

                if (chunkingScheme == ChunkingScheme.FullFile)
                {
                    string         alreadyExistingContent       = contentFilter.AlreadyExistingContent;
                    Stream         alreadyExistingContentStream = new MemoryStream(Encoding.UTF8.GetBytes(alreadyExistingContent));
                    IBlobAllocator blobAllocator = new BlobAllocator();

                    ChunkProcessorFactory.Instance.CreateInstance(chunkingScheme).StreamToBlobs(
                        alreadyExistingContentStream,
                        blobAllocator,
                        out string[] _,
                        out alreadyExistingContentBlobs
                        );
                }
                else if (chunkingScheme == ChunkingScheme.Zip)
                {
                    string alreadyExistingContentResourceId = contentFilter.AlreadyExistingContentResourceId;
                    ChunkProcessorFactory.Instance.CreateInstance(chunkingScheme).StreamToBlobs(
                        resourceManager,
                        alreadyExistingContentResourceId,
                        out string[] _,
                        out alreadyExistingContentBlobs
                        );
                }


                contentFilters.Add(new ContentFilter(
                                       ChunkingScheme: contentFilter.ChunkingScheme.ToString(),
                                       StreamId: contentFilter.StreamId,
                                       ChunksToReturn: contentFilter.ChunksToReturn.ToString(),
                                       AlreadyKnownChunks: alreadyExistingContentBlobs.Keys.ToArray()
                                       ));
            }

            return(contentFilters.ToArray());
        }
        private void ValidateAndParseParameters(
            string ChunkingSchemeInString,
            string ChunksToReturnInString,
            string StreamId,
            string AlreadyExistingContent,
            string AlreadyExistingContentResourceId,
            out ChunkingScheme OutputParsedChunkingScheme,
            out ChunksToReturn OutputParsedChunksToReturn)
        {
            if (String.IsNullOrWhiteSpace(ChunkingSchemeInString))
            {
                throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(ChunkingSchemeInString)}' parameter is invalid.");
            }

            if (!Enum.TryParse(ChunkingSchemeInString, true, out ChunkingScheme ParsedChunkingScheme))
            {
                throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(ChunkingSchemeInString)}' parameter can not be parsed to enum.");
            }

            if (String.IsNullOrWhiteSpace(ChunksToReturnInString))
            {
                throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(ChunksToReturnInString)}' parameter is invalid.");
            }

            if (!Enum.TryParse(ChunksToReturnInString, true, out ChunksToReturn ParsedChunksToReturn))
            {
                throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(ChunksToReturnInString)}' parameter is invalid.");
            }

            if (String.IsNullOrWhiteSpace(StreamId))
            {
                throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(StreamId)}' parameter is invalid.");
            }

            OutputParsedChunkingScheme = ParsedChunkingScheme;
            OutputParsedChunksToReturn = ParsedChunksToReturn;

            if (ParsedChunkingScheme == ChunkingScheme.FullFile)
            {
                if (AlreadyExistingContent == null)
                {
                    throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(AlreadyExistingContent)}' parameter is invalid.");
                }

                if (AlreadyExistingContentResourceId != null)
                {
                    throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(AlreadyExistingContentResourceId)}' parameter shouldn't be populated.");
                }
            }

            if (ParsedChunkingScheme == ChunkingScheme.Zip)
            {
                if (AlreadyExistingContentResourceId == null)
                {
                    throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(AlreadyExistingContentResourceId)}' parameter is invalid.");
                }

                if (AlreadyExistingContent != null)
                {
                    throw new ArgumentException($"GetChunkedFileContentFilter '{nameof(AlreadyExistingContent)}' parameter shouldn't be populated.");
                }
            }
        }
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;
        }
Exemplo n.º 6
0
        private void ValidateAndParseParameters(
            string ChunkingSchemeInString,
            string StreamId,
            string NewContent,
            string LastKnownHostContent,
            string NewContentResourceId,
            string LastKnownHostContentResourceId,
            out ChunkingScheme OutputParsedChunkingScheme)
        {
            if (String.IsNullOrWhiteSpace(ChunkingSchemeInString))
            {
                throw new ArgumentException($"PutChunkedFileStream '${nameof(ChunkingSchemeInString)}' parameter is invalid.");
            }

            if (!Enum.TryParse(ChunkingSchemeInString, true, out ChunkingScheme ParsedChunkingScheme))
            {
                throw new ArgumentException($"PutChunkedFileStream '{nameof(ChunkingSchemeInString)}' parameter can not be parsed to enum.");
            }

            if (String.IsNullOrWhiteSpace(StreamId))
            {
                throw new ArgumentException($"PutChunkedFileStream '{nameof(StreamId)}' parameter is invalid.");
            }

            OutputParsedChunkingScheme = ParsedChunkingScheme;

            if (ParsedChunkingScheme == ChunkingScheme.FullFile)
            {
                if (NewContent == null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(NewContent)}' parameter is invalid.");
                }

                if (LastKnownHostContent == null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(LastKnownHostContent)}' parameter is invalid.");
                }

                if (NewContentResourceId != null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(NewContentResourceId)}' parameter shouldn't be populated.");
                }

                if (LastKnownHostContentResourceId != null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(LastKnownHostContentResourceId)}' parameter shouldn't be populated.");
                }
            }

            if (ParsedChunkingScheme == ChunkingScheme.Zip)
            {
                if (NewContentResourceId == null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(NewContentResourceId)}' parameter is invalid.");
                }

                if (LastKnownHostContentResourceId == null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(LastKnownHostContentResourceId)}' parameter is invalid.");
                }

                if (NewContent != null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(NewContent)}' parameter shouldn't be populated.");
                }

                if (LastKnownHostContent != null)
                {
                    throw new ArgumentException($"PutChunkedFileStream '{nameof(LastKnownHostContent)}' parameter shouldn't be populated.");
                }
            }
        }