示例#1
0
        public void Copy(
            IRepository <Uri> contentRepository,
            IRepository <int> snapshotRepository)
        {
            contentRepository.EnsureNotNull(nameof(contentRepository));
            snapshotRepository.EnsureNotNull(nameof(snapshotRepository));

            var contentUrisToCopy = _uriRepository.ListKeys()
                                    .Except(contentRepository.ListKeys())
                                    .ToArray();

            foreach (var contentUri in contentUrisToCopy)
            {
                var content = _uriRepository.RetrieveValue(contentUri);

                if (!Id.ContentUriValid(contentUri, content))
                {
                    throw new ChunkyardException(
                              $"Invalid content: {contentUri}");
                }

                contentRepository.StoreValue(contentUri, content);

                _probe.CopiedContent(contentUri);
            }

            var snapshotIdsToCopy = _intRepository.ListKeys()
                                    .Except(snapshotRepository.ListKeys())
                                    .ToArray();

            foreach (var snapshotId in snapshotIdsToCopy)
            {
                // We convert a SnapshotReference from/to bytes to check if
                // these bytes are valid
                snapshotRepository.StoreValue(
                    snapshotId,
                    DataConvert.ObjectToBytes(
                        GetSnapshotReference(snapshotId)));

                _probe.CopiedSnapshot(snapshotId);
            }
        }