Exemple #1
0
        public static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("NHibernate.Debug.config.xml"));
            string fileServiceHostAddr = null;
            var p = new OptionSet() {
                { "a|addr=", v => { fileServiceHostAddr = v;
                    logger.InfoFormat("File service remote address: {0}", v); }}
            };
            List<string> extra = p.Parse(args);

            if (string.IsNullOrEmpty(fileServiceHostAddr)) {
                fileServiceHostAddr = "localhost";
            }

            //var proxy = new WcfProxy<IFileService>(
            //        new WebHttpBinding(),
            //        new EndpointAddress(string.Format(
            //            "http://{0}:18081/FileService/",
            //            fileServiceHostAddr)));
            //proxy.Endpoint.Behaviors.Add(new WebHttpBehavior());
            //ChannelFactory<IFileService> cf = new ChannelFactory<IFileService>(new WebHttpBinding(), string.Format(
            //            "http://{0}:18081/FileService/",
            //            fileServiceHostAddr));
            //cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
            //var proxy = cf.CreateChannel();

            var proxy = new ManualFileServiceClient(string.Format(
                        "http://{0}:18081/FileService/", fileServiceHostAddr));

            using (var fs = new FuseDedupFilesystem(proxy)) {
                string[] unhandled = fs.ParseFuseArguments(args);
                foreach (string key in fs.FuseOptions.Keys) {
                    logger.InfoFormat("FUSE Option: {0}={1}", key, fs.FuseOptions[key]);
                }
                string mountingPoint = unhandled[unhandled.Length - 1];
                logger.InfoFormat("Mounting Point: {0}", mountingPoint);
                fs.MountPoint = mountingPoint;
                fs.EnableFuseDebugOutput = true;
                fs.Start();
            }
        }
Exemple #2
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();
        }