Ejemplo n.º 1
0
        public Archive Open(string path)
        {
            var package              = Package.Open(path, FileMode.Open);
            var metadata             = package.GetPart(new Uri("/Metadata.xml", UriKind.Relative)).GetStream();
            var mapProvider          = new MapProvider(package);
            var metadataStreamMapper = new MetadataStreamMapper(ChecksumSize);
            var metadataRepository   = OpenRepository(package, "/Metadata.dat", metadataStreamMapper, metadataStreamMapper.BufferSize);
            var dataRepository       = OpenRepository(package, "/Data.dat", new DataStreamMapper(BlockSize), BlockSize);
            var storage              = new Storage(_hash, mapProvider, metadataRepository, dataRepository);
            var mapProcessor         = new MapProcessorFactory(storage);
            var repository           = new Repository(mapProcessor, storage.MapIds.ToList(), BlockSize);

            return(new Archive(package, repository, metadata));
        }
Ejemplo n.º 2
0
        public Archive Create(string path)
        {
            var package              = Package.Open(path, FileMode.Create);
            var metadata             = package.CreatePart(new Uri("/Metadata.xml", UriKind.Relative), System.Net.Mime.MediaTypeNames.Text.Xml).GetStream();
            var mapProvider          = new MapProvider(package);
            var metadataStreamMapper = new MetadataStreamMapper(ChecksumSize);
            var metadataRepository   = CreateRepository(package, "/Metadata.dat", metadataStreamMapper, metadataStreamMapper.BufferSize);
            var dataRepository       = CreateRepository(package, "/Data.dat", new DataStreamMapper(BlockSize), BlockSize);
            var storage              = new Storage(_hash, mapProvider, metadataRepository, dataRepository);
            var mapProcessor         = new MapProcessorFactory(storage);
            var repository           = new Repository(mapProcessor, storage.MapIds.ToList(), BlockSize);

            package.Flush();

            return(new Archive(package, repository, metadata));
        }
Ejemplo n.º 3
0
        public ManagedRepository(int blockSize, int checksumSize, string workDirectory)
        {
            var hash = new MD5Hash();

            MetadataStream = File.Open(Path.Combine(workDirectory, Guid.NewGuid() + ".metadata"), FileMode.CreateNew);
            DataStream     = File.Open(Path.Combine(workDirectory, Guid.NewGuid() + ".data"), FileMode.CreateNew);

            var mapStreamMapper = new MapStreamMapper();
            var mapProvider     = new MapProvider(mapStreamMapper, MapStreamMapper.BufferSize, workDirectory);

            MapProvider = mapProvider;

            var metadataStreamMapper = new MetadataStreamMapper(checksumSize);
            var metadataRepository   = new StreamRepository <MetadataItem>(MetadataStream, metadataStreamMapper, metadataStreamMapper.BufferSize);

            var dataStreamMapper = new DataStreamMapper(blockSize);
            var dataRepository   = new StreamRepository <byte[]>(DataStream, dataStreamMapper, blockSize);

            _storage = new Storage(hash, mapProvider, metadataRepository, dataRepository);
            var mapProcessorFactory = new MapProcessorFactory(_storage);

            _repository = new Darch.Deduplication.Repository(mapProcessorFactory, _storage.MapIds.ToList(), blockSize);
        }