Exemplo n.º 1
0
 public DeployService(ICatalogConfigRepository catalogConfigRepository,
                      ICatalogRepository catalogRepository,
                      IDeployWorkConfigRepository deployWorkConfigRepository,
                      IFtpFactory ftpFactory,
                      ICompressor compressor,
                      ICodeBuilderFactory codeBuilderFactory,
                      IOptions <AppSettings> appSettings)
 {
     _catalogConfigRepository    = catalogConfigRepository;
     _catalogRepository          = catalogRepository;
     _deployWorkConfigRepository = deployWorkConfigRepository;
     _ftpFactory         = ftpFactory;
     _compressor         = compressor;
     _codeBuilderFactory = codeBuilderFactory;
     _appSettings        = appSettings;
 }
Exemplo n.º 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 });
                    }
                }
            }
        }