예제 #1
0
 public static void TestRegisterFilePart(string db, string file, string offset, string count)
 {
     logger.DebugFormat("DB file path: {0}", db);
     var dbs = new ChunkDbService(db, false);
     var dedup = new DeduplicationService(dbs);
     dedup.RegisterFilePart(file, long.Parse(offset), int.Parse(count));
 }
예제 #2
0
 public FileService(DistributedDiskManager dDiskManager,
     DeduplicationService dedupService,
     string baseDir)
 {
     _dDiskManager = dDiskManager;
     _baseDir = baseDir;
     _dedupService = dedupService;
 }
예제 #3
0
 public static void TestGetDedupFileParts1(string db, string path, string offset, string count)
 {
     logger.DebugFormat("DB file path: {0}", db);
     var dbs = new ChunkDbService(db, false);
     var ds = new DeduplicationService(dbs);
     IList<Tuple<string, long, int>> result =
         ds.GetDedupFileSourceLocations(path, long.Parse(offset), int.Parse(count));
     result.ToList().ForEach(x => logger.Debug(x));
 }
예제 #4
0
 public static void TestAddFileToDownload(string chunkDb, string datafile,
     string chunkMap, string torrentFile)
 {
     logger.DebugFormat("DB file path: {0}", chunkDb);
     var dbs = new ChunkDbService(chunkDb, false);
     var ds = new DeduplicationService(dbs);
     var torrentBytes = File.ReadAllBytes(torrentFile);
     var torrent = Torrent.Load(torrentBytes);
     ds.AddFileToDownload(datafile, File.ReadAllBytes(chunkMap),
         torrentBytes, torrent.Files[0].Length);
 }
예제 #5
0
        public static void TestRead(string db, string file, string length, string offset, string count, string realfile)
        {
            logger.DebugFormat("DB file path: {0}", db);
            var dbs = new ChunkDbService(db, false);
            var ds = new DeduplicationService(dbs);
            var writer = new DedupDiskWriter(ds);
            var c = int.Parse(count);
            var buffer = new byte[c];
            var f = new TorrentFile(file, long.Parse(length));
            var o = long.Parse(offset);
            int actualRead = writer.Read(f, o, buffer, 0, c);

            byte[] bufferToCompare = new byte[c];
            using (var rf = File.OpenRead(realfile)) {
                rf.Seek(o, SeekOrigin.Begin);
                rf.Read(bufferToCompare, 0, bufferToCompare.Length);
            }

            Assert.IsTrue(buffer.SequenceEqual(bufferToCompare));
        }
 public static void TestDownloadFile(string db, string torrentPath, string savePath)
 {
     //System.Diagnostics.Debugger.Launch();
     var dbs = new ChunkDbService(db, false);
     var ds = new DeduplicationService(dbs);
     var writer = new DedupDiskWriter(ds);
     var engineSettings = new EngineSettings();
     engineSettings.PreferEncryption = false;
     engineSettings.AllowedEncryption = EncryptionTypes.All;
     int port = 33123;
     var ip = NetUtil.GetLocalIPByInterface("Local Area Connection");
     engineSettings.ReportedAddress = new IPEndPoint(ip, port);
     var engine = new ClientEngine(engineSettings, new DedupDiskWriter(ds));
     var vd = new VirtualDiskDownloadService(engine, new FileInfoTable<TorrentManager>());
     var torrent = Torrent.Load(torrentPath);
     logger.DebugFormat("Loaded torrent file: {0}, piece length: {1}.",
         torrent.Name, torrent.PieceLength);
     var filePath = Path.Combine(savePath, torrent.Name);
     vd.StartDownloadingFile(torrent, savePath, dbs.GetManagedFile(filePath).ChunkMap.LastPieceInProfile);
     Console.Read();
 }
예제 #7
0
        public static void TestReadFile(string db, string torrentPath, string baseDir, string filePath, string origianlFile)
        {
            //System.Diagnostics.Debugger.Launch();
            var kernel = new StandardKernel();
            kernel.Load(new ServiceNinjectModule());

            kernel.Bind<FileInfoTable<TorrentManager>>().ToSelf().InSingletonScope();

            var dbs = new ChunkDbService(db, false);
            var ds = new DeduplicationService(dbs);
            kernel.Bind<DeduplicationService>().ToConstant(ds).InSingletonScope();

            var writer = new DedupDiskWriter(ds);

            var engineSettings = new EngineSettings();
            engineSettings.PreferEncryption = false;
            engineSettings.AllowedEncryption = EncryptionTypes.All;
            int port = 33123;
            var ip = NetUtil.GetLocalIPByInterface("Local Area Connection");
            engineSettings.ReportedAddress = new IPEndPoint(ip, port);
            var engine = new ClientEngine(engineSettings, new DedupDiskWriter(ds));

            kernel.Bind<DiskManager>().ToConstant(engine.DiskManager).InSingletonScope();
            kernel.Bind<ClientEngine>().ToConstant(engine).InSingletonScope();

            kernel.Bind<DistributedDiskManager>().ToSelf();
            kernel.Bind<FileService>().ToSelf().WithConstructorArgument("baseDir", baseDir);

            kernel.Bind<VirtualDiskDownloadService>().ToSelf();
            var vd = kernel.Get<VirtualDiskDownloadService>();

            var torrent = Torrent.Load(torrentPath);
            logger.DebugFormat("Loaded torrent file: {0}, piece length: {1}.",
                torrent.Name, torrent.PieceLength);
            vd.StartDownloadingFile(torrent, baseDir, -1);

            KernelContainer.Kernel = kernel;

            var m = new HurricaneServiceManager();
            m.Start();

            var url = string.Format("http://{0}:18081/FileService/", ip.ToString());
            logger.DebugFormat("Contacting service at {0}", url);
            var client = new ManualFileServiceClient(url);
            string tstmsg = "tstmsg";
            var resp = client.Echo(tstmsg);
            Assert.AreEqual(resp, tstmsg);

            byte[] resultData = null;

            try {
                var pathStatus = client.GetPathStatus(filePath);
                logger.DebugFormat("File size: {0}", pathStatus.FileSize);
            } catch (Exception ex) {
                logger.Error(ex);
            }

            try {
                // can only read 49352.
                resultData = client.Read(filePath, 0, 49253);
            } catch (Exception ex) {
                logger.Error(ex);
            }

            var actualData = IOUtil.Read(origianlFile, 0, 49252);

            try {
                Assert.IsTrue(actualData.SequenceEqual(resultData),
                    "File part should match.");
                logger.Debug("Read succeeded.");
            } catch (Exception ex) {
                logger.Error(ex);
            }

            Console.Read();
        }