Beispiel #1
0
        public async Task Process(BatchConfig batch, BatchOption option)
        {
            foreach (var command in batch.Commands)
            {
                if (command is TargetCommand targetCommand)
                {
                    if (option == BatchOption.ApplyCurrentState)
                    {
                        await ITargetProcessor.ApplyCurrentStateAsync(targetCommand);
                    }

                    else if (option == BatchOption.ResetState)
                    {
                        await ITargetProcessor.ResetState(targetCommand);
                    }

                    else
                    {
                        await ITargetProcessor.Process(targetCommand);
                    }
                }

                else if (command is OkCommand)
                {
                    await IOkProcessor.Process(command as OkCommand);
                }
            }
        }
Beispiel #2
0
        public override async Task Process(TargetCommand command)
        {
            foreach (var ftp in command.Target.Ftp)
            {
                var targetFtp = CreateTargetFtp(command, ftp);

                using (var ftpClient = IFtpFactory.Client(targetFtp))
                {
                    var lastRun = await ReadLastRunAsync(ftpClient);

                    var modifiedSince = lastRun?.Dt;

                    var localFiles    = GetFiles(command.Target);
                    var filesToUpload = localFiles;

                    if (modifiedSince.HasValue)
                    {
                        filesToUpload =
                            localFiles
                            .Where(x => AppliesToModified(x, modifiedSince))
                            .ToList();
                    }

                    if (lastRun != null)
                    {
                        var remoteFilesHash =
                            lastRun
                            .Files
                            .ToHashSet();

                        var root = IRootHelper.GetRoot();

                        foreach (var file in localFiles)
                        {
                            var remotePath = root.GetRealtive(file);
                            if (remoteFilesHash.Contains(remotePath))
                            {
                                continue;
                            }

                            if (!filesToUpload.Any(x => x.FullName == file.FullName))
                            {
                                filesToUpload.Add(file);
                            }
                        }
                    }

                    IOutputConsole.WriteLine($"Target [{command.Value}/{targetFtp.Name}]");

                    if (!filesToUpload.HasContent())
                    {
                        PrintNoFiles();
                    }
                    else
                    {
                        IOutputConsole.WriteLine($"found {filesToUpload.Count} files");
                        await UploadFilesAsync(targetFtp, filesToUpload);
                    }

                    if (!command.Target.CleanupDisable)
                    {
                        await CleanupAsync(targetFtp, lastRun, localFiles);
                    }

                    await UploadLastRunAsync(ftpClient, localFiles);

                    PrintFinished();

                    if (command.Target.OK.HasContent())
                    {
                        await IOkProcessor.Process(new OkCommand { Url = command.Target.OK });
                    }
                }
            }
        }