Пример #1
0
        protected GlacierGatewayTestBase(bool testMode)
        {
            _logger          = Substitute.For <ILogger <GlacierGateway> >();
            _glacier         = Substitute.For <IAmazonGlacier>();
            _updater         = Substitute.For <IConsolePercentUpdater>();
            _archiveProvider = Substitute.For <IArchiveProvider>();

            // We need to initialize the MemoryStream with some data so that
            // the sanity checks don't fail
            var bytes = Enumerable.Range(0, 100).Select(a => (byte)a).ToArray();

            _archiveProvider.GetFileStream(Arg.Any <string>(), Arg.Any <string>()).Returns(new MemoryStream(bytes));

            _sut = new GlacierGateway(_glacier, _logger, _updater, _archiveProvider, null, testMode);

            _glacier.ListVaultsAsync(Arg.Any <ListVaultsRequest>())
            .Returns(new ListVaultsResponse
            {
                VaultList = new List <DescribeVaultOutput>
                {
                    new DescribeVaultOutput
                    {
                        VaultName = PreexistingVaultName
                    }
                }
            });
            _glacier.CreateVaultAsync(Arg.Any <CreateVaultRequest>())
            .Returns(new CreateVaultResponse
            {
                HttpStatusCode = HttpStatusCode.OK
            });
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var parameters = ExecutionParameters.GetParametersFromArgs(args);

            if (parameters == null)
            {
                Log.Fatal("No config file could be found in the default location (my documents) and none was specified in the parameters.");
                Environment.Exit(0);
            }

            var errors = parameters.GetValidationErrors();

            if (errors.Any())
            {
                Log.Fatal("Configuration/parameter errors occurredt:");
                foreach (var e in errors)
                {
                    Log.Fatal(e);
                }
                Environment.Exit(0);
            }

            Log.InfoFormat("Glacier valut: {0}", parameters.Glacier.VaultName);
            var glacierGateway = new GlacierGateway(parameters.Glacier);

            Log.InfoFormat("Archiving pictures from: {0}", parameters.Avalanche.CatalongFilePath);
            var lightroomRepository = new LightroomRepository(parameters.Avalanche.CatalongFilePath);

            Log.InfoFormat("Collection name: {0}", parameters.Avalanche.AdobeCollectionName);
            var allPictures = lightroomRepository.GetAllPictures(parameters.Avalanche.AdobeCollectionName);
            var toUpload    = allPictures.Where(a => a.LibraryCount > 0 && string.IsNullOrWhiteSpace(a.CopyName)).ToList();

            Log.InfoFormat("Selected {0} pictures out from {1}", toUpload.Count, allPictures.Count);
            using (var insomniac = new Insomniac())
            {
                var uploader = new GlacierUploader(lightroomRepository, glacierGateway, parameters.DryRun);
                uploader.RunUploader(toUpload);
            }

            var missing = allPictures.Where(p => !File.Exists(Path.Combine(p.AbsolutePath, p.FileName))).ToList();

            Log.InfoFormat("Downloading {0} missing files...", missing.Count);

            Log.Info("Done");
        }
Пример #3
0
        public static void Main(string[] args)
        {
            var parameters = ExecutionParameters.GetParametersFromArgs(args);

            if (parameters == null)
            {
                _log.Fatal("No config file could be found in the default location (my documents) and none was specified in the parameters.");
                Environment.Exit(0);
            }

            var errors = parameters.GetValidationErrors();

            if (errors.Any())
            {
                _log.Fatal("Configuration/parameter errors occurredt:");
                foreach (var e in errors)
                {
                    _log.Fatal(e);
                }
                Environment.Exit(0);
            }

            using (var insomniac = new Insomniac())
            {
                var lightroomRepo = new LightroomRepository(parameters.Avalanche.CatalongFilePath);
                var avalancheRepo = new AvalancheRepository(parameters.Avalanche.AvalancheFilePath);
                var gateway       = new GlacierGateway(parameters.Glacier);

                var catalogId        = lightroomRepo.GetUniqueId();
                var allPictures      = lightroomRepo.GetAllPictures();
                var filteredPictures = allPictures.Where(a => a.LibraryCount > 0 && !avalancheRepo.FileIsArchived(a.FileId)).ToList();

                _log.InfoFormat("Backing up {0} images", filteredPictures.Count);

                var index = 0;
                foreach (var f in filteredPictures)
                {
                    _log.InfoFormat("Archiving {0}/{1}: {2}", ++index, filteredPictures.Count, Path.Combine(f.AbsolutePath, f.FileName));

                    // Try three times
                    ArchivedPictureModel archive = null;
                    for (var i = 0; i < 3; ++i)
                    {
                        try
                        {
                            archive = gateway.SaveImage(f, parameters.Glacier.VaultName);
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Error!!! {0}", ex);
                            continue;
                        }
                        break;
                    }

                    if (archive == null)
                    {
                        continue;
                    }

                    avalancheRepo.MarkFileAsArchived(archive, parameters.Glacier.VaultName, parameters.Glacier.Region, parameters.Avalanche.CatalongFilePath, catalogId.ToString());
                }

                _log.Info("Done");
            }
        }
Пример #4
0
 public GlacierUploader(LightroomRepository lightroomRepository, GlacierGateway glacierGateway, bool dryRun = false)
 {
     _lightroomRepository = lightroomRepository;
     _glacierGateway      = glacierGateway;
     _dryRun = dryRun;
 }