Esempio n. 1
0
        static void Main(string[] args)
        {
            ExportFamily exportFamily = ExportFamily.Microsoft;
            bool showHelp = false;
            var p = new OptionSet
            {
                "Usage: GoogleDriveOfflineBackup.CLI.exe [OPTIONS]",
                "Backup the contents of your Google Drive locally.",
                {
                    "h|help",
                    "show this help message and exit",
                    v => showHelp = v != null
                },
                {
                    "e=|export=",
                    "Select the formats to export to (Microsoft, Open, Pdf)",
                    v => exportFamily = ParseExportFamily(v)
                }
            };

            List<string> extra;
            try {
                extra = p.Parse(args);
            } catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try with --help for more information");
                return;
            }

            if (showHelp || extra.Any())
            {
                p.WriteOptionDescriptions(Console.Out);
                return;
            }

            // TODO: be able to backup only a subfolder (use PathResolver for that) e.g. --root=/Photos/Summer

            var driveServiceFactory = new DriveServiceFactory();
            var driveService = driveServiceFactory.Create();
            var fileSystem = new FileSystem();
            var downloader = new Downloader(driveService, fileSystem);
            var walker = new Walker(driveService);
            var backupService = new FileBackupService(walker, downloader, fileSystem);

            Console.WriteLine("Export formats: {0}", exportFamily);
            downloader.ExportFamily = exportFamily;
            downloader.Downloading += (object sender, FileDownloadingEventArgs e) => {
                Console.WriteLine(
                    "Downloading {0} (size {1}) in {2}",
                    e.File.Name,
                    e.File.Size,
                    e.LocalPath);
            };

            backupService.Backup(".");

            Console.Write("Press enter to exit");
            Console.ReadLine();
        }
 public void SetUp()
 {
     mockDriveService = new Mock<IDriveService>(MockBehavior.Strict);
     mockFileSystem = Utils.CreateStubFileSystem(MockBehavior.Strict);
     downloader = new Downloader(mockDriveService.Object, mockFileSystem.Object);
     mockStream = new Mock<Stream>();
     mockGetRequest = new Mock<IGetRequest>(MockBehavior.Strict);
 }
 public void ShouldWorkWithFileNodeBackupService()
 {
     var fs = new DryRunFileSystem();
     var driveService = new DryRunDriveService();
     IDownloader downloader = new Downloader(driveService, fs);
     FileNodeBackupService service = new FileNodeBackupService(downloader);
     service.Backup(Utils.MockFileNode("file1", "file1.txt", "text/plain"), "/temp");
     Assert.AreEqual(1, ((DryRunFileBase)fs.File).CreateCount);
 }
        public void CountExportFiles_OneGoogleFile()
        {
            IFileNode fileNode = Utils.MockFileNode("file", "file1.gdoc", MimeTypes.GoogleDoc);
            IDriveService driveService = Mock.Of<IDriveService>();
            IFileSystem fileSystem = Mock.Of<IFileSystem>();

            // use the actual downloader
            var downloader = new Downloader(driveService, fileSystem)
            {
                ExportFamily = ExportFamily.Microsoft | ExportFamily.Pdf
            };
            backupService = new FileNodeBackupService(downloader);
            int result = backupService.CountExportFiles(fileNode);
            Assert.AreEqual(2, result);
        }
        public void CountExportFiles_OneFolderWithTwoFiles()
        {
            IFileNode fileNode = Utils.MockFileNode("folder", "folder",
                Utils.MockFileNode("file", "file1.txt", "text/plain"),
                Utils.MockFileNode("file2", "file2.txt", "text/plain")
                );
            IDriveService driveService = Mock.Of<IDriveService>();
            IFileSystem fileSystem = Mock.Of<IFileSystem>();

            // use the actual downloader
            var downloader = new Downloader(driveService, fileSystem);
            backupService = new FileNodeBackupService(downloader);
            int result = backupService.CountExportFiles(fileNode);
            Assert.AreEqual(2, result);
        }