Пример #1
0
        public async Task ResetState(TargetCommand command)
        {
            foreach (var ftp in command.Target.Ftp)
            {
                var targetFtp = CreateTargetFtp(command, ftp);

                using (var ftpClient = IFtpFactory.Client(targetFtp))
                {
                    await ftpClient.DeleteAsync(_LastRunFileName);

                    IOutputConsole.ClearLine();
                    IOutputConsole.WriteLine($"Reset state [{targetFtp.Name}] OK.");
                    IOutputConsole.WriteLine("");
                }
            }
        }
Пример #2
0
        public async Task ApplyCurrentStateAsync(TargetCommand command)
        {
            var files = GetFiles(command.Target);

            foreach (var ftp in command.Target.Ftp)
            {
                var targetFtp = CreateTargetFtp(command, ftp);

                using (var ftpClient = IFtpFactory.Client(targetFtp))
                {
                    await UploadLastRunAsync(ftpClient, files);

                    IOutputConsole.ClearLine();
                    IOutputConsole.WriteLine($"Apply current state [{targetFtp.Name}] OK.");
                    IOutputConsole.WriteLine("");
                }
            }
        }
Пример #3
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 });
                    }
                }
            }
        }