コード例 #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();
        }
コード例 #2
0
 public void SetUp()
 {
     mockWalker = new Mock<IWalker>(MockBehavior.Strict);
     mockDownloader = new Mock<IDownloader>(MockBehavior.Strict);
     mockFileSystem = Utils.CreateStubFileSystem(MockBehavior.Strict);
     backupService = new FileBackupService(
         mockWalker.Object,
         mockDownloader.Object,
         mockFileSystem.Object);
 }