コード例 #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var stopWatch = new DebugStopwatch();

            stopWatch.Start();

            foreach (var(remotePath, remoteWriteTime) in _ftpService.GetFilesInfo())
            {
                using var scope = _serviceProvider.CreateScope();
                var _repository = scope.ServiceProvider.GetRequiredService <IFileInfoRepository>();
                var fileInfo    = await _repository.GetAsync(remotePath) ?? new FileInfo(remotePath, remoteWriteTime);

                // If status = finished then file has been processed complete already and we
                // do not export it again. Only record when it showed on FTP again, and remove it
                if (fileInfo.Status == FileStatus.Finished)
                {
                    fileInfo.UpdateWriteTime(remoteWriteTime);
                    _ftpService.DeleteFile(fileInfo.Path);
                }

                if (fileInfo.Status == FileStatus.Initial)
                {
                    var fileBytes = await _ftpService.GetFileAsync(fileInfo.Path);

                    if (fileBytes != null)
                    {
                        if (await _exportService.Export(fileBytes))
                        {
                            fileInfo.UpdateStatus();
                        }
                    }
                }

                if (fileInfo.Status == FileStatus.Sent)
                {
                    if (_ftpService.DeleteFile(fileInfo.Path))
                    {
                        fileInfo.UpdateStatus();
                    }
                }

                await _repository.SaveAsync(fileInfo);
            }

            stopWatch.Stop();
            System.Diagnostics.Debug.WriteLine(stopWatch.Elapsed);

            // await Task.CompletedTask;

/*             while (!stoppingToken.IsCancellationRequested)
 *          {
 *              _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
 *              await Task.Delay(1000, stoppingToken);
 *          } */
        }
コード例 #2
0
        /// <summary>
        /// Executes the node.
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        public override bool Execute(IFlowRuntimeService runtime, DataPinScope scope)
        {
            if (ftpServerService == null)
            {
                ftpServerService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFtpServerConfigurationService>();
            }

            var servername = scope.GetValue <string>(InPinServer);
            var server     = ftpServerService.GetByName(servername);

            if (serviceCache.Keys.Contains(server.Type.ToString()))
            {
                ftpService = serviceCache[server.Type.ToString()];
            }
            else
            {
                ftpService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFtpService>(server.Type.ToString());
                serviceCache.Add(server.Type.ToString(), ftpService);
            }
            var filename = scope.GetValue <string>(InPinFileName);
            var path     = scope.GetValue <string>(InPinPath);

            ftpService.DeleteFile(server, path + filename);
            runtime.EnqueueNode(OutNodeSuccess, scope);

            return(true);
        }
コード例 #3
0
ファイル: FtpClient.cs プロジェクト: wexman/Cake.Ftp
 /// <summary>
 /// Deletes a file at the specified URI.
 /// </summary>
 /// <param name="serverUri">FTP File URI.</param>
 /// <param name="settings">The settings.</param>
 public void DeleteFile(Uri serverUri, FtpSettings settings)
 {
     if (serverUri == null)
     {
         throw new ArgumentNullException(nameof(serverUri), "Server URI is null.");
     }
     if (string.IsNullOrWhiteSpace(settings.Username))
     {
         throw new ArgumentNullException(nameof(settings.Username), "Username is null.");
     }
     if (string.IsNullOrWhiteSpace(settings.Password))
     {
         throw new ArgumentNullException(nameof(settings.Password), "Password is null.");
     }
     if (serverUri.Scheme != Uri.UriSchemeFtp)
     {
         throw new ArgumentOutOfRangeException(nameof(serverUri), "Server URI scheme is not FTP.");
     }
     _ftpService.DeleteFile(serverUri, settings.Username, settings.Password);
 }
コード例 #4
0
ファイル: FtpClient.cs プロジェクト: nick-hoang/Cake.Ftp
        /// <summary>
        /// Deletes a file at the specified URI.
        /// </summary>
        /// <param name="serverUri">FTP File URI.</param>
        /// <param name="settings">The settings.</param>
        public void DeleteFile(Uri serverUri, FtpSettings settings)
        {
            CheckParams(serverUri, settings);

            _ftpService.DeleteFile(serverUri, settings.Username, settings.Password);
        }