示例#1
0
        public string CreateTargetFolder(params string[] folderPath)
        {
            var fullPath = Path.Combine(
                new[] { TargetPath }.And(folderPath)
                );

            LocalFileSystem.EnsureFolderExists(fullPath);
            return(Path.Combine(folderPath));
        }
示例#2
0
        public static int Main(params string[] args)
        {
            Console.CancelKeyPress += OnCancel;
            Console.OutputEncoding  = System.Text.Encoding.UTF8;

            if (!TryParseOptionsFrom(args, out var opts))
            {
                return(-1);
            }

            if (opts.ShowedHelp ||
                opts.ShowedVersion)
            {
                return(0);
            }

            // TODO: when more than just local filesystems are handled,
            //       this should move elsewhere
            if (!Directory.Exists(opts.Target) &&
                opts.CreateTargetIfRequired)
            {
                LocalFileSystem.EnsureFolderExists(opts.Target);
            }

            using var container = CreateContainerScopeFor(opts);

            var source           = container.ResolveSourceFileSystem();
            var target           = container.ResolveTargetFileSystem();
            var archive          = container.ResolveArchiveFileSystem();
            var archiver         = container.Resolve <IArchiver>();
            var staleFileRemover = container.Resolve <IStaleFileRemover>();

            archiver.RunArchiveOperations(
                target,
                archive,
                source);

            staleFileRemover.RemoveStaleFiles(source, target);

            var synchronizer = container.Resolve <ISynchronizer>();

            synchronizer.Synchronize(
                $"Start sync: {source.BasePath} => {target.BasePath}",
                source,
                target);

            return(0);
        }
示例#3
0
        public static IContainer WithHistoryRepositoryFor(
            this IContainer container,
            IOptions opts)
        {
            if (opts.NoHistory)
            {
                return(container.WithRegistration(
                           typeof(ITargetHistoryRepository),
                           new NullTargetHistoryRepository()
                           ));
            }

            return(container.WithRegistration <ITargetHistoryRepository>(
                       typeof(ITargetHistoryRepository),
                       r =>
            {
                if (opts.NoHistory)
                {
                    return new NullTargetHistoryRepository();
                }

                var targetFolder = opts.Target;
                if (string.IsNullOrWhiteSpace(opts.HistoryDatabase))
                {
                    opts.HistoryDatabase = TargetHistoryRepository.DB_NAME;
                }
                else
                {
                    targetFolder = Path.GetDirectoryName(opts.HistoryDatabase);
                    opts.HistoryDatabase = Path.GetFileName(opts.HistoryDatabase);
                }

                LocalFileSystem.EnsureFolderExists(
                    Path.GetDirectoryName(
                        targetFolder
                        )
                    );

                return new TargetHistoryRepository(
                    r.Resolve <IMessageWriter>(),
                    targetFolder,
                    opts.HistoryDatabase
                    );
            },
                       null,
                       Reuse.Singleton
                       ));
        }
示例#4
0
        private static ArenaFile CreateFile(
            string baseFolder,
            string subFolder = null,
            string name      = null,
            byte[] data      = null)
        {
            data ??= GetRandomBytes(MIN_FILE_SIZE, MAX_FILE_SIZE);
            name ??= GetRandomString(4);
            var path             = CombinePaths(baseFolder, subFolder, name);
            var containingFolder = Path.GetDirectoryName(path);

            LocalFileSystem.EnsureFolderExists(containingFolder);

            File.WriteAllBytes(path, data);
            return(new ArenaFile(
                       path,
                       CombinePaths(subFolder, name),
                       data));
        }